From d5679ac1d914ff779d2889b54f4623c0d9282507 Mon Sep 17 00:00:00 2001 From: admin Date: Sat, 19 Dec 2020 16:33:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- U8AppMain/FrmMain.cs | 73 ++++++++++++++++++++++++--------- U8AppMain/Voucher/Vouch.cs | 4 +- U8AppMain/Voucher/VoucherDAL.cs | 26 +++++++----- U8AppMain/Voucher/Vouchs.cs | 4 +- 4 files changed, 73 insertions(+), 34 deletions(-) diff --git a/U8AppMain/FrmMain.cs b/U8AppMain/FrmMain.cs index c4f176f..c6cbb1f 100644 --- a/U8AppMain/FrmMain.cs +++ b/U8AppMain/FrmMain.cs @@ -221,27 +221,62 @@ namespace U8AppMain private void 领料单ToolStripMenuItem_Click(object sender, EventArgs e) { - var a = new Voucher.VoucherDAL(connStr); - a.Add(new Voucher.Vouch() - { - DDate=DateTime.Today, - CRdCode="201", - CDepCode="5401", - CPersonCode="wx014", - CMaker="朱杰", - Vt_id="30718", - IswfControlled=0, - Vouchs=new List() { - new Voucher.Vouchs(){ - CInvCode="107001", - Iquantity=20, - CwhCode="2", - - } - + //单据号 日期 部门编码 业务员 制单人 存货编码 数量 + if (this.dataTable == null || this.dataTable.Rows.Count == 0) + { + return; + } + var bomLookup = new Dictionary(); + try + { + foreach (DataRow row in this.dataTable.Rows) + { + var Vouch = new Voucher.Vouch(); + var Vouchs = new Voucher.Vouchs(); + Vouch.CCode = row["单据号"].ToString(); + Vouch.DDate = DateTime.Parse(row["日期"].ToString()); + Vouch.CDepCode = row["部门编码"].ToString(); + Vouch.CPersonCode = row["业务员"].ToString(); + Vouch.CMaker = row["制单人"].ToString(); + Vouch.CRdCode = "201"; + + Vouch.Vt_id = "30718"; + Vouch.IswfControlled = 0; + var strKey = Vouch.CCode; + if (bomLookup.ContainsKey(strKey)) + { + Vouch = bomLookup[strKey]; + } + else + { + bomLookup.Add(strKey, Vouch); + } + Vouchs.CInvCode = row["存货编码"].ToString(); + Vouchs.Iquantity = int.Parse(row["数量"].ToString()); + Vouch.Vouchs.Add(Vouchs); } - });; + foreach (var item in bomLookup.Values) + { + var a = new Voucher.VoucherDAL(connStr); + if (a.Add(item)) + { + this.richTextBox1.SelectionColor = Color.Green; + this.richTextBox1.AppendText($"{item.CCode} {item.cDefine12} 保存成功\r\n"); + } + else + { + this.richTextBox1.SelectionColor = Color.Red; + this.richTextBox1.AppendText($"{item.CCode} 保存出错\r\n"); + } + } + } + catch (Exception err) + { + this.richTextBox1.SelectionColor = Color.Red; + this.richTextBox1.AppendText($"{err.Message}读取数据出错\r\n"); + return; + } } } } diff --git a/U8AppMain/Voucher/Vouch.cs b/U8AppMain/Voucher/Vouch.cs index 1e8d932..1139c23 100644 --- a/U8AppMain/Voucher/Vouch.cs +++ b/U8AppMain/Voucher/Vouch.cs @@ -34,9 +34,9 @@ namespace U8AppMain.Voucher public DateTime dnverifytime { get; set; } - public IEnumerable Vouchs { get; set; } = new List(); - + public ICollection Vouchs { get; set; } = new List(); + public string cDefine12 { get; set; } diff --git a/U8AppMain/Voucher/VoucherDAL.cs b/U8AppMain/Voucher/VoucherDAL.cs index 6046b29..83727d6 100644 --- a/U8AppMain/Voucher/VoucherDAL.cs +++ b/U8AppMain/Voucher/VoucherDAL.cs @@ -37,7 +37,7 @@ namespace U8AppMain.Voucher _connStr = connStr; } - public void Add(Vouch vouch) + public bool Add(Vouch vouch) { var conn = new SqlConnection(this._connStr); @@ -46,10 +46,12 @@ namespace U8AppMain.Voucher try { //获取ID - var idEnity = new IdEnity(); - idEnity.cAcc_Id = "003"; - idEnity.cVouchType = "mv"; - idEnity.iAmount = vouch.Vouchs.Count(); + var idEnity = new IdEnity + { + cAcc_Id = "003", + cVouchType = "mv", + iAmount = vouch.Vouchs.Count() + }; DynamicParameters sp = new DynamicParameters(idEnity); sp.Add("@iFatherId", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output); sp.Add("@iChildId", 0, System.Data.DbType.Int32, System.Data.ParameterDirection.Output); @@ -71,15 +73,16 @@ namespace U8AppMain.Voucher //组装Code var cCode = prefix + cSeed.Substring(2,cSeed.Length-2) + maxCode.ToString().PadLeft(5, '0'); //主表 - var sql = @"insert into MaterialAppVouch(id,ddate,ccode,crdcode,cdepcode,cpersoncode,cmaker,vt_id,iswfcontrolled,dnmaketime) - values(@id,@ddate,@ccode,@crdcode,@cdepcode,@cpersoncode,@cmaker,@vt_id,@iswfcontrolled, getdate())"; + var sql = @"insert into MaterialAppVouch(id,ddate,ccode,crdcode,cdepcode,cpersoncode,cmaker,vt_id,iswfcontrolled,dnmaketime,cDefine12) + values(@id,@ddate,@ccode,@crdcode,@cdepcode,@cpersoncode,@cmaker,@vt_id,@iswfcontrolled, getdate(),@cDefine12)"; vouch.ID = iFatherId; + vouch.cDefine12 = vouch.CCode; vouch.CCode = cCode; conn.Execute(sql, vouch, trans); sql = @"INSERT INTO MaterialAppVouchs (autoid, id, cinvcode, inum, iquantity , cwhcode, iexpiratdatecalcu, irowno, iordertype, isotype , ipesotype) VALUES (@autoid, @id, @cinvcode, @inum, @iquantity , @cwhcode, @iexpiratdatecalcu, @irowno, @iordertype, @isotype , @ipesotype)"; //明细 - var n = vouch.Vouchs.Count(); + var n = vouch.Vouchs.Count()-1; foreach (var item in vouch.Vouchs) { item.autoid = iChildId - n; @@ -90,18 +93,19 @@ namespace U8AppMain.Voucher conn.Execute(sql, vouch.Vouchs, trans); trans.Commit(); } - catch (Exception err) + catch (Exception err ) { trans.Rollback(); throw err; + return false; } finally { - + conn.Close(); } - + return true; diff --git a/U8AppMain/Voucher/Vouchs.cs b/U8AppMain/Voucher/Vouchs.cs index d167ff4..bcb34fe 100644 --- a/U8AppMain/Voucher/Vouchs.cs +++ b/U8AppMain/Voucher/Vouchs.cs @@ -21,12 +21,12 @@ namespace U8AppMain.Voucher public int Iquantity { get; set; } - public string CwhCode { get; set; } + public string CwhCode { get; set; } = "2"; public int IExpiratdatecalcu { get; set; } - public int IRowNO { get; set; } + public int IRowNO { get; set; } public int IorderType { get; set; }