361 lines
13 KiB
C#
361 lines
13 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Windows.Forms;
|
||
using System.Xml.Serialization;
|
||
using System.IO;
|
||
using System.Configuration;
|
||
using NX.ERP.U8;
|
||
|
||
namespace U8AppMain
|
||
{
|
||
public partial class FrmMain : Form
|
||
{
|
||
public FrmMain()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private NX.ERP.U8.U8LoginContext u8LoginContext = null;
|
||
|
||
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)
|
||
{
|
||
string tag;
|
||
if (item.succeed == "0")
|
||
{
|
||
this.richTextBox1.SelectionColor = Color.Green;
|
||
tag = "成功";
|
||
}
|
||
else
|
||
{
|
||
this.richTextBox1.SelectionColor = Color.Red;
|
||
tag = "出错";
|
||
}
|
||
this.richTextBox1.AppendText($"[{tag}] 单号:({item.key}),信息:{item.dsc} \r\n");
|
||
}
|
||
this.richTextBox1.SelectionColor = Color.Black;
|
||
this.richTextBox1.AppendText($"---------------------------------------------------------------------------------------\r\n");
|
||
|
||
}
|
||
|
||
|
||
private ResultEnity.ufinterface HttpPost(string body)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = HttpHelper.HttpPost(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 string connStr = ConfigurationManager.AppSettings.Get("connStr");
|
||
private DataTable dataTable;
|
||
|
||
|
||
|
||
|
||
|
||
private void BtnReadExcel_Click(object sender, EventArgs e)
|
||
{
|
||
var opentFileDlg = new OpenFileDialog
|
||
{
|
||
Filter = "EXCEL文件(*.xls;*.xlsx)|*.xls;*.xlsx"
|
||
};
|
||
|
||
if (opentFileDlg.ShowDialog() == DialogResult.OK)
|
||
{
|
||
|
||
using (var file = new FileStream(opentFileDlg.FileName, FileMode.Open))
|
||
{
|
||
dataTable = ExcelHelper.ExcelToDataTable(file);
|
||
this.dataGridView1.DataSource = dataTable;
|
||
}
|
||
}
|
||
return;
|
||
}
|
||
|
||
private void ImportBom_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
|
||
{
|
||
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.Version.Define12 = row.Field<string>("母件编码") + 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)
|
||
{
|
||
|
||
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 = this.HttpPost(strbody);
|
||
|
||
PrintLog(response);
|
||
Application.DoEvents();
|
||
}
|
||
}
|
||
|
||
private 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();
|
||
purchase.purchaseapp.header.define12 = 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 = this.HttpPost(strbody);
|
||
PrintLog(response);
|
||
Application.DoEvents();
|
||
}
|
||
|
||
}
|
||
|
||
private void richTextBox1_TextChanged(object sender, EventArgs e)
|
||
{
|
||
richTextBox1.SelectionStart = richTextBox1.Text.Length;
|
||
//滚动到光标位置
|
||
richTextBox1.ScrollToCaret();
|
||
}
|
||
|
||
private void 领料单ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
//单据号 日期 部门编码 业务员 制单人 存货编码 数量
|
||
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
|
||
{
|
||
return;
|
||
}
|
||
var bomLookup = new Dictionary<string, Voucher.Vouch>();
|
||
try
|
||
{
|
||
foreach (DataRow row in this.dataTable.Rows)
|
||
{
|
||
var Vouch = new Voucher.Vouch();
|
||
var Vouchs = new Voucher.Vouchs();
|
||
Vouch.CCode = row["单据号"].ToString();
|
||
Vouch.DDate = DateTime.Parse(row["日期"].ToString());
|
||
Vouch.CDepCode = row["部门编码"].ToString();
|
||
Vouch.CPersonCode = row["业务员"].ToString();
|
||
Vouch.CMaker = row["制单人"].ToString();
|
||
Vouch.CRdCode = "201";
|
||
Vouch.Vt_id = "30718";
|
||
Vouch.IswfControlled = 0;
|
||
var strKey = Vouch.CCode;
|
||
if (bomLookup.ContainsKey(strKey))
|
||
{
|
||
Vouch = bomLookup[strKey];
|
||
}
|
||
else
|
||
{
|
||
bomLookup.Add(strKey, Vouch);
|
||
}
|
||
Vouchs.CInvCode = row["存货编码"].ToString();
|
||
Vouchs.Iquantity = int.Parse(row["数量"].ToString());
|
||
Vouch.Vouchs.Add(Vouchs);
|
||
}
|
||
foreach (var item in bomLookup.Values)
|
||
{
|
||
var a = new Voucher.VoucherDAL(this.u8LoginContext.Constr4Net);
|
||
if (a.Add(item))
|
||
{
|
||
this.richTextBox1.SelectionColor = Color.Green;
|
||
this.richTextBox1.AppendText($" {item.cDefine12} 导入成功 ,实际U8单号: {item.CCode} \r\n");
|
||
}
|
||
else
|
||
{
|
||
this.richTextBox1.SelectionColor = Color.Red;
|
||
this.richTextBox1.AppendText($"{item.CCode} 导入出错\r\n");
|
||
}
|
||
}
|
||
this.richTextBox1.AppendText($"--------------------------------------------------------------------------------------------\r\n");
|
||
}
|
||
catch (Exception err)
|
||
{
|
||
this.richTextBox1.SelectionColor = Color.Red;
|
||
this.richTextBox1.AppendText($"{err.Message}读取数据出错\r\n");
|
||
return;
|
||
}
|
||
}
|
||
|
||
private void 打印ToolStripMenuItem1_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
|
||
|
||
//u8LoginContext = new NX.ERP.U8.U8LoginContext();
|
||
//u8LoginContext.Login(true);
|
||
}
|
||
|
||
private void toolStripMenuItem2_Click(object sender, EventArgs e)
|
||
{
|
||
var a = new NX.ERP.U8.Store.PuStoreInDAL();
|
||
a.AddPuStoreIn(new NX.ERP.Model.Store.PuStoreIn()
|
||
{
|
||
Code = "0001",
|
||
//PersonCode = "wx065",
|
||
//PuCode = "0002",
|
||
Date = DateTime.Today,
|
||
//Id = 1000021,
|
||
RdCode = "101",
|
||
Depcode = "24",
|
||
Source = "采购到货单",
|
||
Whcode = "1",
|
||
SourceCode = "CGDH210100187",
|
||
PuStoreInDetails = new List<NX.ERP.Model.Store.PuStoreInDetail>() {
|
||
new NX.ERP.Model.Store.PuStoreInDetail(){
|
||
//Batch="001",
|
||
Quantity=1,
|
||
//Id=1,
|
||
Invcode="201763",
|
||
//PuStoreInId=1002001,
|
||
SorceDetailId=1000023624,
|
||
}
|
||
|
||
}
|
||
}); ; ;
|
||
}
|
||
|
||
private void 材料出库单ToolStripMenuItem_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
|
||
//var a = new STVocher();
|
||
//a.AddVocher();
|
||
var a = new NX.ERP.U8.Store.MaterielStoreOutDAL();
|
||
a.AddMaterielStoreOut(new NX.ERP.Model.Store.MaterielStoreOut()
|
||
{
|
||
Id = 1111,
|
||
Code = "2222",
|
||
Source = "生产订单",
|
||
SourceCode = "SCDD210100009",
|
||
Whcode = "2",
|
||
|
||
Date = DateTime.Now,
|
||
Details = new List<NX.ERP.Model.Store.MaterielStoreOutDetail>()
|
||
{
|
||
new NX.ERP.Model.Store.MaterielStoreOutDetail()
|
||
{
|
||
BinCode="002070206",
|
||
Cinvcode="218174",
|
||
|
||
sorceDetailId=1000200145,
|
||
Quantity=1,
|
||
}
|
||
}
|
||
});
|
||
|
||
|
||
|
||
}
|
||
}
|
||
}
|