S_CMN_004.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_003.cs
  5. * 2.功能描述:职务选择列表页面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 张国印 2014/09/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ComponentModel;
  12. using System.Data;
  13. using System.Text;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Basics.Library;
  18. using Dongke.IBOSS.PRD.Client.CommonModule;
  19. namespace Dongke.IBOSS.PRD.Client.Controls
  20. {
  21. /// <summary>
  22. /// 职务选择列表页面
  23. /// </summary>
  24. public partial class S_CMN_004 : FormBase
  25. {
  26. #region 成员变量
  27. private DataTable _dataSource; // 画面的数据源
  28. private DataRow _postRow; // 返回用户的DataRow
  29. #endregion
  30. # region 构造函数
  31. /// <summary>
  32. /// 构造函数
  33. /// </summary>
  34. public S_CMN_004()
  35. : this("")
  36. {
  37. }
  38. /// <summary>
  39. /// 重载的构造函数
  40. /// </summary>
  41. /// <param name="postName">职务名称</param>
  42. public S_CMN_004(string postName)
  43. {
  44. InitializeComponent();
  45. this.txtPostName.Text = postName;
  46. // 按钮
  47. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  48. this.btnOK.Text = ButtonText.BTN_OK;
  49. this.btnClose.Text = ButtonText.BTN_CANCEL;
  50. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  51. }
  52. #endregion
  53. #region 属性
  54. /// <summary>
  55. /// 获取或者设定画面的数据源。
  56. /// </summary>
  57. [Description("获取或者设定画面的数据源。")]
  58. public new DataTable DataSource
  59. {
  60. get
  61. {
  62. return _dataSource;
  63. }
  64. set
  65. {
  66. _dataSource = value;
  67. }
  68. }
  69. /// <summary>
  70. /// 返回选择的行
  71. /// </summary>
  72. public DataRow PostRow
  73. {
  74. get
  75. {
  76. return _postRow;
  77. }
  78. set
  79. {
  80. _postRow = value;
  81. }
  82. }
  83. #endregion
  84. #region 控件事件
  85. /// <summary>
  86. /// 页面加载事件
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void S_CMN_004_Load(object sender, EventArgs e)
  91. {
  92. try
  93. {
  94. this.dgvPost.AutoGenerateColumns = false;
  95. if (!string.IsNullOrEmpty(this.txtPostName.Text))
  96. {
  97. Search();
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. // 对异常进行共通处理
  103. ExceptionManager.HandleEventException(this.ToString(),
  104. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  105. }
  106. }
  107. /// <summary>
  108. /// 查询按钮按下事件
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void btnSearch_Click(object sender, EventArgs e)
  113. {
  114. try
  115. {
  116. Search();
  117. }
  118. catch (Exception ex)
  119. {
  120. // 对异常进行共通处理
  121. ExceptionManager.HandleEventException(this.ToString(),
  122. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  123. }
  124. }
  125. /// <summary>
  126. /// 确定按钮按下事件
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void btnOK_Click(object sender, EventArgs e)
  131. {
  132. try
  133. {
  134. Commit();
  135. }
  136. catch (Exception ex)
  137. {
  138. // 对异常进行共通处理
  139. ExceptionManager.HandleEventException(this.ToString(),
  140. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  141. }
  142. }
  143. /// <summary>
  144. /// 关闭按钮按下事件
  145. /// </summary>
  146. /// <param name="sender"></param>
  147. /// <param name="e"></param>
  148. private void btnClose_Click(object sender, EventArgs e)
  149. {
  150. this.DialogResult = DialogResult.Cancel;
  151. this.Close();
  152. }
  153. /// <summary>
  154. /// KeyDown事件
  155. /// </summary>
  156. /// <param name="sender"></param>
  157. /// <param name="e"></param>
  158. private void dgvPost_KeyDown(object sender, KeyEventArgs e)
  159. {
  160. try
  161. {
  162. // 拷贝单元格文本到剪切板
  163. if (e.KeyData == (Keys.Control | Keys.C))
  164. {
  165. if (dgvPost.CurrentRow != null
  166. && !string.IsNullOrEmpty(dgvPost.CurrentRow.Cells[dgvPost.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  167. {
  168. Clipboard.SetText(dgvPost.CurrentRow.Cells[dgvPost.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  169. }
  170. }
  171. else if (e.KeyData == Keys.Enter)
  172. {
  173. Commit();
  174. }
  175. }
  176. catch (Exception ex)
  177. {
  178. // 对异常进行共通处理
  179. ExceptionManager.HandleEventException(this.ToString(),
  180. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  181. }
  182. }
  183. /// <summary>
  184. /// 双击DataGridView窗体,返回选中记录
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void dgvPost_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  189. {
  190. try
  191. {
  192. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  193. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  194. {
  195. Commit();
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. // 对异常进行共通处理
  201. ExceptionManager.HandleEventException(this.ToString(),
  202. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  203. }
  204. }
  205. #endregion
  206. #region 私有方法
  207. /// <summary>
  208. /// 查询方法
  209. /// </summary>
  210. private void Search()
  211. {
  212. // 清空之前的查询结果
  213. this.dgvPost.DataSource = null;
  214. // 根据查询条件查询数据源中的数据,并显示
  215. DataTable userTable = this.DataSource.Copy();
  216. userTable.DefaultView.RowFilter = GetFilterExpression();
  217. this.dgvPost.DataSource = userTable.DefaultView.ToTable();
  218. this.dgvPost.Focus();
  219. // 当没有查询结果时,提示无查询结构消息
  220. if (this.dgvPost.RowCount <= 0)
  221. {
  222. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  223. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  224. this.txtPostCode.Focus();
  225. this.btnOK.Enabled = false;
  226. return;
  227. }
  228. this.btnOK.Enabled = true;
  229. }
  230. /// <summary>
  231. /// 根据画面输入内容拼接过滤条件
  232. /// </summary>
  233. /// <returns></returns>
  234. private string GetFilterExpression()
  235. {
  236. StringBuilder strbFilterExpressions = new StringBuilder();
  237. strbFilterExpressions.Append("(1=1");
  238. if (!string.IsNullOrEmpty(this.txtPostCode.Text))
  239. {
  240. // 用户编码条件
  241. strbFilterExpressions.Append(string.Format(" AND PostCode LIKE '%{0}%'",
  242. Utility.SelectFilterLike(this.txtPostCode.Text.Trim())));
  243. }
  244. if (!string.IsNullOrEmpty(this.txtPostName.Text))
  245. {
  246. // 用户名称条件
  247. strbFilterExpressions.Append(string.Format(" AND PostName LIKE '%{0}%'",
  248. Utility.SelectFilterLike(this.txtPostName.Text.Trim())));
  249. }
  250. strbFilterExpressions.Append(")");
  251. return strbFilterExpressions.ToString();
  252. }
  253. /// <summary>
  254. /// 提交时给取得的行赋值
  255. /// </summary>
  256. private void Commit()
  257. {
  258. if (this.dgvPost.CurrentCell != null)
  259. {
  260. this.PostRow = this.dgvPost.GetDataRow(this.dgvPost.CurrentCell.RowIndex);
  261. this.DialogResult = DialogResult.OK;
  262. this.Close();
  263. }
  264. }
  265. #endregion
  266. private void btnClearCondition_Click(object sender, EventArgs e)
  267. {
  268. this.txtPostCode.Clear();
  269. this.txtPostName.Clear();
  270. }
  271. }
  272. }