F_MST_0502.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014
  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. if (ValidationCode(this.txtGoodsCode.Text) == false)
  262. {
  263. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品编码"), this.Text,
  264. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  265. return;
  266. }
  267. }
  268. //实体赋值
  269. if (this._thisGoodsEntity == null)
  270. {
  271. this._thisGoodsEntity = new GoodsEntity();
  272. }
  273. this._thisGoodsEntity.GoodsCode = this.txtGoodsCode.Text;
  274. this._thisGoodsEntity.GoodsModel = this.txtGoodsModel.Text;
  275. this._thisGoodsEntity.GoodsName = this.txtGoodsName.Text;
  276. this._thisGoodsEntity.GoodsSpecification = this.txtGoodsSpecification.Text;
  277. this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  278. this._thisGoodsEntity.GlazeTypeID = this.ddlGlazeTypeID.SelectedValue.ToString() == "" ? null : (int?)Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
  279. this._thisGoodsEntity.MudQuantity = this.txtMudWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtMudWeight.Text);
  280. this._thisGoodsEntity.GlazeQuantity = this.txtGlazeWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtGlazeWeight.Text);
  281. this._thisGoodsEntity.LusterwareWeight = this.txtLusterwareWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtLusterwareWeight.Text);
  282. this._thisGoodsEntity.ProductionCycle = this.txtProductionCycle.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtProductionCycle.Text);
  283. this._thisGoodsEntity.StartingDate = this.dtpStartingDate.Value.Date;
  284. this._thisGoodsEntity.AutoLossCycle = (this.txtSPM001.DataValue.HasValue ? Convert.ToInt32(this.txtSPM001.DataValue) : 0);
  285. this._thisGoodsEntity.DeliverLimitCycle = (this.txtSPM002.DataValue.HasValue ? Convert.ToInt32(this.txtSPM002.DataValue) : 0);
  286. this._thisGoodsEntity.MouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
  287. this._thisGoodsEntity.StandardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
  288. this._thisGoodsEntity.MouldMaterialCode = this.txtMouldMaterialCode.Text;
  289. this._thisGoodsEntity.WaterLabelCode = this.txtWaterLabelCode.Text;
  290. this._thisGoodsEntity.PlateLimitNum = (this.txtPlateLimitNum.DataValue.HasValue ? Convert.ToInt32(this.txtPlateLimitNum.DataValue) : 0);
  291. this._thisGoodsEntity.UnitPrice = (this.txtUnitPrice.DataValue.HasValue ? this.txtUnitPrice.DataValue.Value : 0);
  292. this._thisGoodsEntity.ReservedDays = (this.txtReservedDays.DataValue.HasValue ? Convert.ToInt32(this.txtReservedDays.DataValue) : 0);
  293. this._thisGoodsEntity.PackageNum = this.txtPackageNum.Text.Trim();
  294. this._thisGoodsEntity.OutletDistance = this.txtOutletDistance.Text.Trim();
  295. this._thisGoodsEntity.MaterialCode = this.txtMaterialCode.Text.Trim();
  296. this._thisGoodsEntity.MaterialRemark = this.txtMaterialRemark.Text;
  297. this._thisGoodsEntity.PrintCopies = (this.txtCopies.DataValue.HasValue ? Convert.ToInt32(this.txtCopies.DataValue) : 0);
  298. this._sapInfo.AcceptChanges();
  299. this._thisGoodsEntity.SAPInfo = this._sapInfo;
  300. this._thisGoodsEntity.LogoID = Convert.ToInt32(ftcLogo.SelectedValue);
  301. if (this.txtMouldWeight.DataValue != null)
  302. {
  303. this._thisGoodsEntity.MouldWeight = this.txtMouldWeight.DataValue;
  304. }
  305. if (this.txtMouldCost.DataValue != null)
  306. {
  307. this._thisGoodsEntity.MouldCost = this.txtMouldCost.DataValue;
  308. }
  309. if (this.txtSEATCOVERCODE.DataValue != null)
  310. {
  311. this._thisGoodsEntity.SeatCoverCode = Convert.ToInt32(this.txtSEATCOVERCODE.DataValue);
  312. }
  313. if (this.cbCeaseFlag.Checked)
  314. {
  315. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  316. }
  317. else
  318. {
  319. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  320. }
  321. if (this.cbValueFlag.Checked)
  322. {
  323. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  324. }
  325. else
  326. {
  327. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  328. }
  329. this._thisGoodsEntity.ScrapSumFlag = (this.chkScrapSumFlag.Checked ? "1" : "0");
  330. this._thisGoodsEntity.GoodsLineType = (this.chkGLT.Checked ? "1" : "0");
  331. this._thisGoodsEntity.Remarks = this.txtRemarks.Text;
  332. //首先将未修改的图片从集合中删除
  333. for (int i = 0; i < _imgList.Count; i++)
  334. {
  335. this._picByteList.RemoveAt(Constant.INT_IS_ZERO);
  336. this._smallByteList.RemoveAt(Constant.INT_IS_ZERO);
  337. }
  338. this._imgList.Clear();
  339. //循环插入图片
  340. for (int i = 0; i < _picByteList.Count; i++)
  341. {
  342. GoodsImageEntity imgEntity = new GoodsImageEntity();
  343. imgEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  344. byte[] buffer = _picByteList[i];
  345. imgEntity.Image = buffer;
  346. imgEntity.Thumbnail = _smallByteList[i];
  347. this._imgList.Add(imgEntity);
  348. }
  349. //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
  350. if (this._updateImgList.Count != Constant.INT_IS_ZERO)
  351. {
  352. for (int i = 0; i < this._updateImgList.Count; i++)
  353. {
  354. GoodsImageEntity updateImgEntity = this._updateImgList[i];
  355. this._imgList.Add(updateImgEntity);
  356. }
  357. }
  358. if (this._formGoodsId == Constant.INT_IS_ZERO)
  359. {
  360. int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  361. {
  362. return SystemModuleProxy.Service.AddGoods(this._thisGoodsEntity, this._imgList, this._attList);
  363. }));
  364. if (MyReturn > Constant.INT_IS_ZERO)
  365. {
  366. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  367. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  368. PageInitialization();
  369. }
  370. else if (MyReturn == -10)
  371. {
  372. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  373. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  374. this.txtMaterialCode.Focus();
  375. return;
  376. }
  377. else
  378. {
  379. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  380. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  381. }
  382. }
  383. else
  384. {
  385. int MyReturn = SystemModuleProxy.Service.UpdateGoods(_thisGoodsEntity, _imgList, _attList);
  386. if (MyReturn > Constant.INT_IS_ZERO)
  387. {
  388. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  389. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  390. this.DialogResult = DialogResult.OK;
  391. }
  392. else if (MyReturn == -10)
  393. {
  394. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  395. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  396. this.txtMaterialCode.Focus();
  397. return;
  398. }
  399. else if (MyReturn == -500)
  400. {
  401. MessageBox.Show(Messages.MSG_CMN_W012, this.Text, MessageBoxButtons.OK,
  402. MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  403. this.DialogResult = DialogResult.OK;
  404. }
  405. else
  406. {
  407. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  408. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  409. }
  410. }
  411. }
  412. catch (Exception ex)
  413. {
  414. // 对异常进行共通处理
  415. ExceptionManager.HandleEventException(this.ToString(),
  416. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  417. }
  418. }
  419. /// <summary>
  420. /// 上传缩略图
  421. /// </summary>
  422. private void btnUpload_Click(object sender, EventArgs e)
  423. {
  424. try
  425. {
  426. odlgFile.Filter = Constant.FILTER_PIC;
  427. odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  428. odlgFile.RestoreDirectory = true;
  429. odlgFile.Title = "选择产品图片";
  430. odlgFile.FileName = null;
  431. odlgFile.RestoreDirectory = true;
  432. if (odlgFile.ShowDialog() == DialogResult.OK)
  433. {
  434. FileInfo file = new FileInfo(odlgFile.FileName);
  435. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  436. {
  437. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "产品图片", "大小", "1M"),
  438. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  439. }
  440. else
  441. {
  442. Image PicImage = Image.FromStream(file.OpenRead());
  443. this._picByteList.Add(ImageToByte(PicImage));
  444. GetThumbnail(file);
  445. BindImg();
  446. }
  447. }
  448. }
  449. catch (Exception ex)
  450. {
  451. // 对异常进行共通处理
  452. ExceptionManager.HandleEventException(this.ToString(),
  453. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  454. }
  455. }
  456. /// <summary>
  457. /// 删除某缩略图
  458. /// </summary>
  459. private void btnDelete_Click(object sender, EventArgs e)
  460. {
  461. try
  462. {
  463. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  464. {
  465. int index = lvSelect.Index;
  466. if (index < Constant.INT_IS_ZERO)
  467. {
  468. index = Constant.INT_IS_ZERO;
  469. }
  470. ilPic.Images.RemoveAt(index);
  471. this._picByteList.RemoveAt(index);
  472. this._smallByteList.RemoveAt(index);
  473. lvPic.Items.RemoveAt(index);
  474. if (index < this._imgList.Count)
  475. {
  476. if (this._imgList[index].GoodsImageID != Constant.INT_IS_ZERO)
  477. {
  478. GoodsImageEntity deleteImgEntity = this._imgList[index];
  479. this._imgList[index].ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  480. this._updateImgList.Add(deleteImgEntity);
  481. this._imgList.RemoveAt(index);
  482. }
  483. }
  484. }
  485. BindImg();
  486. }
  487. catch (Exception ex)
  488. {
  489. // 对异常进行共通处理
  490. ExceptionManager.HandleEventException(this.ToString(),
  491. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  492. }
  493. }
  494. /// <summary>
  495. /// 关闭窗体
  496. /// </summary>
  497. private void btnCancel_Click(object sender, EventArgs e)
  498. {
  499. this.DialogResult = DialogResult.OK;
  500. }
  501. /// <summary>
  502. /// 查看图片
  503. /// </summary>
  504. private void lvPic_DoubleClick(object sender, EventArgs e)
  505. {
  506. try
  507. {
  508. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  509. {
  510. int index = lvSelect.Index;
  511. if (index < Constant.INT_IS_ZERO)
  512. {
  513. index = Constant.INT_IS_ZERO;
  514. }
  515. F_CMN_0102 addGoods = new F_CMN_0102(_picByteList[index]);
  516. DialogResult dialogresult = addGoods.ShowDialog();
  517. }
  518. }
  519. catch (Exception ex)
  520. {
  521. // 对异常进行共通处理
  522. ExceptionManager.HandleEventException(this.ToString(),
  523. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  524. }
  525. }
  526. #endregion
  527. #region 私有方法
  528. /// <summary>
  529. /// 加载页面所需的数据源
  530. /// </summary>
  531. private void LoadDataSource()
  532. {
  533. try
  534. {
  535. // 绑定釉料类别
  536. DataTable dtGlazeType = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, Constant.INT_IS_ONE);
  537. if (dtGlazeType != null)
  538. {
  539. ddlGlazeTypeID.DisplayMember = "DictionaryValue";
  540. ddlGlazeTypeID.ValueMember = "DictionaryID";
  541. ddlGlazeTypeID.DataSource = dtGlazeType;
  542. }
  543. DataSet logos = SystemModuleProxy.Service.GetLogoInfo();
  544. if (logos != null && logos.Tables.Count > 0)
  545. {
  546. ftcLogo.DisplayMember = "LogoNameCode";
  547. ftcLogo.ValueMember = "LogoID";
  548. ftcLogo.DataSource = logos.Tables[0];
  549. }
  550. }
  551. catch (Exception ex)
  552. {
  553. throw ex;
  554. }
  555. }
  556. /// <summary>
  557. /// 绑定缩略图到控件中
  558. /// </summary>
  559. private void BindImg()
  560. {
  561. try
  562. {
  563. //每次绑定要清空数据源
  564. this.ilPic.Images.Clear();
  565. //将缩略图二进制集合中的数据转换成图片文件
  566. List<Image> LSImageList = new List<Image>();
  567. foreach (byte[] smallby in _smallByteList)
  568. {
  569. LSImageList.Add(byteArrayToImage(smallby));
  570. }
  571. //添加数据源
  572. foreach (Image img in LSImageList)
  573. {
  574. ilPic.Images.Add(img);
  575. }
  576. this.ilPic.ImageSize = new Size(Constant.INT_IS_HUNDRED, Constant.INT_IS_HUNDRED);
  577. this.lvPic.LargeImageList = this.ilPic;
  578. this.lvPic.BeginUpdate();
  579. //清空列表的数据源
  580. lvPic.Items.Clear();
  581. //添加列表的数据源
  582. for (int i = 0; i < ilPic.Images.Count; i++)
  583. {
  584. ListViewItem lvi = new ListViewItem();
  585. lvi.ImageIndex = i;
  586. this.lvPic.Items.Add(lvi);
  587. }
  588. this.lvPic.EndUpdate();
  589. }
  590. catch (Exception ex)
  591. {
  592. throw ex;
  593. }
  594. }
  595. /// <summary>
  596. /// 重绘缩略图并把缩略图转为二进制储存在集合众
  597. /// </summary>
  598. /// <param name="sourceFile">图片实体</param>
  599. /// <returns></returns>
  600. private void GetThumbnail(FileInfo sourceFile)
  601. {
  602. try
  603. {
  604. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  605. ImageFormat thisFormat = imgSource.RawFormat;
  606. int sW = Constant.INT_IS_ZERO, sH = Constant.INT_IS_ZERO;
  607. // 按比例缩放
  608. int sWidth = imgSource.Width;
  609. int sHeight = imgSource.Height;
  610. int destWidth = Constant.INT_IS_HUNDRED;
  611. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  612. if (sHeight > destHeight || sWidth > destWidth)
  613. {
  614. if ((sWidth * destHeight) > (sHeight * destWidth))
  615. {
  616. sW = destWidth;
  617. sH = (destWidth * sHeight) / sWidth;
  618. }
  619. else
  620. {
  621. sH = destHeight;
  622. sW = (sWidth * destHeight) / sHeight;
  623. }
  624. }
  625. else
  626. {
  627. sW = sWidth;
  628. sH = sHeight;
  629. }
  630. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  631. Graphics g = Graphics.FromImage(outBmp);
  632. g.Clear(Color.Black);
  633. // 设置画布的描绘质量
  634. g.CompositingQuality = CompositingQuality.HighQuality;
  635. g.SmoothingMode = SmoothingMode.HighQuality;
  636. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  637. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / Constant.INT_IS_TWO, (destHeight - sH) /
  638. Constant.INT_IS_TWO, sW, sH), Constant.INT_IS_ZERO, Constant.INT_IS_ZERO,
  639. imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  640. g.Dispose();
  641. //将重绘的图片转为二进制并保存
  642. Image image = (Image)outBmp;
  643. byte[] smallbuffer = ImageToByte(image);
  644. this._smallByteList.Add(smallbuffer);
  645. imgSource.Dispose();
  646. outBmp.Dispose();
  647. }
  648. catch (Exception ex)
  649. {
  650. throw ex;
  651. }
  652. }
  653. /// <summary>
  654. /// 根据原图片宽高比获取缩略图的高(根据宽)
  655. /// </summary>
  656. /// <param name="BigWidth">原图宽度</param>
  657. /// <param name="BigHeight">原图高度</param>
  658. /// <param name="SmallWidth">缩略图宽度</param>
  659. /// <returns>缩略图的高度</returns>
  660. private int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  661. {
  662. try
  663. {
  664. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  665. return Convert.ToInt32(SmallWidth / scale);
  666. }
  667. catch (Exception ex)
  668. {
  669. throw ex;
  670. }
  671. }
  672. /// <summary>
  673. /// 验证添加项
  674. /// </summary>
  675. private int ValidationText()
  676. {
  677. int ErrorID = 0;
  678. if (this.ddlGlazeTypeID.SelectedValue.ToString() == string.Empty)
  679. {
  680. ErrorID = 7;
  681. }
  682. if (this.txtGoodsName.Text == string.Empty)
  683. {
  684. ErrorID = 3;
  685. }
  686. if (scbGoodsType.SearchedItem == null)
  687. {
  688. ErrorID = 6;
  689. }
  690. if (this.txtGoodsCode.Text == string.Empty)
  691. {
  692. ErrorID = 1;
  693. }
  694. return ErrorID;
  695. }
  696. /// <summary>
  697. /// 绑定缩略图到缩略图集合中
  698. /// </summary>
  699. /// <param name="ImageData">图片集合</param>
  700. private void BindByteImage(DataSet ImageData)
  701. {
  702. try
  703. {
  704. foreach (DataRow dr in ImageData.Tables[0].Rows)
  705. {
  706. //将数据库中的缩略图取出
  707. this._smallByteList.Add((byte[])dr[2]);
  708. this._picByteList.Add((byte[])dr[3]);
  709. //绑定实体到修改图片集合中
  710. GoodsImageEntity imgEntity = new GoodsImageEntity();
  711. imgEntity.GoodsImageID = Convert.ToDecimal(dr[0]);
  712. imgEntity.GoodsID = Convert.ToDecimal(dr[1]);
  713. imgEntity.Thumbnail = (byte[])dr[2];
  714. imgEntity.Image = (byte[])dr[3];
  715. imgEntity.AccountID = Convert.ToDecimal(dr[4]);
  716. imgEntity.ValueFlag = Convert.ToDecimal(dr[5]);
  717. imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
  718. imgEntity.CreateUserID = Convert.ToDecimal(dr[7]);
  719. imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
  720. imgEntity.UpdateUserID = Convert.ToDecimal(dr[9]);
  721. imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
  722. this._imgList.Add(imgEntity);
  723. }
  724. //绑定缩略图
  725. BindImg();
  726. }
  727. catch (Exception ex)
  728. {
  729. throw ex;
  730. }
  731. }
  732. /// <summary>
  733. /// 将数据库中的二进制转换成图片
  734. /// </summary>
  735. /// <param name="data">需要转换成图片的二进制数据</param>
  736. /// <returns>图片文件实体</returns>
  737. private static Image byteArrayToImage(object data)
  738. {
  739. try
  740. {
  741. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  742. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  743. return returnImage;
  744. }
  745. catch (Exception ex)
  746. {
  747. throw ex;
  748. }
  749. }
  750. /// <summary>
  751. /// 将图片文件转换成二进制
  752. /// </summary>
  753. /// <param name="img">需要转换的图片</param>
  754. /// <returns>图片二进制数据</returns>
  755. private static byte[] ImageToByte(Image img)
  756. {
  757. try
  758. {
  759. byte[] smallbuffer = null;
  760. using (MemoryStream ms = new MemoryStream())
  761. {
  762. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  763. ms.Position = Constant.INT_IS_ZERO;
  764. smallbuffer = new byte[ms.Length];
  765. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  766. ms.Flush();
  767. }
  768. return smallbuffer;
  769. }
  770. catch (Exception ex)
  771. {
  772. throw ex;
  773. }
  774. }
  775. /// <summary>
  776. /// 验证产品编号唯一性
  777. /// </summary>
  778. /// <param name="goodsCode">产品编号</param>
  779. /// <returns>是否重复,真为不重复,可插入</returns>
  780. private bool ValidationCode(string goodsCode)
  781. {
  782. try
  783. {
  784. GoodsEntity vgoods = new GoodsEntity();
  785. vgoods.GoodsCodeOnly = goodsCode;
  786. int i = ((DataSet)SystemModuleProxy.Service.SerachGoods(vgoods)).Tables[0].Rows.Count;
  787. if (i > Constant.INT_IS_ZERO)
  788. {
  789. return false;
  790. }
  791. else
  792. {
  793. return true;
  794. }
  795. }
  796. catch (Exception ex)
  797. {
  798. throw ex;
  799. }
  800. }
  801. /// <summary>
  802. /// 页面控件初始化
  803. /// </summary>
  804. private void PageInitialization()
  805. {
  806. //页面控件初始化
  807. this.txtGoodsCode.Text = "";
  808. //this.gtsGoodaType.GoodsTypeCode = null;
  809. //this.gtsGoodaType.GoodsTypeID = null;
  810. //this.gtsGoodaType.GoodsTypeName = null;
  811. //this.gtsGoodaType.Text = "";
  812. this.scbGoodsType.ClearValue();
  813. this.txtGoodsName.Text = "";
  814. this.txtGoodsModel.Text = "";
  815. this.txtGoodsSpecification.Text = "";
  816. this.txtMudWeight.Text = "";
  817. this.txtGlazeWeight.Text = "";
  818. //this.ddlGlazeTypeID.SelectedValue = null;
  819. this.txtProductionCycle.Text = "";
  820. this.txtLusterwareWeight.Text = "";
  821. this.txtRemarks.Text = "";
  822. this.lvPic.Items.Clear();
  823. this.cbCeaseFlag.Checked = true;
  824. this.cbValueFlag.Checked = true;
  825. this.chkGLT.Checked = false;
  826. this.txtSPM001.DataValue = 0;
  827. this.txtSPM002.DataValue = 0;
  828. this.txtMouldOutputCount.DataValue = 1;
  829. this.txtStandardGroutingNum.DataValue = 0;
  830. this.dtpStartingDate.Value = DateTime.Now.Date;
  831. //成员变量初始化
  832. this._thisGoodsEntity = new GoodsEntity();
  833. this._picByteList = new List<byte[]>();
  834. this._smallByteList = new List<byte[]>();
  835. this._imgList = new List<GoodsImageEntity>();
  836. this._updateImgList = new List<GoodsImageEntity>();
  837. this.txtUnitPrice.DataValue = 0;
  838. this.txtPlateLimitNum.DataValue = 0;
  839. this.txtReservedDays.DataValue = 0;
  840. this.txtPackageNum.Text = "";
  841. this.txtOutletDistance.Text = "";
  842. this.txtMaterialCode.Text = "";
  843. this.txtMaterialRemark.Text = "";
  844. this.txtMouldWeight.DataValue = null;
  845. this.txtMouldCost.DataValue = null;
  846. this.txtSEATCOVERCODE.DataValue = null;
  847. this.txtWaterLabelCode.Clear();
  848. this.chkScrapSumFlag.Checked = true;
  849. this.txtMouldMaterialCode.Clear();
  850. foreach (DataRow row in this._sapInfo.Rows)
  851. {
  852. row["materialcode"] = DBNull.Value;
  853. row["materialremark"] = DBNull.Value;
  854. row["WaterLabelCode"] = DBNull.Value;
  855. }
  856. this._sapInfo.AcceptChanges();
  857. }
  858. #endregion
  859. #region SAP物料
  860. private void dgvGoodsSap_SelectionChanged(object sender, EventArgs e)
  861. {
  862. if (this.dgvGoodsSap.CurrentRow == null)
  863. {
  864. //this.txtSAPCode.Clear();
  865. //this.txtSAPRemark.Clear();
  866. return;
  867. }
  868. try
  869. {
  870. this.txtSAPCode.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialcode"].Value + "";
  871. this.txtSAPRemark.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialremark"].Value + "";
  872. this.txtSAPWaterLabelCode.Text = this.dgvGoodsSap.CurrentRow.Cells["colWaterLabelCode"].Value + "";
  873. }
  874. catch (Exception ex)
  875. {
  876. // 对异常进行共通处理
  877. ExceptionManager.HandleEventException(this.ToString(),
  878. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  879. }
  880. }
  881. private void txtSAPCode_Validated(object sender, EventArgs e)
  882. {
  883. if (this.dgvGoodsSap.CurrentRow == null)
  884. {
  885. return;
  886. }
  887. try
  888. {
  889. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  890. if (row != null)
  891. {
  892. row["materialcode"] = txtSAPCode.Text;
  893. row.EndEdit();
  894. }
  895. }
  896. catch (Exception ex)
  897. {
  898. // 对异常进行共通处理
  899. ExceptionManager.HandleEventException(this.ToString(),
  900. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  901. }
  902. }
  903. private void txtSAPRemark_Validated(object sender, EventArgs e)
  904. {
  905. if (this.dgvGoodsSap.CurrentRow == null)
  906. {
  907. return;
  908. }
  909. try
  910. {
  911. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  912. if (row != null)
  913. {
  914. row["materialremark"] = txtSAPRemark.Text;
  915. row.EndEdit();
  916. }
  917. }
  918. catch (Exception ex)
  919. {
  920. // 对异常进行共通处理
  921. ExceptionManager.HandleEventException(this.ToString(),
  922. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  923. }
  924. }
  925. private void txtSAPWaterLabelCode_Validated(object sender, EventArgs e)
  926. {
  927. if (this.dgvGoodsSap.CurrentRow == null)
  928. {
  929. return;
  930. }
  931. try
  932. {
  933. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  934. if (row != null)
  935. {
  936. row["WaterLabelCode"] = txtSAPWaterLabelCode.Text;
  937. row.EndEdit();
  938. }
  939. }
  940. catch (Exception ex)
  941. {
  942. // 对异常进行共通处理
  943. ExceptionManager.HandleEventException(this.ToString(),
  944. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  945. }
  946. }
  947. #endregion
  948. private void txtMouldOutputCount_TextChanged(object sender, EventArgs e)
  949. {
  950. try
  951. {
  952. int mouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
  953. int standardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
  954. this.txtStandardGroutingSum.DataValue = mouldOutputCount * standardGroutingNum;
  955. }
  956. catch (Exception ex)
  957. {
  958. // 对异常进行共通处理
  959. ExceptionManager.HandleEventException(this.ToString(),
  960. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  961. }
  962. }
  963. }
  964. }