S_CMN_016.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_016.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_016 : 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_016(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 string SetJobsCode
  76. {
  77. get;
  78. set;
  79. }
  80. /// <summary>
  81. /// 选择的数据
  82. /// </summary>
  83. public DataTable SelTable
  84. {
  85. get;
  86. set;
  87. }
  88. /// <summary>
  89. /// 返回选择的组织行
  90. /// </summary>
  91. public DataRow ProductionLineRow
  92. {
  93. get
  94. {
  95. return _productionLineRow;
  96. }
  97. set
  98. {
  99. _productionLineRow = value;
  100. }
  101. }
  102. /// <summary>
  103. /// 返回选择的组织多行
  104. /// </summary>
  105. public DataTable dataDT
  106. {
  107. get
  108. {
  109. return _dataDT;
  110. }
  111. set
  112. {
  113. _dataDT = value;
  114. }
  115. }
  116. #endregion
  117. #region 事件
  118. /// <summary>
  119. /// 窗体加载
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void S_CMN_015_Load(object sender, EventArgs e)
  124. {
  125. try
  126. {
  127. this.dgvProcedure.AutoGenerateColumns = false;
  128. this.txtProcedureCode.Text = SetJobsCode;
  129. if (!string.IsNullOrEmpty(this.txtProcedureCode.Text))
  130. {
  131. Search();
  132. }
  133. }
  134. catch (Exception ex)
  135. {
  136. // 对异常进行共通处理
  137. ExceptionManager.HandleEventException(this.ToString(),
  138. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  139. }
  140. }
  141. /// <summary>
  142. /// 查询按钮按下事件
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void btnSearch_Click(object sender, EventArgs e)
  147. {
  148. try
  149. {
  150. Search();
  151. }
  152. catch (Exception ex)
  153. {
  154. // 对异常进行共通处理
  155. ExceptionManager.HandleEventException(this.ToString(),
  156. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  157. }
  158. }
  159. /// <summary>
  160. /// 确定按钮按下事件
  161. /// </summary>
  162. /// <param name="sender"></param>
  163. /// <param name="e"></param>
  164. private void btnOK_Click(object sender, EventArgs e)
  165. {
  166. try
  167. {
  168. Commit();
  169. }
  170. catch (Exception ex)
  171. {
  172. // 对异常进行共通处理
  173. ExceptionManager.HandleEventException(this.ToString(),
  174. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  175. }
  176. }
  177. /// <summary>
  178. /// 关闭按钮按下事件
  179. /// </summary>
  180. /// <param name="sender"></param>
  181. /// <param name="e"></param>
  182. private void btnClose_Click(object sender, EventArgs e)
  183. {
  184. this.DialogResult = DialogResult.Cancel;
  185. this.Close();
  186. }
  187. /// <summary>
  188. /// KeyDown事件
  189. /// </summary>
  190. /// <param name="sender"></param>
  191. /// <param name="e"></param>
  192. private void dgvProductionLine_KeyDown(object sender, KeyEventArgs e)
  193. {
  194. try
  195. {
  196. // 拷贝单元格文本到剪切板
  197. if (e.KeyData == (Keys.Control | Keys.C))
  198. {
  199. if (this.dgvProcedure.CurrentRow != null
  200. && !string.IsNullOrEmpty(dgvProcedure.CurrentRow.Cells[dgvProcedure.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  201. {
  202. Clipboard.SetText(dgvProcedure.CurrentRow.Cells[dgvProcedure.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  203. }
  204. }
  205. else if (e.KeyData == Keys.Enter)
  206. {
  207. Commit();
  208. }
  209. }
  210. catch (Exception ex)
  211. {
  212. // 对异常进行共通处理
  213. ExceptionManager.HandleEventException(this.ToString(),
  214. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  215. }
  216. }
  217. /// <summary>
  218. /// 双击DataGridView窗体,返回选中记录
  219. /// </summary>
  220. /// <param name="sender"></param>
  221. /// <param name="e"></param>
  222. private void dgvProductionLine_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  223. {
  224. try
  225. {
  226. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  227. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  228. {
  229. //判断有没有复选框,如果有不做任何操作
  230. if (!this.Sel.Visible)
  231. {
  232. Commit();
  233. }
  234. }
  235. }
  236. catch (Exception ex)
  237. {
  238. // 对异常进行共通处理
  239. ExceptionManager.HandleEventException(this.ToString(),
  240. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  241. }
  242. }
  243. #endregion
  244. #region 私有方法
  245. /// <summary>
  246. /// 查询方法
  247. /// </summary>
  248. private void Search()
  249. {
  250. // 清空之前的查询结果
  251. this.dgvProcedure.DataSource = null;
  252. // 根据查询条件查询数据源中的数据,并显示
  253. DataTable ProductionLineTable = this.DataSource.Copy();
  254. ProductionLineTable.DefaultView.RowFilter = GetFilterExpression();
  255. this.dgvProcedure.DataSource = ProductionLineTable.DefaultView.ToTable();
  256. this.dgvProcedure.Focus();
  257. // 当没有查询结果时,提示无查询结构消息
  258. if (this.dgvProcedure.RowCount <= 0)
  259. {
  260. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  261. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  262. this.txtProcedureName.Focus();
  263. this.btnOK.Enabled = false;
  264. return;
  265. }
  266. this.btnOK.Enabled = true;
  267. }
  268. /// <summary>
  269. /// 提交时给取得的行赋值
  270. /// </summary>
  271. private void Commit()
  272. {
  273. if (this.Sel.Visible)
  274. {
  275. if (this.dgvProcedure.CurrentCell != null)
  276. {
  277. this.dataDT = (DataTable)this.dgvProcedure.DataSource;
  278. this.DialogResult = DialogResult.OK;
  279. }
  280. }
  281. else
  282. {
  283. if (this.dgvProcedure.CurrentCell != null)
  284. {
  285. ProductionLineRow = this.dgvProcedure.GetDataRow(this.dgvProcedure.CurrentCell.RowIndex);
  286. this.DialogResult = DialogResult.OK;
  287. }
  288. }
  289. this.Close();
  290. }
  291. /// <summary>
  292. /// 根据画面输入内容拼接过滤条件
  293. /// </summary>
  294. /// <returns></returns>
  295. private string GetFilterExpression()
  296. {
  297. StringBuilder strbFilterExpressions = new StringBuilder();
  298. strbFilterExpressions.Append("(1=1");
  299. if (!string.IsNullOrEmpty(this.txtProcedureCode.Text))
  300. {
  301. // 产品类别编码条件
  302. strbFilterExpressions.Append(string.Format(" AND ProcedureCode LIKE '%{0}%'",
  303. Utility.SelectFilterLike(this.txtProcedureCode.Text.Trim())));
  304. }
  305. if (!string.IsNullOrEmpty(this.txtProcedureName.Text))
  306. {
  307. // 产品类别名称条件
  308. strbFilterExpressions.Append(string.Format(" AND ProcedureName LIKE '%{0}%'",
  309. Utility.SelectFilterLike(this.txtProcedureName.Text.Trim())));
  310. }
  311. strbFilterExpressions.Append(")");
  312. return strbFilterExpressions.ToString();
  313. }
  314. #endregion
  315. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  316. {
  317. for (int i = 0; i < this.dgvProcedure.Rows.Count; i++)
  318. {
  319. this.dgvProcedure.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  320. }
  321. }
  322. private void btnClearCondition_Click(object sender, EventArgs e)
  323. {
  324. this.txtProcedureCode.Clear();
  325. this.txtProcedureName.Clear();
  326. }
  327. }
  328. }