S_CMN_022.cs 10 KB

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