123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using DevExpress.XtraEditors;
- using ProjectBase.Controls;
- using SIMDP.Model;
- using SIMDP.BLL;
- using ProjectBase.Data.Logs;
- using SIMDP.Util;
- using ProjectBase.Data.BaseDAL;
- using System.Timers;
- namespace SIMDP
- {
- public partial class FormRules : BaseDock
- {
- //BlRule blRule = new BlRule();
- //private System.Timers.Timer timer = null;
- //private int interval = 1000;
- //private int count = 0;
- //private delegate void winFormDelegate();
- ///// <summary>
- ///// 30s刷新一次表格
- ///// </summary>
- //private const int timeSpan = 30;
- public FormRules()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 初始化导航控件
- /// </summary>
- private void InitNavBarControl()
- {
- this.navBarControl1.Items.Clear();
- this.navBarGroup1.ItemLinks.Clear();
- List<MoRule> moRules = BLLFactory<BlRule>.Instance.GetAll();
- foreach (MoRule item in moRules)
- {
- DevExpress.XtraNavBar.NavBarItem navBarItem = new DevExpress.XtraNavBar.NavBarItem();
- navBarItem.Caption = item.RuleName;
- navBarItem.Name = item.RuleId.ToString();
- navBarItem.SmallImage = global::SIMDP.Properties.Resources.BOReport_16x16;
- navBarItem.LinkClicked += new DevExpress.XtraNavBar.NavBarLinkEventHandler(NavBarItem_Click);
- this.navBarControl1.Items.AddRange(new DevExpress.XtraNavBar.NavBarItem[] { navBarItem });
- this.navBarGroup1.ItemLinks.AddRange(new DevExpress.XtraNavBar.NavBarItemLink[] { new DevExpress.XtraNavBar.NavBarItemLink(navBarItem) });
- }
- if (this.navBarGroup1.ItemLinks.Count > 0)
- {
- this.navBarControl1.SelectedLink = this.navBarGroup1.ItemLinks[0];
- }
- InitControl();
- }
- /// <summary>
- /// 初始化界面右侧控件
- /// </summary>
- private void InitControl()
- {
- if (this.navBarGroup1.ItemLinks.Count > 0)
- {
- string id = this.navBarControl1.SelectedLink.ItemName.ToString();
- MoRule rule = BLLFactory<BlRule>.Instance.FindByID(id);
- #region 刷新控件
- this.label_Rules.Text = rule.RuleName + "列表:";
- this.label_Rules.Visible = true;
- this.gridControl_Rules.Visible = true;
- #endregion
- this.gridControl_Rules.DataSource = BLLFactory<BlRule>.Instance.AnalyzeRuleValue(rule);
- this.gridControl_Rules.RefreshDataSource();
- }
- }
- private void NavBarItem_Click(object sender, DevExpress.XtraNavBar.NavBarLinkEventArgs e)
- {
- string id = e.Link.ItemName;
- MoRule rule = BLLFactory<BlRule>.Instance.FindByID(id);
- this.label_Rules.Text = rule.RuleName + "列表:";
- this.gridControl_Rules.DataSource = BLLFactory<BlRule>.Instance.AnalyzeRuleValue(rule);
- this.gridControl_Rules.RefreshDataSource();
- }
- //private void btn_Edit_Click(object sender, EventArgs e)
- //{
- // DataTable dt = this.gridControl_Rules.DataSource as DataTable;
- // DataRowView selectRow = this.gridView_Rules.GetFocusedRow() as DataRowView;
- // DataRow row = selectRow.Row;
- // FormEditRuleValue editRules = new FormEditRuleValue(dt, row, "Edit");
- // editRules.ShowDialog();
- //}
- //private void btn_Delete_Click(object sender, EventArgs e)
- //{
- // try
- // {
- // DataRowView selectRow = this.gridView_Rules.GetFocusedRow() as DataRowView;
- // DataRow row = selectRow.Row;
- // if (DevExpress.XtraEditors.XtraMessageBox.Show("您确定删除选定的记录么?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
- // {
- // return;
- // }
- // DataTable dt = this.gridControl_Rules.DataSource as DataTable;
- // dt.Rows.Remove(row);
- // if (dt.Rows.Count == 1)
- // {
- // DevExpress.XtraEditors.XtraMessageBox.Show("只有一条信息,无法删除。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- // }
- // string ruleValue = BLLFactory<BlRule>.Instance.FormRuleValue(dt);
- // MoRule rule = BLLFactory<BlRule>.Instance.FindByID(dt.Rows[0]["RuleId"]);
- // rule.RuleValue = ruleValue;
- // bool flag = BLLFactory<BlRule>.Instance.Update(rule, dt.Rows[0]["RuleId"]);
- // if (flag)
- // {
- // DevExpress.XtraEditors.XtraMessageBox.Show("删除成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // }
- // else
- // {
- // DevExpress.XtraEditors.XtraMessageBox.Show("删除失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // }
- // }
- // catch (Exception ex)
- // {
- // DevExpress.XtraEditors.XtraMessageBox.Show("删除失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // LogHelper.log.Error(string.Format("修改数据库rules出现错误:{0}", ex));
- // }
- //}
- //private void btn_Add_Click(object sender, EventArgs e)
- //{
- // DataTable dt = this.gridControl_Rules.DataSource as DataTable;
- // //BlDataPoint bl = new BlDataPoint();
- // DataTable dtRule = BLLFactory<BlDataPoint>.Instance.GetVar();
- // if (dt.Rows.Count == dtRule.Rows.Count)
- // {
- // DevExpress.XtraEditors.XtraMessageBox.Show("变量都已存在,无法添加。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- // return;
- // }
- // FormEditRuleValue editRules = new FormEditRuleValue(dt,null, "Add");
- // editRules.ShowDialog();
- //}
- private void menu_Refresh_Click(object sender, EventArgs e)
- {
- InitNavBarControl();
- }
- private void menu_Delete_Click(object sender, EventArgs e)
- {
- try
- {
- if (this.navBarGroup1.ItemLinks.Count <= 0)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("没有可删除的项。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- return;
- }
- if (DevExpress.XtraEditors.XtraMessageBox.Show("您确定删除选定的项么?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
- {
- return;
- }
- string id = this.navBarControl1.SelectedLink.ItemName.ToString();
- bool flag = BLLFactory<BlRule>.Instance.Delete(id, SysEnvironment.CurrentLoginID);
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("删除成功。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- InitNavBarControl();
- }
- else
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("删除失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- }
- catch (Exception ex)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("删除失败。", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("删除数据库rules出现错误:{0}", ex));
- }
- }
- private void menu_Add_Click(object sender, EventArgs e)
- {
- FormEditRule editRule = new FormEditRule();
- editRule.saveData += new FormEditRule.save(InitNavBarControl);
- editRule.ShowDialog();
- }
- /// <summary>
- /// 点击导航栏item,图标变大
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void navBarControl1_CustomDrawLink(object sender, DevExpress.XtraNavBar.ViewInfo.CustomDrawNavBarElementEventArgs e)
- {
- DevExpress.XtraNavBar.ViewInfo.NavLinkInfoArgs info = e.ObjectInfo as DevExpress.XtraNavBar.ViewInfo.NavLinkInfoArgs;
- if (info.State == DevExpress.Utils.Drawing.ObjectState.Selected | info.State == DevExpress.Utils.Drawing.ObjectState.Pressed)
- {
- //e.Graphics.FillRectangle(Brushes.Red, e.ObjectInfo.Bounds); item背景颜色
- e.Graphics.DrawImage(e.Image,info.ImageRectangle);
- e.Appearance.DrawString(e.Cache, info.Link.Caption, info.CaptionRectangle);
- //e.Appearance.DrawVString(e.Cache,info.Link.Caption,new Font("宋体",16),Brushes.Black,e.ObjectInfo.Bounds,StringFormat.GenericDefault,0);
- e.Handled = true;
- }
- }
- private void gridView_Rules_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
- {
- if (e.Column.FieldName == "Type")
- {
- e.DisplayText = SysEnvironment.dirType.FirstOrDefault(p => p.Key == Convert.ToInt32(e.Value)).Value;
- }
- }
- private void menu_Edit_Click(object sender, EventArgs e)
- {
- string id = this.navBarControl1.SelectedLink.ItemName.ToString();
- MoRule rule = BLLFactory<BlRule>.Instance.FindByID(id);
- FormEditRule editRule = new FormEditRule();
- editRule.rule = rule;
- editRule.saveData += new FormEditRule.save(InitNavBarControl);
- editRule.ShowDialog();
- }
- private void FormRules_Load(object sender, EventArgs e)
- {
- // this.splitContainerControl1.SplitterPosition =100;
- InitNavBarControl();
- //timer = new System.Timers.Timer(interval);
- //timer.Elapsed += Refresh_Elapsed;
- //timer.Start();
- }
- /// <summary>
- /// 定时刷新
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- //private void Refresh_Elapsed(object sender, ElapsedEventArgs e)
- //{
- // count++;
- // if (this.chk_Refresh.Checked != true)
- // {
- // return;
- // }
- // if (count % timeSpan == 0)
- // {
- // if (this.InvokeRequired)
- // {
- // winFormDelegate mes = new winFormDelegate(InitControl);
- // this.Invoke(mes, null);
- // }
- // else
- // {
- // InitControl();
- // }
- // count = 0;
- // }
- //}
- }
- }
|