127 lines
5.0 KiB
C#
127 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Serialization;
|
|
using System.IO;
|
|
namespace U8AppMain
|
|
{
|
|
public partial class FrmMain : Form
|
|
{
|
|
public FrmMain()
|
|
{
|
|
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)
|
|
{
|
|
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))
|
|
{
|
|
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);
|
|
}
|
|
foreach (var item in bomLookup.Values)
|
|
{
|
|
|
|
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)
|
|
{
|
|
var opentFileDlg = new OpenFileDialog
|
|
{
|
|
Filter = "EXCEL2003|*.xls|EXCLE2007|*.xlsx"
|
|
};
|
|
|
|
if (opentFileDlg.ShowDialog() == DialogResult.OK)
|
|
{
|
|
|
|
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<string, Purchase.ufinterface>();
|
|
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;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|