F_MST_0502.cs 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  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 Dongke.IBOSS.PRD.Basics.BaseControls;
  11. using Dongke.IBOSS.PRD.Basics.BaseResources;
  12. using Dongke.IBOSS.PRD.Client.CommonModule;
  13. using Dongke.IBOSS.PRD.Client.CommonModule.FormCommon;
  14. using Dongke.IBOSS.PRD.WCF.DataModels;
  15. using Dongke.IBOSS.PRD.WCF.Proxys;
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Data;
  19. using System.Drawing;
  20. using System.Drawing.Drawing2D;
  21. using System.Drawing.Imaging;
  22. using System.IO;
  23. using System.Windows.Forms;
  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. this.cbGLTDetail.Enabled = this.chkGLT.Checked;
  75. }
  76. #endregion
  77. #region 事件
  78. /// <summary>
  79. /// 窗体加载
  80. /// </summary>
  81. private void F_MST_0702_Load(object sender, EventArgs e)
  82. {
  83. try
  84. {
  85. this.scbGoodsType.IsOnlyDisplayEnd = true;
  86. LoadDataSource();
  87. if (this._formStatus == Constant.FormMode.Edit)
  88. {
  89. // 产品编码不能编辑 add by chenxy 2016-08-16 begin
  90. this.txtGoodsCode.ReadOnly = true;
  91. // 产品编码不能编辑 add by chenxy 2016-08-16 end
  92. //根据goodsId查询对应的产品信息
  93. this._thisGoodsEntity.GoodsID = this._formGoodsId;
  94. DataSet updateGoods = SystemModuleProxy.Service.SerachGoods(this._thisGoodsEntity);
  95. if (updateGoods.Tables[0].Rows.Count != Constant.INT_IS_ZERO)
  96. {
  97. //把值绑入实体
  98. DataRow drGoods = updateGoods.Tables[0].Rows[0];
  99. this._thisGoodsEntity.GoodsCode = drGoods["GoodsCode"].ToString();
  100. this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(drGoods["GOODSTYPEID"]);
  101. this._thisGoodsEntity.GlazeTypeID = Convert.ToInt32(drGoods["GLAZETYPEID"]);
  102. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(drGoods["CEASEFLAG"]);
  103. this._thisGoodsEntity.SecurityCodeBindFlag = Convert.ToInt32(drGoods["SECURITYCODEBINDFLAG"]);
  104. this._thisGoodsEntity.SecurityCodeCheckFlag = Convert.ToInt32(drGoods["SECURITYCODECHECKFLAG"]);
  105. this._thisGoodsEntity.Remarks = drGoods["Remarks"].ToString();
  106. this._thisGoodsEntity.AccountID = Convert.ToInt32(drGoods["AccountID"]);
  107. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(drGoods["ValueFlag"]);
  108. this._thisGoodsEntity.CreateTime = Convert.ToDateTime(drGoods["CreateTime"]);
  109. this._thisGoodsEntity.CreateUserID = Convert.ToInt32(drGoods["CreateUserID"]);
  110. this._thisGoodsEntity.UpdateTime = Convert.ToDateTime(drGoods["UpdateTime"]);
  111. this._thisGoodsEntity.UpdateUserID = Convert.ToInt32(drGoods["UpdateUserID"]);
  112. this._thisGoodsEntity.OPTimeStamp = Convert.ToDateTime(drGoods["OPTimeStamp"]);
  113. this._thisGoodsEntity.StartingDate = Convert.ToDateTime(drGoods["StartingDate"]);
  114. this._thisGoodsEntity.AutoLossCycle = Convert.ToInt32(drGoods["AutoLossCycle"]);
  115. this._thisGoodsEntity.DeliverLimitCycle = Convert.ToInt32(drGoods["DeliverLimitCycle"]);
  116. this._thisGoodsEntity.PlateLimitNum = Convert.ToInt32(drGoods["PlateLimitNum"]);
  117. this._thisGoodsEntity.UnitPrice = Convert.ToDecimal(drGoods["UnitPrice"]);
  118. this._thisGoodsEntity.ReservedDays = Convert.ToInt32(drGoods["ReservedDays"]);
  119. this._thisGoodsEntity.MouldOutputCount = Convert.ToInt32(drGoods["MouldOutputCount"]);
  120. this._thisGoodsEntity.StandardGroutingNum = Convert.ToInt32(drGoods["StandardGroutingNum"]);
  121. this._thisGoodsEntity.MouldMaterialCode = drGoods["MouldMaterialCode"] + "";
  122. this._thisGoodsEntity.WaterLabelCode = drGoods["WaterLabelCode"] + "";
  123. if (drGoods["PROTECTDAMRATE"].ToString() != null && drGoods["PROTECTDAMRATE"].ToString() != "") {
  124. this._thisGoodsEntity.ProtectdaMrate = Convert.ToDecimal(drGoods["PROTECTDAMRATE"].ToString());//保坯率
  125. }
  126. if (drGoods["ATTENDANCE"].ToString() != null && drGoods["ATTENDANCE"].ToString() != "")
  127. {
  128. this._thisGoodsEntity.Attendance = Convert.ToDecimal(drGoods["ATTENDANCE"].ToString());//保坯率
  129. }
  130. if (drGoods["PRODUCEDAYS"].ToString() != null && drGoods["PRODUCEDAYS"].ToString() != "")
  131. {
  132. this._thisGoodsEntity.ProductDays = Convert.ToDecimal(drGoods["PRODUCEDAYS"].ToString());//保坯率
  133. }
  134. if (drGoods["DAYGROUTINGNUMBER"].ToString() != null && drGoods["DAYGROUTINGNUMBER"].ToString() != "")
  135. {
  136. this._thisGoodsEntity.DaygroutingNumber = Convert.ToDecimal(drGoods["DAYGROUTINGNUMBER"].ToString());//保坯率
  137. }
  138. if (!string.IsNullOrEmpty(drGoods["MudStoreType"] + ""))
  139. {
  140. this._thisGoodsEntity.MudStoreType = Convert.ToInt32(drGoods["MudStoreType"]);
  141. }
  142. //将实体的值赋给各控件
  143. this.txtGoodsCode.Text = drGoods["GoodsCode"].ToString();
  144. this.txtGoodsName.Text = drGoods["GoodsName"].ToString();
  145. this.txtGoodsSpecification.Text = drGoods["GoodsSpecification"].ToString();
  146. this.txtGoodsModel.Text = drGoods["GoodsModel"].ToString();
  147. this.scbGoodsType.CheckedData = updateGoods.Tables[0];
  148. //this.scbGoodsType.InitValue(drGoods["GoodsTypeName"].ToString(), _thisGoodsEntity.GoodsTypeID);
  149. this.scbGoodsType.Text = drGoods["GoodsTypeName"].ToString();
  150. this.ddlGlazeTypeID.SelectedValue = _thisGoodsEntity.GlazeTypeID;
  151. if (_thisGoodsEntity.MudStoreType != null)
  152. {
  153. this.ddlMudStoreType.SelectedValue = _thisGoodsEntity.MudStoreType;
  154. }
  155. this.txtMudWeight.Text = drGoods["MudWeight"].ToString();
  156. this.txtGlazeWeight.Text = drGoods["GlazeWeight"].ToString();
  157. this.txtLusterwareWeight.Text = drGoods["LusterwareWeight"].ToString();
  158. this.txtProductionCycle.Text = drGoods["ProductionCycle"].ToString();
  159. this.cbCeaseFlag.Checked = (_thisGoodsEntity.CeaseFlag == Constant.INT_IS_ONE);
  160. this.cbSecurityCodeBindFlag.Checked = (_thisGoodsEntity.SecurityCodeBindFlag == Constant.INT_IS_ONE);
  161. this.cbSecurityCodeCheckFlag.Checked = (_thisGoodsEntity.SecurityCodeCheckFlag == Constant.INT_IS_ONE);
  162. this.cbValueFlag.Checked = (this._thisGoodsEntity.ValueFlag == Constant.INT_IS_ONE);
  163. this.txtRemarks.Text = this._thisGoodsEntity.Remarks;
  164. this.dtpStartingDate.Value = this._thisGoodsEntity.StartingDate;
  165. this.txtSPM001.DataValue = this._thisGoodsEntity.AutoLossCycle;
  166. this.txtSPM002.DataValue = this._thisGoodsEntity.DeliverLimitCycle;
  167. this.txtMouldOutputCount.DataValue = this._thisGoodsEntity.MouldOutputCount;
  168. this.txtStandardGroutingNum.DataValue = this._thisGoodsEntity.StandardGroutingNum;
  169. this.txtMouldMaterialCode.Text = this._thisGoodsEntity.MouldMaterialCode;
  170. this.txtWaterLabelCode.Text = this._thisGoodsEntity.WaterLabelCode;
  171. this.txtCertificateCode.Text = this._thisGoodsEntity.CertificateCode;
  172. this.txtPlateLimitNum1.DataValue = this._thisGoodsEntity.PlateLimitNum;
  173. this.txtUnitPrice.DataValue = this._thisGoodsEntity.UnitPrice;
  174. this.txtReservedDays.DataValue = this._thisGoodsEntity.ReservedDays;
  175. this.chkGLT.Checked = (drGoods["GOODS_LINE_TYPE"] + "" == "1");
  176. this.cbGLTDetail.Enabled = this.chkGLT.Checked;
  177. this.cbGLTDetail.SelectedValue = (drGoods["GOODS_LINE_CODE"] + "");
  178. this.txtPackageNum.Text = drGoods["PackageNum"].ToString();
  179. this.txtOutletDistance.Text = drGoods["OutletDistance"].ToString();
  180. this.scbSAPCode1.Text = drGoods["MaterialCode"].ToString();
  181. this.txtMaterialRemark.Text = drGoods["MaterialRemark"].ToString();
  182. this.txtCopies.Text = drGoods["printcopies"].ToString();
  183. this.ftcLogo.InitValue(drGoods["logoname"] + "", drGoods["logoid"]);
  184. if (drGoods["MouldWeight"] != DBNull.Value)
  185. {
  186. this.txtMouldWeight.DataValue = Convert.ToDecimal(drGoods["MouldWeight"]);
  187. }
  188. if (drGoods["MouldCost"] != DBNull.Value)
  189. {
  190. this.txtMouldCost.DataValue = Convert.ToDecimal(drGoods["MouldCost"]);
  191. }
  192. this.chkScrapSumFlag.Checked = (drGoods["ScrapSumFlag"] + "" == "1");
  193. this.cbPlanFlag.Checked = (drGoods["PlanFlag"] + "" == "1");
  194. if (drGoods["SeatCoverCode"] != DBNull.Value)
  195. {
  196. this.txtSEATCOVERCODE.DataValue = Convert.ToInt32(drGoods["SeatCoverCode"]);
  197. }
  198. if (this._thisGoodsEntity.ProductDays.ToString() != null && this._thisGoodsEntity.ProductDays.ToString() != "") {
  199. this.txtproductDays.Text = this._thisGoodsEntity.ProductDays.ToString();
  200. }
  201. if (this._thisGoodsEntity.Attendance.ToString() != null && this._thisGoodsEntity.Attendance.ToString() != "")
  202. {
  203. this.txtattendance.Text = this._thisGoodsEntity.Attendance.ToString();
  204. }
  205. if (this._thisGoodsEntity.DaygroutingNumber.ToString() != null && this._thisGoodsEntity.DaygroutingNumber.ToString() != "")
  206. {
  207. this.txtdaygroutingNumber.Text = this._thisGoodsEntity.DaygroutingNumber.ToString();
  208. }
  209. if (this._thisGoodsEntity.ProtectdaMrate.ToString() != null && this._thisGoodsEntity.ProtectdaMrate.ToString() != "")
  210. {
  211. this.txtprotectdaMrate.Text = this._thisGoodsEntity.ProtectdaMrate.ToString();
  212. }
  213. //查询对应的图片
  214. DataSet dsImg = SystemModuleProxy.Service.getImageByGoodsId(this._formGoodsId);
  215. BindByteImage(dsImg);
  216. }
  217. }
  218. // 产品物料信息
  219. ClientRequestEntity cre = new ClientRequestEntity();
  220. cre.NameSpace = "MST_Goods";
  221. cre.Name = "GetGoodsSAPByEdit";
  222. cre.Request = this._formGoodsId;
  223. // 调用服务器端获取数据集
  224. ServiceResultEntity sre = SystemModuleProxy.Service.DoRequest(cre);
  225. if (sre != null && sre.Data != null && sre.Data.Tables.Count > 0)
  226. {
  227. this._sapInfo = sre.Data.Tables[0];
  228. this.dgvGoodsSap.DataSource = this._sapInfo;
  229. }
  230. this.txtGoodsCode.Focus();
  231. }
  232. catch (Exception ex)
  233. {
  234. // 对异常进行共通处理
  235. ExceptionManager.HandleEventException(this.ToString(),
  236. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  237. }
  238. }
  239. /// <summary>
  240. /// 获取数据事件
  241. /// </summary>
  242. private void btnSave_Click(object sender, EventArgs e)
  243. {
  244. try
  245. {
  246. //基础数据验证
  247. int ErrorId = ValidationText();
  248. if (ErrorId != Constant.INT_IS_ZERO)
  249. {
  250. string errorAddress = "";
  251. switch (ErrorId)
  252. {
  253. case 1:
  254. this.txtGoodsCode.Focus();
  255. errorAddress = "产品编码";
  256. break;
  257. case 3:
  258. this.txtGoodsName.Focus();
  259. errorAddress = "产品名称";
  260. break;
  261. case 6:
  262. this.scbGoodsType.Focus();
  263. errorAddress = "产品类别";
  264. break;
  265. case 7:
  266. this.ddlGlazeTypeID.Focus();
  267. errorAddress = "釉料类别";
  268. break;
  269. default:
  270. break;
  271. };
  272. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, errorAddress),
  273. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  274. return;
  275. }
  276. if (string.IsNullOrEmpty(scbSAPCode1.Text))
  277. {
  278. this.scbSAPCode1.Focus();
  279. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "物料编码"),
  280. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  281. return;
  282. }
  283. //if (string.IsNullOrEmpty(txtGroutmaterialcode.Text))
  284. //{
  285. // this.txtGroutmaterialcode.Focus();
  286. // MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "注浆初始物料编码"),
  287. // this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  288. // return;
  289. //}
  290. if (string.IsNullOrEmpty(ftcLogo.SelectedValue + ""))
  291. {
  292. this.ftcLogo.Focus();
  293. MessageBox.Show(string.Format(Messages.MSG_CMN_W005, "注浆商标"),
  294. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  295. return;
  296. }
  297. //查询产品编号唯一性
  298. if ((this.txtGoodsCode.Text.Trim() != this._thisGoodsEntity.GoodsCode && _formStatus == Constant.FormMode.Edit)
  299. || this._formStatus == Constant.FormMode.Add)
  300. {
  301. if (ValidationCode(this.txtGoodsCode.Text.Trim()) == false)
  302. {
  303. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "产品编码"), this.Text,
  304. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  305. return;
  306. }
  307. }
  308. //实体赋值
  309. if (this._thisGoodsEntity == null)
  310. {
  311. this._thisGoodsEntity = new GoodsEntity();
  312. }
  313. this._thisGoodsEntity.GoodsCode = this.txtGoodsCode.Text.Trim();
  314. this._thisGoodsEntity.GoodsModel = this.txtGoodsModel.Text.Trim();
  315. this._thisGoodsEntity.GoodsName = this.txtGoodsName.Text.Trim();
  316. this._thisGoodsEntity.GoodsSpecification = this.txtGoodsSpecification.Text;
  317. this._thisGoodsEntity.GoodsTypeID = Convert.ToInt32(scbGoodsType.SearchedItem["GoodsTypeID"]);
  318. this._thisGoodsEntity.GlazeTypeID = this.ddlGlazeTypeID.SelectedValue.ToString() == "" ? null : (int?)Convert.ToInt32(this.ddlGlazeTypeID.SelectedValue);
  319. this._thisGoodsEntity.MudStoreType = this.ddlMudStoreType.SelectedValue.ToString() == "" ? null : (int?)Convert.ToInt32(this.ddlMudStoreType.SelectedValue);
  320. this._thisGoodsEntity.MudQuantity = this.txtMudWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtMudWeight.Text);
  321. this._thisGoodsEntity.GlazeQuantity = this.txtGlazeWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtGlazeWeight.Text);
  322. this._thisGoodsEntity.LusterwareWeight = this.txtLusterwareWeight.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtLusterwareWeight.Text);
  323. this._thisGoodsEntity.ProductionCycle = this.txtProductionCycle.Text == "" ? Constant.INT_IS_ZERO : Convert.ToDecimal(this.txtProductionCycle.Text);
  324. this._thisGoodsEntity.StartingDate = this.dtpStartingDate.Value.Date;
  325. this._thisGoodsEntity.AutoLossCycle = (this.txtSPM001.DataValue.HasValue ? Convert.ToInt32(this.txtSPM001.DataValue) : 0);
  326. this._thisGoodsEntity.DeliverLimitCycle = (this.txtSPM002.DataValue.HasValue ? Convert.ToInt32(this.txtSPM002.DataValue) : 0);
  327. this._thisGoodsEntity.MouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
  328. this._thisGoodsEntity.StandardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
  329. this._thisGoodsEntity.MouldMaterialCode = this.txtMouldMaterialCode.Text.Trim();
  330. this._thisGoodsEntity.WaterLabelCode = this.txtWaterLabelCode.Text;
  331. this._thisGoodsEntity.CertificateCode = this.txtCertificateCode.Text;
  332. this._thisGoodsEntity.PlateLimitNum = (this.txtPlateLimitNum1.DataValue.HasValue ? Convert.ToInt32(this.txtPlateLimitNum1.DataValue) : 0);
  333. this._thisGoodsEntity.UnitPrice = (this.txtUnitPrice.DataValue.HasValue ? this.txtUnitPrice.DataValue.Value : 0);
  334. this._thisGoodsEntity.ReservedDays = (this.txtReservedDays.DataValue.HasValue ? Convert.ToInt32(this.txtReservedDays.DataValue) : 0);
  335. this._thisGoodsEntity.PackageNum = this.txtPackageNum.Text.Trim();
  336. this._thisGoodsEntity.OutletDistance = this.txtOutletDistance.Text.Trim();
  337. this._thisGoodsEntity.MaterialCode = this.scbSAPCode1.Text.Trim();
  338. this._thisGoodsEntity.MaterialRemark = this.txtMaterialRemark.Text;
  339. this._thisGoodsEntity.PrintCopies = (this.txtCopies.DataValue.HasValue ? Convert.ToInt32(this.txtCopies.DataValue) : 0);
  340. this._thisGoodsEntity.ProductDays = Convert.ToDecimal(this.txtproductDays.Text);//生产天数
  341. this._thisGoodsEntity.DaygroutingNumber= Convert.ToDecimal(this.txtdaygroutingNumber.Text);
  342. this._thisGoodsEntity.Attendance = Convert.ToDecimal(this.txtattendance.Text);
  343. this._thisGoodsEntity.ProtectdaMrate = Convert.ToDecimal(this.txtprotectdaMrate.Text);
  344. this._sapInfo.AcceptChanges();
  345. this._thisGoodsEntity.SAPInfo = this._sapInfo;
  346. this._thisGoodsEntity.LogoID = Convert.ToInt32(ftcLogo.SelectedValue);
  347. if (this.txtMouldWeight.DataValue != null)
  348. {
  349. this._thisGoodsEntity.MouldWeight = this.txtMouldWeight.DataValue;
  350. }
  351. if (this.txtMouldCost.DataValue != null)
  352. {
  353. this._thisGoodsEntity.MouldCost = this.txtMouldCost.DataValue;
  354. }
  355. if (this.txtSEATCOVERCODE.DataValue != null)
  356. {
  357. this._thisGoodsEntity.SeatCoverCode = Convert.ToInt32(this.txtSEATCOVERCODE.DataValue);
  358. }
  359. if (this.cbCeaseFlag.Checked)
  360. {
  361. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  362. }
  363. else
  364. {
  365. this._thisGoodsEntity.CeaseFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  366. }
  367. if (this.cbValueFlag.Checked)
  368. {
  369. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  370. }
  371. else
  372. {
  373. this._thisGoodsEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  374. }
  375. if (this.cbSecurityCodeBindFlag.Checked)
  376. {
  377. this._thisGoodsEntity.SecurityCodeBindFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  378. }
  379. else
  380. {
  381. this._thisGoodsEntity.SecurityCodeBindFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  382. }
  383. if (this.cbSecurityCodeCheckFlag.Checked)
  384. {
  385. this._thisGoodsEntity.SecurityCodeCheckFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  386. }
  387. else
  388. {
  389. this._thisGoodsEntity.SecurityCodeCheckFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  390. }
  391. this._thisGoodsEntity.ScrapSumFlag = (this.chkScrapSumFlag.Checked ? "1" : "0");
  392. this._thisGoodsEntity.PlanFlag = (this.cbPlanFlag.Checked ? "1" : "0");
  393. this._thisGoodsEntity.GoodsLineType = (this.chkGLT.Checked ? "1" : "0");
  394. this._thisGoodsEntity.GoodsLineCode = this.chkGLT.Checked ? this.cbGLTDetail.SelectedValue.ToString() : "L";
  395. this._thisGoodsEntity.Remarks = this.txtRemarks.Text;
  396. //首先将未修改的图片从集合中删除
  397. for (int i = 0; i < _imgList.Count; i++)
  398. {
  399. this._picByteList.RemoveAt(Constant.INT_IS_ZERO);
  400. this._smallByteList.RemoveAt(Constant.INT_IS_ZERO);
  401. }
  402. this._imgList.Clear();
  403. //循环插入图片
  404. for (int i = 0; i < _picByteList.Count; i++)
  405. {
  406. GoodsImageEntity imgEntity = new GoodsImageEntity();
  407. imgEntity.ValueFlag = Convert.ToInt32(Constant.ValueFlag.Effective);
  408. byte[] buffer = _picByteList[i];
  409. imgEntity.Image = buffer;
  410. imgEntity.Thumbnail = _smallByteList[i];
  411. this._imgList.Add(imgEntity);
  412. }
  413. //如果是编辑模式,有被删除的图片,那么要把这些图片也加入到集合中
  414. if (this._updateImgList.Count != Constant.INT_IS_ZERO)
  415. {
  416. for (int i = 0; i < this._updateImgList.Count; i++)
  417. {
  418. GoodsImageEntity updateImgEntity = this._updateImgList[i];
  419. this._imgList.Add(updateImgEntity);
  420. }
  421. }
  422. if (this._formGoodsId == Constant.INT_IS_ZERO)
  423. {
  424. int MyReturn = (int)DoAsync(new BaseAsyncMethod(() =>
  425. {
  426. return SystemModuleProxy.Service.AddGoods(this._thisGoodsEntity, this._imgList, this._attList);
  427. }));
  428. if (MyReturn > Constant.INT_IS_ZERO)
  429. {
  430. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  431. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  432. PageInitialization();
  433. }
  434. else if (MyReturn == -10)
  435. {
  436. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  437. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  438. this.scbSAPCode1.Focus();
  439. return;
  440. }
  441. else
  442. {
  443. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  444. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  445. }
  446. }
  447. else
  448. {
  449. int MyReturn = SystemModuleProxy.Service.UpdateGoods(_thisGoodsEntity, _imgList, _attList);
  450. if (MyReturn > Constant.INT_IS_ZERO)
  451. {
  452. MessageBox.Show(string.Format(Messages.MSG_CMN_I001, "产品档案", "保存"),
  453. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  454. this.DialogResult = DialogResult.OK;
  455. }
  456. else if (MyReturn == -10)
  457. {
  458. MessageBox.Show(string.Format(Messages.MSG_CMN_W006, "物料编码"), this.Text,
  459. MessageBoxButtons.OK, MessageBoxIcon.Warning);
  460. this.scbSAPCode1.Focus();
  461. return;
  462. }
  463. else if (MyReturn == -500)
  464. {
  465. MessageBox.Show(Messages.MSG_CMN_W012, this.Text, MessageBoxButtons.OK,
  466. MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
  467. this.DialogResult = DialogResult.OK;
  468. }
  469. else
  470. {
  471. MessageBox.Show(string.Format(Messages.MSG_CMN_W001, "产品档案", "保存"),
  472. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
  473. }
  474. }
  475. }
  476. catch (Exception ex)
  477. {
  478. // 对异常进行共通处理
  479. ExceptionManager.HandleEventException(this.ToString(),
  480. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  481. }
  482. }
  483. /// <summary>
  484. /// 上传缩略图
  485. /// </summary>
  486. private void btnUpload_Click(object sender, EventArgs e)
  487. {
  488. try
  489. {
  490. odlgFile.Filter = Constant.FILTER_PIC;
  491. odlgFile.FilterIndex = Constant.INT_IS_ZERO;
  492. odlgFile.RestoreDirectory = true;
  493. odlgFile.Title = "选择产品图片";
  494. odlgFile.FileName = null;
  495. odlgFile.RestoreDirectory = true;
  496. if (odlgFile.ShowDialog() == DialogResult.OK)
  497. {
  498. FileInfo file = new FileInfo(odlgFile.FileName);
  499. if (Constant.UPLOAD_PIC_MAX_SIZE < file.Length)
  500. {
  501. MessageBox.Show(string.Format(Messages.MSG_CMN_W013, "产品图片", "大小", "1M"),
  502. this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
  503. }
  504. else
  505. {
  506. Image PicImage = Image.FromStream(file.OpenRead());
  507. this._picByteList.Add(ImageToByte(PicImage));
  508. GetThumbnail(file);
  509. BindImg();
  510. }
  511. }
  512. }
  513. catch (Exception ex)
  514. {
  515. // 对异常进行共通处理
  516. ExceptionManager.HandleEventException(this.ToString(),
  517. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  518. }
  519. }
  520. /// <summary>
  521. /// 删除某缩略图
  522. /// </summary>
  523. private void btnDelete_Click(object sender, EventArgs e)
  524. {
  525. try
  526. {
  527. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  528. {
  529. int index = lvSelect.Index;
  530. if (index < Constant.INT_IS_ZERO)
  531. {
  532. index = Constant.INT_IS_ZERO;
  533. }
  534. ilPic.Images.RemoveAt(index);
  535. this._picByteList.RemoveAt(index);
  536. this._smallByteList.RemoveAt(index);
  537. lvPic.Items.RemoveAt(index);
  538. if (index < this._imgList.Count)
  539. {
  540. if (this._imgList[index].GoodsImageID != Constant.INT_IS_ZERO)
  541. {
  542. GoodsImageEntity deleteImgEntity = this._imgList[index];
  543. this._imgList[index].ValueFlag = Convert.ToInt32(Constant.ValueFlag.Invalid);
  544. this._updateImgList.Add(deleteImgEntity);
  545. this._imgList.RemoveAt(index);
  546. }
  547. }
  548. }
  549. BindImg();
  550. }
  551. catch (Exception ex)
  552. {
  553. // 对异常进行共通处理
  554. ExceptionManager.HandleEventException(this.ToString(),
  555. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  556. }
  557. }
  558. /// <summary>
  559. /// 关闭窗体
  560. /// </summary>
  561. private void btnCancel_Click(object sender, EventArgs e)
  562. {
  563. this.DialogResult = DialogResult.OK;
  564. }
  565. /// <summary>
  566. /// 查看图片
  567. /// </summary>
  568. private void lvPic_DoubleClick(object sender, EventArgs e)
  569. {
  570. try
  571. {
  572. foreach (ListViewItem lvSelect in lvPic.SelectedItems)
  573. {
  574. int index = lvSelect.Index;
  575. if (index < Constant.INT_IS_ZERO)
  576. {
  577. index = Constant.INT_IS_ZERO;
  578. }
  579. F_CMN_0102 addGoods = new F_CMN_0102(_picByteList[index]);
  580. DialogResult dialogresult = addGoods.ShowDialog();
  581. }
  582. }
  583. catch (Exception ex)
  584. {
  585. // 对异常进行共通处理
  586. ExceptionManager.HandleEventException(this.ToString(),
  587. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  588. }
  589. }
  590. /// <summary>
  591. /// SAP物料编码改变事件
  592. /// </summary>
  593. /// <param name="sender"></param>
  594. /// <param name="e"></param>
  595. private void txtSAPRemark_TextChanged(object sender, EventArgs e)
  596. {
  597. if (this.dgvGoodsSap.CurrentRow == null)
  598. {
  599. return;
  600. }
  601. try
  602. {
  603. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  604. if (row != null)
  605. {
  606. row["materialremark"] = txtSAPRemark.Text;
  607. row.EndEdit();
  608. }
  609. }
  610. catch (Exception ex)
  611. {
  612. // 对异常进行共通处理
  613. ExceptionManager.HandleEventException(this.ToString(),
  614. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  615. }
  616. }
  617. /// <summary>
  618. ///
  619. /// </summary>
  620. /// <param name="sender"></param>
  621. /// <param name="e"></param>
  622. private void txtMouldOutputCount_TextChanged(object sender, EventArgs e)
  623. {
  624. try
  625. {
  626. int mouldOutputCount = (this.txtMouldOutputCount.DataValue.HasValue ? Convert.ToInt32(this.txtMouldOutputCount.DataValue) : 1);
  627. int standardGroutingNum = (this.txtStandardGroutingNum.DataValue.HasValue ? Convert.ToInt32(this.txtStandardGroutingNum.DataValue) : 0);
  628. this.txtStandardGroutingSum.DataValue = mouldOutputCount * standardGroutingNum;
  629. }
  630. catch (Exception ex)
  631. {
  632. // 对异常进行共通处理
  633. ExceptionManager.HandleEventException(this.ToString(),
  634. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  635. }
  636. }
  637. /// <summary>
  638. ///
  639. /// </summary>
  640. /// <param name="sender"></param>
  641. /// <param name="e"></param>
  642. private void chkGLT_Click(object sender, EventArgs e)
  643. {
  644. this.cbGLTDetail.Enabled = this.chkGLT.Checked;
  645. }
  646. #endregion
  647. #region 私有方法
  648. /// <summary>
  649. /// 加载页面所需的数据源
  650. /// </summary>
  651. private void LoadDataSource()
  652. {
  653. try
  654. {
  655. // 绑定釉料类别
  656. DataTable dtGlazeType = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC002, Constant.INT_IS_ONE);
  657. if (dtGlazeType != null)
  658. {
  659. ddlGlazeTypeID.DisplayMember = "DictionaryValue";
  660. ddlGlazeTypeID.ValueMember = "DictionaryID";
  661. ddlGlazeTypeID.DataSource = dtGlazeType;
  662. }
  663. // 绑定坯库类型
  664. DataTable dtMudStoreType = SystemModuleProxy.Service.GetDataDictionaryByType(Constant.DictionaryType.TPC009, Constant.INT_IS_ONE);
  665. if (dtMudStoreType != null)
  666. {
  667. //cq MODIFY 20210826 产品档案坯库类型取汉字(这里是Remarks)
  668. //ddlMudStoreType.DisplayMember = "DictionaryValue";
  669. //begin
  670. ddlMudStoreType.DisplayMember = "Remarks";
  671. ddlMudStoreType.ValueMember = "DictionaryID";
  672. ddlMudStoreType.DataSource = dtMudStoreType;
  673. }
  674. DataSet logos = SystemModuleProxy.Service.GetLogoInfo();
  675. if (logos != null && logos.Tables.Count > 0)
  676. {
  677. ftcLogo.DisplayMember = "LogoNameCode";
  678. ftcLogo.ValueMember = "LogoID";
  679. ftcLogo.DataSource = logos.Tables[0];
  680. }
  681. //L:立浇 G:高压 M:粘接高压(三水厂) Q:吊装线
  682. DataTable dt = new DataTable();
  683. dt.Columns.Add("key");
  684. dt.Columns.Add("value");
  685. dt.Rows.Add(new object[] { "L", "立浇【L】" });
  686. dt.Rows.Add(new object[] { "G", "高压【G】" });
  687. dt.Rows.Add(new object[] { "M", "粘接高压(三水厂)【M】" });
  688. //dt.Rows.Add(new object[] { "Q", "吊装线" });
  689. this.cbGLTDetail.DataSource = dt;
  690. this.cbGLTDetail.ValueMember = "key";
  691. this.cbGLTDetail.DisplayMember = "value";
  692. }
  693. catch (Exception ex)
  694. {
  695. throw ex;
  696. }
  697. }
  698. /// <summary>
  699. /// 绑定缩略图到控件中
  700. /// </summary>
  701. private void BindImg()
  702. {
  703. try
  704. {
  705. //每次绑定要清空数据源
  706. this.ilPic.Images.Clear();
  707. //将缩略图二进制集合中的数据转换成图片文件
  708. List<Image> LSImageList = new List<Image>();
  709. foreach (byte[] smallby in _smallByteList)
  710. {
  711. LSImageList.Add(byteArrayToImage(smallby));
  712. }
  713. //添加数据源
  714. foreach (Image img in LSImageList)
  715. {
  716. ilPic.Images.Add(img);
  717. }
  718. this.ilPic.ImageSize = new Size(Constant.INT_IS_HUNDRED, Constant.INT_IS_HUNDRED);
  719. this.lvPic.LargeImageList = this.ilPic;
  720. this.lvPic.BeginUpdate();
  721. //清空列表的数据源
  722. lvPic.Items.Clear();
  723. //添加列表的数据源
  724. for (int i = 0; i < ilPic.Images.Count; i++)
  725. {
  726. ListViewItem lvi = new ListViewItem();
  727. lvi.ImageIndex = i;
  728. this.lvPic.Items.Add(lvi);
  729. }
  730. this.lvPic.EndUpdate();
  731. }
  732. catch (Exception ex)
  733. {
  734. throw ex;
  735. }
  736. }
  737. /// <summary>
  738. /// 重绘缩略图并把缩略图转为二进制储存在集合众
  739. /// </summary>
  740. /// <param name="sourceFile">图片实体</param>
  741. /// <returns></returns>
  742. private void GetThumbnail(FileInfo sourceFile)
  743. {
  744. try
  745. {
  746. Image imgSource = Image.FromStream(sourceFile.OpenRead());
  747. ImageFormat thisFormat = imgSource.RawFormat;
  748. int sW = Constant.INT_IS_ZERO, sH = Constant.INT_IS_ZERO;
  749. // 按比例缩放
  750. int sWidth = imgSource.Width;
  751. int sHeight = imgSource.Height;
  752. int destWidth = Constant.INT_IS_HUNDRED;
  753. int destHeight = getSmallImageHeight(sWidth, sHeight, destWidth);
  754. if (sHeight > destHeight || sWidth > destWidth)
  755. {
  756. if ((sWidth * destHeight) > (sHeight * destWidth))
  757. {
  758. sW = destWidth;
  759. sH = (destWidth * sHeight) / sWidth;
  760. }
  761. else
  762. {
  763. sH = destHeight;
  764. sW = (sWidth * destHeight) / sHeight;
  765. }
  766. }
  767. else
  768. {
  769. sW = sWidth;
  770. sH = sHeight;
  771. }
  772. Bitmap outBmp = new Bitmap(destWidth, destHeight);
  773. Graphics g = Graphics.FromImage(outBmp);
  774. g.Clear(Color.Black);
  775. // 设置画布的描绘质量
  776. g.CompositingQuality = CompositingQuality.HighQuality;
  777. g.SmoothingMode = SmoothingMode.HighQuality;
  778. g.InterpolationMode = InterpolationMode.HighQualityBicubic;
  779. g.DrawImage(imgSource, new Rectangle((destWidth - sW) / Constant.INT_IS_TWO, (destHeight - sH) /
  780. Constant.INT_IS_TWO, sW, sH), Constant.INT_IS_ZERO, Constant.INT_IS_ZERO,
  781. imgSource.Width, imgSource.Height, GraphicsUnit.Pixel);
  782. g.Dispose();
  783. //将重绘的图片转为二进制并保存
  784. Image image = (Image)outBmp;
  785. byte[] smallbuffer = ImageToByte(image);
  786. this._smallByteList.Add(smallbuffer);
  787. imgSource.Dispose();
  788. outBmp.Dispose();
  789. }
  790. catch (Exception ex)
  791. {
  792. throw ex;
  793. }
  794. }
  795. /// <summary>
  796. /// 根据原图片宽高比获取缩略图的高(根据宽)
  797. /// </summary>
  798. /// <param name="BigWidth">原图宽度</param>
  799. /// <param name="BigHeight">原图高度</param>
  800. /// <param name="SmallWidth">缩略图宽度</param>
  801. /// <returns>缩略图的高度</returns>
  802. private int getSmallImageHeight(int BigWidth, int BigHeight, int SmallWidth)
  803. {
  804. try
  805. {
  806. decimal scale = Convert.ToDecimal(BigWidth) / Convert.ToDecimal(BigHeight);
  807. return Convert.ToInt32(SmallWidth / scale);
  808. }
  809. catch (Exception ex)
  810. {
  811. throw ex;
  812. }
  813. }
  814. /// <summary>
  815. /// 验证添加项
  816. /// </summary>
  817. private int ValidationText()
  818. {
  819. int ErrorID = 0;
  820. if (this.ddlGlazeTypeID.SelectedValue.ToString() == string.Empty)
  821. {
  822. ErrorID = 7;
  823. }
  824. if (this.txtGoodsName.Text.Trim() == string.Empty)
  825. {
  826. ErrorID = 3;
  827. }
  828. if (scbGoodsType.SearchedItem == null)
  829. {
  830. ErrorID = 6;
  831. }
  832. if (this.txtGoodsCode.Text.Trim() == string.Empty)
  833. {
  834. ErrorID = 1;
  835. }
  836. return ErrorID;
  837. }
  838. /// <summary>
  839. /// 绑定缩略图到缩略图集合中
  840. /// </summary>
  841. /// <param name="ImageData">图片集合</param>
  842. private void BindByteImage(DataSet ImageData)
  843. {
  844. try
  845. {
  846. foreach (DataRow dr in ImageData.Tables[0].Rows)
  847. {
  848. //将数据库中的缩略图取出
  849. this._smallByteList.Add((byte[])dr[2]);
  850. this._picByteList.Add((byte[])dr[3]);
  851. //绑定实体到修改图片集合中
  852. GoodsImageEntity imgEntity = new GoodsImageEntity();
  853. imgEntity.GoodsImageID = Convert.ToDecimal(dr[0]);
  854. imgEntity.GoodsID = Convert.ToDecimal(dr[1]);
  855. imgEntity.Thumbnail = (byte[])dr[2];
  856. imgEntity.Image = (byte[])dr[3];
  857. imgEntity.AccountID = Convert.ToDecimal(dr[4]);
  858. imgEntity.ValueFlag = Convert.ToDecimal(dr[5]);
  859. imgEntity.CreateTime = Convert.ToDateTime(dr[6]);
  860. imgEntity.CreateUserID = Convert.ToDecimal(dr[7]);
  861. imgEntity.UpdateTime = Convert.ToDateTime(dr[8]);
  862. imgEntity.UpdateUserID = Convert.ToDecimal(dr[9]);
  863. imgEntity.OPTimeStamp = Convert.ToDateTime(dr[10]);
  864. this._imgList.Add(imgEntity);
  865. }
  866. //绑定缩略图
  867. BindImg();
  868. }
  869. catch (Exception ex)
  870. {
  871. throw ex;
  872. }
  873. }
  874. /// <summary>
  875. /// 将数据库中的二进制转换成图片
  876. /// </summary>
  877. /// <param name="data">需要转换成图片的二进制数据</param>
  878. /// <returns>图片文件实体</returns>
  879. private static Image byteArrayToImage(object data)
  880. {
  881. try
  882. {
  883. System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])data);
  884. System.Drawing.Image returnImage = System.Drawing.Image.FromStream(ms);
  885. return returnImage;
  886. }
  887. catch (Exception ex)
  888. {
  889. throw ex;
  890. }
  891. }
  892. /// <summary>
  893. /// 将图片文件转换成二进制
  894. /// </summary>
  895. /// <param name="img">需要转换的图片</param>
  896. /// <returns>图片二进制数据</returns>
  897. private static byte[] ImageToByte(Image img)
  898. {
  899. try
  900. {
  901. byte[] smallbuffer = null;
  902. using (MemoryStream ms = new MemoryStream())
  903. {
  904. img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
  905. ms.Position = Constant.INT_IS_ZERO;
  906. smallbuffer = new byte[ms.Length];
  907. ms.Read(smallbuffer, Constant.INT_IS_ZERO, Convert.ToInt32(ms.Length));
  908. ms.Flush();
  909. }
  910. return smallbuffer;
  911. }
  912. catch (Exception ex)
  913. {
  914. throw ex;
  915. }
  916. }
  917. /// <summary>
  918. /// 验证产品编号唯一性
  919. /// </summary>
  920. /// <param name="goodsCode">产品编号</param>
  921. /// <returns>是否重复,真为不重复,可插入</returns>
  922. private bool ValidationCode(string goodsCode)
  923. {
  924. try
  925. {
  926. GoodsEntity vgoods = new GoodsEntity();
  927. vgoods.GoodsCodeOnly = goodsCode;
  928. int i = ((DataSet)SystemModuleProxy.Service.SerachGoods(vgoods)).Tables[0].Rows.Count;
  929. if (i > Constant.INT_IS_ZERO)
  930. {
  931. return false;
  932. }
  933. else
  934. {
  935. return true;
  936. }
  937. }
  938. catch (Exception ex)
  939. {
  940. throw ex;
  941. }
  942. }
  943. /// <summary>
  944. /// 页面控件初始化
  945. /// </summary>
  946. private void PageInitialization()
  947. {
  948. //页面控件初始化
  949. this.txtGoodsCode.Text = "";
  950. //this.gtsGoodaType.GoodsTypeCode = null;
  951. //this.gtsGoodaType.GoodsTypeID = null;
  952. //this.gtsGoodaType.GoodsTypeName = null;
  953. //this.gtsGoodaType.Text = "";
  954. this.scbGoodsType.ClearValue();
  955. this.txtGoodsName.Text = "";
  956. this.txtGoodsModel.Text = "";
  957. this.txtGoodsSpecification.Text = "";
  958. this.txtMudWeight.Text = "";
  959. this.txtGlazeWeight.Text = "";
  960. //this.ddlGlazeTypeID.SelectedValue = null;
  961. this.txtProductionCycle.Text = "";
  962. this.txtLusterwareWeight.Text = "";
  963. this.txtRemarks.Text = "";
  964. this.lvPic.Items.Clear();
  965. this.cbCeaseFlag.Checked = true;
  966. this.cbValueFlag.Checked = true;
  967. this.chkGLT.Checked = false;
  968. this.txtSPM001.DataValue = 0;
  969. this.txtSPM002.DataValue = 0;
  970. this.txtMouldOutputCount.DataValue = 1;
  971. this.txtStandardGroutingNum.DataValue = 0;
  972. this.dtpStartingDate.Value = DateTime.Now.Date;
  973. //成员变量初始化
  974. this._thisGoodsEntity = new GoodsEntity();
  975. this._picByteList = new List<byte[]>();
  976. this._smallByteList = new List<byte[]>();
  977. this._imgList = new List<GoodsImageEntity>();
  978. this._updateImgList = new List<GoodsImageEntity>();
  979. this.txtUnitPrice.DataValue = 0;
  980. this.txtPlateLimitNum1.DataValue = 0;
  981. this.txtReservedDays.DataValue = 0;
  982. this.txtPackageNum.Text = "";
  983. this.txtOutletDistance.Text = "";
  984. this.scbSAPCode1.Text = "";
  985. this.txtMaterialRemark.Text = "";
  986. this.txtMouldWeight.DataValue = null;
  987. this.txtMouldCost.DataValue = null;
  988. this.txtSEATCOVERCODE.DataValue = null;
  989. this.txtWaterLabelCode.Clear();
  990. this.txtCertificateCode.Clear();
  991. this.chkScrapSumFlag.Checked = true;
  992. this.txtMouldMaterialCode.Clear();
  993. foreach (DataRow row in this._sapInfo.Rows)
  994. {
  995. row["materialcode"] = DBNull.Value;
  996. row["materialremark"] = DBNull.Value;
  997. row["WaterLabelCode"] = DBNull.Value;
  998. row["PlateLimitNum"] = DBNull.Value;
  999. }
  1000. this._sapInfo.AcceptChanges();
  1001. }
  1002. #endregion
  1003. #region SAP物料
  1004. private void dgvGoodsSap_SelectionChanged(object sender, EventArgs e)
  1005. {
  1006. if (this.dgvGoodsSap.CurrentRow == null)
  1007. {
  1008. //this.scbSAPCode2.Clear();
  1009. //this.txtSAPRemark.Clear();
  1010. return;
  1011. }
  1012. try
  1013. {
  1014. this.scbSAPCode2.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialcode"].Value + "";
  1015. this.txtSAPRemark.Text = this.dgvGoodsSap.CurrentRow.Cells["colmaterialremark"].Value + "";
  1016. this.txtSAPWaterLabelCode.Text = this.dgvGoodsSap.CurrentRow.Cells["colWaterLabelCode"].Value + "";
  1017. this.txtSAPCertificateCode.Text = this.dgvGoodsSap.CurrentRow.Cells["colCertificateCode"].Value + "";
  1018. this.txtPlateLimitNum.Text = this.dgvGoodsSap.CurrentRow.Cells["colPlateLimitNum"].Value + "";
  1019. }
  1020. catch (Exception ex)
  1021. {
  1022. // 对异常进行共通处理
  1023. ExceptionManager.HandleEventException(this.ToString(),
  1024. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1025. }
  1026. }
  1027. private void txtSAPCode_Validated(object sender, EventArgs e)
  1028. {
  1029. //if (this.dgvGoodsSap.CurrentRow == null)
  1030. //{
  1031. // return;
  1032. //}
  1033. //try
  1034. //{
  1035. // DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1036. // if (row != null)
  1037. // {
  1038. // row["materialcode"] = scbSAPCode2.Text;
  1039. // row.EndEdit();
  1040. // }
  1041. //}
  1042. //catch (Exception ex)
  1043. //{
  1044. // // 对异常进行共通处理
  1045. // ExceptionManager.HandleEventException(this.ToString(),
  1046. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1047. //}
  1048. }
  1049. private void txtSAPRemark_Validated(object sender, EventArgs e)
  1050. {
  1051. //if (this.dgvGoodsSap.CurrentRow == null)
  1052. //{
  1053. // return;
  1054. //}
  1055. //try
  1056. //{
  1057. // DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1058. // if (row != null)
  1059. // {
  1060. // row["materialremark"] = txtSAPRemark.Text;
  1061. // row.EndEdit();
  1062. // }
  1063. //}
  1064. //catch (Exception ex)
  1065. //{
  1066. // // 对异常进行共通处理
  1067. // ExceptionManager.HandleEventException(this.ToString(),
  1068. // System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1069. //}
  1070. }
  1071. private void txtSAPWaterLabelCode_Validated(object sender, EventArgs e)
  1072. {
  1073. if (this.dgvGoodsSap.CurrentRow == null)
  1074. {
  1075. return;
  1076. }
  1077. try
  1078. {
  1079. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1080. if (row != null)
  1081. {
  1082. row["WaterLabelCode"] = txtSAPWaterLabelCode.Text;
  1083. row.EndEdit();
  1084. }
  1085. }
  1086. catch (Exception ex)
  1087. {
  1088. // 对异常进行共通处理
  1089. ExceptionManager.HandleEventException(this.ToString(),
  1090. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1091. }
  1092. }
  1093. private void txtSAPCertificateCode_Validated(object sender, EventArgs e)
  1094. {
  1095. if (this.dgvGoodsSap.CurrentRow == null)
  1096. {
  1097. return;
  1098. }
  1099. try
  1100. {
  1101. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1102. if (row != null)
  1103. {
  1104. row["CertificateCode"] = txtSAPCertificateCode.Text;
  1105. row.EndEdit();
  1106. }
  1107. }
  1108. catch (Exception ex)
  1109. {
  1110. // 对异常进行共通处理
  1111. ExceptionManager.HandleEventException(this.ToString(),
  1112. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1113. }
  1114. }
  1115. /// <summary>
  1116. /// 物料编码改变事件
  1117. /// </summary>
  1118. /// <param name="sender"></param>
  1119. /// <param name="e"></param>
  1120. private void scbSAPCode2_TextValueChanged(object sender, WinForm.Controls.ScbSearchBox.TextChangeEventArgs e)
  1121. {
  1122. if (this.dgvGoodsSap.CurrentRow == null)
  1123. {
  1124. return;
  1125. }
  1126. try
  1127. {
  1128. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1129. if (row != null)
  1130. {
  1131. row["materialcode"] = scbSAPCode2.Text;
  1132. row.EndEdit();
  1133. }
  1134. }
  1135. catch (Exception ex)
  1136. {
  1137. // 对异常进行共通处理
  1138. ExceptionManager.HandleEventException(this.ToString(),
  1139. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1140. }
  1141. }
  1142. /// <summary>
  1143. /// 装板限制数量改变事件
  1144. /// </summary>
  1145. /// <param name="sender"></param>
  1146. /// <param name="e"></param>
  1147. private void txtPlateLimitNum_Validated(object sender, EventArgs e)
  1148. {
  1149. if (this.dgvGoodsSap.CurrentRow == null)
  1150. {
  1151. return;
  1152. }
  1153. try
  1154. {
  1155. DataRowView row = this.dgvGoodsSap.CurrentRow.DataBoundItem as DataRowView;
  1156. if (row != null)
  1157. {
  1158. if (txtPlateLimitNum.Text != "")
  1159. {
  1160. row["PlateLimitNum"] = txtPlateLimitNum.Text;
  1161. }
  1162. else {
  1163. row["PlateLimitNum"] = DBNull.Value;
  1164. }
  1165. row.EndEdit();
  1166. }
  1167. }
  1168. catch (Exception ex)
  1169. {
  1170. // 对异常进行共通处理
  1171. ExceptionManager.HandleEventException(this.ToString(),
  1172. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  1173. }
  1174. }
  1175. /// <summary>
  1176. /// 防伪码绑定改变事件
  1177. /// </summary>
  1178. /// <param name="sender"></param>
  1179. /// <param name="e"></param>
  1180. private void cbSecurityCodeBindFlag_CheckedChanged(object sender, EventArgs e)
  1181. {
  1182. if (!this.cbSecurityCodeBindFlag.Checked)
  1183. {
  1184. this.cbSecurityCodeCheckFlag.Checked = false;
  1185. }
  1186. }
  1187. /// <summary>
  1188. /// 防伪码验证改变事件
  1189. /// </summary>
  1190. /// <param name="sender"></param>
  1191. /// <param name="e"></param>
  1192. private void cbSecurityCodeCheckFlag_CheckedChanged(object sender, EventArgs e)
  1193. {
  1194. if (this.cbSecurityCodeCheckFlag.Checked)
  1195. {
  1196. this.cbSecurityCodeBindFlag.Checked = true;
  1197. }
  1198. }
  1199. #endregion
  1200. }
  1201. }