修改导入显示
This commit is contained in:
@@ -3,4 +3,9 @@
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
|
||||
</startup>
|
||||
<appSettings>
|
||||
|
||||
<add key="url" value="http://192.168.0.242/U8EAI/import.asp"/>
|
||||
<add key="conn" value=""/>
|
||||
</appSettings>
|
||||
</configuration>
|
||||
|
||||
216
U8AppMain/FrmMain.Designer.cs
generated
216
U8AppMain/FrmMain.Designer.cs
generated
@@ -29,118 +29,160 @@ namespace U8AppMain
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.BtnBomImport = new System.Windows.Forms.Button();
|
||||
this.panel2 = new System.Windows.Forms.Panel();
|
||||
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();
|
||||
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
|
||||
this.操作ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.BtnReadExcel = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.导入ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ImportBom = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.BtnPurchaseImport = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
|
||||
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
|
||||
this.dataGridView1 = new System.Windows.Forms.DataGridView();
|
||||
this.menuStrip1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
|
||||
this.splitContainer1.Panel1.SuspendLayout();
|
||||
this.splitContainer1.Panel2.SuspendLayout();
|
||||
this.splitContainer1.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// panel1
|
||||
// menuStrip1
|
||||
//
|
||||
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;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(800, 42);
|
||||
this.panel1.TabIndex = 0;
|
||||
this.menuStrip1.Font = new System.Drawing.Font("Segoe UI", 9F);
|
||||
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.操作ToolStripMenuItem,
|
||||
this.导入ToolStripMenuItem});
|
||||
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
|
||||
this.menuStrip1.Name = "menuStrip1";
|
||||
this.menuStrip1.Padding = new System.Windows.Forms.Padding(9, 4, 0, 4);
|
||||
this.menuStrip1.Size = new System.Drawing.Size(1200, 27);
|
||||
this.menuStrip1.TabIndex = 0;
|
||||
this.menuStrip1.Text = "menuStrip1";
|
||||
//
|
||||
// BtnBomImport
|
||||
// 操作ToolStripMenuItem
|
||||
//
|
||||
this.BtnBomImport.Location = new System.Drawing.Point(108, 12);
|
||||
this.BtnBomImport.Name = "BtnBomImport";
|
||||
this.BtnBomImport.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnBomImport.TabIndex = 0;
|
||||
this.BtnBomImport.Text = "Bom导入";
|
||||
this.BtnBomImport.UseVisualStyleBackColor = true;
|
||||
this.BtnBomImport.Click += new System.EventHandler(this.BtnBomImport_Click);
|
||||
this.操作ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.BtnReadExcel});
|
||||
this.操作ToolStripMenuItem.Name = "操作ToolStripMenuItem";
|
||||
this.操作ToolStripMenuItem.Size = new System.Drawing.Size(45, 19);
|
||||
this.操作ToolStripMenuItem.Text = "文件";
|
||||
//
|
||||
// panel2
|
||||
// BtnReadExcel
|
||||
//
|
||||
this.panel2.Controls.Add(this.textBox1);
|
||||
this.panel2.Controls.Add(this.kryptonDataGridView1);
|
||||
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel2.Location = new System.Drawing.Point(0, 42);
|
||||
this.panel2.Name = "panel2";
|
||||
this.panel2.Size = new System.Drawing.Size(800, 408);
|
||||
this.panel2.TabIndex = 1;
|
||||
this.BtnReadExcel.Name = "BtnReadExcel";
|
||||
this.BtnReadExcel.Size = new System.Drawing.Size(180, 22);
|
||||
this.BtnReadExcel.Text = "读取Excel";
|
||||
this.BtnReadExcel.Click += new System.EventHandler(this.BtnReadExcel_Click);
|
||||
//
|
||||
// kryptonDataGridView1
|
||||
// 导入ToolStripMenuItem
|
||||
//
|
||||
this.kryptonDataGridView1.AllowUserToAddRows = false;
|
||||
this.kryptonDataGridView1.AllowUserToDeleteRows = false;
|
||||
this.kryptonDataGridView1.AllowUserToResizeRows = false;
|
||||
this.kryptonDataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.kryptonDataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.kryptonDataGridView1.Location = new System.Drawing.Point(0, 0);
|
||||
this.kryptonDataGridView1.Name = "kryptonDataGridView1";
|
||||
this.kryptonDataGridView1.ReadOnly = true;
|
||||
this.kryptonDataGridView1.RowTemplate.Height = 23;
|
||||
this.kryptonDataGridView1.Size = new System.Drawing.Size(800, 408);
|
||||
this.kryptonDataGridView1.TabIndex = 0;
|
||||
this.导入ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ImportBom,
|
||||
this.BtnPurchaseImport});
|
||||
this.导入ToolStripMenuItem.Name = "导入ToolStripMenuItem";
|
||||
this.导入ToolStripMenuItem.Size = new System.Drawing.Size(45, 19);
|
||||
this.导入ToolStripMenuItem.Text = "导入";
|
||||
//
|
||||
// BtnImportExcel
|
||||
// ImportBom
|
||||
//
|
||||
this.BtnImportExcel.Location = new System.Drawing.Point(12, 12);
|
||||
this.BtnImportExcel.Name = "BtnImportExcel";
|
||||
this.BtnImportExcel.Size = new System.Drawing.Size(75, 23);
|
||||
this.BtnImportExcel.TabIndex = 1;
|
||||
this.BtnImportExcel.Text = "读取Exel";
|
||||
this.BtnImportExcel.UseVisualStyleBackColor = true;
|
||||
this.BtnImportExcel.Click += new System.EventHandler(this.BtnImportExcel_Click);
|
||||
this.ImportBom.Name = "ImportBom";
|
||||
this.ImportBom.Size = new System.Drawing.Size(180, 22);
|
||||
this.ImportBom.Text = "BOM";
|
||||
this.ImportBom.Click += new System.EventHandler(this.ImportBom_Click);
|
||||
//
|
||||
// textBox1
|
||||
// BtnPurchaseImport
|
||||
//
|
||||
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(800, 261);
|
||||
this.textBox1.TabIndex = 1;
|
||||
this.BtnPurchaseImport.Name = "BtnPurchaseImport";
|
||||
this.BtnPurchaseImport.Size = new System.Drawing.Size(180, 22);
|
||||
this.BtnPurchaseImport.Text = "请购单";
|
||||
this.BtnPurchaseImport.Click += new System.EventHandler(this.BtnPurchaseImport_Click);
|
||||
//
|
||||
// button1
|
||||
// splitContainer1
|
||||
//
|
||||
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);
|
||||
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.splitContainer1.Location = new System.Drawing.Point(0, 27);
|
||||
this.splitContainer1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.splitContainer1.Name = "splitContainer1";
|
||||
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
|
||||
//
|
||||
// splitContainer1.Panel1
|
||||
//
|
||||
this.splitContainer1.Panel1.Controls.Add(this.dataGridView1);
|
||||
//
|
||||
// splitContainer1.Panel2
|
||||
//
|
||||
this.splitContainer1.Panel2.Controls.Add(this.richTextBox1);
|
||||
this.splitContainer1.Size = new System.Drawing.Size(1200, 722);
|
||||
this.splitContainer1.SplitterDistance = 450;
|
||||
this.splitContainer1.TabIndex = 0;
|
||||
//
|
||||
// richTextBox1
|
||||
//
|
||||
this.richTextBox1.BackColor = System.Drawing.Color.White;
|
||||
this.richTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
|
||||
this.richTextBox1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.richTextBox1.Name = "richTextBox1";
|
||||
this.richTextBox1.ReadOnly = true;
|
||||
this.richTextBox1.Size = new System.Drawing.Size(1200, 268);
|
||||
this.richTextBox1.TabIndex = 0;
|
||||
this.richTextBox1.Text = "";
|
||||
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
|
||||
//
|
||||
// dataGridView1
|
||||
//
|
||||
this.dataGridView1.AllowUserToAddRows = false;
|
||||
this.dataGridView1.AllowUserToDeleteRows = false;
|
||||
this.dataGridView1.AllowUserToOrderColumns = true;
|
||||
this.dataGridView1.BackgroundColor = System.Drawing.SystemColors.ButtonHighlight;
|
||||
this.dataGridView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.dataGridView1.ColumnHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.Single;
|
||||
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.dataGridView1.GridColor = System.Drawing.SystemColors.ActiveBorder;
|
||||
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
|
||||
this.dataGridView1.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4);
|
||||
this.dataGridView1.Name = "dataGridView1";
|
||||
this.dataGridView1.ReadOnly = true;
|
||||
this.dataGridView1.RowTemplate.Height = 23;
|
||||
this.dataGridView1.Size = new System.Drawing.Size(1200, 450);
|
||||
this.dataGridView1.TabIndex = 0;
|
||||
//
|
||||
// FrmMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.panel2);
|
||||
this.Controls.Add(this.panel1);
|
||||
this.ClientSize = new System.Drawing.Size(1200, 749);
|
||||
this.Controls.Add(this.splitContainer1);
|
||||
this.Controls.Add(this.menuStrip1);
|
||||
this.Font = new System.Drawing.Font("微软雅黑", 11F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
|
||||
this.MainMenuStrip = this.menuStrip1;
|
||||
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
|
||||
this.Name = "FrmMain";
|
||||
this.Text = "Form1";
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.panel2.ResumeLayout(false);
|
||||
this.panel2.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.kryptonDataGridView1)).EndInit();
|
||||
this.Text = "U8导入";
|
||||
this.menuStrip1.ResumeLayout(false);
|
||||
this.menuStrip1.PerformLayout();
|
||||
this.splitContainer1.Panel1.ResumeLayout(false);
|
||||
this.splitContainer1.Panel2.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
|
||||
this.splitContainer1.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button BtnBomImport;
|
||||
private System.Windows.Forms.Panel panel2;
|
||||
private ComponentFactory.Krypton.Toolkit.KryptonDataGridView kryptonDataGridView1;
|
||||
private System.Windows.Forms.Button BtnImportExcel;
|
||||
private System.Windows.Forms.TextBox textBox1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.MenuStrip menuStrip1;
|
||||
private System.Windows.Forms.ToolStripMenuItem 操作ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem BtnReadExcel;
|
||||
private System.Windows.Forms.ToolStripMenuItem 导入ToolStripMenuItem;
|
||||
private System.Windows.Forms.ToolStripMenuItem ImportBom;
|
||||
private System.Windows.Forms.ToolStripMenuItem BtnPurchaseImport;
|
||||
private System.Windows.Forms.SplitContainer splitContainer1;
|
||||
private System.Windows.Forms.RichTextBox richTextBox1;
|
||||
private System.Windows.Forms.DataGridView dataGridView1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Serialization;
|
||||
using System.IO;
|
||||
using System.Configuration;
|
||||
|
||||
namespace U8AppMain
|
||||
{
|
||||
public partial class FrmMain : Form
|
||||
@@ -19,56 +21,69 @@ namespace U8AppMain
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private DataTable dataTable;
|
||||
private async void BtnBomImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
var bomLookup = new Dictionary<string, Bom.ufinterface>();
|
||||
foreach (DataRow row in this.dataTable.Rows)
|
||||
private void PrintLog(ResultEnity.ufinterface info)
|
||||
{
|
||||
this.richTextBox1.SelectionColor = Color.Black;
|
||||
this.richTextBox1.AppendText($"单据:{info.requestroottag} 操作:{info.proc} \r\n");
|
||||
|
||||
foreach (var item in info.Items)
|
||||
{
|
||||
var bom = new Bom.ufinterface();
|
||||
var comp = new Bom.ComponentBody();
|
||||
bom.Bom.Version.Version = Convert.ToInt32(row["版本号"]);
|
||||
bom.Bom.Version.VersionDesc = row.Field<string>("版本说明");
|
||||
bom.Bom.Parent.InvCode = row.Field<string>("母件编码");
|
||||
bom.Bom.Version.VersionEffDate = DateTime.Parse(row["版本生效日"].ToString());
|
||||
//bom.Bom.Version.BomType ="1" row.Field<string>("BOM类别");
|
||||
bom.Bom.Parent.ParentScrap = decimal.Parse(row["母件损耗率"].ToString());
|
||||
var strKey = $"{bom.Bom.Parent.InvCode}-{bom.Bom.Version.Version}";
|
||||
if (bomLookup.ContainsKey(strKey))
|
||||
string tag;
|
||||
if (item.succeed == "0")
|
||||
{
|
||||
bom = bomLookup[strKey];
|
||||
this.richTextBox1.SelectionColor = Color.Green;
|
||||
tag = "成功";
|
||||
}
|
||||
else
|
||||
{
|
||||
bomLookup.Add(strKey, bom);
|
||||
this.richTextBox1.SelectionColor = Color.Red;
|
||||
tag = "出错";
|
||||
}
|
||||
comp.Component.OpComponentId = bom.Bom.ComponentBodies.Count;
|
||||
comp.Component.EffBegDate = bom.Bom.Version.VersionEffDate;
|
||||
comp.Component.InvCode = row.Field<string>("子件编码");
|
||||
comp.Component.SortSeq = row.Field<string>("行号");
|
||||
comp.Component.OptionsId = bom.Bom.ComponentBodies.Count;
|
||||
comp.Component.BaseQtyN = decimal.Parse(row["基本用量分子"].ToString());
|
||||
comp.Component.BaseQtyD = decimal.Parse(row["基础数量分母"].ToString());
|
||||
comp.Component.CompScrap = decimal.Parse(row["子件损耗率"].ToString());
|
||||
comp.ComponentOpt.WIPType = row["供应类型"].ToString();
|
||||
comp.ComponentOpt.OptionsId = bom.Bom.ComponentBodies.Count;
|
||||
bom.Bom.ComponentBodies.Add(comp);
|
||||
this.richTextBox1.AppendText($"[{tag}] 单号:({item.key}),信息:{item.dsc} \r\n");
|
||||
}
|
||||
foreach (var item in bomLookup.Values)
|
||||
{
|
||||
this.richTextBox1.SelectionColor = Color.Black;
|
||||
this.richTextBox1.AppendText($"---------------------------------------------------------------------------------------\r\n");
|
||||
|
||||
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
|
||||
var response = await HttpHelper.Post("", strbody);
|
||||
this.textBox1.Text += response;
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnImportExcel_Click(object sender, EventArgs e)
|
||||
|
||||
private async Task<ResultEnity.ufinterface> HttpPost(string body)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var response = await HttpHelper.Post(url, body);
|
||||
return XmlHelper.XmlDeserialize<ResultEnity.ufinterface>(response, Encoding.UTF8);
|
||||
// var strResult = $"单据:{result.requestroottag} 操作:{result.proc} \r\n";
|
||||
//foreach (var item in result.Items)
|
||||
//{
|
||||
// strResult += $" 单号:{item.key} 单号:{item.u8key} ------------执行结果: {item.dsc} \r\n";
|
||||
//}
|
||||
|
||||
// return strResult;
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
this.richTextBox1.Text = err.Message;
|
||||
return null;
|
||||
//return err.Message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private string url = ConfigurationManager.AppSettings.Get("url");
|
||||
private DataTable dataTable;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void BtnReadExcel_Click(object sender, EventArgs e)
|
||||
{
|
||||
var opentFileDlg = new OpenFileDialog
|
||||
{
|
||||
Filter = "EXCEL2003|*.xls|EXCLE2007|*.xlsx"
|
||||
Filter = "EXCEL文件(*.xls;*.xlsx)|*.xls;*.xlsx"
|
||||
};
|
||||
|
||||
if (opentFileDlg.ShowDialog() == DialogResult.OK)
|
||||
@@ -77,50 +92,130 @@ namespace U8AppMain
|
||||
using (var file = new FileStream(opentFileDlg.FileName, FileMode.Open))
|
||||
{
|
||||
dataTable = ExcelHelper.ExcelToDataTable(file);
|
||||
this.kryptonDataGridView1.DataSource = dataTable;
|
||||
this.dataGridView1.DataSource = dataTable;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
private async void button1_Click(object sender, EventArgs e)
|
||||
private async void ImportBom_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
|
||||
|
||||
var bomLookup = new Dictionary<string, Purchase.ufinterface>();
|
||||
foreach (DataRow row in this.dataTable.Rows)
|
||||
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
|
||||
{
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
var bomLookup = new Dictionary<string, Bom.ufinterface>();
|
||||
try
|
||||
{
|
||||
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<string>("版本说明");
|
||||
bom.Bom.Parent.InvCode = row.Field<string>("母件编码");
|
||||
bom.Bom.Version.VersionEffDate = DateTime.Parse(row["版本生效日"].ToString());
|
||||
bom.Bom.Parent.ParentScrap = decimal.Parse(row["母件损耗率"].ToString());
|
||||
var strKey = $"{bom.Bom.Parent.InvCode}-{bom.Bom.Version.Version}";
|
||||
if (bomLookup.ContainsKey(strKey))
|
||||
{
|
||||
bom = bomLookup[strKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
bomLookup.Add(strKey, bom);
|
||||
}
|
||||
comp.Component.OpComponentId = bom.Bom.ComponentBodies.Count;
|
||||
comp.Component.EffBegDate = bom.Bom.Version.VersionEffDate;
|
||||
comp.Component.InvCode = row.Field<string>("子件编码");
|
||||
comp.Component.SortSeq = row.Field<string>("行号");
|
||||
comp.Component.OptionsId = bom.Bom.ComponentBodies.Count;
|
||||
comp.Component.BaseQtyN = decimal.Parse(row["基本用量分子"].ToString());
|
||||
comp.Component.BaseQtyD = decimal.Parse(row["基础数量分母"].ToString());
|
||||
comp.Component.CompScrap = decimal.Parse(row["子件损耗率"].ToString());
|
||||
comp.ComponentOpt.WIPType = row["供应类型"].ToString();
|
||||
comp.ComponentOpt.OptionsId = bom.Bom.ComponentBodies.Count;
|
||||
bom.Bom.ComponentBodies.Add(comp);
|
||||
}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
|
||||
this.richTextBox1.SelectionColor = Color.Red;
|
||||
this.richTextBox1.AppendText("读取数据出错\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in bomLookup.Values)
|
||||
{
|
||||
|
||||
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
|
||||
var response = await this.HttpPost(strbody);
|
||||
|
||||
PrintLog(response);
|
||||
Application.DoEvents();
|
||||
}
|
||||
}
|
||||
|
||||
private async void BtnPurchaseImport_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
var bomLookup = new Dictionary<string, Purchase.ufinterface>();
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
this.richTextBox1.SelectionColor = Color.Red;
|
||||
this.richTextBox1.AppendText("读取数据出错\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var item in bomLookup.Values)
|
||||
{
|
||||
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
|
||||
var response = await HttpHelper.Post("", strbody);
|
||||
this.textBox1.Text += response;
|
||||
var response = await this.HttpPost(strbody);
|
||||
PrintLog(response);
|
||||
Application.DoEvents();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void richTextBox1_TextChanged(object sender, EventArgs e)
|
||||
{
|
||||
richTextBox1.SelectionStart = richTextBox1.Text.Length;
|
||||
//滚动到光标位置
|
||||
richTextBox1.ScrollToCaret();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,4 +117,7 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
23
U8AppMain/ResultEnity/Item.cs
Normal file
23
U8AppMain/ResultEnity/Item.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
namespace U8AppMain.ResultEnity
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
// <item key = "CGQGD2132133" succeed="0" dsc="ok" u8key="CGQGD2132133"></item>
|
||||
|
||||
[XmlAttribute]
|
||||
public string key { get; set; }
|
||||
[XmlAttribute]
|
||||
|
||||
public string succeed { get; set; }
|
||||
[XmlAttribute]
|
||||
public string dsc { get; set; }
|
||||
[XmlAttribute]
|
||||
public string u8key { get; set; }
|
||||
}
|
||||
}
|
||||
29
U8AppMain/ResultEnity/ufinterface.cs
Normal file
29
U8AppMain/ResultEnity/ufinterface.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
namespace U8AppMain.ResultEnity
|
||||
{
|
||||
public class ufinterface
|
||||
{
|
||||
// <ufinterface roottag = "return" docid="123" proc="add" sender="u8" receiver="003"
|
||||
// request-roottag="purchaseapp">
|
||||
// <item key = "CGQGD2132133" succeed="0" dsc="ok" u8key="CGQGD2132133"></item>
|
||||
//</ufinterface>
|
||||
[XmlAttribute]
|
||||
public string roottag { get; set; }
|
||||
[XmlAttribute]
|
||||
public string docid { get; set; }
|
||||
[XmlAttribute]
|
||||
public string proc { get; set; }
|
||||
[XmlAttribute]
|
||||
public string receiver { get; set; }
|
||||
[XmlAttribute(attributeName: "request-roottag")]
|
||||
public string requestroottag { get; set; }
|
||||
|
||||
[XmlElement(Type = typeof(Item),ElementName ="item")]
|
||||
public List<Item> Items { get; set; } = new List<Item>();
|
||||
}
|
||||
}
|
||||
@@ -36,23 +36,8 @@
|
||||
<Reference Include="BouncyCastle.Crypto, Version=1.8.6.0, Culture=neutral, PublicKeyToken=0e99375e54769942, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.6\lib\net40\BouncyCastle.Crypto.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Design, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Design.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Docking, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Docking.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Navigator, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Navigator.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Ribbon, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Ribbon.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Toolkit, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Toolkit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ComponentFactory.Krypton.Workspace, Version=4.5.0.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Krypton.Components.Suite.4.5.9\lib\net20\ComponentFactory.Krypton.Workspace.dll</HintPath>
|
||||
<Reference Include="Dapper, Version=1.60.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Dapper.1.60.6\lib\net451\Dapper.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="ICSharpCode.SharpZipLib, Version=1.2.0.246, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\SharpZipLib.1.2.0\lib\net45\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
@@ -70,6 +55,7 @@
|
||||
<HintPath>..\packages\NPOI.2.5.2\lib\net45\NPOI.OpenXmlFormats.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
@@ -105,6 +91,8 @@
|
||||
<Compile Include="Purchase\HeaderEnity.cs" />
|
||||
<Compile Include="Purchase\PurchaseEnity.cs" />
|
||||
<Compile Include="Purchase\ufinterface.cs" />
|
||||
<Compile Include="ResultEnity\Item.cs" />
|
||||
<Compile Include="ResultEnity\ufinterface.cs" />
|
||||
<Compile Include="XmlHelper.cs" />
|
||||
<EmbeddedResource Include="FrmMain.resx">
|
||||
<DependentUpon>FrmMain.cs</DependentUpon>
|
||||
|
||||
@@ -53,6 +53,30 @@ namespace U8AppMain
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="s"></param>
|
||||
/// <param name="encoding"></param>
|
||||
/// <returns></returns>
|
||||
public static T XmlDeserialize<T>(string s, Encoding encoding)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s))
|
||||
throw new ArgumentNullException("s");
|
||||
if (encoding == null)
|
||||
throw new ArgumentNullException("encoding");
|
||||
|
||||
XmlSerializer mySerializer = new XmlSerializer(typeof(T));
|
||||
s = s.Replace(" ", " ");
|
||||
using (MemoryStream ms = new MemoryStream(encoding.GetBytes(s)))
|
||||
{
|
||||
using (StreamReader sr = new StreamReader(ms, encoding))
|
||||
{
|
||||
return (T)mySerializer.Deserialize(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Dapper" version="1.60.6" targetFramework="net452" />
|
||||
<package id="Krypton.Components.Suite" version="4.5.9" targetFramework="net45" />
|
||||
<package id="NPOI" version="2.5.2" targetFramework="net45" />
|
||||
<package id="Portable.BouncyCastle" version="1.8.6" targetFramework="net45" />
|
||||
|
||||
Reference in New Issue
Block a user