S_CMN_025.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_018.cs
  5. * 2.功能描述:工种控件查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/11/4 1.0 新建
  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. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. namespace Dongke.IBOSS.PRD.Client.Controls
  21. {
  22. public partial class S_CMN_025 : FormBase
  23. {
  24. #region 成员变量
  25. private DataTable _dataSource; // 画面的数据源
  26. private DataRow _jobsRow; // 返回用户的DataRow
  27. private DataRow _productionLineRow; // 返回类别的DataRow
  28. private DataTable _dataDT; //返回选择数据源
  29. #endregion
  30. #region 构造函数
  31. /// <summary>
  32. /// 重载的构造函数
  33. /// </summary>
  34. public S_CMN_025()
  35. {
  36. InitializeComponent();
  37. // 按钮
  38. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  39. this.btnOK.Text = ButtonText.BTN_OK;
  40. this.btnClose.Text = ButtonText.BTN_CANCEL;
  41. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  42. }
  43. public S_CMN_025(int flag)
  44. {
  45. InitializeComponent();
  46. if (flag == 1)
  47. {
  48. this.Sel.Visible = true;
  49. this.chkChooseAll.Visible = true;
  50. }
  51. else
  52. {
  53. this.Sel.Visible = false;
  54. this.chkChooseAll.Visible = false;
  55. }
  56. // 按钮
  57. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  58. this.btnOK.Text = ButtonText.BTN_OK;
  59. this.btnClose.Text = ButtonText.BTN_CANCEL;
  60. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  61. }
  62. public S_CMN_025(string DefectFineCode)
  63. {
  64. InitializeComponent();
  65. this.txtDefectCode.Text = DefectFineCode;
  66. // 按钮
  67. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  68. this.btnOK.Text = ButtonText.BTN_OK;
  69. this.btnClose.Text = ButtonText.BTN_CANCEL;
  70. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  71. }
  72. #endregion
  73. #region 属性
  74. /// <summary>
  75. /// 返回选择的组织多行
  76. /// </summary>
  77. public DataTable dataDT
  78. {
  79. get
  80. {
  81. return _dataDT;
  82. }
  83. set
  84. {
  85. _dataDT = value;
  86. }
  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 SelTable { get; set; }
  106. /// <summary>
  107. /// 传入的缺陷扣罚编码
  108. /// </summary>
  109. public string SetDefectFineCodeCode { get; set; }
  110. /// <summary>
  111. /// 获取或者设定画面的数据源。
  112. /// </summary>
  113. [Description("获取或者设定画面的数据源。")]
  114. public new DataTable DataSource
  115. {
  116. get
  117. {
  118. return _dataSource;
  119. }
  120. set
  121. {
  122. _dataSource = value;
  123. }
  124. }
  125. /// <summary>
  126. /// 返回选择的行
  127. /// </summary>
  128. public DataRow JobsRow
  129. {
  130. get
  131. {
  132. return _jobsRow;
  133. }
  134. set
  135. {
  136. _jobsRow = value;
  137. }
  138. }
  139. #endregion
  140. #region 控件事件
  141. /// <summary>
  142. /// 窗体加载
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void S_CMN_024_Load(object sender, EventArgs e)
  147. {
  148. try
  149. {
  150. // 绑定缺陷类型数据
  151. DataSet dsResultAccount = SystemModuleProxy.Service.GetAllDefectTypeInfo();
  152. DataView dv = dsResultAccount.Tables[0].DefaultView;
  153. dv.RowFilter = "valueflag=1";
  154. DataTable dtDefectType = dv.ToTable();
  155. DataRow nullrow = dtDefectType.NewRow();
  156. //nullrow["DefectTypeID"] = DBNull.Value;
  157. //nullrow["DefectTypeName"] = DBNull.Value;
  158. dtDefectType.Rows.InsertAt(nullrow, 0);
  159. this.cboDEFECTTYPENAME.ValueMember = "DefectTypeID";
  160. this.cboDEFECTTYPENAME.DisplayMember = "DefectTypeName";
  161. this.cboDEFECTTYPENAME.DataSource = dtDefectType;
  162. this.dgvJobs.AutoGenerateColumns = false;
  163. this.txtDefectCode.Text = SetDefectFineCodeCode;
  164. if (!string.IsNullOrEmpty(this.txtDefectCode.Text))
  165. {
  166. Search();
  167. }
  168. }
  169. catch (Exception ex)
  170. {
  171. // 对异常进行共通处理
  172. ExceptionManager.HandleEventException(this.ToString(),
  173. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  174. }
  175. }
  176. /// <summary>
  177. /// 查询按钮按下事件
  178. /// </summary>
  179. /// <param name="sender"></param>
  180. /// <param name="e"></param>
  181. private void btnSearch_Click(object sender, System.EventArgs e)
  182. {
  183. try
  184. {
  185. Search();
  186. }
  187. catch (Exception ex)
  188. {
  189. // 对异常进行共通处理
  190. ExceptionManager.HandleEventException(this.ToString(),
  191. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  192. }
  193. }
  194. /// <summary>
  195. /// KeyDown事件
  196. /// </summary>
  197. /// <param name="sender"></param>
  198. /// <param name="e"></param>
  199. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  200. {
  201. try
  202. {
  203. // 拷贝单元格文本到剪切板
  204. if (e.KeyData == (Keys.Control | Keys.C))
  205. {
  206. if (dgvJobs.CurrentRow != null
  207. && !string.IsNullOrEmpty(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  208. {
  209. Clipboard.SetText(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  210. }
  211. }
  212. else if (e.KeyData == Keys.Enter)
  213. {
  214. Commit();
  215. }
  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. /// 确定按钮按下事件
  226. /// </summary>
  227. /// <param name="sender"></param>
  228. /// <param name="e"></param>
  229. private void btnOK_Click(object sender, System.EventArgs e)
  230. {
  231. try
  232. {
  233. Commit();
  234. }
  235. catch (Exception ex)
  236. {
  237. // 对异常进行共通处理
  238. ExceptionManager.HandleEventException(this.ToString(),
  239. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  240. }
  241. }
  242. /// <summary>
  243. /// 关闭按钮按下事件
  244. /// </summary>
  245. /// <param name="sender"></param>
  246. /// <param name="e"></param>
  247. private void btnClose_Click(object sender, System.EventArgs e)
  248. {
  249. this.DialogResult = DialogResult.Cancel;
  250. this.Close();
  251. }
  252. /// <summary>
  253. /// 双击DataGridView窗体,返回选中记录
  254. /// </summary>
  255. /// <param name="sender"></param>
  256. /// <param name="e"></param>
  257. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  258. {
  259. try
  260. {
  261. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  262. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  263. {
  264. Commit();
  265. }
  266. }
  267. catch (Exception ex)
  268. {
  269. // 对异常进行共通处理
  270. ExceptionManager.HandleEventException(this.ToString(),
  271. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  272. }
  273. }
  274. /// <summary>
  275. /// 全选
  276. /// </summary>
  277. /// <param name="sender"></param>
  278. /// <param name="e"></param>
  279. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  280. {
  281. try
  282. {
  283. for (int i = 0; i < this.dgvJobs.Rows.Count; i++)
  284. {
  285. this.dgvJobs.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  286. }
  287. }
  288. catch (Exception ex)
  289. {
  290. // 对异常进行共通处理
  291. ExceptionManager.HandleEventException(this.ToString(),
  292. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  293. }
  294. }
  295. #endregion
  296. #region 私有方法
  297. /// <summary>
  298. /// 查询方法
  299. /// </summary>
  300. private void Search()
  301. {
  302. // 清空之前的查询结果
  303. this.dgvJobs.DataSource = null;
  304. if (_dataSource == null)
  305. {
  306. DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  307. {
  308. return SystemModuleProxy.Service.GetDefectData(1);
  309. }));
  310. if (defectds != null
  311. && defectds.Tables.Count > Constant.INT_IS_ZERO
  312. && defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  313. {
  314. defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
  315. _dataSource = defectds.Tables[0].DefaultView.ToTable();
  316. }
  317. }
  318. if (_dataSource != null)
  319. {
  320. _dataSource.DefaultView.RowFilter = GetFilterExpression();
  321. this.dgvJobs.DataSource = _dataSource.DefaultView.ToTable();
  322. this.dgvJobs.Focus();
  323. }
  324. // 当没有查询结果时,提示无查询结构消息
  325. if (this.dgvJobs.RowCount <= 0)
  326. {
  327. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  328. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  329. this.txtDefectCode.Focus();
  330. this.btnOK.Enabled = false;
  331. return;
  332. }
  333. this.btnOK.Enabled = true;
  334. }
  335. /// <summary>
  336. /// 提交时给取得的行赋值
  337. /// </summary>
  338. private void Commit()
  339. {
  340. try
  341. {
  342. if (this.Sel.Visible)
  343. {
  344. if (this.dgvJobs.CurrentCell != null)
  345. {
  346. this.dataDT = (DataTable)this.dgvJobs.DataSource;
  347. this.DialogResult = DialogResult.OK;
  348. }
  349. }
  350. else
  351. {
  352. if (this.dgvJobs.CurrentCell != null)
  353. {
  354. ProductionLineRow = this.dgvJobs.GetDataRow(this.dgvJobs.CurrentCell.RowIndex);
  355. this.DialogResult = DialogResult.OK;
  356. }
  357. }
  358. this.Close();
  359. }
  360. catch (Exception ex)
  361. {
  362. throw ex;
  363. }
  364. }
  365. /// <summary>
  366. /// 根据画面输入内容拼接过滤条件
  367. /// </summary>
  368. /// <returns></returns>
  369. private string GetFilterExpression()
  370. {
  371. StringBuilder strbFilterExpressions = new StringBuilder();
  372. strbFilterExpressions.Append("(1=1");
  373. if (!string.IsNullOrEmpty(this.txtDefectCode.Text) || !string.IsNullOrEmpty(this.txtDefectName.Text))
  374. {
  375. // 编码条件
  376. strbFilterExpressions.Append(string.Format(" AND DefectCode LIKE '%{0}%'",
  377. Utility.SelectFilterLike(this.txtDefectCode.Text.Trim())));
  378. // 名称条件
  379. strbFilterExpressions.Append(string.Format(" AND DefectName LIKE '%{0}%'",
  380. Utility.SelectFilterLike(this.txtDefectName.Text.Trim())));
  381. }
  382. if (!string.IsNullOrEmpty(this.cboDEFECTTYPENAME.Text))
  383. {
  384. // 缺陷名称条件
  385. strbFilterExpressions.Append(string.Format(" AND DEFECTTYPEID = {0}",
  386. this.cboDEFECTTYPENAME.SelectedValue));
  387. }
  388. if (!string.IsNullOrWhiteSpace(this.txtREMARKS.Text))
  389. {
  390. // 缺陷名称条件
  391. strbFilterExpressions.Append(string.Format(" AND REMARKS LIKE '%{0}%'",
  392. Utility.SelectFilterLike(this.txtREMARKS.Text.Trim())));
  393. }
  394. strbFilterExpressions.Append(")");
  395. return strbFilterExpressions.ToString();
  396. }
  397. #endregion
  398. private void btnClearCondition_Click(object sender, EventArgs e)
  399. {
  400. this.txtDefectCode.Clear();
  401. this.txtDefectName.Clear();
  402. this.txtREMARKS.Clear();
  403. this.cboDEFECTTYPENAME.SelectedIndex = -1;
  404. }
  405. }
  406. }