F_MST_0502.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_MST_0502.cs
  5. * 2.功能描述:新建或编辑产品档案信息
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 庄天威 2014/09/13 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Drawing.Drawing2D;
  15. using System.Drawing.Imaging;
  16. using System.IO;
  17. using System.Windows.Forms;
  18. using Dongke.IBOSS.PRD.Basics.BaseControls;
  19. using Dongke.IBOSS.PRD.Basics.BaseResources;
  20. using Dongke.IBOSS.PRD.Client.CommonModule;
  21. using Dongke.IBOSS.PRD.Client.CommonModule.FormCommon;
  22. using Dongke.IBOSS.PRD.WCF.DataModels;
  23. using Dongke.IBOSS.PRD.WCF.Proxys;
  24. namespace Dongke.IBOSS.PRD.Client.SystemModule
  25. {
  26. /// <summary>
  27. /// 新建或编辑产品档案信息
  28. /// </summary>
  29. public partial class F_MST_0502 : FormBase
  30. {
  31. #region 成员变量
  32. //页面状态
  33. private Constant.FormMode _formStatus;
  34. // 产品ID
  35. private int _formGoodsId;
  36. // 产品图片二进制集合
  37. private List<byte[]> _picByteList = new List<byte[]>();
  38. // 产品图片缩略图二进制集合
  39. private List<byte[]> _smallByteList = new List<byte[]>();
  40. // 产品图片实体集合
  41. private List<GoodsImageEntity> _imgList = new List<GoodsImageEntity>();
  42. // 已存在的图片实体集合(修改)
  43. private List<GoodsImageEntity> _updateImgList = new List<GoodsImageEntity>();
  44. // 产品附件实体集合
  45. private List<GoodsAttachmentEntity> _attList = new List<GoodsAttachmentEntity>();
  46. // 当前编辑实体
  47. private GoodsEntity _thisGoodsEntity = new GoodsEntity();
  48. #endregion
  49. #region 构造函数
  50. /// <summary>
  51. /// 新建/编辑产品档案窗体构造
  52. /// </summary>
  53. /// <param name="modelId">窗体模式,0为新建,1为编辑</param>
  54. /// <param name="goodsId">编辑产品ID</param>
  55. public F_MST_0502(Constant.FormMode status, int goodsId)
  56. {
  57. InitializeComponent();
  58. this._formStatus = status;
  59. this._formGoodsId = goodsId;
  60. if (this._formStatus == Constant.FormMode.Add)
  61. {
  62. this.Text = FormTitles.F_MST_0502_ADD;
  63. }
  64. else
  65. {
  66. this.Text = FormTitles.F_MST_0502_EDIT;
  67. }
  68. this.btnSave.Text = ButtonText.BTN_SAVE;
  69. this.btnCancel.Text = ButtonText.BTN_CLOSE;
  70. this.btnUpload.Text = ButtonText.BTN_UPLOAD;
  71. this.btnDelete.Text = ButtonText.BTN_DELETE;
  72. }
  73. #endregion
  74. #region 事件
  75. /// <summary>
  76. /// 窗体加载
  77. /// </summary>
  78. private void F_MST_0702_Load(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. this.scbGoodsType.IsOnlyDisplayEnd = true;
  83. LoadDataSource();
  84. if (this._formStatus == Constant.FormMode.Edit)
  85. {
  86. // 产品编码不能编辑 add by chenxy 2016-08-16 begin
  87. this.txtGoodsCode.ReadOnly = true;
  88. // 产品编码不能编辑 add by chenxy 2016-08-16 end
  89. //根据goodsId查询对应的产品信息
  90. this._thisGoodsEntity.GoodsID = this._formGoodsId;
  91. DataSet updateGoods = SystemModuleProxy.Service.SerachGoods(this._thisGoodsEntity);
  92. if (updateGoods.Tables[0].Rows.Count != Constant.INT_IS_ZERO)
  93. {
  94. //把值绑入实体
  95. DataRow drGoods = updateGoods.Tables[0].Rows[0];
  96. this._thisGoodsEntity.GoodsCode = drGoods["GoodsCode"].ToString();
  97. this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(drGoods["GOODSTYPEID"]);
  98. this._thisGoodsEntity.GlazeTypeID = Convert.ToInt32(drGoods["GLAZETYPEID"]);
  99. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(drGoods["CEASEFLAG"]);
  100. this._thisGoodsEntity.Remarks = drGoods["Remarks"].ToString();
  101. this._thisGoodsEntity.AccountID = Convert.ToInt32(drGoods["AccountID"]);
  102. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(drGoods["ValueFlag"]);
  103. this._thisGoodsEntity.CreateTime = Convert.ToDateTime(drGoods["CreateTime"]);
  104. this._thisGoodsEntity.CreateUserID = Convert.ToInt32(drGoods["CreateUserID"]);
  105. this._thisGoodsEntity.UpdateTime = Convert.ToDateTime(drGoods["UpdateTime"]);
  106. this._thisGoodsEntity.UpdateUserID = Convert.ToInt32(drGoods["UpdateUserID"]);
  107. this._thisGoodsEntity.OPTimeStamp = Convert.ToDateTime(drGoods["OPTimeStamp"]);
  108. this._thisGoodsEntity.StartingDate = Convert.ToDateTime(drGoods["StartingDate"]);
  109. this._thisGoodsEntity.AutoLossCycle = Convert.ToInt32(drGoods["AutoLossCycle"]);
  110. this._thisGoodsEntity.DeliverLimitCycle = Convert.ToInt32(drGoods["DeliverLimitCycle"]);
  111. this._thisGoodsEntity.PlateLimitNum = Convert.ToInt32(drGoods["PlateLimitNum"]);
  112. this._thisGoodsEntity.UnitPrice = Convert.ToDecimal(drGoods["UnitPrice"]);
  113. this._thisGoodsEntity.ReservedDays = Convert.ToInt32(drGoods["ReservedDays"]);
  114. this._thisGoodsEntity.MouldOutputCount = Convert.ToInt32(drGoods["MouldOutputCount"]);
  115. this._thisGoodsEntity.StandardGroutingNum = Convert.ToInt32(drGoods["StandardGroutingNum"]);
  116. this._thisGoodsEntity.MouldMaterialCode = drGoods["MouldMaterialCode"] + "";
  117. this._thisGoodsEntity.WaterLabelCode = drGoods["WaterLabelCode"] + "";
  118. //将实体的值赋给各控件
  119. this.txtGoodsCode.Text = drGoods["GoodsCode"].ToString();
  120. this.txtGoodsName.Text = drGoods["GoodsName"].ToString();
  121. this.txtGoodsSpecification.Text = drGoods["GoodsSpecification"].ToString();
  122. this.txtGoodsModel.Text = drGoods["GoodsModel"].ToString();
  123. this.scbGoodsType.CheckedData = updateGoods.Tables[0];
  124. //this.scbGoodsType.InitValue(drGoods["GoodsTypeName"].ToString(), _thisGoodsEntity.GoodsTypeID);
  125. this.scbGoodsType.Text = drGoods["GoodsTypeName"].ToString();
  126. this.ddlGlazeTypeID.SelectedValue = _thisGoodsEntity.GlazeTypeID;
  127. this.txtMudWeight.Text = drGoods["MudWeight"].ToString();
  128. this.txtGlazeWeight.Text = drGoods["GlazeWeight"].ToString();
  129. this.txtLusterwareWeight.Text = drGoods["LusterwareWeight"].ToString();
  130. this.txtProductionCycle.Text = drGoods["ProductionCycle"].ToString();
  131. this.cbCeaseFlag.Checked = (_thisGoodsEntity.CeaseFlag == Constant.INT_IS_ONE);
  132. this.cbValueFlag.Checked = (this._thisGoodsEntity.ValueFlag == Constant.INT_IS_ONE);
  133. this.txtRemarks.Text = this._thisGoodsEntity.Remarks;
  134. this.dtpStartingDate.Value = this._thisGoodsEntity.StartingDate;
  135. this.txtSPM001.DataValue = this._thisGoodsEntity.AutoLossCycle;
  136. this.txtSPM002.DataValue = this._thisGoodsEntity.DeliverLimitCycle;
  137. this.txtMouldOutputCount.DataValue = this._thisGoodsEntity.MouldOutputCount;
  138. this.txtStandardGroutingNum.DataValue = this._thisGoodsEntity.StandardGroutingNum;
  139. this.txtMouldMaterialCode.Text = this._thisGoodsEntity.MouldMaterialCode;
  140. this.txtWaterLabelCode.Text = this._thisGoodsEntity.WaterLabelCode;
  141. this.txtPlateLimitNum.DataValue = this._thisGoodsEntity.PlateLimitNum;
  142. this.txtUnitPrice.DataValue = this._thisGoodsEntity.UnitPrice;
  143. this.txtReservedDays.DataValue = this._thisGoodsEntity.ReservedDays;
  144. this.txtPackageNum.Text = drGoods["PackageNum"].ToString();
  145. this.txtOutletDistance.Text = drGoods["OutletDistance"].ToString();
  146. this.txtMaterialCode.Text = drGoods["MaterialCode"].ToString();
  147. this.txtGroutmaterialcode.Text = drGoods["groutmaterialcode"].ToString();
  148. this.txtMaterialRemark.Text = drGoods["MaterialRemark"].ToString();
  149. this.txtCopies.Text = drGoods["printcopies"].ToString();
  150. if (drGoods["MouldWeight"] != DBNull.Value)
  151. {
  152. this.txtMouldWeight.DataValue = Convert.ToDecimal(drGoods["MouldWeight"]);
  153. }
  154. if (drGoods["MouldCost"] != DBNull.Value)
  155. {
  156. this.txtMouldCost.DataValue = Convert.ToDecimal(drGoods["MouldCost"]);
  157. }
  158. this.chkScrapSumFlag.Checked = (drGoods["ScrapSumFlag"] + "" == "1");
  159. if (drGoods["SeatCoverCode"] != DBNull.Value)
  160. {
  161. this.txtSEATCOVERCODE.DataValue = Convert.ToInt32(drGoods["SeatCoverCode"]);
  162. }
  163. //查询对应的图片
  164. DataSet dsImg = SystemModuleProxy.Service.getImageByGoodsId(this._formGoodsId);
  165. BindByteImage(dsImg);
  166. }
  167. }
  168. }
  169. catch (Exception ex)
  170. {
  171. // 对异常进行共通处理
  172. ExceptionManager.HandleEventException(this.ToString(),
  173. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  174. }
  175. }
  176. /// <summary>
  177. /// 获取数据事件
  178. /// </summary>
  179. private void btnSave_Click(object sender, EventArgs e)
  180. {
  181. try
  182. {
  183. //基础数据验证
  184. int ErrorId = ValidationText();
  185. if (ErrorId != Constant.INT_IS_ZERO)
  186. {
  187. string errorAddress = "";
  188. switch (ErrorId)
  189. {
  190. case 1:
  191. this.txtGoodsCode.Focus();
  192. errorAddress = "产品编码";
  193. break;
  194. case 3:
  195. this.txtGoodsName.Focus();
  196. errorAddress = "产品名称";
  197. break;
  198. case 6:
  199. this.scbGoodsType.Focus();
  200. errorAddress = "产品类别";
  201. break;
  202. case 7:
  203. this.ddlGlazeTypeID.Focus();
  204. errorAddress = "釉料类别";
  205. break;
  206. default:
  207. break;
  208. };
  209. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
  210. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  211. return;
  212. }
  213. if (string.IsNullOrEmpty(txtMaterialCode.Text))
  214. {
  215. this.txtMaterialCode.Focus();
  216. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "物料编码"),
  217. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  218. return;
  219. }
  220. if (string.IsNullOrEmpty(txtGroutmaterialcode.Text))
  221. {
  222. this.txtGroutmaterialcode.Focus();
  223. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "注浆初始物料编码"),
  224. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  225. return;
  226. }
  227. if (string.IsNullOrEmpty(txtMouldMaterialCode.Text))
  228. {
  229. this.txtMouldMaterialCode.Focus();
  230. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "模具物料编码"),
  231. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  232. return;
  233. }
  234. //查询产品编号唯一性
  235. if ((this.txtGoodsCode.Text != this._thisGoodsEntity.GoodsCode && _formStatus == Constant.FormMode.Edit)
  236. || this._formStatus == Constant.FormMode.Add)
  237. {
  238. if (ValidationCode(this.txtGoodsCode.Text) == false)
  239. {
  240. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品编码"), this.Text,
  241. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  242. return;
  243. }
  244. }
  245. //实体赋值
  246. if (this._thisGoodsEntity == null)
  247. {
  248. this._thisGoodsEntity = new GoodsEntity();
  249. }
  250. this._thisGoodsEntity.GoodsCode = this.txtGoodsCode.Text;
  251. this._thisGoodsEntity.GoodsModel = this.txtGoodsModel.Text;
  252. this._thisGoodsEntity.GoodsName = this.txtGoodsName.Text;
  253. this._thisGoodsEntity.GoodsSpecification = this.txtGoodsSpecification.Text;
  254. this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  255. this._thisGoodsEntity.GlazeTypeID = this.ddlGlazeTypeID.SelectedValue.ToString() == "" ? null : (int?)Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
  256. this._thisGoodsEntity.MudQuantity = this.txtMudWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtMudWeight.Text);
  257. this._thisGoodsEntity.GlazeQuantity = this.txtGlazeWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtGlazeWeight.Text);
  258. this._thisGoodsEntity.LusterwareWeight = this.txtLusterwareWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtLusterwareWeight.Text);
  259. this._thisGoodsEntity.ProductionCycle = this.txtProductionCycle.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtProductionCycle.Text);
  260. this._thisGoodsEntity.StartingDate = this.dtpStartingDate.Value.Date;
  261. this._thisGoodsEntity.AutoLossCycle = (this.txtSPM001.DataValue.HasValue ? Convert.ToInt32(this.txtSPM001.DataValue) : 0);
  262. this._thisGoodsEntity.DeliverLimitCycle = (this.txtSPM002.DataValue.HasValue ? Convert.ToInt32(this.txtSPM002.DataValue) : 0);
  263. this._thisGoodsEntity.MouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
  264. this._thisGoodsEntity.StandardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
  265. this._thisGoodsEntity.MouldMaterialCode = this.txtMouldMaterialCode.Text;
  266. this._thisGoodsEntity.WaterLabelCode = this.txtWaterLabelCode.Text;
  267. this._thisGoodsEntity.PlateLimitNum = (this.txtPlateLimitNum.DataValue.HasValue ? Convert.ToInt32(this.txtPlateLimitNum.DataValue) : 0);
  268. this._thisGoodsEntity.UnitPrice = (this.txtUnitPrice.DataValue.HasValue ? this.txtUnitPrice.DataValue.Value : 0);
  269. this._thisGoodsEntity.ReservedDays = (this.txtReservedDays.DataValue.HasValue ? Convert.ToInt32(this.txtReservedDays.DataValue) : 0);
  270. this._thisGoodsEntity.PackageNum = this.txtPackageNum.Text.Trim();
  271. this._thisGoodsEntity.OutletDistance = this.txtOutletDistance.Text.Trim();
  272. this._thisGoodsEntity.MaterialCode = this.txtMaterialCode.Text.Trim();
  273. this._thisGoodsEntity.Groutmaterialcode = this.txtGroutmaterialcode.Text.Trim();
  274. this._thisGoodsEntity.MaterialRemark = this.txtMaterialRemark.Text;
  275. this._thisGoodsEntity.PrintCopies = (this.txtCopies.DataValue.HasValue ? Convert.ToInt32(this.txtCopies.DataValue) : 0);
  276. if (this.txtMouldWeight.DataValue != null)
  277. {
  278. this._thisGoodsEntity.MouldWeight = this.txtMouldWeight.DataValue;
  279. }
  280. if (this.txtMouldCost.DataValue != null)
  281. {
  282. this._thisGoodsEntity.MouldCost = this.txtMouldCost.DataValue;
  283. }
  284. if (this.txtSEATCOVERCODE.DataValue != null)
  285. {
  286. this._thisGoodsEntity.SeatCoverCode = Convert.ToInt32(this.txtSEATCOVERCODE.DataValue);
  287. }
  288. if (this.cbCeaseFlag.Checked)
  289. {
  290. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  291. }
  292. else
  293. {
  294. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  295. }
  296. if (this.cbValueFlag.Checked)
  297. {
  298. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  299. }
  300. else
  301. {
  302. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  303. }
  304. this._thisGoodsEntity.ScrapSumFlag = (this.chkScrapSumFlag.Checked ? "1" : "0");
  305. this._thisGoodsEntity.Remarks = this.txtRemarks.Text;
  306. //首先将未修改的图片从集合中删除
  307. for (int i = 0; i < _imgList.Count; i++)
  308. {
  309. this._picByteList.RemoveAt(Constant.INT_IS_ZERO);
  310. this._smallByteList.RemoveAt(Constant.INT_IS_ZERO);
  311. }
  312. this._imgList.Clear();
  313. //循环插入图片
  314. for (int i = 0; i < _picByteList.Count; i++)
  315. {
  316. GoodsImageEntity imgEntity = new GoodsImageEntity();
  317. imgEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  318. byte[] buffer = _picByteList[i];
  319. imgEntity.Image = buffer;
  320. imgEntity.Thumbnail = _smallByteList[i];
  321. this._imgList.Add(imgEntity);
  322. }
  323. //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
  324. if (this._updateImgList.Count != Constant.INT_IS_ZERO)
  325. {
  326. for (int i = 0; i < this._updateImgList.Count; i++)
  327. {
  328. GoodsImageEntity updateImgEntity = this._updateImgList[i];
  329. this._imgList.Add(updateImgEntity);
  330. }
  331. }
  332. if (this._formGoodsId == Constant.INT_IS_ZERO)
  333. {
  334. int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  335. {
  336. return SystemModuleProxy.Service.AddGoods(this._thisGoodsEntity, this._imgList, this._attList);
  337. }));
  338. if (MyReturn > Constant.INT_IS_ZERO)
  339. {
  340. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  341. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  342. PageInitialization();
  343. }
  344. else if (MyReturn == -10)
  345. {
  346. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  347. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  348. this.txtMaterialCode.Focus();
  349. return;
  350. }
  351. else
  352. {
  353. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  354. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  355. }
  356. }
  357. else
  358. {
  359. int MyReturn = SystemModuleProxy.Service.UpdateGoods(_thisGoodsEntity, _imgList, _attList);
  360. if (MyReturn > Constant.INT_IS_ZERO)
  361. {
  362. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  363. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  364. this.DialogResult = DialogResult.OK;
  365. }
  366. else if (MyReturn == -10)
  367. {
  368. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  369. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  370. this.txtMaterialCode.Focus();
  371. return;
  372. }
  373. else if (MyReturn == -500)
  374. {
  375. MessageBox.Show(Messages.MSG_CMN_W012, this.Text, MessageBoxButtons.OK,
  376. MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  377. this.DialogResult = DialogResult.OK;
  378. }
  379. else
  380. {
  381. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  382. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  383. }
  384. }
  385. }
  386. catch (Exception ex)
  387. {
  388. // 对异常进行共通处理
  389. ExceptionManager.HandleEventException(this.ToString(),
  390. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  391. }
  392. }
  393. /// <summary>
  394. /// 上传缩略图
  395. /// </summary>
  396. private void btnUpload_Click(object sender, EventArgs e)
  397. {
  398. try
  399. {
  400. odlgFile.Filter = Constant.FILTER_PIC;
  401. odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  402. odlgFile.RestoreDirectory = true;
  403. odlgFile.Title = "选择产品图片";
  404. odlgFile.FileName = null;
  405. odlgFile.RestoreDirectory = true;
  406. if (odlgFile.ShowDialog() == DialogResult.OK)
  407. {
  408. FileInfo file = new FileInfo(odlgFile.FileName);
  409. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  410. {
  411. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "产品图片", "大小", "1M"),
  412. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  413. }
  414. else
  415. {
  416. Image PicImage = Image.FromStream(file.OpenRead());
  417. this._picByteList.Add(ImageToByte(PicImage));
  418. GetThumbnail(file);
  419. BindImg();
  420. }
  421. }
  422. }
  423. catch (Exception ex)
  424. {
  425. // 对异常进行共通处理
  426. ExceptionManager.HandleEventException(this.ToString(),
  427. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  428. }
  429. }
  430. /// <summary>
  431. /// 删除某缩略图
  432. /// </summary>
  433. private void btnDelete_Click(object sender, EventArgs e)
  434. {
  435. try
  436. {
  437. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  438. {
  439. int index = lvSelect.Index;
  440. if (index < Constant.INT_IS_ZERO)
  441. {
  442. index = Constant.INT_IS_ZERO;
  443. }
  444. ilPic.Images.RemoveAt(index);
  445. this._picByteList.RemoveAt(index);
  446. this._smallByteList.RemoveAt(index);
  447. lvPic.Items.RemoveAt(index);
  448. if (index < this._imgList.Count)
  449. {
  450. if (this._imgList[index].GoodsImageID != Constant.INT_IS_ZERO)
  451. {
  452. GoodsImageEntity deleteImgEntity = this._imgList[index];
  453. this._imgList[index].ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  454. this._updateImgList.Add(deleteImgEntity);
  455. this._imgList.RemoveAt(index);
  456. }
  457. }
  458. }
  459. BindImg();
  460. }
  461. catch (Exception ex)
  462. {
  463. // 对异常进行共通处理
  464. ExceptionManager.HandleEventException(this.ToString(),
  465. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  466. }
  467. }
  468. /// <summary>
  469. /// 关闭窗体
  470. /// </summary>
  471. private void btnCancel_Click(object sender, EventArgs e)
  472. {
  473. this.DialogResult = DialogResult.OK;
  474. }
  475. /// <summary>
  476. /// 查看图片
  477. /// </summary>
  478. private void lvPic_DoubleClick(object sender, EventArgs e)
  479. {
  480. try
  481. {
  482. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  483. {
  484. int index = lvSelect.Index;
  485. if (index < Constant.INT_IS_ZERO)
  486. {
  487. index = Constant.INT_IS_ZERO;
  488. }
  489. F_CMN_0102 addGoods = new F_CMN_0102(_picByteList[index]);
  490. DialogResult dialogresult = addGoods.ShowDialog();
  491. }
  492. }
  493. catch (Exception ex)
  494. {
  495. // 对异常进行共通处理
  496. ExceptionManager.HandleEventException(this.ToString(),
  497. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  498. }
  499. }
  500. #endregion
  501. #region 私有方法
  502. /// <summary>
  503. /// 加载页面所需的数据源
  504. /// </summary>
  505. private void LoadDataSource()
  506. {
  507. try
  508. {
  509. // 绑定釉料类别
  510. DataTable dtGlazeType = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, Constant.INT_IS_ONE);
  511. if (dtGlazeType != null)
  512. {
  513. ddlGlazeTypeID.DisplayMember = "DictionaryValue";
  514. ddlGlazeTypeID.ValueMember = "DictionaryID";
  515. ddlGlazeTypeID.DataSource = dtGlazeType;
  516. }
  517. }
  518. catch (Exception ex)
  519. {
  520. throw ex;
  521. }
  522. }
  523. /// <summary>
  524. /// 绑定缩略图到控件中
  525. /// </summary>
  526. private void BindImg()
  527. {
  528. try
  529. {
  530. //每次绑定要清空数据源
  531. this.ilPic.Images.Clear();
  532. //将缩略图二进制集合中的数据转换成图片文件
  533. List<Image> LSImageList = new List<Image>();
  534. foreach (byte[] smallby in _smallByteList)
  535. {
  536. LSImageList.Add(byteArrayToImage(smallby));
  537. }
  538. //添加数据源
  539. foreach (Image img in LSImageList)
  540. {
  541. ilPic.Images.Add(img);
  542. }
  543. this.ilPic.ImageSize = new Size(Constant.INT_IS_HUNDRED, Constant.INT_IS_HUNDRED);
  544. this.lvPic.LargeImageList = this.ilPic;
  545. this.lvPic.BeginUpdate();
  546. //清空列表的数据源
  547. lvPic.Items.Clear();
  548. //添加列表的数据源
  549. for (int i = 0; i < ilPic.Images.Count; i++)
  550. {
  551. ListViewItem lvi = new ListViewItem();
  552. lvi.ImageIndex = i;
  553. this.lvPic.Items.Add(lvi);
  554. }
  555. this.lvPic.EndUpdate();
  556. }
  557. catch (Exception ex)
  558. {
  559. throw ex;
  560. }
  561. }
  562. /// <summary>
  563. /// 重绘缩略图并把缩略图转为二进制储存在集合众
  564. /// </summary>
  565. /// <param name="sourceFile">图片实体</param>
  566. /// <returns></returns>
  567. private void GetThumbnail(FileInfo sourceFile)
  568. {
  569. try
  570. {
  571. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  572. ImageFormat thisFormat = imgSource.RawFormat;
  573. int sW = Constant.INT_IS_ZERO, sH = Constant.INT_IS_ZERO;
  574. // 按比例缩放
  575. int sWidth = imgSource.Width;
  576. int sHeight = imgSource.Height;
  577. int destWidth = Constant.INT_IS_HUNDRED;
  578. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  579. if (sHeight > destHeight || sWidth > destWidth)
  580. {
  581. if ((sWidth * destHeight) > (sHeight * destWidth))
  582. {
  583. sW = destWidth;
  584. sH = (destWidth * sHeight) / sWidth;
  585. }
  586. else
  587. {
  588. sH = destHeight;
  589. sW = (sWidth * destHeight) / sHeight;
  590. }
  591. }
  592. else
  593. {
  594. sW = sWidth;
  595. sH = sHeight;
  596. }
  597. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  598. Graphics g = Graphics.FromImage(outBmp);
  599. g.Clear(Color.Black);
  600. // 设置画布的描绘质量
  601. g.CompositingQuality = CompositingQuality.HighQuality;
  602. g.SmoothingMode = SmoothingMode.HighQuality;
  603. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  604. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / Constant.INT_IS_TWO, (destHeight - sH) /
  605. Constant.INT_IS_TWO, sW, sH), Constant.INT_IS_ZERO, Constant.INT_IS_ZERO,
  606. imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  607. g.Dispose();
  608. //将重绘的图片转为二进制并保存
  609. Image image = (Image)outBmp;
  610. byte[] smallbuffer = ImageToByte(image);
  611. this._smallByteList.Add(smallbuffer);
  612. imgSource.Dispose();
  613. outBmp.Dispose();
  614. }
  615. catch (Exception ex)
  616. {
  617. throw ex;
  618. }
  619. }
  620. /// <summary>
  621. /// 根据原图片宽高比获取缩略图的高(根据宽)
  622. /// </summary>
  623. /// <param name="BigWidth">原图宽度</param>
  624. /// <param name="BigHeight">原图高度</param>
  625. /// <param name="SmallWidth">缩略图宽度</param>
  626. /// <returns>缩略图的高度</returns>
  627. private int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  628. {
  629. try
  630. {
  631. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  632. return Convert.ToInt32(SmallWidth / scale);
  633. }
  634. catch (Exception ex)
  635. {
  636. throw ex;
  637. }
  638. }
  639. /// <summary>
  640. /// 验证添加项
  641. /// </summary>
  642. private int ValidationText()
  643. {
  644. int ErrorID = 0;
  645. if (this.ddlGlazeTypeID.SelectedValue.ToString() == string.Empty)
  646. {
  647. ErrorID = 7;
  648. }
  649. if (this.txtGoodsName.Text == string.Empty)
  650. {
  651. ErrorID = 3;
  652. }
  653. if (scbGoodsType.SearchedItem == null)
  654. {
  655. ErrorID = 6;
  656. }
  657. if (this.txtGoodsCode.Text == string.Empty)
  658. {
  659. ErrorID = 1;
  660. }
  661. return ErrorID;
  662. }
  663. /// <summary>
  664. /// 绑定缩略图到缩略图集合中
  665. /// </summary>
  666. /// <param name="ImageData">图片集合</param>
  667. private void BindByteImage(DataSet ImageData)
  668. {
  669. try
  670. {
  671. foreach (DataRow dr in ImageData.Tables[0].Rows)
  672. {
  673. //将数据库中的缩略图取出
  674. this._smallByteList.Add((byte[])dr[2]);
  675. this._picByteList.Add((byte[])dr[3]);
  676. //绑定实体到修改图片集合中
  677. GoodsImageEntity imgEntity = new GoodsImageEntity();
  678. imgEntity.GoodsImageID = Convert.ToDecimal(dr[0]);
  679. imgEntity.GoodsID = Convert.ToDecimal(dr[1]);
  680. imgEntity.Thumbnail = (byte[])dr[2];
  681. imgEntity.Image = (byte[])dr[3];
  682. imgEntity.AccountID = Convert.ToDecimal(dr[4]);
  683. imgEntity.ValueFlag = Convert.ToDecimal(dr[5]);
  684. imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
  685. imgEntity.CreateUserID = Convert.ToDecimal(dr[7]);
  686. imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
  687. imgEntity.UpdateUserID = Convert.ToDecimal(dr[9]);
  688. imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
  689. this._imgList.Add(imgEntity);
  690. }
  691. //绑定缩略图
  692. BindImg();
  693. }
  694. catch (Exception ex)
  695. {
  696. throw ex;
  697. }
  698. }
  699. /// <summary>
  700. /// 将数据库中的二进制转换成图片
  701. /// </summary>
  702. /// <param name="data">需要转换成图片的二进制数据</param>
  703. /// <returns>图片文件实体</returns>
  704. private static Image byteArrayToImage(object data)
  705. {
  706. try
  707. {
  708. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  709. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  710. return returnImage;
  711. }
  712. catch (Exception ex)
  713. {
  714. throw ex;
  715. }
  716. }
  717. /// <summary>
  718. /// 将图片文件转换成二进制
  719. /// </summary>
  720. /// <param name="img">需要转换的图片</param>
  721. /// <returns>图片二进制数据</returns>
  722. private static byte[] ImageToByte(Image img)
  723. {
  724. try
  725. {
  726. byte[] smallbuffer = null;
  727. using (MemoryStream ms = new MemoryStream())
  728. {
  729. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  730. ms.Position = Constant.INT_IS_ZERO;
  731. smallbuffer = new byte[ms.Length];
  732. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  733. ms.Flush();
  734. }
  735. return smallbuffer;
  736. }
  737. catch (Exception ex)
  738. {
  739. throw ex;
  740. }
  741. }
  742. /// <summary>
  743. /// 验证产品编号唯一性
  744. /// </summary>
  745. /// <param name="goodsCode">产品编号</param>
  746. /// <returns>是否重复,真为不重复,可插入</returns>
  747. private bool ValidationCode(string goodsCode)
  748. {
  749. try
  750. {
  751. GoodsEntity vgoods = new GoodsEntity();
  752. vgoods.GoodsCodeOnly = goodsCode;
  753. int i = ((DataSet)SystemModuleProxy.Service.SerachGoods(vgoods)).Tables[0].Rows.Count;
  754. if (i > Constant.INT_IS_ZERO)
  755. {
  756. return false;
  757. }
  758. else
  759. {
  760. return true;
  761. }
  762. }
  763. catch (Exception ex)
  764. {
  765. throw ex;
  766. }
  767. }
  768. /// <summary>
  769. /// 页面控件初始化
  770. /// </summary>
  771. private void PageInitialization()
  772. {
  773. //页面控件初始化
  774. this.txtGoodsCode.Text = "";
  775. //this.gtsGoodaType.GoodsTypeCode = null;
  776. //this.gtsGoodaType.GoodsTypeID = null;
  777. //this.gtsGoodaType.GoodsTypeName = null;
  778. //this.gtsGoodaType.Text = "";
  779. this.scbGoodsType.ClearValue();
  780. this.txtGoodsName.Text = "";
  781. this.txtGoodsModel.Text = "";
  782. this.txtGoodsSpecification.Text = "";
  783. this.txtMudWeight.Text = "";
  784. this.txtGlazeWeight.Text = "";
  785. this.ddlGlazeTypeID.SelectedValue = null;
  786. this.txtProductionCycle.Text = "";
  787. this.txtLusterwareWeight.Text = "";
  788. this.txtRemarks.Text = "";
  789. this.lvPic.Items.Clear();
  790. this.cbCeaseFlag.Checked = true;
  791. this.cbValueFlag.Checked = true;
  792. this.txtSPM001.DataValue = 0;
  793. this.txtSPM002.DataValue = 0;
  794. this.txtMouldOutputCount.DataValue = 1;
  795. this.txtStandardGroutingNum.DataValue = 0;
  796. this.dtpStartingDate.Value = DateTime.Now.Date;
  797. //成员变量初始化
  798. this._thisGoodsEntity = new GoodsEntity();
  799. this._picByteList = new List<byte[]>();
  800. this._smallByteList = new List<byte[]>();
  801. this._imgList = new List<GoodsImageEntity>();
  802. this._updateImgList = new List<GoodsImageEntity>();
  803. this.txtUnitPrice.DataValue = 0;
  804. this.txtPlateLimitNum.DataValue = 0;
  805. this.txtReservedDays.DataValue = 0;
  806. this.txtPackageNum.Text = "";
  807. this.txtOutletDistance.Text = "";
  808. this.txtMaterialCode.Text = "";
  809. this.txtGroutmaterialcode.Text = "";
  810. this.txtMaterialRemark.Text = "";
  811. this.txtMouldWeight.DataValue = null;
  812. this.txtMouldCost.DataValue = null;
  813. this.txtSEATCOVERCODE.DataValue = null;
  814. this.chkScrapSumFlag.Checked = true;
  815. }
  816. #endregion
  817. }
  818. }