初始化代码

This commit is contained in:
admin
2020-12-18 13:51:58 +08:00
parent 42e945036f
commit abb13c805d
13 changed files with 316 additions and 72 deletions

View File

@@ -4,10 +4,12 @@ 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
@@ -17,13 +19,88 @@ namespace U8AppMain
InitializeComponent();
}
private void BtnBomImport_Click(object sender, EventArgs e)
private DataTable dataTable;
private async void BtnBomImport_Click(object sender, EventArgs e)
{
var bom = new Bom.ufinterface();
bom.Bom.ComponentBodies.Add(new Bom.ComponentBody());
bom.Bom.ComponentBodies.Add(new Bom.ComponentBody());
MessageBox.Show(XmlHelper.XmlSerialize(bom, Encoding.UTF8));
// 判断是否是BOM导入的格式
//母件编码 BOM类别 版本号 版本说明 版本生效日 替代标识 替代说明 母件损耗率 子件编码 行号 基本用量 - 分子 基础数量 - 分母 子件损耗率 供应类型 创建日期 创建人
var colums = new Dictionary<string, string>();
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<string, Bom.BomEnity>();
foreach (DataRow row in this.dataTable.Rows)
{
var bom = new Bom.BomEnity();
var comp = new Bom.ComponentBody();
bom.Version.Version = Convert.ToInt32(row["版本号"]);
bom.Version.VersionDesc = row.Field<string>("版本说明");
bom.Parent.InvCode = row.Field<string>("母件编码");
bom.Version.VersionEffDate = DateTime.Parse(row.Field<string>("版本生效日"));
bom.Version.BomType = row.Field<string>("BOM类别");
bom.Parent.ParentScrap = decimal.Parse(row["母件损耗率"].ToString());
var strKey = $"{bom.Parent.InvCode}-{bom.Version.Version}";
if (bomLookup.ContainsKey(strKey))
{
bom = bomLookup[strKey];
}
else
{
bomLookup.Add(strKey, bom);
}
comp.Component.InvCode = row.Field<string>("子件编码");
comp.Component.SortSeq = row.Field<string>("行号");
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();
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());
var strbody = XmlHelper.XmlSerialize(bomLookup.Values.ToList(), Encoding.UTF8);
var response = await HttpHelper.Post("", strbody);
MessageBox.Show(response);
}
private void BtnImportExcel_Click(object sender, EventArgs e)
{
var opentFileDlg = new OpenFileDialog();
opentFileDlg.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;
}
return;
}
}
}