S_CMN_018.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. /// <summary>
  23. /// 工种控件查询界面
  24. /// </summary>
  25. public partial class S_CMN_018 : FormBase
  26. {
  27. #region 成员变量
  28. private DataTable _dataSource; // 画面的数据源
  29. #endregion
  30. #region 构造函数
  31. /// <summary>
  32. /// 重载的构造函数
  33. /// </summary>
  34. public S_CMN_018()
  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. #endregion
  44. #region 属性
  45. /// <summary>
  46. /// 选择的数据
  47. /// </summary>
  48. public DataTable SelTable { get; set; }
  49. /// <summary>
  50. /// 传入的工种编码
  51. /// </summary>
  52. public string SetJobsCode { get; set; }
  53. /// <summary>
  54. /// 获取或者设定画面的数据源。
  55. /// </summary>
  56. [Description("获取或者设定画面的数据源。")]
  57. public new DataTable DataSource
  58. {
  59. get
  60. {
  61. return _dataSource;
  62. }
  63. set
  64. {
  65. _dataSource = value;
  66. }
  67. }
  68. #endregion
  69. #region 控件事件
  70. /// <summary>
  71. /// 窗体加载
  72. /// </summary>
  73. /// <param name="sender"></param>
  74. /// <param name="e"></param>
  75. private void S_CMN_018_Load(object sender, EventArgs e)
  76. {
  77. try
  78. {
  79. this.dgvJobs.AutoGenerateColumns = false;
  80. this.txtJobsCode.Text = SetJobsCode;
  81. if (!string.IsNullOrEmpty(this.txtJobsCode.Text))
  82. {
  83. Search();
  84. }
  85. }
  86. catch (Exception ex)
  87. {
  88. // 对异常进行共通处理
  89. ExceptionManager.HandleEventException(this.ToString(),
  90. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  91. }
  92. }
  93. /// <summary>
  94. /// 查询按钮按下事件
  95. /// </summary>
  96. /// <param name="sender"></param>
  97. /// <param name="e"></param>
  98. private void btnSearch_Click(object sender, System.EventArgs e)
  99. {
  100. try
  101. {
  102. Search();
  103. }
  104. catch (Exception ex)
  105. {
  106. // 对异常进行共通处理
  107. ExceptionManager.HandleEventException(this.ToString(),
  108. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  109. }
  110. }
  111. /// <summary>
  112. /// KeyDown事件
  113. /// </summary>
  114. /// <param name="sender"></param>
  115. /// <param name="e"></param>
  116. private void dgvOrganization_KeyDown(object sender, KeyEventArgs e)
  117. {
  118. try
  119. {
  120. // 拷贝单元格文本到剪切板
  121. if (e.KeyData == (Keys.Control | Keys.C))
  122. {
  123. if (dgvJobs.CurrentRow != null
  124. && !string.IsNullOrEmpty(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  125. {
  126. Clipboard.SetText(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  127. }
  128. }
  129. else if (e.KeyData == Keys.Enter)
  130. {
  131. Commit();
  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 btnOK_Click(object sender, System.EventArgs e)
  147. {
  148. try
  149. {
  150. Commit();
  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 btnClose_Click(object sender, System.EventArgs e)
  165. {
  166. this.DialogResult = DialogResult.Cancel;
  167. this.Close();
  168. }
  169. /// <summary>
  170. /// 双击DataGridView窗体,返回选中记录
  171. /// </summary>
  172. /// <param name="sender"></param>
  173. /// <param name="e"></param>
  174. private void dgvOrganization_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  175. {
  176. try
  177. {
  178. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  179. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  180. {
  181. Commit();
  182. }
  183. }
  184. catch (Exception ex)
  185. {
  186. // 对异常进行共通处理
  187. ExceptionManager.HandleEventException(this.ToString(),
  188. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  189. }
  190. }
  191. /// <summary>
  192. /// 全选
  193. /// </summary>
  194. /// <param name="sender"></param>
  195. /// <param name="e"></param>
  196. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  197. {
  198. try
  199. {
  200. for (int i = 0; i < this.dgvJobs.Rows.Count; i++)
  201. {
  202. this.dgvJobs.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  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. #endregion
  213. #region 私有方法
  214. /// <summary>
  215. /// 查询方法
  216. /// </summary>
  217. private void Search()
  218. {
  219. // 清空之前的查询结果
  220. this.dgvJobs.DataSource = null;
  221. if (_dataSource == null)
  222. {
  223. DataSet defectds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  224. {
  225. return SystemModuleProxy.Service.GetJobsData(1);
  226. }));
  227. if (defectds != null
  228. && defectds.Tables.Count > Constant.INT_IS_ZERO
  229. && defectds.Tables[0].Rows.Count > Constant.INT_IS_ZERO)
  230. {
  231. defectds.Tables[0].DefaultView.RowFilter = "valueflag =1";
  232. _dataSource = defectds.Tables[0].DefaultView.ToTable();
  233. }
  234. }
  235. if (_dataSource != null)
  236. {
  237. _dataSource.DefaultView.RowFilter = GetFilterExpression();
  238. this.dgvJobs.DataSource = _dataSource.DefaultView.ToTable();
  239. this.dgvJobs.Focus();
  240. }
  241. // 当没有查询结果时,提示无查询结构消息
  242. if (this.dgvJobs.RowCount <= 0)
  243. {
  244. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  245. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  246. this.txtJobsCode.Focus();
  247. this.btnOK.Enabled = false;
  248. return;
  249. }
  250. this.btnOK.Enabled = true;
  251. }
  252. /// <summary>
  253. /// 提交时给取得的行赋值
  254. /// </summary>
  255. private void Commit()
  256. {
  257. try
  258. {
  259. DataTable invDt = (DataTable)this.dgvJobs.DataSource;
  260. if (invDt == null || invDt.Rows.Count == Constant.INT_IS_ZERO)
  261. {
  262. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  263. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  264. return;
  265. }
  266. invDt.AcceptChanges();
  267. invDt = invDt.Copy();
  268. string filter = "Sel = 1";
  269. invDt.DefaultView.RowFilter = filter;
  270. invDt = invDt.DefaultView.ToTable();
  271. // 如果选中了数据就关闭窗体,反之则不关
  272. if (invDt.Rows.Count > 0)
  273. {
  274. SelTable = invDt;
  275. this.DialogResult = DialogResult.OK;
  276. this.Close();
  277. }
  278. else
  279. {
  280. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  281. "没有选择数据"),this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  282. }
  283. }
  284. catch (Exception ex)
  285. {
  286. throw ex;
  287. }
  288. }
  289. /// <summary>
  290. /// 根据画面输入内容拼接过滤条件
  291. /// </summary>
  292. /// <returns></returns>
  293. private string GetFilterExpression()
  294. {
  295. StringBuilder strbFilterExpressions = new StringBuilder();
  296. strbFilterExpressions.Append("(1=1");
  297. if (!string.IsNullOrEmpty(this.txtJobsCode.Text))
  298. {
  299. // 工种编码条件
  300. strbFilterExpressions.Append(string.Format(" AND JobsCode LIKE '%{0}%'",
  301. Utility.SelectFilterLike(this.txtJobsCode.Text.Trim())));
  302. }
  303. if (!string.IsNullOrEmpty(this.txtJobsName.Text))
  304. {
  305. // 工种名称条件
  306. strbFilterExpressions.Append(string.Format(" AND JobsName LIKE '%{0}%'",
  307. Utility.SelectFilterLike(this.txtJobsName.Text.Trim())));
  308. }
  309. strbFilterExpressions.Append(")");
  310. return strbFilterExpressions.ToString();
  311. }
  312. #endregion
  313. private void btnClearCondition_Click(object sender, EventArgs e)
  314. {
  315. this.txtJobsCode.Clear();
  316. this.txtJobsName.Clear();
  317. }
  318. }
  319. }