S_CMN_007.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_007.cs
  5. * 2.功能描述:用户信息控件查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/09/15 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_007 : FormBase
  25. {
  26. #region 成员变量
  27. private DataTable _dataSource; // 画面的数据源
  28. private DataRow _dataRow; // 返回原画面的DataRow
  29. private DataTable _dataDT; //返回选择数据源
  30. #endregion
  31. #region 构造函数
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. public S_CMN_007()
  36. :this(0)
  37. {
  38. // 周兴 2018-2-27 注释
  39. //InitializeComponent();
  40. //// 按钮
  41. //this.btnSearch.Text = ButtonText.BTN_SEARCH;
  42. //this.btnOK.Text = ButtonText.BTN_OK;
  43. //this.btnClose.Text = ButtonText.BTN_CANCEL;
  44. //this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  45. }
  46. public S_CMN_007(int flag)
  47. {
  48. InitializeComponent();
  49. // 按钮
  50. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  51. this.btnOK.Text = ButtonText.BTN_OK;
  52. this.btnClose.Text = ButtonText.BTN_CLOSE;
  53. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  54. if (flag == 1)
  55. {
  56. this.sel.Visible = true;
  57. this.chkChooseAll.Visible = true;
  58. }
  59. else
  60. {
  61. this.sel.Visible = false;
  62. this.chkChooseAll.Visible = false;
  63. }
  64. }
  65. #endregion
  66. #region 属性
  67. /// <summary>
  68. /// 获取或者设定画面的数据源。
  69. /// </summary>
  70. [Description("获取或者设定画面的数据源。")]
  71. public new DataTable DataSource
  72. {
  73. get
  74. {
  75. return _dataSource;
  76. }
  77. set
  78. {
  79. _dataSource = value;
  80. }
  81. }
  82. /// <summary>
  83. /// 返回选择的组织行
  84. /// </summary>
  85. public DataRow DataRow
  86. {
  87. get
  88. {
  89. return _dataRow;
  90. }
  91. set
  92. {
  93. _dataRow = value;
  94. }
  95. }
  96. /// <summary>
  97. /// 返回选择的组织多行
  98. /// </summary>
  99. public DataTable dataDT
  100. {
  101. get
  102. {
  103. return _dataDT;
  104. }
  105. set
  106. {
  107. _dataDT = value;
  108. }
  109. }
  110. #endregion
  111. #region 私有方法/函数
  112. /// <summary>
  113. /// 查询方法
  114. /// </summary>
  115. private void Search()
  116. {
  117. this.dgvUser.AutoGenerateColumns = false;
  118. // 清空之前的查询结果
  119. this.dgvUser.DataSource = null;
  120. // 根据查询条件查询数据源中的数据,并显示
  121. DataTable MouldTypeTable = this.DataSource.Copy();
  122. MouldTypeTable.DefaultView.RowFilter = GetFilterExpression();
  123. this.dgvUser.DataSource = MouldTypeTable.DefaultView.ToTable();
  124. this.dgvUser.Focus();
  125. // 当没有查询结果时,提示无查询结构消息
  126. if (this.dgvUser.RowCount <= 0)
  127. {
  128. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  129. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  130. this.txtUserCode.Focus();
  131. this.btnOK.Enabled = false;
  132. return;
  133. }
  134. this.btnOK.Enabled = true;
  135. }
  136. /// <summary>
  137. /// 提交时给取得的行赋值
  138. /// </summary>
  139. private void Commit()
  140. {
  141. if (this.sel.Visible)
  142. {
  143. if (this.dgvUser.CurrentCell != null)
  144. {
  145. this.dataDT = (DataTable)this.dgvUser.DataSource;
  146. this.DialogResult = DialogResult.OK;
  147. }
  148. }
  149. else
  150. {
  151. if (this.dgvUser.CurrentCell != null)
  152. {
  153. DataRow = this.dgvUser.GetDataRow(this.dgvUser.CurrentCell.RowIndex);
  154. this.DialogResult = DialogResult.OK;
  155. }
  156. }
  157. this.Close();
  158. }
  159. /// <summary>
  160. /// 根据画面输入内容拼接过滤条件
  161. /// </summary>
  162. /// <returns></returns>
  163. private string GetFilterExpression()
  164. {
  165. StringBuilder strbFilterExpressions = new StringBuilder();
  166. strbFilterExpressions.Append("(1=1");
  167. if (!string.IsNullOrEmpty(this.txtUserCode.Text))
  168. {
  169. // 成型线类型编码
  170. strbFilterExpressions.Append(string.Format(" AND USERCODE LIKE '%{0}%'",
  171. Utility.SelectFilterLike(this.txtUserCode.Text.Trim())));
  172. }
  173. if (!string.IsNullOrEmpty(this.txtUserName.Text))
  174. {
  175. // 成型线类型名称
  176. strbFilterExpressions.Append(string.Format(" AND USERNAME LIKE '%{0}%'",
  177. Utility.SelectFilterLike(this.txtUserName.Text.Trim())));
  178. }
  179. strbFilterExpressions.Append(")");
  180. return strbFilterExpressions.ToString();
  181. }
  182. #endregion
  183. #region 控件事件
  184. /// <summary>
  185. /// 窗体加载
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void S_CMN_007_Load(object sender, EventArgs e)
  190. {
  191. try
  192. {
  193. this.dgvUser.AutoGenerateColumns = false;
  194. if (!string.IsNullOrEmpty(this.txtUserCode.Text))
  195. {
  196. Search();
  197. }
  198. }
  199. catch (Exception ex)
  200. {
  201. // 对异常进行共通处理
  202. ExceptionManager.HandleEventException(this.ToString(),
  203. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  204. }
  205. }
  206. /// <summary>
  207. /// 查询按钮按下事件
  208. /// </summary>
  209. /// <param name="sender"></param>
  210. /// <param name="e"></param>
  211. private void btnSearch_Click(object sender, System.EventArgs e)
  212. {
  213. try
  214. {
  215. Search();
  216. }
  217. catch (Exception ex)
  218. {
  219. // 对异常进行共通处理
  220. ExceptionManager.HandleEventException(this.ToString(),
  221. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  222. }
  223. }
  224. /// <summary>
  225. /// KeyDown事件
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  230. {
  231. try
  232. {
  233. // 拷贝单元格文本到剪切板
  234. if (e.KeyData == (Keys.Control | Keys.C))
  235. {
  236. if (dgvUser.CurrentRow != null
  237. && !string.IsNullOrEmpty(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  238. {
  239. Clipboard.SetText(dgvUser.CurrentRow.Cells[dgvUser.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  240. }
  241. }
  242. else if (e.KeyData == Keys.Enter)
  243. {
  244. Commit();
  245. }
  246. }
  247. catch (Exception ex)
  248. {
  249. // 对异常进行共通处理
  250. ExceptionManager.HandleEventException(this.ToString(),
  251. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  252. }
  253. }
  254. /// <summary>
  255. /// 确定按钮按下事件
  256. /// </summary>
  257. /// <param name="sender"></param>
  258. /// <param name="e"></param>
  259. private void btnOK_Click(object sender, System.EventArgs e)
  260. {
  261. try
  262. {
  263. Commit();
  264. }
  265. catch (Exception ex)
  266. {
  267. // 对异常进行共通处理
  268. ExceptionManager.HandleEventException(this.ToString(),
  269. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  270. }
  271. }
  272. /// <summary>
  273. /// 关闭按钮按下事件
  274. /// </summary>
  275. /// <param name="sender"></param>
  276. /// <param name="e"></param>
  277. private void btnClose_Click(object sender, System.EventArgs e)
  278. {
  279. this.DialogResult = DialogResult.Cancel;
  280. this.Close();
  281. }
  282. /// <summary>
  283. /// 双击DataGridView窗体,返回选中记录
  284. /// </summary>
  285. /// <param name="sender"></param>
  286. /// <param name="e"></param>
  287. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  288. {
  289. try
  290. {
  291. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  292. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  293. {
  294. //判断有没有复选框,如果有不做任何操作
  295. if (!this.sel.Visible)
  296. {
  297. Commit();
  298. }
  299. }
  300. }
  301. catch (Exception ex)
  302. {
  303. // 对异常进行共通处理
  304. ExceptionManager.HandleEventException(this.ToString(),
  305. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  306. }
  307. }
  308. #endregion
  309. /// <summary>
  310. /// 全选按钮事件
  311. /// </summary>
  312. /// <param name="sender"></param>
  313. /// <param name="e"></param>
  314. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  315. {
  316. for (int i = 0; i < this.dgvUser.Rows.Count; i++)
  317. {
  318. this.dgvUser.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  319. }
  320. }
  321. private void btnClearCondition_Click(object sender, EventArgs e)
  322. {
  323. this.txtUserCode.Clear();
  324. this.txtUserName.Clear();
  325. }
  326. }
  327. }