S_CMN_002.cs 12 KB

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