F_SelectGoods.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. /*******************************************************************************
  2. * Copyright(c) 2012 dongke All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_SelectGoods.cs
  5. * 2.功能描述:产品查询界面
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈冰 2014/09/15 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Data;
  12. using System.Windows.Forms;
  13. using Dongke.IBOSS.PRD.Basics.BaseControls;
  14. using Dongke.IBOSS.PRD.Basics.BaseResources;
  15. using Dongke.IBOSS.PRD.Client.CommonModule;
  16. using Dongke.IBOSS.PRD.WCF.DataModels;
  17. using Dongke.IBOSS.PRD.WCF.Proxys;
  18. using Dongke.IBOSS.PRD.WCF.Proxys.SystemModuleService;
  19. namespace Dongke.IBOSS.PRD.Client.Controls.FormCommon
  20. {
  21. /// <summary>
  22. /// 产品查询界面
  23. /// </summary>
  24. public partial class F_SelectGoods : FormBase
  25. {
  26. #region 构造函数
  27. public F_SelectGoods()
  28. {
  29. InitializeComponent();
  30. this.btnOK.Text = ButtonText.BTN_OK;
  31. this.btnClose.Text = ButtonText.BTN_CANCEL;
  32. this.btnSearch.Text = ButtonText.BTN_SEARCH;
  33. this.btnClearCondition.Text = ButtonText.BTN_CLEARCONDITION;
  34. this.gbxCondition.Text = Constant.LABEL_QUERY_CONDITIONS;
  35. }
  36. #endregion
  37. #region 属性
  38. /// <summary>
  39. /// 选择的数据
  40. /// </summary>
  41. public DataTable SelTable { get; set; }
  42. /// <summary>
  43. /// 转入的产品编码
  44. /// </summary>
  45. public string SetGoodsCode { get; set; }
  46. #endregion
  47. #region 事件
  48. /// <summary>
  49. /// 页面加载
  50. /// </summary>
  51. /// <param name="sender"></param>
  52. /// <param name="e"></param>
  53. private void SelectProduct_Load(object sender, EventArgs e)
  54. {
  55. try
  56. {
  57. // 设置表格不自动创建列
  58. this.dgvGoods.AutoGenerateColumns = false;
  59. // 加载页面所需的数据源
  60. LoadDataSource();
  61. this.txtGoodsCode.Text = this.SetGoodsCode;
  62. btnSearch_Click(null, null);
  63. // 编辑单元格的颜色
  64. this.dgvGoods.IsSetInputColumnsColor = true;
  65. }
  66. catch (Exception ex)
  67. {
  68. // 对异常进行共通处理
  69. ExceptionManager.HandleEventException(this.ToString(),
  70. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  71. }
  72. }
  73. /// <summary>
  74. /// 查询
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. private void btnSearch_Click(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. GoodsEntity goods = new GoodsEntity();
  83. goods.CeaseFlag = 1;
  84. goods.ValueFlag = 1;
  85. if (!string.IsNullOrEmpty(this.txtGoodsCode.Text.Trim()))
  86. {
  87. goods.GoodsCode = this.txtGoodsCode.Text.Trim();
  88. }
  89. if (!string.IsNullOrEmpty(this.txtGoodsName.Text.Trim()))
  90. {
  91. goods.GoodsName = this.txtGoodsName.Text.Trim();
  92. }
  93. if (!string.IsNullOrEmpty(this.txtGoodsSpecification.Text.Trim()))
  94. {
  95. goods.GoodsSpecification = this.txtGoodsSpecification.Text.Trim();
  96. }
  97. if (!string.IsNullOrEmpty(scbGoodsType.SearchedValue + ""))
  98. {
  99. goods.GoodsTypeCode = scbGoodsType.SearchedValue + "";
  100. }
  101. if (!string.IsNullOrEmpty(this.txtGoodsModel.Text.Trim()))
  102. {
  103. goods.GoodsModel = this.txtGoodsModel.Text.Trim();
  104. }
  105. if (this.ddlGlazeTypeID.SelectedValue != null && this.ddlGlazeTypeID.SelectedValue + "" != "")
  106. {
  107. goods.GlazeTypeID = Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
  108. }
  109. // 查询
  110. DataSet ds = (DataSet)DoAsync(new BaseAsyncMethod(() =>
  111. {
  112. return SystemModuleProxy.Service.SerachGoods(goods);
  113. }));
  114. if (ds != null
  115. && ds.Tables.Count > 0
  116. && ds.Tables[0].Rows.Count > 0)
  117. {
  118. this.dgvGoods.DataSource = ds.Tables[0];
  119. // 取消全选
  120. this.chkChooseAll.Checked = false;
  121. this.dgvGoods.CurrentCell = this.dgvGoods.Rows[0].Cells["Sel"];
  122. this.dgvGoods.Columns["Sel"].ReadOnly = false;
  123. }
  124. else
  125. {
  126. // 清空数据
  127. this.dgvGoods.DataSource = null;
  128. // 提示未查找到数据
  129. MessageBox.Show(Messages.MSG_CMN_I002, this.Text,
  130. MessageBoxButtons.OK, MessageBoxIcon.Information);
  131. }
  132. }
  133. catch (Exception ex)
  134. {
  135. // 对异常进行共通处理
  136. ExceptionManager.HandleEventException(this.ToString(),
  137. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  138. }
  139. }
  140. /// <summary>
  141. /// 确定
  142. /// </summary>
  143. /// <param name="sender"></param>
  144. /// <param name="e"></param>
  145. private void btnOK_Click(object sender, EventArgs e)
  146. {
  147. try
  148. {
  149. this.Commit();
  150. }
  151. catch (Exception ex)
  152. {
  153. // 对异常进行共通处理
  154. ExceptionManager.HandleEventException(this.ToString(),
  155. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  156. }
  157. }
  158. /// <summary>
  159. /// 关闭
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. private void btnClose_Click(object sender, EventArgs e)
  164. {
  165. this.Close();
  166. }
  167. /// <summary>
  168. /// 全选
  169. /// </summary>
  170. /// <param name="sender"></param>
  171. /// <param name="e"></param>
  172. private void chkChooseAll_CheckedChanged(object sender, EventArgs e)
  173. {
  174. for (int i = 0; i < this.dgvGoods.Rows.Count; i++)
  175. {
  176. this.dgvGoods.Rows[i].Cells["Sel"].Value = this.chkChooseAll.Checked;
  177. }
  178. }
  179. /// <summary>
  180. /// 选中产品
  181. /// </summary>
  182. /// <param name="sender"></param>
  183. /// <param name="e"></param>
  184. private void dgvGoods_CellClick(object sender, DataGridViewCellEventArgs e)
  185. {
  186. try
  187. {
  188. // 点击的是选中列
  189. if (e.ColumnIndex != -1 && e.RowIndex != -1)
  190. {
  191. if (this.dgvGoods.Columns[e.ColumnIndex].Name == "Sel")
  192. {
  193. int value = int.Parse(this.dgvGoods.Rows[e.RowIndex].Cells["Sel"].Value.ToString());
  194. this.dgvGoods.Rows[e.RowIndex].Cells["Sel"].Value = value == Constant.INT_IS_ONE ? Constant.INT_IS_ZERO : Constant.INT_IS_ONE;
  195. }
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. // 对异常进行共通处理
  201. ExceptionManager.HandleEventException(this.ToString(),
  202. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  203. }
  204. }
  205. /// <summary>
  206. /// 清空条件
  207. /// </summary>
  208. /// <param name="sender"></param>
  209. /// <param name="e"></param>
  210. private void btnClearCondition_Click(object sender, EventArgs e)
  211. {
  212. this.txtGoodsCode.Text = "";
  213. this.txtGoodsName.Text = "";
  214. this.txtGoodsSpecification.Text = "";
  215. this.scbGoodsType.ClearValue();
  216. this.txtGoodsModel.Text = "";
  217. this.ddlGlazeTypeID.SelectedIndex = 0;
  218. }
  219. #endregion
  220. #region 私有方法
  221. /// <summary>
  222. /// 加载页面所需的数据源
  223. /// </summary>
  224. private void LoadDataSource()
  225. {
  226. try
  227. {
  228. // 绑定釉料类别
  229. DataTable dt = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, 1);
  230. if (dt != null)
  231. {
  232. DataRow row = dt.NewRow();
  233. row["DictionaryValue"] = "";
  234. row["DictionaryID"] = DBNull.Value;
  235. dt.Rows.InsertAt(row, 0);
  236. ddlGlazeTypeID.DisplayMember = "DictionaryValue";
  237. ddlGlazeTypeID.ValueMember = "DictionaryID";
  238. ddlGlazeTypeID.DataSource = dt;
  239. }
  240. }
  241. catch (Exception ex)
  242. {
  243. throw ex;
  244. }
  245. }
  246. /// <summary>
  247. /// 点击确定或者回车键时调用
  248. /// </summary>
  249. private void Commit()
  250. {
  251. try
  252. {
  253. DataTable invDt = (DataTable)this.dgvGoods.DataSource;
  254. if (invDt == null || invDt.Rows.Count == 0)
  255. {
  256. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  257. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  258. return;
  259. }
  260. invDt.AcceptChanges();
  261. invDt = invDt.Copy();
  262. string filter = "Sel = 1";
  263. invDt.DefaultView.RowFilter = filter;
  264. invDt = invDt.DefaultView.ToTable();
  265. // 如果选中了数据就关闭窗体,反之则不关
  266. if (invDt.Rows.Count > 0)
  267. {
  268. SelTable = invDt;
  269. this.DialogResult = DialogResult.OK;
  270. this.Close();
  271. }
  272. else
  273. {
  274. MessageBox.Show(string.Format(Messages.MSG_CMN_W007,
  275. "没有选择数据"), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  276. }
  277. }
  278. catch (Exception ex)
  279. {
  280. throw ex;
  281. }
  282. }
  283. #endregion
  284. }
  285. }