PageRenderTime 25ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/CKNetFrameWork/数据管理/Frm_OperLog.cs

http://TrainingFrameWork.codeplex.com
C# | 280 lines | 214 code | 46 blank | 20 comment | 13 complexity | b0801b80e4bbaff058cf58c76176949a MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using WeifenLuo.WinFormsUI.Docking;
  10. using Infragistics.Win.UltraWinGrid;
  11. using WHC.OrderWater.Commons;
  12. using WHC.Pager.Entity;
  13. using Microsoft.Practices.EnterpriseLibrary.Data;
  14. using System.Data.Common;
  15. using Maticsoft.DBUtility;
  16. namespace CKNetFrameWork
  17. {
  18. public partial class Frm_OperLog : DockContent
  19. {
  20. private TrainingDB.BLL.CK_OperLogTab m_bllCK_OperLogTab = new TrainingDB.BLL.CK_OperLogTab();
  21. private int m_nDelIndex = -1;
  22. private bool m_bInsertFlag = false;
  23. private Dictionary<string, string> m_dicColName2AliasName = new Dictionary<string, string>();
  24. private Dictionary<string, string> m_dicColAliasName2Name = new Dictionary<string, string>();
  25. private string m_filter = "";
  26. public Frm_OperLog()
  27. {
  28. InitializeComponent();
  29. }
  30. private void ShowAllRecordInDataGridView(string strWhere)
  31. {
  32. BindData(strWhere);
  33. }
  34. private void buttonShowAll_Click(object sender, EventArgs e)
  35. {
  36. m_filter = "";
  37. ShowAllRecordInDataGridView(m_filter);
  38. }
  39. private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  40. {
  41. ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
  42. }
  43. private void SearchResult()
  44. {
  45. this.pager1.CurrentPageIndex = 1;
  46. m_filter = "";
  47. int nIndex = this.ultraGrid1.ActiveRow.Index;
  48. List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();
  49. string strColumnName;
  50. string strColumnValue;
  51. SearchCondition condition = new SearchCondition();
  52. foreach (object o in lstO)
  53. {
  54. ColumnFilter cf = (ColumnFilter)o;
  55. strColumnName = cf.Column.Key;
  56. strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";
  57. if (strColumnValue != "")
  58. {
  59. condition = condition.AddCondition(m_dicColAliasName2Name[strColumnName], strColumnValue, SqlOperator.Equal);
  60. }
  61. }
  62. m_filter = condition.BuildConditionSql();
  63. m_filter = m_filter.Replace("Where", "");
  64. ShowAllRecordInDataGridView(m_filter);
  65. }
  66. //private void AddNewRow()
  67. //{
  68. // if (Frm_Main.CheckPerm(this.Text, "增加"))
  69. // {
  70. // UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  71. // }
  72. // else
  73. // {
  74. // MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  75. // return;
  76. // }
  77. //}
  78. private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
  79. {
  80. if (e.KeyCode == Keys.Enter)
  81. {
  82. SearchResult();
  83. }
  84. if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
  85. {
  86. if (!m_bInsertFlag)
  87. {
  88. //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
  89. // row.Cells[2] = DateTime.Parse("1900-01-01");
  90. }
  91. }
  92. switch (e.KeyCode)
  93. {
  94. case Keys.Up:
  95. {
  96. string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
  97. int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
  98. int nIndex = ultraGrid1.ActiveRow.Index;
  99. if (nIndex > 0)
  100. nIndex--;
  101. this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
  102. false);
  103. this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
  104. false);
  105. e.Handled = true;
  106. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
  107. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
  108. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
  109. this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
  110. false);
  111. break;
  112. }
  113. case Keys.Down:
  114. {
  115. string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;
  116. int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
  117. int nIndex = ultraGrid1.ActiveRow.Index;
  118. if (nIndex < ultraGrid1.Rows.Count - 1)
  119. nIndex++;
  120. this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
  121. false);
  122. this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
  123. false);
  124. e.Handled = true;
  125. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
  126. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
  127. ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
  128. this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
  129. false);
  130. break;
  131. }
  132. case Keys.Right:
  133. this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
  134. false);
  135. this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
  136. false);
  137. e.Handled = true;
  138. this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
  139. false);
  140. break;
  141. case Keys.Left:
  142. this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
  143. false);
  144. this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
  145. false);
  146. e.Handled = true;
  147. this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
  148. false);
  149. break;
  150. }
  151. }
  152. private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
  153. {
  154. int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
  155. if (iIndex < 0)
  156. return;
  157. m_nDelIndex = ultraGrid1.ActiveRow.Index;
  158. }
  159. public string SqlValueList(string sql)
  160. {
  161. DataSet ds = DbHelperSQL.Query(sql.ToString());
  162. string strTotal = ds.Tables[0].Rows[0]["Total"].ToString();
  163. return strTotal;
  164. }
  165. /// <summary>
  166. /// 执行SQL查询语句,返回所有记录的DataTable集合。
  167. /// </summary>
  168. /// <param name="sql">SQL查询语句</param>
  169. /// <returns></returns>
  170. public DataTable SqlTable(string sql)
  171. {
  172. DataSet ds = DbHelperSQL.Query(sql.ToString());
  173. return ds.Tables[0];
  174. }
  175. private DataTable FindToDataTable(string where, PagerInfo pagerInfo)
  176. {
  177. WHC.Pager.WinControl.PagerHelper helper = new WHC.Pager.WinControl.PagerHelper(@"select CK_OperLogTabID
  178. ,T_ACL_User.Name
  179. ,CONVERT(CHAR(19), CK_OperDate, 20) CK_OperDate
  180. ,CK_OperName
  181. ,CK_ModuleName
  182. ,CK_DanjuNameOrNo from CK_OperLogTab
  183. join T_ACL_User on T_ACL_User.id = CK_OperLogTab.CK_OperUserid ", "*", "CK_OperLogTabID", pagerInfo.PageSize, pagerInfo.CurrenetPageIndex, true, where);
  184. string countSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, true);
  185. string dataSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, false);
  186. string value = SqlValueList(countSql);
  187. pagerInfo.RecordCount = Convert.ToInt32(value);//为了显示具体的信息,需要设置总记录数
  188. DataTable dt = SqlTable(dataSql);
  189. this.pager1.InitPageInfo(pagerInfo.RecordCount, pagerInfo.PageSize);
  190. return dt;
  191. }
  192. private void BindData(string strWhere)
  193. {
  194. this.ultraGrid1.DataSource = null;
  195. DataTable dt = FindToDataTable(strWhere, this.pager1.PagerInfo);
  196. //DataSet ds = m_bllCK_OperLogTab.GetList(strWhere);
  197. foreach (string strTemp in m_dicColName2AliasName.Keys)
  198. {
  199. dt.Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];
  200. }
  201. this.ultraGrid1.DataSource = dt;
  202. this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
  203. this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
  204. }
  205. void pager1_PageChanged(object sender, EventArgs e)
  206. {
  207. BindData(m_filter);
  208. }
  209. void pager1_ExportCurrent(object sender, EventArgs e)
  210. {
  211. MessageUtil.ShowTips("导出当前页");
  212. }
  213. void pager1_ExportAll(object sender, EventArgs e)
  214. {
  215. MessageUtil.ShowTips("导出所有");
  216. }
  217. private void Frm_ClassRoom_Load_1(object sender, EventArgs e)
  218. {
  219. this.pager1.PageChanged += new WHC.Pager.WinControl.PageChangedEventHandler(pager1_PageChanged);
  220. this.pager1.ExportCurrent += new WHC.Pager.WinControl.ExportCurrentEventHandler(pager1_ExportCurrent);
  221. this.pager1.ExportAll += new WHC.Pager.WinControl.ExportAllEventHandler(pager1_ExportAll);
  222. ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);
  223. m_dicColName2AliasName.Add("Name", "用户名");
  224. m_dicColName2AliasName.Add("CK_OperDate", "操作日期");
  225. m_dicColName2AliasName.Add("CK_OperName", "操作");
  226. m_dicColName2AliasName.Add("CK_ModuleName", "模块名称");
  227. m_dicColName2AliasName.Add("CK_DanjuNameOrNo", "单据号");
  228. foreach (string strTemp in m_dicColName2AliasName.Keys)
  229. {
  230. m_dicColAliasName2Name.Add(m_dicColName2AliasName[strTemp], strTemp);
  231. }
  232. }
  233. }
  234. }