Files

492 lines
18 KiB
C#
Raw Permalink 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;
using System.Text;
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;
2021-01-12 14:45:59 +08:00
using NX.ERP.U8;
2020-12-19 13:04:35 +08:00
2020-12-18 11:10:50 +08:00
namespace U8AppMain
{
public partial class FrmMain : Form
{
public FrmMain()
{
InitializeComponent();
}
2021-01-19 11:10:39 +08:00
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
}
2021-01-05 11:11:28 +08:00
private ResultEnity.ufinterface HttpPost(string body)
2020-12-19 13:04:35 +08:00
{
try
2020-12-18 15:23:51 +08:00
{
2021-01-18 09:24:45 +08:00
var response = HttpHelper.HttpPost(U8LoginContext.Instance.EAIUrl, body);
2020-12-19 13:04:35 +08:00
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
}
2021-01-18 09:24:45 +08:00
//private string url = ConfigurationManager.AppSettings.Get("url");
2021-01-19 11:10:39 +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
2021-01-05 11:11:28 +08:00
private 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>("版本说明");
2020-12-23 11:25:49 +08:00
bom.Bom.Version.Define12 = row.Field<string>("母件编码") + row.Field<string>("版本说明");
2020-12-19 13:04:35 +08:00
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);
2021-01-05 11:11:28 +08:00
var response = this.HttpPost(strbody);
2020-12-19 15:30:38 +08:00
2020-12-19 13:04:35 +08:00
PrintLog(response);
Application.DoEvents();
}
}
2021-01-05 11:11:28 +08:00
private void BtnPurchaseImport_Click(object sender, EventArgs e)
2020-12-19 13:04:35 +08:00
{
if (this.dataTable == null || this.dataTable.Rows.Count == 0)
{
return;
}
2021-01-19 11:10:39 +08:00
2021-01-20 09:53:06 +08:00
2020-12-19 13:04:35 +08:00
var bomLookup = new Dictionary<string, Purchase.ufinterface>();
try
{
2021-01-19 11:10:39 +08:00
//获取相关物料的信息
var list = new List<string>();
foreach (DataRow row in this.dataTable.Rows)
{
list.Add(row["存货编码"].ToString().Trim());
}
2021-01-28 10:10:32 +08:00
var InvInfo = new NX.ERP.U8.MaterialDAL().GetList(list).ToDictionary((m) => { return m.MaterialCode; });
2021-01-19 11:10:39 +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 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();
2020-12-23 11:25:49 +08:00
purchase.purchaseapp.header.define12 = row["请购单号"].ToString();
2020-12-19 13:04:35 +08:00
var strKey = purchase.purchaseapp.header.code;
if (bomLookup.ContainsKey(strKey))
{
purchase = bomLookup[strKey];
}
else
{
bomLookup.Add(strKey, purchase);
}
2021-01-19 11:10:39 +08:00
body.inventorycode = row["存货编码"].ToString().Trim();
2021-05-26 08:50:35 +08:00
2021-01-19 11:10:39 +08:00
body.taxrate = InvInfo[body.inventorycode].TaxRate;
2021-05-31 17:06:19 +08:00
// body.requiredate = purchase.purchaseapp.header.date;
2021-05-26 08:50:35 +08:00
body.define25 = row["用料工位"].ToString().Trim();
2020-12-19 13:04:35 +08:00
body.quantity = decimal.Parse(row["数量"].ToString());
2021-05-31 17:06:19 +08:00
body.requiredate = row["需求日期"].ToString().Trim();
2020-12-19 13:04:35 +08:00
purchase.purchaseapp.body.Add(body);
2020-12-18 16:35:46 +08:00
}
2020-12-19 13:04:35 +08:00
}
2021-01-19 14:14:29 +08:00
catch (Exception err)
2020-12-19 13:04:35 +08:00
{
2020-12-18 16:35:46 +08:00
2020-12-19 13:04:35 +08:00
this.richTextBox1.SelectionColor = Color.Red;
2021-01-20 09:53:06 +08:00
this.richTextBox1.AppendText("读取数据出错\r\n" + err.Message);
2020-12-19 13:04:35 +08:00
return;
2020-12-18 16:35:46 +08:00
}
2021-01-20 13:47:44 +08:00
int index = 1;
2020-12-18 16:35:46 +08:00
foreach (var item in bomLookup.Values)
{
2021-01-20 09:53:06 +08:00
item.purchaseapp.header.code = $"CGQG{DateTime.Today.ToString("yyMM")}{index.ToString().PadLeft(5, '0')}";
2020-12-18 16:35:46 +08:00
var strbody = XmlHelper.XmlSerialize(item, Encoding.UTF8);
2021-01-05 11:11:28 +08:00
var response = this.HttpPost(strbody);
2020-12-19 13:04:35 +08:00
PrintLog(response);
2021-01-20 09:53:06 +08:00
index++;
2020-12-19 13:04:35 +08:00
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)
{
2020-12-19 16:33:33 +08:00
//单据号 日期 部门编码 业务员 制单人 存货编码 数量
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)
{
2021-01-18 09:24:45 +08:00
var a = new Voucher.VoucherDAL(U8LoginContext.Instance.Constr4Net);
2021-06-01 15:12:33 +08:00
if (a.Add(item)!="")
2020-12-19 16:33:33 +08:00
{
this.richTextBox1.SelectionColor = Color.Green;
2020-12-23 11:25:49 +08:00
this.richTextBox1.AppendText($" {item.cDefine12} 导入成功 ,实际U8单号: {item.CCode} \r\n");
2020-12-19 16:33:33 +08:00
}
else
{
this.richTextBox1.SelectionColor = Color.Red;
2020-12-23 11:25:49 +08:00
this.richTextBox1.AppendText($"{item.CCode} 导入出错\r\n");
2020-12-19 16:33:33 +08:00
}
2020-12-19 15:30:38 +08:00
}
2020-12-23 11:25:49 +08:00
this.richTextBox1.AppendText($"--------------------------------------------------------------------------------------------\r\n");
2020-12-19 16:33:33 +08:00
}
catch (Exception err)
{
this.richTextBox1.SelectionColor = Color.Red;
this.richTextBox1.AppendText($"{err.Message}读取数据出错\r\n");
return;
}
2020-12-19 15:30:38 +08:00
}
2020-12-25 11:07:27 +08:00
private void 打印ToolStripMenuItem1_Click(object sender, EventArgs e)
{
2021-01-05 11:11:28 +08:00
}
private void 登录ToolStripMenuItem_Click(object sender, EventArgs e)
{
2021-01-19 11:10:39 +08:00
2021-01-07 14:06:26 +08:00
//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();
2021-01-15 09:26:17 +08:00
var id = a.AddVocher(new NX.ERP.Model.Request.PuStoreIn()
2021-01-07 14:06:26 +08:00
{
Code = "0001",
Date = DateTime.Today,
2021-01-15 09:26:17 +08:00
2021-01-21 13:42:23 +08:00
Deptcode = "24",
2021-01-07 14:06:26 +08:00
Whcode = "1",
2021-01-13 15:02:56 +08:00
Source = "采购到货单",
2021-01-09 16:36:17 +08:00
SourceCode = "CGDH210100187",
2021-01-15 09:26:17 +08:00
Details = new List<NX.ERP.Model.Request.PuStoreInDetail>() {
new NX.ERP.Model.Request.PuStoreInDetail(){
2021-01-13 15:02:56 +08:00
2021-01-09 16:36:17 +08:00
Quantity=1,
Invcode="201763",
SorceDetailId=1000023624,
2021-01-15 09:26:17 +08:00
Position=""
2021-01-07 14:06:26 +08:00
}
}
2021-01-13 09:02:37 +08:00
});
2021-01-13 09:26:09 +08:00
2020-12-25 11:07:27 +08:00
}
2021-01-12 14:45:59 +08:00
private void 材料出库单ToolStripMenuItem_Click(object sender, EventArgs e)
{
//var a = new STVocher();
//a.AddVocher();
2021-01-28 10:10:32 +08:00
var a = new NX.ERP.U8.Store.MaterialStoreOutDAL();
a.AddVocher(new NX.ERP.Model.Request.MaterialStoreOut()
2021-01-12 14:45:59 +08:00
{
Id = 1111,
Code = "2222",
Source = "生产订单",
SourceCode = "SCDD210100009",
Whcode = "2",
Date = DateTime.Now,
2021-01-28 10:10:32 +08:00
Details = new List<NX.ERP.Model.Request.MaterialStoreOutDetail>()
2021-01-12 14:45:59 +08:00
{
2021-01-28 10:10:32 +08:00
new NX.ERP.Model.Request.MaterialStoreOutDetail()
2021-01-12 14:45:59 +08:00
{
2021-01-15 09:26:17 +08:00
Position="002070206",
2021-01-15 10:22:35 +08:00
InvCode="218174",
SorceDetailId=1000200145,
2021-01-12 14:45:59 +08:00
Quantity=1,
}
}
});
2021-01-12 16:10:37 +08:00
}
private void 其他入库ToolStripMenuItem_Click(object sender, EventArgs e)
{
var a = new NX.ERP.U8.Store.OtherStoreInDAL();
2021-01-15 10:22:35 +08:00
a.AddVocher(new NX.ERP.Model.Request.OtherStoreInOut()
2021-01-12 16:10:37 +08:00
{
2021-01-13 09:26:09 +08:00
Date = DateTime.Today,
Code = "111",
WhCode = "2",
2021-01-15 10:22:35 +08:00
details = new List<NX.ERP.Model.Request.OtherStoreInOutDetail>()
2021-01-12 16:10:37 +08:00
{
2021-01-15 10:22:35 +08:00
new NX.ERP.Model.Request.OtherStoreInOutDetail()
2021-01-12 16:10:37 +08:00
{
InvCode="218174",
Quantity=2,
Position="002070206"
}
}
}); ;
2021-01-12 14:45:59 +08:00
}
2021-01-13 10:21:56 +08:00
private void 其他出库ToolStripMenuItem_Click(object sender, EventArgs e)
{
var a = new NX.ERP.U8.Store.OtherStoreOutDAL();
2021-01-15 10:22:35 +08:00
a.AddVocher(new NX.ERP.Model.Request.OtherStoreInOut()
2021-01-13 10:21:56 +08:00
{
Date = DateTime.Today,
Code = "111",
WhCode = "2",
2021-01-15 10:22:35 +08:00
details = new List<NX.ERP.Model.Request.OtherStoreInOutDetail>()
2021-01-13 10:21:56 +08:00
{
2021-01-15 10:22:35 +08:00
new NX.ERP.Model.Request.OtherStoreInOutDetail()
2021-01-13 10:21:56 +08:00
{
InvCode="218174",
Quantity=4,
Position="002070206"
}
}
}); ;
}
2021-01-13 15:02:56 +08:00
private void 销售出库ToolStripMenuItem_Click(object sender, EventArgs e)
{
var dal = new NX.ERP.U8.Store.SaleOutDAL();
2021-01-18 15:07:20 +08:00
dal.AddVoucher(new NX.ERP.Model.Request.SaleStoreOut()
2021-01-13 15:02:56 +08:00
{
Code = "222",
Source = "发货单",
SourceCode = "XSFH210100009",
WhCode = "1",
Date = DateTime.Now,
2021-01-18 15:07:20 +08:00
Details = new List<NX.ERP.Model.Request.SaleStoreOutDetail>()
2021-01-13 15:02:56 +08:00
{
2021-01-18 15:07:20 +08:00
new NX.ERP.Model.Request.SaleStoreOutDetail()
2021-01-13 15:02:56 +08:00
{
InvCode="902112",
Position="",
Quantity=1,
2021-01-18 09:24:45 +08:00
SourceDetailId=2921
2021-01-13 15:02:56 +08:00
}
}
});
}
2021-01-13 17:02:03 +08:00
private void 成品入库ToolStripMenuItem_Click(object sender, EventArgs e)
{
2021-05-22 16:44:17 +08:00
//var ap = new NX.ERP.U8.AP.APVouch();
2021-05-26 08:50:35 +08:00
////ap.AddVocher();
2021-05-11 19:35:30 +08:00
//var dal = new NX.ERP.U8.Store.ProductInDAL();
//dal.AddVoucher(new NX.ERP.Model.Request.ProductStoreIn()
//{
// Source = "生产订单",
// SourceCode = "SCDD200900013",
// Date = DateTime.Today,
// WhCode = "1",
// Details = new List<NX.ERP.Model.Request.ProductStoreInDetail>() {
// new NX.ERP.Model.Request.ProductStoreInDetail()
// {
// Batch="",
// InvCode="904005",
// SourceDetailId=1000003338,
// Quantity=1,
// Position=""
// }
// }
//}); ;
2021-01-13 17:02:03 +08:00
}
2021-01-19 11:10:39 +08:00
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void FrmMain_Load(object sender, EventArgs e)
{
try
{
NX.ERP.U8.U8LoginContext.Instance.Login();
2021-01-25 09:47:41 +08:00
NX.ERP.U8.U8LoginContext.Instance.Constr4Net = System.Configuration.ConfigurationManager.AppSettings["connStr"];
2021-01-20 09:53:06 +08:00
this.Text = $"[{NX.ERP.U8.U8LoginContext.Instance.AccID}]{NX.ERP.U8.U8LoginContext.Instance.AccName}";
2021-01-19 11:10:39 +08:00
}
catch (Exception)
{
this.Close();
}
}
}
2020-12-18 11:10:50 +08:00
}