S_CMN_014.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_014.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. using Dongke.IBOSS.PRD.WCF.Proxys;
  20. namespace Dongke.IBOSS.PRD.Client.Controls
  21. {
  22. /// <summary>
  23. /// 缺陷控件查询界面
  24. /// </summary>
  25. public partial class S_CMN_014 : FormBase
  26. {
  27. #region 成员变量
  28. private DataTable _dataSource; // 画面的数据源
  29. #endregion
  30. #region 属性
  31. /// <summary>
  32. /// 选择的数据
  33. /// </summary>
  34. public DataTable SelTable { get; set; }
  35. /// <summary>
  36. /// 传入的缺陷编码
  37. /// </summary>
  38. public string SetDefectCode { get; set; }
  39. #endregion
  40. #region 构造函数
  41. /// <summary>
  42. /// 重载的构造函数
  43. /// </summary>
  44. public S_CMN_014()
  45. {
  46. InitializeComponent();
  47. // 按钮
  48. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  49. this.btnOK.Text = ButtonText.BTN_OK;
  50. this.btnClose.Text = ButtonText.BTN_CANCEL;
  51. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  52. }
  53. #endregion
  54. #region 属性
  55. /// <summary>
  56. /// 获取或者设定画面的数据源。
  57. /// </summary>
  58. [Description("获取或者设定画面的数据源。")]
  59. public new DataTable DataSource
  60. {
  61. get
  62. {
  63. return _dataSource;
  64. }
  65. set
  66. {
  67. _dataSource = value;
  68. }
  69. }
  70. #endregion
  71. #region 控件事件
  72. /// <summary>
  73. /// 窗体加载
  74. /// </summary>
  75. /// <param name="sender"></param>
  76. /// <param name="e"></param>
  77. private void S_CMN_003_Load(object sender, EventArgs e)
  78. {
  79. try
  80. {
  81. // 绑定缺陷类型数据
  82. DataSet dsResultAccount = SystemModuleProxy.Service.GetAllDefectTypeInfo();
  83. DataView dv = dsResultAccount.Tables[0].DefaultView;
  84. dv.RowFilter = "valueflag=1";
  85. DataTable dtDefectType = dv.ToTable();
  86. DataRow nullrow = dtDefectType.NewRow();
  87. //nullrow["DefectTypeID"] = DBNull.Value;
  88. //nullrow["DefectTypeName"] = DBNull.Value;
  89. dtDefectType.Rows.InsertAt(nullrow, 0);
  90. this.cboDEFECTTYPENAME.ValueMember = "DefectTypeID";
  91. this.cboDEFECTTYPENAME.DisplayMember = "DefectTypeName";
  92. this.cboDEFECTTYPENAME.DataSource = dtDefectType;
  93. this.dgvDefect.AutoGenerateColumns = false;
  94. this.txtDefectCode.Text = SetDefectCode;
  95. if (!string.IsNullOrEmpty(this.txtDefectCode.Text))
  96. {
  97. Search();
  98. }
  99. }
  100. catch (Exception ex)
  101. {
  102. // 对异常进行共通处理
  103. ExceptionManager.HandleEventException(this.ToString(),
  104. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  105. }
  106. }
  107. /// <summary>
  108. /// 查询按钮按下事件
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void btnSearch_Click(object sender, System.EventArgs e)
  113. {
  114. try
  115. {
  116. Search();
  117. }
  118. catch (Exception ex)
  119. {
  120. // 对异常进行共通处理
  121. ExceptionManager.HandleEventException(this.ToString(),
  122. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  123. }
  124. }
  125. /// <summary>
  126. /// KeyDown事件
  127. /// </summary>
  128. /// <param name="sender"></param>
  129. /// <param name="e"></param>
  130. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  131. {
  132. try
  133. {
  134. // 拷贝单元格文本到剪切板
  135. if (e.KeyData == (Keys.Control | Keys.C))
  136. {
  137. if (dgvDefect.CurrentRow != null
  138. && !string.IsNullOrEmpty(dgvDefect.CurrentRow.Cells[dgvDefect.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  139. {
  140. Clipboard.SetText(dgvDefect.CurrentRow.Cells[dgvDefect.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  141. }
  142. }
  143. else if (e.KeyData == Keys.Enter)
  144. {
  145. Commit();
  146. }
  147. }
  148. catch (Exception ex)
  149. {
  150. // 对异常进行共通处理
  151. ExceptionManager.HandleEventException(this.ToString(),
  152. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  153. }
  154. }
  155. /// <summary>
  156. /// 确定按钮按下事件
  157. /// </summary>
  158. /// <param name="sender"></param>
  159. /// <param name="e"></param>
  160. private void btnOK_Click(object sender, System.EventArgs e)
  161. {
  162. try
  163. {
  164. Commit();
  165. }
  166. catch (Exception ex)
  167. {
  168. // 对异常进行共通处理
  169. ExceptionManager.HandleEventException(this.ToString(),
  170. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  171. }
  172. }
  173. /// <summary>
  174. /// 关闭按钮按下事件
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void btnClose_Click(object sender, System.EventArgs e)
  179. {
  180. this.DialogResult = DialogResult.Cancel;
  181. this.Close();
  182. }
  183. /// <summary>
  184. /// 双击DataGridView窗体,返回选中记录
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  189. {
  190. try
  191. {
  192. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  193. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  194. {
  195. Commit();
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. // 对异常进行共通处理
  201. ExceptionManager.HandleEventException(this.ToString(),
  202. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  203. }
  204. }
  205. /// <summary>
  206. /// 全选
  207. /// </summary>
  208. /// <param name="sender"></param>
  209. /// <param name="e"></param>
  210. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  211. {
  212. try
  213. {
  214. for (int i = 0; i < this.dgvDefect.Rows.Count; i++)
  215. {
  216. this.dgvDefect.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  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.dgvDefect.DataSource = null;
  235. if (_dataSource == null)
  236. {
  237. DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  238. {
  239. return SystemModuleProxy.Service.GetDefectData(1);
  240. }));
  241. if (defectds != null
  242. && defectds.Tables.Count > Constant.INT_IS_ZERO
  243. && defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  244. {
  245. defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
  246. _dataSource = defectds.Tables[0].DefaultView.ToTable();
  247. }
  248. }
  249. if (_dataSource != null)
  250. {
  251. _dataSource.DefaultView.RowFilter = GetFilterExpression();
  252. this.dgvDefect.DataSource = _dataSource.DefaultView.ToTable();
  253. this.dgvDefect.Focus();
  254. }
  255. // 当没有查询结果时,提示无查询结构消息
  256. if (this.dgvDefect.RowCount <= 0)
  257. {
  258. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  259. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  260. this.txtDefectCode.Focus();
  261. this.btnOK.Enabled = false;
  262. return;
  263. }
  264. this.btnOK.Enabled = true;
  265. }
  266. /// <summary>
  267. /// 提交时给取得的行赋值
  268. /// </summary>
  269. private void Commit()
  270. {
  271. try
  272. {
  273. DataTable invDt = (DataTable)this.dgvDefect.DataSource;
  274. if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO)
  275. {
  276. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  277. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  278. return;
  279. }
  280. invDt.AcceptChanges();
  281. invDt = invDt.Copy();
  282. string filter = "Sel = 1";
  283. invDt.DefaultView.RowFilter = filter;
  284. invDt = invDt.DefaultView.ToTable();
  285. // 如果选中了数据就关闭窗体,反之则不关
  286. if (invDt.Rows.Count > 0)
  287. {
  288. SelTable = invDt;
  289. this.DialogResult = DialogResult.OK;
  290. this.Close();
  291. }
  292. else
  293. {
  294. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  295. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  296. }
  297. }
  298. catch (Exception ex)
  299. {
  300. throw ex;
  301. }
  302. }
  303. /// <summary>
  304. /// 根据画面输入内容拼接过滤条件
  305. /// </summary>
  306. /// <returns></returns>
  307. private string GetFilterExpression()
  308. {
  309. StringBuilder strbFilterExpressions = new StringBuilder();
  310. strbFilterExpressions.Append("(1=1");
  311. if (!string.IsNullOrEmpty(this.txtDefectCode.Text))
  312. {
  313. // 缺陷编码条件
  314. strbFilterExpressions.Append(string.Format(" AND DefectCode LIKE '%{0}%'",
  315. Utility.SelectFilterLike(this.txtDefectCode.Text.Trim())));
  316. }
  317. if (!string.IsNullOrEmpty(this.txtDefectName.Text))
  318. {
  319. // 缺陷名称条件
  320. strbFilterExpressions.Append(string.Format(" AND DefectName LIKE '%{0}%'",
  321. Utility.SelectFilterLike(this.txtDefectName.Text.Trim())));
  322. }
  323. if (!string.IsNullOrEmpty(this.cboDEFECTTYPENAME.Text))
  324. {
  325. // 缺陷名称条件
  326. strbFilterExpressions.Append(string.Format(" AND DEFECTTYPEID = {0}",
  327. this.cboDEFECTTYPENAME.SelectedValue));
  328. }
  329. if (!string.IsNullOrWhiteSpace(this.txtREMARKS.Text))
  330. {
  331. // 缺陷名称条件
  332. strbFilterExpressions.Append(string.Format(" AND REMARKS LIKE '%{0}%'",
  333. Utility.SelectFilterLike(this.txtREMARKS.Text.Trim())));
  334. }
  335. strbFilterExpressions.Append(")");
  336. return strbFilterExpressions.ToString();
  337. }
  338. #endregion
  339. private void btnClearCondition_Click(object sender, EventArgs e)
  340. {
  341. this.txtDefectCode.Clear();
  342. this.txtDefectName.Clear();
  343. this.txtREMARKS.Clear();
  344. this.cboDEFECTTYPENAME.SelectedIndex = -1;
  345. }
  346. }
  347. }