FormLogOperation.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using DevExpress.XtraEditors;
  11. using ProjectBase.Controls;
  12. using SIMDP.BLL;
  13. using SIMDP.Model;
  14. using ProjectBase.Data.BaseDAL;
  15. namespace SIMDP.View
  16. {
  17. public partial class FormLogOperation : DevExpress.XtraEditors.XtraForm
  18. {
  19. BlAuthoryGroup blGroup = new BlAuthoryGroup();
  20. BlLogOperation blOperation = new BlLogOperation();
  21. string condition = null;
  22. public FormLogOperation()
  23. {
  24. InitializeComponent();
  25. }
  26. private void FormLogOperation_Load(object sender, EventArgs e)
  27. {
  28. InitControl();
  29. InitGrid();
  30. InitTree();
  31. }
  32. /// <summary>
  33. /// 初始化控件
  34. /// </summary>
  35. private void InitControl()
  36. {
  37. List<string> tableList = BLLFactory<BlLogOperationSetting>.Instance.GetTableNames();
  38. tableList.Insert(0, "全部表");
  39. this.lookUp_TableName.Properties.DataSource = tableList;
  40. this.lookUp_TableName.Properties.NullText = null;
  41. this.lookUp_TableName.EditValue = tableList[0];
  42. List<string> list = new List<string>() { "全部", "增加", "修改", "删除" };
  43. this.lookUp_Type.Properties.DataSource = list;
  44. this.lookUp_Type.Properties.NullText = null;
  45. this.lookUp_Type.EditValue = list[0];
  46. }
  47. /// <summary>
  48. /// 初始化树
  49. /// </summary>
  50. private void InitTree()
  51. {
  52. this.tree_Operation.BeginUpdate();
  53. this.tree_Operation.Nodes.Clear();
  54. List<MoAuthoryGroup> list = BLLFactory<BlAuthoryGroup>.Instance.GetAll();
  55. List<MoAuthoryGroup> rootList = new List<MoAuthoryGroup>();
  56. foreach (MoAuthoryGroup item in list)
  57. {
  58. if (item.ParentGroupId == "")
  59. {
  60. rootList.Add(item);
  61. }
  62. }
  63. foreach (MoAuthoryGroup root in rootList)
  64. {
  65. if (root != null)
  66. {
  67. TreeNode rootNode = new TreeNode(); //根节点
  68. rootNode.Text = root.GroupName;
  69. rootNode.Name = root.GroupId;
  70. rootNode.ImageIndex = 0;
  71. rootNode.SelectedImageIndex = 0;
  72. rootNode.Tag = string.Format(" operation_groupId = '{0}'", root.GroupId);
  73. this.tree_Operation.Nodes.Add(rootNode);
  74. List<MoAuthoryGroup> subList = BLLFactory<BlAuthoryGroup>.Instance.Find(string.Format(" parent_group_id = '{0}'", root.GroupId));
  75. AddNode(subList, rootNode);
  76. }
  77. }
  78. TreeNode tableNode = new TreeNode("数据库表", 5, 5);
  79. this.tree_Operation.Nodes.Add(tableNode);
  80. List<string> tableList = BLLFactory<BlLogOperation>.Instance.GetFieldList("operation_tableName");
  81. foreach (string tablename in tableList)
  82. {
  83. TreeNode subNode = new TreeNode(tablename);
  84. subNode.ImageIndex = 6;
  85. subNode.SelectedImageIndex = 6;
  86. subNode.Tag = string.Format(" operation_tableName = '{0}'", tablename);
  87. tableNode.Nodes.Add(subNode);
  88. List<string> operationList = new List<string>() { "增加", "修改", "删除" };
  89. foreach (string operationType in operationList)
  90. {
  91. TreeNode operationNode = new TreeNode(operationType);
  92. if (operationType == "增加")
  93. {
  94. operationNode.ImageIndex = 7;
  95. operationNode.SelectedImageIndex = 7;
  96. }
  97. else if (operationType == "修改")
  98. {
  99. operationNode.ImageIndex = 8;
  100. operationNode.SelectedImageIndex = 8;
  101. }
  102. else if (operationType == "删除")
  103. {
  104. operationNode.ImageIndex = 9;
  105. operationNode.SelectedImageIndex = 9;
  106. }
  107. operationNode.Tag = string.Format(" operation_tableName = '{0}' AND operation_type = '{1}'",tablename, operationType);
  108. subNode.Nodes.Add(operationNode);
  109. }
  110. }
  111. this.tree_Operation.ExpandAll();
  112. this.tree_Operation.EndUpdate();
  113. this.tree_Operation.SelectedNode = null;
  114. this.tree_Operation.TabStop = false;
  115. }
  116. /// <summary>
  117. /// 添加树节点
  118. /// </summary>
  119. /// <param name="list"></param>
  120. /// <param name="parentNode"></param>
  121. private void AddNode(List<MoAuthoryGroup> list, TreeNode parentNode)
  122. {
  123. if (list == null)
  124. {
  125. return;
  126. }
  127. foreach (MoAuthoryGroup item in list)
  128. {
  129. TreeNode node = new TreeNode(); //根节点
  130. node.Text = item.GroupName;
  131. node.Name = item.GroupId;
  132. string index = item.GroupId.Substring(0, 1);
  133. node.ImageIndex = Convert.ToInt32(index) - 1;
  134. node.SelectedImageIndex = Convert.ToInt32(index) - 1;
  135. node.Tag = string.Format(" operation_groupId = '{0}'", item.GroupId);
  136. parentNode.Nodes.Add(node);
  137. List<MoAuthoryGroup> subList = BLLFactory<BlAuthoryGroup>.Instance.Find(string.Format(" parent_group_id = '{0}'", item.GroupId));
  138. AddNode(subList, node);
  139. }
  140. }
  141. /// <summary>
  142. /// 选中节点后显示
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void tree_Operation_AfterSelect(object sender, TreeViewEventArgs e)
  147. {
  148. if (e.Node != null && e.Node.Tag != null)
  149. {
  150. condition = e.Node.Tag.ToString();
  151. BindData(condition);
  152. }
  153. else
  154. {
  155. condition = " 1=1";
  156. BindData(condition);
  157. }
  158. }
  159. /// <summary>
  160. /// 初始化表格控件
  161. /// </summary>
  162. private void InitGrid()
  163. {
  164. //entity
  165. this.winGridViewPager1.OnPageChanged += new EventHandler(winGridViewPager1_OnPageChanged);
  166. this.winGridViewPager1.OnStartExport += new EventHandler(winGridViewPager1_OnStartExport);
  167. this.winGridViewPager1.OnRefresh += new EventHandler(winGridViewPager1_OnRefresh);
  168. this.winGridViewPager1.gridView1.CustomColumnDisplayText += new DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventHandler(gridView1_CustomColumnDisplayText);
  169. this.winGridViewPager1.ShowLineNumber = true;
  170. this.winGridViewPager1.BestFitColumnWith = true;
  171. this.winGridViewPager1.DisplayColumns = "Account,Name,GroupId,TableName,Type,Ip,Mac,Time";
  172. #region 添加别名解析
  173. this.winGridViewPager1.AddColumnAlias("ID", "");
  174. this.winGridViewPager1.AddColumnAlias("Account", "登录用户账号");
  175. this.winGridViewPager1.AddColumnAlias("Name", "登录用户名称");
  176. this.winGridViewPager1.AddColumnAlias("GroupId", "所属公司");
  177. this.winGridViewPager1.AddColumnAlias("TableName", "操作表名称");
  178. this.winGridViewPager1.AddColumnAlias("Type", "操作类型");
  179. this.winGridViewPager1.AddColumnAlias("Ip", "IP地址");
  180. this.winGridViewPager1.AddColumnAlias("Mac", "Mac地址");
  181. this.winGridViewPager1.AddColumnAlias("Time", "日志更新时间");
  182. #endregion
  183. this.winGridViewPager1.PrintTitle = "用户操作日志表";
  184. this.winGridViewPager1.gridView1.Appearance.HeaderPanel.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
  185. condition = " 1=1";
  186. BindData(condition);
  187. }
  188. /// <summary>
  189. /// 绑定数据源
  190. /// </summary>
  191. /// <param name="condition"></param>
  192. private void BindData(string condition)
  193. {
  194. this.winGridViewPager1.DataSource = blOperation.FindWithPager(condition, this.winGridViewPager1.PagerInfo);
  195. for (int i = 0; i < this.winGridViewPager1.gridView1.Columns.Count; i++) //设置每列内容居中显示
  196. {
  197. this.winGridViewPager1.gridView1.Columns[i].AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
  198. }
  199. }
  200. /// <summary>
  201. /// 分页控件翻页的操作
  202. /// </summary>
  203. private void winGridViewPager1_OnPageChanged(object sender, EventArgs e)
  204. {
  205. BindData(condition);
  206. }
  207. /// <summary>
  208. /// 分页控件全部导出操作前的操作
  209. /// </summary>
  210. private void winGridViewPager1_OnStartExport(object sender, EventArgs e)
  211. {
  212. this.winGridViewPager1.AllToExport = blOperation.Find(condition);
  213. }
  214. /// <summary>
  215. /// 分页控件刷新操作
  216. /// </summary>
  217. private void winGridViewPager1_OnRefresh(object sender, EventArgs e)
  218. {
  219. BindData(condition);
  220. }
  221. void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
  222. {
  223. if (e.Column.ColumnType == typeof(DateTime))
  224. {
  225. string columnName = e.Column.FieldName;
  226. if (e.Value != null)
  227. {
  228. if (Convert.ToDateTime(e.Value) <= Convert.ToDateTime("1900-1-1"))
  229. {
  230. e.DisplayText = "";
  231. }
  232. else
  233. {
  234. e.DisplayText = Convert.ToDateTime(e.Value).ToString("yyyy-MM-dd HH:mm");//yyyy-MM-dd
  235. }
  236. }
  237. }
  238. Dictionary<string, string> dic = blOperation.GetGroupName();
  239. if (e.Column.FieldName == "GroupId")
  240. {
  241. e.DisplayText = dic.FirstOrDefault(p => p.Key == e.Value.ToString().Trim()).Value;
  242. }
  243. }
  244. private void btn_Query_Click(object sender, EventArgs e)
  245. {
  246. if (string.IsNullOrEmpty(txt_Account.Text) && lookUp_TableName.Text == "全部表" && lookUp_Type.Text == "全部" && string.IsNullOrEmpty(date_Start.Text) && string.IsNullOrEmpty(date_End.Text))
  247. {
  248. BindData(" 1=1");
  249. condition = " 1=1";
  250. return;
  251. }
  252. string sql = " 1=1";
  253. if (!string.IsNullOrEmpty(txt_Account.Text))
  254. {
  255. sql += string.Format(" AND operation_account = '{0}'",txt_Account.Text);
  256. }
  257. if (lookUp_TableName.Text != "全部表")
  258. {
  259. sql += string.Format(" AND operation_tableName = '{0}'", lookUp_TableName.Text);
  260. }
  261. if (lookUp_Type.Text != "全部")
  262. {
  263. sql += string.Format(" AND operation_type = '{0}'", lookUp_Type.Text);
  264. }
  265. if (!string.IsNullOrEmpty(date_Start.Text))
  266. {
  267. sql += string.Format(" AND operation_time >= '{0}'", date_Start.DateTime.ToString("yyyy-MM-dd"));
  268. }
  269. if (!string.IsNullOrEmpty(date_End.Text))
  270. {
  271. sql += string.Format(" AND operation_time < '{0}'", date_End.DateTime.AddDays(1).ToString("yyyy-MM-dd"));
  272. }
  273. BindData(sql);
  274. condition = sql;
  275. }
  276. private void menu_Expand_Click(object sender, EventArgs e)
  277. {
  278. this.tree_Operation.ExpandAll();
  279. }
  280. private void menu_Collapse_Click(object sender, EventArgs e)
  281. {
  282. this.tree_Operation.CollapseAll();
  283. }
  284. private void menu_Refresh_Click(object sender, EventArgs e)
  285. {
  286. InitTree();
  287. }
  288. }
  289. }