From 9881320eda16788ab2d96531c1c23fe0555210d5 Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 18 Dec 2020 16:35:46 +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.Designer.cs | 18 +++++- U8AppMain/FrmMain.cs | 103 +++++++++++++++++------------- U8AppMain/Purchase/EntryEnity.cs | 44 ++++++------- U8AppMain/Purchase/HeaderEnity.cs | 36 +++++------ U8AppMain/Purchase/ufinterface.cs | 34 ++++------ 5 files changed, 126 insertions(+), 109 deletions(-) diff --git a/U8AppMain/FrmMain.Designer.cs b/U8AppMain/FrmMain.Designer.cs index c3bedab..619d374 100644 --- a/U8AppMain/FrmMain.Designer.cs +++ b/U8AppMain/FrmMain.Designer.cs @@ -35,6 +35,7 @@ namespace U8AppMain this.kryptonDataGridView1 = new ComponentFactory.Krypton.Toolkit.KryptonDataGridView(); this.BtnImportExcel = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); + this.button1 = new System.Windows.Forms.Button(); this.panel1.SuspendLayout(); this.panel2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.kryptonDataGridView1)).BeginInit(); @@ -42,6 +43,7 @@ namespace U8AppMain // // panel1 // + this.panel1.Controls.Add(this.button1); this.panel1.Controls.Add(this.BtnImportExcel); this.panel1.Controls.Add(this.BtnBomImport); this.panel1.Dock = System.Windows.Forms.DockStyle.Top; @@ -96,12 +98,23 @@ namespace U8AppMain // // textBox1 // - this.textBox1.Location = new System.Drawing.Point(145, 193); + this.textBox1.Dock = System.Windows.Forms.DockStyle.Bottom; + this.textBox1.Location = new System.Drawing.Point(0, 147); this.textBox1.Multiline = true; this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(515, 246); + this.textBox1.Size = new System.Drawing.Size(800, 261); this.textBox1.TabIndex = 1; // + // button1 + // + this.button1.Location = new System.Drawing.Point(211, 12); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 2; + this.button1.Text = "请购单导入"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // // FrmMain // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); @@ -127,6 +140,7 @@ namespace U8AppMain private ComponentFactory.Krypton.Toolkit.KryptonDataGridView kryptonDataGridView1; private System.Windows.Forms.Button BtnImportExcel; private System.Windows.Forms.TextBox textBox1; + private System.Windows.Forms.Button button1; } } diff --git a/U8AppMain/FrmMain.cs b/U8AppMain/FrmMain.cs index 3ef3925..35e24c8 100644 --- a/U8AppMain/FrmMain.cs +++ b/U8AppMain/FrmMain.cs @@ -22,38 +22,15 @@ namespace U8AppMain private DataTable dataTable; private async void BtnBomImport_Click(object sender, EventArgs e) { - // 判断是否是BOM导入的格式 - //母件编码 BOM类别 版本号 版本说明 版本生效日 替代标识 替代说明 母件损耗率 子件编码 行号 基本用量 - 分子 基础数量 - 分母 子件损耗率 供应类型 创建日期 创建人 - var colums = new Dictionary(); - colums.Add("母件编码", "InvCode"); - colums.Add("BOM类别", "BomType"); - colums.Add("版本号", "Version"); - colums.Add("版本说明", "VersionDesc"); - colums.Add("版本生效日", "版本号"); - colums.Add("替代标识", "版本号"); - colums.Add("替代说明", "版本号"); - colums.Add("母件损耗率", "ParentScrap"); - colums.Add("子件编码", "InvCode"); - colums.Add("行号", "SortSeq"); - colums.Add("基本用量分子", "BaseQtyN"); - colums.Add("基础数量分母", "BaseQtyD"); - colums.Add("子件损耗率", "CompScrap"); - colums.Add("供应类型", "WIPType"); - colums.Add("创建日期", "VersionEffDate"); - - + var bomLookup = new Dictionary(); - - foreach (DataRow row in this.dataTable.Rows) { var bom = new Bom.ufinterface(); var comp = new Bom.ComponentBody(); - bom.Bom.Version.Version = Convert.ToInt32(row["版本号"]); bom.Bom.Version.VersionDesc = row.Field("版本说明"); bom.Bom.Parent.InvCode = row.Field("母件编码"); - bom.Bom.Version.VersionEffDate = DateTime.Parse(row["版本生效日"].ToString()); //bom.Bom.Version.BomType ="1" row.Field("BOM类别"); bom.Bom.Parent.ParentScrap = decimal.Parse(row["母件损耗率"].ToString()); @@ -68,7 +45,6 @@ namespace U8AppMain } comp.Component.OpComponentId = bom.Bom.ComponentBodies.Count; comp.Component.EffBegDate = bom.Bom.Version.VersionEffDate; - comp.Component.InvCode = row.Field("子件编码"); comp.Component.SortSeq = row.Field("行号"); comp.Component.OptionsId = bom.Bom.ComponentBodies.Count; @@ -79,42 +55,77 @@ namespace U8AppMain comp.ComponentOpt.OptionsId = bom.Bom.ComponentBodies.Count; bom.Bom.ComponentBodies.Add(comp); } - - - - //colums.Add("创建人", "版本号"); - - - - //var bom = new Bom.ufinterface(); - //bom.Bom.ComponentBodies.Add(new Bom.ComponentBody()); - //bom.Bom.ComponentBodies.Add(new Bom.ComponentBody()); - - foreach (var item in bomLookup.Values) { var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8); - var response = await HttpHelper.Post("", strbody); + var response = await HttpHelper.Post("", strbody); this.textBox1.Text += response; } - - - } private void BtnImportExcel_Click(object sender, EventArgs e) { - var opentFileDlg = new OpenFileDialog(); - opentFileDlg.Filter = "EXCEL2003|*.xls|EXCLE2007|*.xlsx"; + var opentFileDlg = new OpenFileDialog + { + Filter = "EXCEL2003|*.xls|EXCLE2007|*.xlsx" + }; if (opentFileDlg.ShowDialog() == DialogResult.OK) { - var file = new FileStream(opentFileDlg.FileName, FileMode.Open); - dataTable = ExcelHelper.ExcelToDataTable(file); - this.kryptonDataGridView1.DataSource = dataTable; + + using (var file = new FileStream(opentFileDlg.FileName, FileMode.Open)) + { + dataTable = ExcelHelper.ExcelToDataTable(file); + this.kryptonDataGridView1.DataSource = dataTable; + } } return; } + + private async void button1_Click(object sender, EventArgs e) + { + + + + var bomLookup = new Dictionary(); + foreach (DataRow row in this.dataTable.Rows) + { + var purchase = new Purchase.ufinterface(); + var body = new Purchase.entry(); + purchase.purchaseapp.header.code = row["请购单号"].ToString(); + purchase.purchaseapp.header.date = row["请购日"].ToString(); + purchase.purchaseapp.header.departmentcode = row["部门编码"].ToString(); + + purchase.purchaseapp.header.personcode = row["请购人"].ToString(); + + purchase.purchaseapp.header.purchasetypecode = row["采购类型编号"].ToString(); + + purchase.purchaseapp.header.maker = row["制单人"].ToString(); + + var strKey = purchase.purchaseapp.header.code; + if (bomLookup.ContainsKey(strKey)) + { + purchase = bomLookup[strKey]; + } + else + { + bomLookup.Add(strKey, purchase); + } + body.inventorycode = row["存货编码"].ToString(); + body.requiredate = purchase.purchaseapp.header.date; + body.quantity = decimal.Parse(row["数量"].ToString()); + + purchase.purchaseapp.body.Add(body); + } + foreach (var item in bomLookup.Values) + { + + var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8); + var response = await HttpHelper.Post("", strbody); + this.textBox1.Text += response; + } + + } } } diff --git a/U8AppMain/Purchase/EntryEnity.cs b/U8AppMain/Purchase/EntryEnity.cs index 471a623..c2c9a01 100644 --- a/U8AppMain/Purchase/EntryEnity.cs +++ b/U8AppMain/Purchase/EntryEnity.cs @@ -9,54 +9,54 @@ namespace U8AppMain.Purchase public class entry { - public string vendorcode { get; set; } + //public string vendorcode { get; set; } public string inventorycode { get; set; } - public int quantity { get; set; } + public decimal quantity { get; set; } - public decimal price { get; set; } + //public decimal price { get; set; } - public decimal taxrate { get; set; } + //public decimal taxrate { get; set; } - public decimal taxprice { get; set; } + //public decimal taxprice { get; set; } - public decimal money { get; set; } + //public decimal money { get; set; } - public decimal tax { get; set; } - public decimal sum { get; set; } + //public decimal tax { get; set; } + //public decimal sum { get; set; } public string requiredate { get; set; } public string arrivedate { get; set; } - public string item_class { get; set; } + //public string item_class { get; set; } - public string item_code { get; set; } + //public string item_code { get; set; } - public decimal btaxcost { get; set; } + //public decimal btaxcost { get; set; } - public decimal num { get; set; } + //public decimal num { get; set; } - public string unitid { get; set; } + //public string unitid { get; set; } - public string deptcodeexec { get; set; } - public string personcodeexec { get; set; } + //public string deptcodeexec { get; set; } + //public string personcodeexec { get; set; } - public string currency_name { get; set; } + public string currency_name { get; set; } = "人民币"; - public decimal currency_rate { get; set; } + public decimal currency_rate { get; set; } = 1; - public string originalprice { get; set; } - public string originalmoney { get; set; } + //public string originalprice { get; set; } + //public string originalmoney { get; set; } - public string originaltax { get; set; } + //public string originaltax { get; set; } - public string originalsum { get; set; } + //public string originalsum { get; set; } - public string ivouchrowno { get; set; } + //public string ivouchrowno { get; set; } // //107001 //456 diff --git a/U8AppMain/Purchase/HeaderEnity.cs b/U8AppMain/Purchase/HeaderEnity.cs index a8361c8..d91a2cc 100644 --- a/U8AppMain/Purchase/HeaderEnity.cs +++ b/U8AppMain/Purchase/HeaderEnity.cs @@ -14,28 +14,28 @@ namespace U8AppMain.Purchase public string personcode { get; set; } public string purchasetypecode { get; set; } - public string businesstype { get; set; } + public string businesstype { get; set; } = "普通采购"; public string maker { get; set; } - public string define1 { get; set; } - public string define2 { get; set; } - public string define3 { get; set; } - public string define4 { get; set; } - public string define5 { get; set; } - public string define6 { get; set; } - public string define7 { get; set; } - public string define8 { get; set; } - public string define9 { get; set; } - public string define10 { get; set; } - public string define11{ get; set; } + //public string define1 { get; set; } + //public string define2 { get; set; } + //public string define3 { get; set; } + //public string define4 { get; set; } + //public string define5 { get; set; } + //public string define6 { get; set; } + //public string define7 { get; set; } + //public string define8 { get; set; } + //public string define9 { get; set; } + //public string define10 { get; set; } + //public string define11{ get; set; } - public string define12 { get; set; } - public string define13 { get; set; } - public string define14 { get; set; } - public string define15 { get; set; } - public string define16 { get; set; } - public string memory { get; set; } + //public string define12 { get; set; } + //public string define13 { get; set; } + //public string define14 { get; set; } + //public string define15 { get; set; } + //public string define16 { get; set; } + //public string memory { get; set; } // CGQGD2132131 //2020-12-17 diff --git a/U8AppMain/Purchase/ufinterface.cs b/U8AppMain/Purchase/ufinterface.cs index 51a581e..c0ac11a 100644 --- a/U8AppMain/Purchase/ufinterface.cs +++ b/U8AppMain/Purchase/ufinterface.cs @@ -8,41 +8,33 @@ namespace U8AppMain.Purchase { public class ufinterface { + + //roottag="purchaseapp" billtype="" docid="123" receiver="u8" sender="003" + // proc="add" codeexchanged="N" exportneedexch="N" version="2.0" [System.Xml.Serialization.XmlAttribute] - public string roottag { get; set; } + public string roottag { get; set; } = "purchaseapp"; [System.Xml.Serialization.XmlAttribute] - public string billtype { get; set; } + public string billtype { get; set; } = ""; [System.Xml.Serialization.XmlAttribute] - public string docid { get; set; } + public string docid { get; set; } = "123"; [System.Xml.Serialization.XmlAttribute] - public string receiver { get; set; } + public string receiver { get; set; } = "u8"; [System.Xml.Serialization.XmlAttribute] - public string sender { get; set; } + public string sender { get; set; } = "003"; [System.Xml.Serialization.XmlAttribute] - public string proc { get; set; } + public string proc { get; set; } = "add"; [System.Xml.Serialization.XmlAttribute] - public string codeexchanged { get; set; } + public string codeexchanged { get; set; } = "N"; [System.Xml.Serialization.XmlAttribute] - public string exportneedexch { get; set; } + public string exportneedexch { get; set; } = "N"; [System.Xml.Serialization.XmlAttribute] - public string version { get; set; } + public string version { get; set; } = "2.0"; - //roottag="purchaseapp" - // billtype="" - // docid="123" - // receiver="u8" - // sender="003" - // proc="add" - // codeexchanged="N" - // exportneedexch="N" - // version="2.0" - - - public PurchaseEnity purchaseapp { get; set; } = new PurchaseEnity(); + public PurchaseEnity purchaseapp { get; set; } = new PurchaseEnity();