S_CMN_008.cs 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_008.cs
  5. * 2.功能描述:工程选择列表页面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 冯雪 2014/09/16 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.FormCommon
  21. {
  22. /// <summary>
  23. /// 工种选择列表页面
  24. /// </summary>
  25. public partial class S_CMN_008 : FormBase
  26. {
  27. #region 成员变量
  28. private DataTable _dataSource; // 画面的数据源
  29. private DataRow _jobsRow; // 返回用户的DataRow
  30. #endregion
  31. # region 构造函数
  32. /// <summary>
  33. /// 构造函数
  34. /// </summary>
  35. public S_CMN_008()
  36. : this("")
  37. {
  38. }
  39. /// <summary>
  40. /// 重载的构造函数
  41. /// </summary>
  42. /// <param name="jobsName">工种名称</param>
  43. public S_CMN_008(string jobsName)
  44. {
  45. InitializeComponent();
  46. this.txtJobsName.Text = jobsName;
  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. /// <summary>
  71. /// 返回选择的行
  72. /// </summary>
  73. public DataRow JobsRow
  74. {
  75. get
  76. {
  77. return _jobsRow;
  78. }
  79. set
  80. {
  81. _jobsRow = value;
  82. }
  83. }
  84. /// <summary>
  85. /// 工种编码
  86. /// </summary>
  87. public string SetJobsCode { get; set; }
  88. #endregion
  89. #region 私有方法
  90. /// <summary>
  91. /// 查询方法
  92. /// </summary>
  93. private void Search()
  94. {
  95. // 清空之前的查询结果
  96. this.dgvJobs.DataSource = null;
  97. // 根据查询条件查询数据源中的数据,并显示
  98. if (this.DataSource == null)
  99. {
  100. DataSet ds = SystemModuleProxy.Service.GetJobsData(0);
  101. if (ds != null && ds.Tables.Count > Constant.INT_IS_ZERO)
  102. {
  103. this.DataSource = ds.Tables[0];
  104. }
  105. else
  106. {
  107. this.DataSource = new DataTable("new");
  108. }
  109. }
  110. DataTable userTable = this.DataSource.Copy();
  111. userTable.DefaultView.RowFilter = GetFilterExpression();
  112. this.dgvJobs.DataSource = userTable.DefaultView.ToTable();
  113. this.dgvJobs.Focus();
  114. // 当没有查询结果时,提示无查询结构消息
  115. if (this.dgvJobs.RowCount <= 0)
  116. {
  117. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  118. this.Text,MessageBoxButtons.OK,MessageBoxIcon.Warning);
  119. this.txtJobsCode.Focus();
  120. this.btnOK.Enabled = false;
  121. return;
  122. }
  123. this.btnOK.Enabled = true;
  124. }
  125. /// <summary>
  126. /// 根据画面输入内容拼接过滤条件
  127. /// </summary>
  128. /// <returns></returns>
  129. private string GetFilterExpression()
  130. {
  131. StringBuilder strbFilterExpressions = new StringBuilder();
  132. strbFilterExpressions.Append("(1=1");
  133. if (!string.IsNullOrEmpty(this.txtJobsCode.Text))
  134. {
  135. // 工种编码条件
  136. strbFilterExpressions.Append(string.Format(" AND JobsCode LIKE '%{0}%'",
  137. Utility.SelectFilterLike(this.txtJobsCode.Text.Trim())));
  138. }
  139. if (!string.IsNullOrEmpty(this.txtJobsName.Text))
  140. {
  141. // 工种名称条件
  142. strbFilterExpressions.Append(string.Format(" AND JobsName LIKE '%{0}%'",
  143. Utility.SelectFilterLike(this.txtJobsName.Text.Trim())));
  144. }
  145. strbFilterExpressions.Append(")");
  146. return strbFilterExpressions.ToString();
  147. }
  148. /// <summary>
  149. /// 提交时给取得的行赋值
  150. /// </summary>
  151. private void Commit()
  152. {
  153. if (this.dgvJobs.CurrentCell != null)
  154. {
  155. this.JobsRow = this.dgvJobs.GetDataRow(this.dgvJobs.CurrentCell.RowIndex);
  156. this.DialogResult = DialogResult.OK;
  157. this.Close();
  158. }
  159. }
  160. #endregion
  161. #region 事件方法
  162. /// <summary>
  163. /// 页面加载事件
  164. /// </summary>
  165. /// <param name="sender"></param>
  166. /// <param name="e"></param>
  167. private void S_CMN_008_Load(object sender, EventArgs e)
  168. {
  169. try
  170. {
  171. this.dgvJobs.AutoGenerateColumns = false;
  172. this.txtJobsCode.Text = this.SetJobsCode;
  173. if (!string.IsNullOrEmpty(this.txtJobsName.Text)
  174. || !string.IsNullOrEmpty(this.txtJobsCode.Text))
  175. {
  176. Search();
  177. }
  178. }
  179. catch (Exception ex)
  180. {
  181. // 对异常进行共通处理
  182. ExceptionManager.HandleEventException(this.ToString(),
  183. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  184. }
  185. }
  186. /// <summary>
  187. /// 查询按钮按下事件
  188. /// </summary>
  189. /// <param name="sender"></param>
  190. /// <param name="e"></param>
  191. private void btnSearch_Click(object sender, EventArgs e)
  192. {
  193. try
  194. {
  195. Search();
  196. }
  197. catch (Exception ex)
  198. {
  199. // 对异常进行共通处理
  200. ExceptionManager.HandleEventException(this.ToString(),
  201. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  202. }
  203. }
  204. /// <summary>
  205. /// 确定按钮按下事件
  206. /// </summary>
  207. /// <param name="sender"></param>
  208. /// <param name="e"></param>
  209. private void btnOK_Click(object sender, EventArgs e)
  210. {
  211. try
  212. {
  213. Commit();
  214. }
  215. catch (Exception ex)
  216. {
  217. // 对异常进行共通处理
  218. ExceptionManager.HandleEventException(this.ToString(),
  219. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  220. }
  221. }
  222. /// <summary>
  223. /// 关闭按钮按下事件
  224. /// </summary>
  225. /// <param name="sender"></param>
  226. /// <param name="e"></param>
  227. private void btnClose_Click(object sender, EventArgs e)
  228. {
  229. this.DialogResult = DialogResult.Cancel;
  230. this.Close();
  231. }
  232. /// <summary>
  233. /// KeyDown事件
  234. /// </summary>
  235. /// <param name="sender"></param>
  236. /// <param name="e"></param>
  237. private void dgvJobs_KeyDown(object sender, KeyEventArgs e)
  238. {
  239. try
  240. {
  241. // 拷贝单元格文本到剪切板
  242. if (e.KeyData == (Keys.Control | Keys.C))
  243. {
  244. if (dgvJobs.CurrentRow != null
  245. && !string.IsNullOrEmpty(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  246. {
  247. Clipboard.SetText(dgvJobs.CurrentRow.Cells[dgvJobs.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  248. }
  249. }
  250. else if (e.KeyData == Keys.Enter)
  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. /// 双击DataGridView窗体,返回选中记录
  264. /// </summary>
  265. /// <param name="sender"></param>
  266. /// <param name="e"></param>
  267. private void dgvJobs_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  268. {
  269. try
  270. {
  271. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  272. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  273. {
  274. Commit();
  275. }
  276. }
  277. catch (Exception ex)
  278. {
  279. // 对异常进行共通处理
  280. ExceptionManager.HandleEventException(this.ToString(),
  281. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  282. }
  283. }
  284. #endregion
  285. private void btnClearCondition_Click(object sender, EventArgs e)
  286. {
  287. this.txtJobsCode.Clear();
  288. this.txtJobsName.Clear();
  289. }
  290. }
  291. }