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.Data.Logs; using ProjectBase.Util; using SIMDP.Model; using SIMDP.BLL; using ProjectBase.Data.BaseDAL; namespace SIMDP.View { public partial class FormLogLogIn : DevExpress.XtraEditors.XtraForm { //BlAuthoryGroup blGroup = new BlAuthoryGroup(); //BlLogLogIn blLogIn = new BlLogLogIn(); string condition = null; public FormLogLogIn() { InitializeComponent(); } private void FormLogLogIn_Load(object sender, EventArgs e) { InitTree(); InitGrid(); } /// /// 初始化树 /// private void InitTree() { this.tree_LogIn.BeginUpdate(); this.tree_LogIn.Nodes.Clear(); List list = BLLFactory.Instance.GetAll(); List rootList = new List(); foreach (MoAuthoryGroup item in list) { if (item.ParentGroupId == "") { rootList.Add(item); } } foreach (MoAuthoryGroup root in rootList) { if (root != null) { TreeNode rootNode = new TreeNode(); //根节点 rootNode.Text = root.GroupName; rootNode.Name = root.GroupId; rootNode.Tag = string.Format(" logIn_groupId = '{0}'", root.GroupId); rootNode.ImageIndex = 0; rootNode.SelectedImageIndex = 0; this.tree_LogIn.Nodes.Add(rootNode); List subList = BLLFactory.Instance.Find(string.Format(" parent_group_id = '{0}'", root.GroupId)); AddNode(subList, rootNode); } } this.tree_LogIn.ExpandAll(); this.tree_LogIn.EndUpdate(); this.tree_LogIn.SelectedNode = null; this.tree_LogIn.TabStop = false; //移除焦点 } /// /// 添加树节点 /// /// /// private void AddNode(List list, TreeNode parentNode) { if (list == null) { return; } foreach (MoAuthoryGroup item in list) { TreeNode node = new TreeNode(); //根节点 node.Text = item.GroupName; node.Name = item.GroupId; node.Tag = string.Format(" logIn_groupId = '{0}'", item.GroupId); string index = item.GroupId.Substring(0, 1); node.ImageIndex = Convert.ToInt32(index) - 1; node.SelectedImageIndex = Convert.ToInt32(index) - 1; parentNode.Nodes.Add(node); List subList = BLLFactory.Instance.Find(string.Format(" parent_group_id = '{0}'", item.GroupId)); AddNode(subList, node); } } /// /// 选中节点后显示 /// /// /// private void tree_LogIn_AfterSelect(object sender, TreeViewEventArgs e) { if (e.Node != null && e.Node.Tag != null) { condition = e.Node.Tag.ToString(); BindData(condition); } else { condition = " 1=1"; BindData(condition); } } /// /// 初始化表格控件 /// 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.gridView1.CustomColumnDisplayText += new DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventHandler(gridView1_CustomColumnDisplayText); this.winGridViewPager1.ShowLineNumber = true; this.winGridViewPager1.BestFitColumnWith = true; this.winGridViewPager1.DisplayColumns = "Account,Name,GroupId,Description,Ip,Mac,Time"; #region 添加别名解析 this.winGridViewPager1.AddColumnAlias("ID", ""); this.winGridViewPager1.AddColumnAlias("Account", "登录用户账号"); this.winGridViewPager1.AddColumnAlias("Name", "登录用户名称"); this.winGridViewPager1.AddColumnAlias("GroupId", "所属公司"); this.winGridViewPager1.AddColumnAlias("Description", "日志描述"); this.winGridViewPager1.AddColumnAlias("Ip", "IP地址"); this.winGridViewPager1.AddColumnAlias("Mac", "Mac地址"); this.winGridViewPager1.AddColumnAlias("Time", "日志更新时间"); #endregion this.winGridViewPager1.PrintTitle = "用户登录日志表"; this.winGridViewPager1.gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center; condition = " 1=1"; BindData(condition); } /// /// 绑定数据源 /// /// private void BindData(string condition) { this.winGridViewPager1.DataSource = BLLFactory.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; } } /// /// 分页控件翻页的操作 /// private void winGridViewPager1_OnPageChanged(object sender, EventArgs e) { BindData(condition); } /// /// 分页控件全部导出操作前的操作 /// private void winGridViewPager1_OnStartExport(object sender, EventArgs e) { this.winGridViewPager1.AllToExport = BLLFactory.Instance.Find(condition); } /// /// 分页控件刷新操作 /// private void winGridViewPager1_OnRefresh(object sender, EventArgs e) { BindData(condition); } 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 } } } Dictionary dic = BLLFactory.Instance.GetGroupName(); if (e.Column.FieldName == "GroupId") { e.DisplayText = dic.FirstOrDefault(p => p.Key == e.Value.ToString().Trim()).Value; } } private void menu_Expand_Click(object sender, EventArgs e) { this.tree_LogIn.ExpandAll(); } private void menu_Collapse_Click(object sender, EventArgs e) { this.tree_LogIn.CollapseAll(); } private void menu_Refresh_Click(object sender, EventArgs e) { InitTree(); } private void btn_Query_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_Account.Text) && string.IsNullOrEmpty(txt_UserName.Text) && string.IsNullOrEmpty(txt_IP.Text) && string.IsNullOrEmpty(txt_Mac.Text) && string.IsNullOrEmpty(txt_Des.Text) && string.IsNullOrEmpty(date_Start.Text) && string.IsNullOrEmpty(date_End.Text)) { BindData(" 1=1"); condition = " 1=1"; return; } string sql = " 1=1"; if (!string.IsNullOrEmpty(txt_Account.Text)) { sql += string.Format(" AND logIn_account = '{0}'",txt_Account.Text); } if (!string.IsNullOrEmpty(txt_UserName.Text)) { sql += string.Format(" AND logIn_name = '{0}'",txt_UserName.Text); } if (!string.IsNullOrEmpty(txt_IP.Text)) { sql += string.Format(" AND logIn_ip = '{0}'",txt_IP.Text); } if (!string.IsNullOrEmpty(txt_Mac.Text)) { sql += string.Format(" AND logIn_mac = '{0}'",txt_Mac.Text); } if (!string.IsNullOrEmpty(date_Start.Text)) { sql += string.Format(" AND logIn_time >= '{0}'", date_Start.DateTime.ToString("yyyy-MM-dd")); } if (!string.IsNullOrEmpty(date_End.Text)) { sql += string.Format(" AND logIn_time < '{0}'", date_End.DateTime.AddDays(1).ToString("yyyy-MM-dd")); } BindData(sql); condition = sql; } } }