S_CMN_006.cs 11 KB

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