123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Windows.Forms;
- using ProjectBase.Data.Logs;
- using ProjectBase.Data.BaseDAL;
- using SIMDP.BLL;
- using SIMDP.Model;
- using ProjectBase.Util;
- namespace SIMDP.View
- {
- public partial class FormBlack : DevExpress.XtraEditors.XtraForm
- {
- string condition = null;
- /// <summary>
- /// 授权类型的字典表
- /// </summary>
- private Dictionary<string, string> Dic_Type
- {
- get
- {
- Dictionary<string, string> type = new Dictionary<string, string>();
- type.Add("-1", "全部");
- type.Add("1", "白名单");
- type.Add("0", "黑名单");
- return type;
- }
- }
- public FormBlack()
- {
- InitializeComponent();
- }
- private void FormBlack_Load(object sender, EventArgs e)
- {
- InitControl();
- InitGrid();
- }
- /// <summary>
- /// 初始化控件
- /// </summary>
- private void InitControl()
- {
- //下拉框--类型
- this.lookUp_Type.Properties.DataSource = Dic_Type;
- this.lookUp_Type.Properties.ValueMember = "Key";
- this.lookUp_Type.Properties.DisplayMember = "Value";
- this.lookUp_Type.Properties.NullText = null;
- this.lookUp_Type.EditValue = "-1";
- //下拉框--所属用户
- List<MoAuthoryUser> userList = BLLFactory<BlAuthoryUser>.Instance.GetAll();
- Dictionary<string, string> dic = new Dictionary<string, string>();
- dic.Add("-1","全部用户");
- foreach (MoAuthoryUser item in userList)
- {
- dic.Add(item.LoginAccount,item.UserName);
- }
- this.lookUp_UserName.Properties.DataSource = dic;
- this.lookUp_UserName.Properties.ValueMember = "Key";
- this.lookUp_UserName.Properties.DisplayMember = "Value";
- this.lookUp_UserName.Properties.NullText = null;
- this.lookUp_UserName.EditValue = "-1";
- }
- /// <summary>
- /// 初始化表格控件
- /// </summary>
- private void InitGrid()
- {
- //entity
- this.winGridViewPager1.OnPageChanged += new EventHandler(winGridViewPager1_OnPageChanged);
- this.winGridViewPager1.OnStartExport += new EventHandler(winGridViewPager1_OnStartExport);
- this.winGridViewPager1.OnRefresh += new EventHandler(winGridViewPager1_OnRefresh);
- this.winGridViewPager1.OnEditSelected += new EventHandler(winGridViewPager1_OnEditSelected);
- this.winGridViewPager1.OnAddNew += new EventHandler(winGridViewPager1_OnAddNew);
- this.winGridViewPager1.OnDeleteSelected += new EventHandler(winGridViewPager1_OnDeleteSelected);
- this.winGridViewPager1.gridView1.CustomColumnDisplayText += new DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventHandler(gridView1_CustomColumnDisplayText);
- this.winGridViewPager1.gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);
- this.winGridViewPager1.ShowLineNumber = true;
- this.winGridViewPager1.BestFitColumnWith = true;
- this.winGridViewPager1.DisplayColumns = "Name,UserName,Type,Forbid,IPStart,IPEnd,Note,CreatorName,CreateTime,EditorName,EditTime";
- #region 添加别名解析
- this.winGridViewPager1.AddColumnAlias("ID", "");
- this.winGridViewPager1.AddColumnAlias("Name", "显示名称");
- this.winGridViewPager1.AddColumnAlias("UserAccount", "");
- this.winGridViewPager1.AddColumnAlias("UserName", "所属用户");
- this.winGridViewPager1.AddColumnAlias("Type", "授权类型");
- this.winGridViewPager1.AddColumnAlias("Forbid", "是否禁用");
- this.winGridViewPager1.AddColumnAlias("IPStart", "IP起始地址");
- this.winGridViewPager1.AddColumnAlias("IPEnd", "IP结束地址");
- this.winGridViewPager1.AddColumnAlias("Note", "备注");
- this.winGridViewPager1.AddColumnAlias("CreatorAccount", "");
- this.winGridViewPager1.AddColumnAlias("CreatorName", "创建人名称");
- this.winGridViewPager1.AddColumnAlias("CreateTime", "创建时间");
- this.winGridViewPager1.AddColumnAlias("EditorAccount", "");
- this.winGridViewPager1.AddColumnAlias("EditorName", "编辑人名称");
- this.winGridViewPager1.AddColumnAlias("EditTime", "编辑时间");
- #endregion
- this.winGridViewPager1.PrintTitle = "系统黑白名单表";
- this.winGridViewPager1.gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
- BindData(" 1=1");
- condition = " 1=1";
- }
- /// <summary>
- /// 绑定数据源
- /// </summary>
- /// <param name="condition"></param>
- private void BindData(string condition)
- {
- this.winGridViewPager1.DataSource = BLLFactory<BlWhite>.Instance.FindWithPager(condition, this.winGridViewPager1.PagerInfo);
- for (int i = 0; i < this.winGridViewPager1.gridView1.Columns.Count; i++) //设置每列内容居中显示
- {
- this.winGridViewPager1.gridView1.Columns[i].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
- }
- }
- /// <summary>
- /// 分页控件翻页的操作
- /// </summary>
- private void winGridViewPager1_OnPageChanged(object sender, EventArgs e)
- {
- BindData(condition);
- }
- /// <summary>
- /// 分页控件全部导出操作前的操作
- /// </summary>
- private void winGridViewPager1_OnStartExport(object sender, EventArgs e)
- {
- this.winGridViewPager1.AllToExport = BLLFactory<BlWhite>.Instance.Find(condition);
- }
- /// <summary>
- /// 分页控件刷新操作
- /// </summary>
- private void winGridViewPager1_OnRefresh(object sender, EventArgs e)
- {
- BindData(condition);
- }
- /// <summary>
- /// 分页控件编辑项操作
- /// </summary>
- private void winGridViewPager1_OnEditSelected(object sender, EventArgs e)
- {
- MoWhite selectRow = this.winGridViewPager1.gridView1.GetFocusedRow() as MoWhite;
- FormEditBlack editBlack = new FormEditBlack();
- editBlack.white = selectRow;
- editBlack.ShowDialog();
- if (editBlack.DialogResult == DialogResult.OK)
- {
- BindData(condition);
- }
- }
- /// <summary>
- /// 分页控件新增操作
- /// </summary>
- private void winGridViewPager1_OnAddNew(object sender, EventArgs e)
- {
- FormEditBlack editBlack = new FormEditBlack();
- editBlack.ShowDialog();
- if (editBlack.DialogResult == DialogResult.OK)
- {
- BindData(condition);
- }
- }
- /// <summary>
- /// 分页控件删除操作
- /// </summary>
- private void winGridViewPager1_OnDeleteSelected(object sender, EventArgs e)
- {
- try
- {
- if (DevExpress.XtraEditors.XtraMessageBox.Show("您确定删除选定的记录么?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
- {
- return;
- }
- MoWhite selectRow = this.winGridViewPager1.gridView1.GetFocusedRow() as MoWhite;
- int id = Convert.ToInt32(selectRow.ID);
- bool flag = BLLFactory<BlWhite>.Instance.Delete(id, SysEnvironment.CurrentLoginID);
- if (flag)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("删除成功。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- BindData(condition);
- }
- }
- catch (Exception ex)
- {
- DevExpress.XtraEditors.XtraMessageBox.Show("删除失败。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
- LogHelper.log.Error(string.Format("删除数据库black出现错误:{0}", ex));
- }
- }
- void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
- {
- if (e.Column.ColumnType == typeof(DateTime))
- {
- string columnName = e.Column.FieldName;
- if (e.Value != null)
- {
- if (Convert.ToDateTime(e.Value) <= Convert.ToDateTime("1900-1-1"))
- {
- e.DisplayText = "";
- }
- else
- {
- e.DisplayText = Convert.ToDateTime(e.Value).ToString("yyyy-MM-dd HH:mm");//yyyy-MM-dd
- }
- }
- }
- if (e.Column.FieldName == "Type")
- {
- e.DisplayText = Dic_Type[(e.Value).ToString()];
- }
- }
- void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
- {
- //AuthorizeType,Forbid
- if (e.Column.FieldName == "Type")
- {
- Color color = Color.White;
- if (e.CellValue.ToString() == "0")
- {
- e.Appearance.BackColor = Color.Black;
- e.Appearance.BackColor2 = Color.LightCyan;
- }
- else
- {
- e.Appearance.BackColor = Color.White;
- }
- }
- if (e.Column.FieldName == "Forbid")
- {
- Color color = Color.White;
- if (e.CellValue.ToString().ToBoolean())
- {
- e.Appearance.BackColor = Color.Red;
- e.Appearance.BackColor2 = Color.LightCyan;
- }
- }
- }
- private void btn_Query_Click(object sender, EventArgs e)
- {
- if ( string.IsNullOrEmpty(txt_Name.Text) && lookUp_UserName.Text == "全部用户" && lookUp_Type.Text == "全部" && check_Forbid.CheckState != CheckState.Checked)
- {
- BindData(" 1=1");
- condition = " 1=1";
- return;
- }
- string sql = " 1=1";
- if (!string.IsNullOrEmpty(txt_Name.Text))
- {
- sql += string.Format(" AND black_name = '{0}'", txt_Name.Text);
- }
- if (lookUp_UserName.Text != "全部用户")
- {
- sql += string.Format(" AND black_UserAccount = {0}", lookUp_UserName.EditValue.ToString());
- }
- if (lookUp_Type.Text != "全部")
- {
- sql += string.Format(" AND black_type = {0}", lookUp_Type.EditValue.ToString());
- }
- if (check_Forbid.CheckState == CheckState.Checked)
- {
- sql += string.Format(" AND black_forbid = {0}", 1);
- }
- BindData(sql);
- condition = sql;
- }
- private void simpleButton2_Click(object sender, EventArgs e)
- {
- winGridViewPager1_OnAddNew(sender, e);
- }
- }
- }
|