S_CMN_028.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /*******************************************************************************
  2. * Copyright(c) 2017 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:S_CMN_028.cs
  5. * 2.功能描述:图标控件查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 王鑫 2017/02/08 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. namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
  20. {
  21. public partial class S_CMN_028 : FormBase
  22. {
  23. #region 成员变量
  24. private DataTable _dataSource; // 画面的数据源
  25. private DataRow _productionLineRow; // 返回类别的DataRow
  26. private DataTable _dataDT; //返回选择数据源
  27. #endregion
  28. #region 构造函数
  29. /// <summary>
  30. /// 构造函数
  31. /// </summary>
  32. /// <param name="flag">多选标记</param>
  33. public S_CMN_028(int flag)
  34. {
  35. InitializeComponent();
  36. if (flag == 1)
  37. {
  38. this.Sel.Visible = true;
  39. this.chkChooseAll.Visible = true;
  40. }
  41. else
  42. {
  43. this.Sel.Visible = false;
  44. this.chkChooseAll.Visible = false;
  45. }
  46. // 按钮
  47. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  48. this.btnOK.Text = ButtonText.BTN_OK;
  49. this.btnClose.Text = ButtonText.BTN_CANCEL;
  50. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  51. }
  52. #endregion
  53. #region 属性
  54. /// <summary>
  55. /// 获取或者设定画面的数据源。
  56. /// </summary>
  57. [Description("获取或者设定画面的数据源。")]
  58. public new DataTable DataSource
  59. {
  60. get
  61. {
  62. return _dataSource;
  63. }
  64. set
  65. {
  66. _dataSource = value;
  67. }
  68. }
  69. /// <summary>
  70. /// 传入的工种编码
  71. /// </summary>
  72. public string SetJobsCode
  73. {
  74. get;
  75. set;
  76. }
  77. /// <summary>
  78. /// 选择的数据
  79. /// </summary>
  80. public DataTable SelTable
  81. {
  82. get;
  83. set;
  84. }
  85. /// <summary>
  86. /// 返回选择的组织行
  87. /// </summary>
  88. public DataRow ProductionLineRow
  89. {
  90. get
  91. {
  92. return _productionLineRow;
  93. }
  94. set
  95. {
  96. _productionLineRow = value;
  97. }
  98. }
  99. /// <summary>
  100. /// 返回选择的组织多行
  101. /// </summary>
  102. public DataTable dataDT
  103. {
  104. get
  105. {
  106. return _dataDT;
  107. }
  108. set
  109. {
  110. _dataDT = value;
  111. }
  112. }
  113. #endregion
  114. #region 事件
  115. /// <summary>
  116. /// 窗体加载
  117. /// </summary>
  118. /// <param name="sender"></param>
  119. /// <param name="e"></param>
  120. private void S_CMN_028_Load(object sender, EventArgs e)
  121. {
  122. try
  123. {
  124. this.dgvLogo.AutoGenerateColumns = false;
  125. this.txtLogoCode.Text = SetJobsCode;
  126. if (!string.IsNullOrEmpty(this.txtLogoCode.Text))
  127. {
  128. Search();
  129. }
  130. }
  131. catch (Exception ex)
  132. {
  133. // 对异常进行共通处理
  134. ExceptionManager.HandleEventException(this.ToString(),
  135. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  136. }
  137. }
  138. /// <summary>
  139. /// 查询按钮按下事件
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void btnSearch_Click(object sender, EventArgs e)
  144. {
  145. try
  146. {
  147. Search();
  148. }
  149. catch (Exception ex)
  150. {
  151. // 对异常进行共通处理
  152. ExceptionManager.HandleEventException(this.ToString(),
  153. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  154. }
  155. }
  156. /// <summary>
  157. /// 确定按钮按下事件
  158. /// </summary>
  159. /// <param name="sender"></param>
  160. /// <param name="e"></param>
  161. private void btnOK_Click(object sender, EventArgs e)
  162. {
  163. try
  164. {
  165. Commit();
  166. }
  167. catch (Exception ex)
  168. {
  169. // 对异常进行共通处理
  170. ExceptionManager.HandleEventException(this.ToString(),
  171. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  172. }
  173. }
  174. /// <summary>
  175. /// 关闭按钮按下事件
  176. /// </summary>
  177. /// <param name="sender"></param>
  178. /// <param name="e"></param>
  179. private void btnClose_Click(object sender, EventArgs e)
  180. {
  181. this.DialogResult = DialogResult.Cancel;
  182. this.Close();
  183. }
  184. /// <summary>
  185. /// KeyDown事件
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void dgvProductionLine_KeyDown(object sender, KeyEventArgs e)
  190. {
  191. try
  192. {
  193. // 拷贝单元格文本到剪切板
  194. if (e.KeyData == (Keys.Control | Keys.C))
  195. {
  196. if (this.dgvLogo.CurrentRow != null
  197. && !string.IsNullOrEmpty(dgvLogo.CurrentRow.Cells[dgvLogo.CurrentCell.ColumnIndex].EditedFormattedValue + ""))
  198. {
  199. Clipboard.SetText(dgvLogo.CurrentRow.Cells[dgvLogo.CurrentCell.ColumnIndex].EditedFormattedValue + "");
  200. }
  201. }
  202. else if (e.KeyData == Keys.Enter)
  203. {
  204. Commit();
  205. }
  206. }
  207. catch (Exception ex)
  208. {
  209. // 对异常进行共通处理
  210. ExceptionManager.HandleEventException(this.ToString(),
  211. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  212. }
  213. }
  214. /// <summary>
  215. /// 双击DataGridView窗体,返回选中记录
  216. /// </summary>
  217. /// <param name="sender"></param>
  218. /// <param name="e"></param>
  219. private void dgvProductionLine_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
  220. {
  221. try
  222. {
  223. // 判断是否是双击列头,如果是双击列头的话,不做任何操作
  224. if (-1 < e.RowIndex && -1 < e.ColumnIndex)
  225. {
  226. //判断有没有复选框,如果有不做任何操作
  227. if (!this.Sel.Visible)
  228. {
  229. Commit();
  230. }
  231. }
  232. }
  233. catch (Exception ex)
  234. {
  235. // 对异常进行共通处理
  236. ExceptionManager.HandleEventException(this.ToString(),
  237. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  238. }
  239. }
  240. #endregion
  241. #region 私有方法
  242. /// <summary>
  243. /// 查询方法
  244. /// </summary>
  245. private void Search()
  246. {
  247. // 清空之前的查询结果
  248. this.dgvLogo.DataSource = null;
  249. // 根据查询条件查询数据源中的数据,并显示
  250. DataTable ProductionLineTable = this.DataSource.Copy();
  251. ProductionLineTable.DefaultView.RowFilter = GetFilterExpression();
  252. this.dgvLogo.DataSource = ProductionLineTable.DefaultView.ToTable();
  253. this.dgvLogo.Focus();
  254. // 当没有查询结果时,提示无查询结构消息
  255. if (this.dgvLogo.RowCount <= 0)
  256. {
  257. MessageBox.Show(ControlsTips.DK_SearchBox_NoResult,
  258. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  259. this.txtLogoName.Focus();
  260. this.btnOK.Enabled = false;
  261. return;
  262. }
  263. this.btnOK.Enabled = true;
  264. }
  265. /// <summary>
  266. /// 提交时给取得的行赋值
  267. /// </summary>
  268. private void Commit()
  269. {
  270. if (this.Sel.Visible)
  271. {
  272. if (this.dgvLogo.CurrentCell != null)
  273. {
  274. this.dataDT = (DataTable)this.dgvLogo.DataSource;
  275. this.DialogResult = DialogResult.OK;
  276. }
  277. }
  278. else
  279. {
  280. if (this.dgvLogo.CurrentCell != null)
  281. {
  282. ProductionLineRow = this.dgvLogo.GetDataRow(this.dgvLogo.CurrentCell.RowIndex);
  283. this.DialogResult = DialogResult.OK;
  284. }
  285. }
  286. this.Close();
  287. }
  288. /// <summary>
  289. /// 根据画面输入内容拼接过滤条件
  290. /// </summary>
  291. /// <returns></returns>
  292. private string GetFilterExpression()
  293. {
  294. StringBuilder strbFilterExpressions = new StringBuilder();
  295. strbFilterExpressions.Append("(1=1");
  296. if (!string.IsNullOrEmpty(this.txtLogoCode.Text))
  297. {
  298. // 产品类别编码条件
  299. strbFilterExpressions.Append(string.Format(" AND LogoCode LIKE '%{0}%'",
  300. Utility.SelectFilterLike(this.txtLogoCode.Text.Trim())));
  301. }
  302. if (!string.IsNullOrEmpty(this.txtLogoName.Text))
  303. {
  304. // 产品类别名称条件
  305. strbFilterExpressions.Append(string.Format(" AND LogoName LIKE '%{0}%'",
  306. Utility.SelectFilterLike(this.txtLogoName.Text.Trim())));
  307. }
  308. strbFilterExpressions.Append(")");
  309. return strbFilterExpressions.ToString();
  310. }
  311. #endregion
  312. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  313. {
  314. for (int i = 0; i < this.dgvLogo.Rows.Count; i++)
  315. {
  316. this.dgvLogo.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  317. }
  318. }
  319. private void btnClearCondition_Click(object sender, EventArgs e)
  320. {
  321. this.txtLogoCode.Clear();
  322. this.txtLogoName.Clear();
  323. }
  324. }
  325. }