Files
U8-Import/U8AppMain/FrmMain.cs

248 lines
8.9 KiB
C#
Raw Normal View History

2020-12-18 11:10:50 +08:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
2020-12-18 13:51:58 +08:00
using System.Net.Http;
2020-12-18 11:10:50 +08:00
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Serialization;
2020-12-18 13:51:58 +08:00
using System.IO;
2020-12-19 13:04:35 +08:00
using System.Configuration;
2020-12-18 11:10:50 +08:00
namespace U8AppMain
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
2020-12-19 13:04:35 +08:00
private void PrintLog(ResultEnity.ufinterface info)
2020-12-18 11:10:50 +08:00
{
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Black;
this.richTextBox1.AppendText($"单据:{info.requestroottag} 操作:{info.proc} \r\n");
2020-12-19 15:30:38 +08:00
2020-12-19 13:04:35 +08:00
foreach (var item in info.Items)
2020-12-18 13:51:58 +08:00
{
2020-12-19 13:04:35 +08:00
string tag;
if (item.succeed == "0")
2020-12-18 13:51:58 +08:00
{
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Green;
tag = "成功";
2020-12-18 13:51:58 +08:00
}
else
{
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Red;
tag = "出错";
2020-12-18 13:51:58 +08:00
}
2020-12-19 13:04:35 +08:00
this.richTextBox1.AppendText($"[{tag}] 单号:({item.key}),信息:{item.dsc} \r\n");
2020-12-18 13:51:58 +08:00
}
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Black;
this.richTextBox1.AppendText($"---------------------------------------------------------------------------------------\r\n");
2020-12-19 15:30:38 +08:00
2020-12-19 13:04:35 +08:00
}
private async Task<ResultEnity.ufinterface> HttpPost(string body)
{
try
2020-12-18 15:23:51 +08:00
{
2020-12-19 13:04:35 +08:00
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;
2020-12-18 15:23:51 +08:00
}
2020-12-19 13:04:35 +08:00
2020-12-18 13:51:58 +08:00
}
2020-12-19 13:04:35 +08:00
private string url = ConfigurationManager.AppSettings.Get("url");
2020-12-19 15:30:38 +08:00
private string connStr = ConfigurationManager.AppSettings.Get("connStr");
2020-12-19 13:04:35 +08:00
private DataTable dataTable;
private void BtnReadExcel_Click(object sender, EventArgs e)
2020-12-18 13:51:58 +08:00
{
2020-12-18 16:35:46 +08:00
var opentFileDlg = new OpenFileDialog
{
2020-12-19 13:04:35 +08:00
Filter = "EXCEL文件(*.xls;*.xlsx)|*.xls;*.xlsx"
2020-12-18 16:35:46 +08:00
};
2020-12-18 13:51:58 +08:00
if (opentFileDlg.ShowDialog() == DialogResult.OK)
{
2020-12-18 16:35:46 +08:00
using (var file = new FileStream(opentFileDlg.FileName, FileMode.Open))
{
dataTable = ExcelHelper.ExcelToDataTable(file);
2020-12-19 13:04:35 +08:00
this.dataGridView1.DataSource = dataTable;
2020-12-18 16:35:46 +08:00
}
2020-12-18 13:51:58 +08:00
}
return;
2020-12-18 11:10:50 +08:00
}
2020-12-18 16:35:46 +08:00
2020-12-19 13:04:35 +08:00
private async void ImportBom_Click(object sender, EventArgs e)
2020-12-18 16:35:46 +08:00
{
2020-12-19 13:04:35 +08:00
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
{
return;
}
2020-12-18 16:35:46 +08:00
2020-12-19 13:04:35 +08:00
var bomLookup = new Dictionary<string, Bom.ufinterface>();
try
2020-12-18 16:35:46 +08:00
{
2020-12-19 13:04:35 +08:00
foreach (DataRow row in this.dataTable.Rows)
2020-12-18 16:35:46 +08:00
{
2020-12-19 13:04:35 +08:00
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);
2020-12-18 16:35:46 +08:00
}
2020-12-19 13:04:35 +08:00
}
2020-12-19 15:30:38 +08:00
catch (Exception)
2020-12-19 13:04:35 +08:00
{
this.richTextBox1.SelectionColor = Color.Red;
this.richTextBox1.AppendText("读取数据出错\r\n");
return;
}
2020-12-19 15:30:38 +08:00
2020-12-19 13:04:35 +08:00
foreach (var item in bomLookup.Values)
{
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
var response = await this.HttpPost(strbody);
2020-12-19 15:30:38 +08:00
2020-12-19 13:04:35 +08:00
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)
2020-12-18 16:35:46 +08:00
{
2020-12-19 13:04:35 +08:00
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);
2020-12-18 16:35:46 +08:00
}
2020-12-19 13:04:35 +08:00
}
catch (Exception)
{
2020-12-18 16:35:46 +08:00
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Red;
this.richTextBox1.AppendText("读取数据出错\r\n");
return;
2020-12-18 16:35:46 +08:00
}
2020-12-19 15:30:38 +08:00
2020-12-18 16:35:46 +08:00
foreach (var item in bomLookup.Values)
{
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
2020-12-19 13:04:35 +08:00
var response = await this.HttpPost(strbody);
PrintLog(response);
Application.DoEvents();
2020-12-18 16:35:46 +08:00
}
}
2020-12-19 13:04:35 +08:00
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.SelectionStart = richTextBox1.Text.Length;
//滚动到光标位置
richTextBox1.ScrollToCaret();
}
2020-12-19 15:30:38 +08:00
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<Voucher.Vouchs>() {
new Voucher.Vouchs(){
CInvCode="107001",
Iquantity=20,
CwhCode="2",
}
}
});;
}
2020-12-18 11:10:50 +08:00
}
}