S_CMN_015.cs 11 KB

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