S_CMN_024.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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_024 : 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_024()
  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_024(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_024(string DefectFineCode)
  63. {
  64. InitializeComponent();
  65. this.txtDefectFineCode.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. this.dgvJobs.AutoGenerateColumns = false;
  151. this.txtDefectFineCode.Text = SetDefectFineCodeCode;
  152. if (!string.IsNullOrEmpty(this.txtDefectFineCode.Text))
  153. {
  154. Search();
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. // 对异常进行共通处理
  160. ExceptionManager.HandleEventException(this.ToString(),
  161. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  162. }
  163. }
  164. /// <summary>
  165. /// 查询按钮按下事件
  166. /// </summary>
  167. /// <param name="sender"></param>
  168. /// <param name="e"></param>
  169. private void btnSearch_Click(object sender, System.EventArgs e)
  170. {
  171. try
  172. {
  173. Search();
  174. }
  175. catch (Exception ex)
  176. {
  177. // 对异常进行共通处理
  178. ExceptionManager.HandleEventException(this.ToString(),
  179. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  180. }
  181. }
  182. /// <summary>
  183. /// KeyDown事件
  184. /// </summary>
  185. /// <param name="sender"></param>
  186. /// <param name="e"></param>
  187. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  188. {
  189. try
  190. {
  191. // 拷贝单元格文本到剪切板
  192. if (e.KeyData == (Keys.Control | Keys.C))
  193. {
  194. if (dgvJobs.CurrentRow != null
  195. && !string.IsNullOrEmpty(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  196. {
  197. Clipboard.SetText(dgvJobs.CurrentRow.Cells[dgvJobs.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. /// 确定按钮按下事件
  214. /// </summary>
  215. /// <param name="sender"></param>
  216. /// <param name="e"></param>
  217. private void btnOK_Click(object sender, System.EventArgs e)
  218. {
  219. try
  220. {
  221. Commit();
  222. }
  223. catch (Exception ex)
  224. {
  225. // 对异常进行共通处理
  226. ExceptionManager.HandleEventException(this.ToString(),
  227. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  228. }
  229. }
  230. /// <summary>
  231. /// 关闭按钮按下事件
  232. /// </summary>
  233. /// <param name="sender"></param>
  234. /// <param name="e"></param>
  235. private void btnClose_Click(object sender, System.EventArgs e)
  236. {
  237. this.DialogResult = DialogResult.Cancel;
  238. this.Close();
  239. }
  240. /// <summary>
  241. /// 双击DataGridView窗体,返回选中记录
  242. /// </summary>
  243. /// <param name="sender"></param>
  244. /// <param name="e"></param>
  245. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  246. {
  247. try
  248. {
  249. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  250. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  251. {
  252. Commit();
  253. }
  254. }
  255. catch (Exception ex)
  256. {
  257. // 对异常进行共通处理
  258. ExceptionManager.HandleEventException(this.ToString(),
  259. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  260. }
  261. }
  262. /// <summary>
  263. /// 全选
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  268. {
  269. try
  270. {
  271. for (int i = 0; i < this.dgvJobs.Rows.Count; i++)
  272. {
  273. this.dgvJobs.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  274. }
  275. }
  276. catch (Exception ex)
  277. {
  278. // 对异常进行共通处理
  279. ExceptionManager.HandleEventException(this.ToString(),
  280. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  281. }
  282. }
  283. #endregion
  284. #region 私有方法
  285. /// <summary>
  286. /// 查询方法
  287. /// </summary>
  288. private void Search()
  289. {
  290. // 清空之前的查询结果
  291. this.dgvJobs.DataSource = null;
  292. if (_dataSource == null)
  293. {
  294. DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  295. {
  296. return SystemModuleProxy.Service.GetAllDefectFine();
  297. }));
  298. if (defectds != null
  299. && defectds.Tables.Count > Constant.INT_IS_ZERO
  300. && defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  301. {
  302. defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
  303. _dataSource = defectds.Tables[0].DefaultView.ToTable();
  304. }
  305. }
  306. if (_dataSource != null)
  307. {
  308. _dataSource.DefaultView.RowFilter = GetFilterExpression();
  309. this.dgvJobs.DataSource = _dataSource.DefaultView.ToTable();
  310. this.dgvJobs.Focus();
  311. }
  312. // 当没有查询结果时,提示无查询结构消息
  313. if (this.dgvJobs.RowCount <= 0)
  314. {
  315. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  316. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  317. this.txtDefectFineCode.Focus();
  318. this.btnOK.Enabled = false;
  319. return;
  320. }
  321. this.btnOK.Enabled = true;
  322. }
  323. /// <summary>
  324. /// 提交时给取得的行赋值
  325. /// </summary>
  326. private void Commit()
  327. {
  328. try
  329. {
  330. if (this.Sel.Visible)
  331. {
  332. if (this.dgvJobs.CurrentCell != null)
  333. {
  334. this.dataDT = (DataTable)this.dgvJobs.DataSource;
  335. this.DialogResult = DialogResult.OK;
  336. }
  337. }
  338. else
  339. {
  340. if (this.dgvJobs.CurrentCell != null)
  341. {
  342. ProductionLineRow = this.dgvJobs.GetDataRow(this.dgvJobs.CurrentCell.RowIndex);
  343. this.DialogResult = DialogResult.OK;
  344. }
  345. }
  346. this.Close();
  347. }
  348. catch (Exception ex)
  349. {
  350. throw ex;
  351. }
  352. }
  353. /// <summary>
  354. /// 根据画面输入内容拼接过滤条件
  355. /// </summary>
  356. /// <returns></returns>
  357. private string GetFilterExpression()
  358. {
  359. StringBuilder strbFilterExpressions = new StringBuilder();
  360. strbFilterExpressions.Append("(1=1");
  361. if (!string.IsNullOrEmpty(this.txtDefectFineCode.Text))
  362. {
  363. // 工种编码条件
  364. strbFilterExpressions.Append(string.Format(" AND DefectFineCode LIKE '%{0}%'",
  365. Utility.SelectFilterLike(this.txtDefectFineCode.Text.Trim())));
  366. }
  367. strbFilterExpressions.Append(")");
  368. return strbFilterExpressions.ToString();
  369. }
  370. #endregion
  371. private void btnClearCondition_Click(object sender, EventArgs e)
  372. {
  373. this.txtDefectFineCode.Clear();
  374. }
  375. }
  376. }