F_MST_0502.cs 36 KB

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