You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
374 lines
14 KiB
374 lines
14 KiB
3 years ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.ComponentModel;
|
||
|
using System.Data;
|
||
|
using System.Drawing;
|
||
|
using System.Text;
|
||
|
using System.Windows.Forms;
|
||
|
using Stone.Common;
|
||
|
using Stone.Entity;
|
||
|
using Stone.WinBiz.JISAdmin;
|
||
|
using System.IO;
|
||
|
using System.Threading;
|
||
|
|
||
|
namespace Stone.WinModule.AssembleAdmin
|
||
|
{
|
||
|
public partial class frmEdiPrintAssembleScan : Stone.WinModule.frmBase
|
||
|
{
|
||
|
string PackageGroupName = "";
|
||
|
int PackageQty = 0;
|
||
|
|
||
|
public frmEdiPrintAssembleScan()
|
||
|
{
|
||
|
InitializeComponent();
|
||
|
}
|
||
|
|
||
|
private void frmEdiPrintAssembleScan_Load(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
|
||
|
PackageGroupName = MyAppconfig.ReadValue("JIS扫描打印类型");
|
||
|
PackageQty = Convert.ToInt32(MyAppconfig.ReadValue("JIS扫描打印装箱数"));
|
||
|
|
||
|
this.lblPackageGroupName.Text = PackageGroupName + " (" + PackageQty + ")";
|
||
|
|
||
|
GetOrderScan(null);
|
||
|
|
||
|
ReOrderUpdateGrid();
|
||
|
|
||
|
timer2.Enabled = true;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
MyMessageBox.ShowMessagePop(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void txtBillNo_KeyDown(object sender, KeyEventArgs e)
|
||
|
{
|
||
|
|
||
|
|
||
|
if (e.KeyCode == Keys.Enter)
|
||
|
{
|
||
|
Gm_WMS.DataAccess.DataService.LocalDBService db = null;
|
||
|
try
|
||
|
{
|
||
|
db = new Gm_WMS.DataAccess.DataService.LocalDBService();
|
||
|
db.BeginTrans();
|
||
|
|
||
|
string OrderNumber = this.txtBillNo.Text.Trim().ToUpper();
|
||
|
if (OrderNumber == "") throw new Exception("请扫描订单号");
|
||
|
OrderNumber = OrderNumber + "1";
|
||
|
|
||
|
|
||
|
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(db);
|
||
|
|
||
|
if (!chkNow.Checked)
|
||
|
{
|
||
|
DataSet dsNow = t_JIS_Seq5000.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc");
|
||
|
if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在");
|
||
|
if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsTransport"]) == true) throw new Exception(OrderNumber + " 已经扫描过了");
|
||
|
if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == false) throw new Exception(OrderNumber + " 未打印,不能扫描");
|
||
|
|
||
|
DataSet dsNext = t_JIS_Seq5000.GetData("top 1 *", "[IsPrintAssemble]=0 and [PackageGroupName]='" + PackageGroupName + "'", "[SwetTime] asc, [CallOffNumber] asc");
|
||
|
if (dsNext.Tables[0].Rows.Count == 0) throw new Exception("当前无可用打印数据");
|
||
|
|
||
|
|
||
|
t_JIS_Seq5000.Edit("[IsTransport]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString());
|
||
|
t_JIS_Seq5000.Edit("[IsPrintAssemble]=1", "[ID]=" + dsNext.Tables[0].Rows[0]["ID"].ToString());
|
||
|
|
||
|
AddPrintAssemble(dsNow.Tables[0].Rows[0]["OrderNumber"].ToString(), db);
|
||
|
|
||
|
ShowInfo(dsNext, t_JIS_Seq5000);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
dsNext.Tables[0].TableName = "BillHead";
|
||
|
F_JIS5000_Print.PrintAssembly(dsNext);
|
||
|
F_JIS5000_Print.PrintAssemblyLabel(dsNext);
|
||
|
|
||
|
string filename = WriteMES(dsNow, false);
|
||
|
FtpMES(filename);
|
||
|
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (GetOrderScan(t_JIS_Seq5000) != "") throw new Exception("系统中还有未扫描订单,请先扫描");
|
||
|
|
||
|
DataSet dsNow = t_JIS_Seq5000.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc");
|
||
|
if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在");
|
||
|
if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == true) throw new Exception(OrderNumber + " 已经打印过了");
|
||
|
|
||
|
t_JIS_Seq5000.Edit("[IsPrintAssemble]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString());
|
||
|
|
||
|
ShowInfo(dsNow, t_JIS_Seq5000);
|
||
|
dsNow.Tables[0].TableName = "BillHead";
|
||
|
F_JIS5000_Print.PrintAssembly(dsNow);
|
||
|
F_JIS5000_Print.PrintAssemblyLabel(dsNow);
|
||
|
|
||
|
}
|
||
|
|
||
|
db.Commit();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
if (db != null) db.Rollback();
|
||
|
|
||
|
MyMessageBox.ShowMessagePop(ex.Message);
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
this.txtBillNo.Focus();
|
||
|
this.txtBillNo.SelectAll();
|
||
|
|
||
|
if (db != null) db.EndTrans();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void chkNow_CheckedChanged(object sender, EventArgs e)
|
||
|
{
|
||
|
if (this.chkNow.Checked)
|
||
|
{
|
||
|
this.groupBox1.Text = this.chkNow.Text;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
this.groupBox1.Text = "扫描上一个订单";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void ShowInfo(DataSet dsData, Entity_t_JIS_Seq5000 t_JIS_Seq5000)
|
||
|
{
|
||
|
this.lblOrderNumber.Text = "订单号:" + dsData.Tables[0].Rows[0]["OrderNumber"].ToString();
|
||
|
this.lblVariant.Text = "车 型:" + dsData.Tables[0].Rows[0]["Variant"].ToString();
|
||
|
this.lblPartColor.Text = "颜 色:" + dsData.Tables[0].Rows[0]["PartColor"].ToString();
|
||
|
|
||
|
|
||
|
GetOrderScan(t_JIS_Seq5000);
|
||
|
}
|
||
|
|
||
|
private string GetOrderScan(Entity_t_JIS_Seq5000 t_JIS_Seq5000)
|
||
|
{
|
||
|
if (t_JIS_Seq5000 == null) t_JIS_Seq5000 = new Entity_t_JIS_Seq5000();
|
||
|
|
||
|
string ret = "";
|
||
|
|
||
|
DataSet dsData = t_JIS_Seq5000.GetData("top 1 *", "IsPrintAssemble=1 and IsTransport=0 and [PackageGroupName]='" + PackageGroupName + "'", "[ID] desc");
|
||
|
if (dsData.Tables[0].Rows.Count > 0)
|
||
|
{
|
||
|
ret = dsData.Tables[0].Rows[0]["OrderNumber"].ToString();
|
||
|
}
|
||
|
|
||
|
this.lblOrderNumberScan.Text = "未扫描订单:" + ret;
|
||
|
|
||
|
return ret;
|
||
|
|
||
|
}
|
||
|
|
||
|
private void AddPrintAssemble(string OrderNumber, Gm_WMS.DataAccess.DataService.LocalDBService db)
|
||
|
{
|
||
|
Entity_t_JIS_PrintAssemble t_JIS_PrintAssemble = new Entity_t_JIS_PrintAssemble(db);
|
||
|
DataRow drNew = null;
|
||
|
|
||
|
drNew = t_JIS_PrintAssemble.Table.NewRow();
|
||
|
drNew["OrderNumber"] = OrderNumber;
|
||
|
drNew["PackageGroupName"] = PackageGroupName;
|
||
|
drNew["SuperMarket"] = "SMA";
|
||
|
t_JIS_PrintAssemble.Add(drNew);
|
||
|
|
||
|
drNew = t_JIS_PrintAssemble.Table.NewRow();
|
||
|
drNew["OrderNumber"] = OrderNumber;
|
||
|
drNew["PackageGroupName"] = PackageGroupName;
|
||
|
drNew["SuperMarket"] = "SMB";
|
||
|
t_JIS_PrintAssemble.Add(drNew);
|
||
|
|
||
|
}
|
||
|
|
||
|
#region ftp_mes
|
||
|
|
||
|
private static string WriteMES(DataSet dsData, bool isReOrder)
|
||
|
{
|
||
|
string ID = dsData.Tables[0].Rows[0]["ID"].ToString();
|
||
|
string OrderNumber = dsData.Tables[0].Rows[0]["OrderNumber"].ToString();
|
||
|
DateTime SwetTime = Convert.ToDateTime(dsData.Tables[0].Rows[0]["SwetTime"]);
|
||
|
string CheckSequence = dsData.Tables[0].Rows[0]["CheckSequence"].ToString();
|
||
|
|
||
|
EntityBase v_JIS_Tod = new Entity_v_JIS_Tod();
|
||
|
if (isReOrder) v_JIS_Tod = new Entity_v_JIS_Tod_ReOrder();
|
||
|
|
||
|
DataSet dsTod = v_JIS_Tod.GetData("[SeqID]=" + dsData.Tables[0].Rows[0]["ID"].ToString());
|
||
|
|
||
|
|
||
|
|
||
|
StreamWriter sw = null;
|
||
|
string filename = "";
|
||
|
try
|
||
|
{
|
||
|
filename = MyIO.GetAppPath() + "\\MES_BAK\\";
|
||
|
if (!Directory.Exists(filename))
|
||
|
{
|
||
|
Directory.CreateDirectory(filename);
|
||
|
}
|
||
|
|
||
|
|
||
|
filename += ID + ".csv";
|
||
|
OrderNumber = OrderNumber.Substring(0, OrderNumber.Length - 1);
|
||
|
|
||
|
sw = new StreamWriter(filename, false, Encoding.Default);
|
||
|
|
||
|
foreach (DataRow drData in dsTod.Tables[0].Rows)
|
||
|
{
|
||
|
string partNumber = drData["partNumber"].ToString().Trim();
|
||
|
|
||
|
|
||
|
string line = ID + ",";
|
||
|
line += OrderNumber + ",";
|
||
|
line += MyDateTime.Format(SwetTime, MyDateTimeType.Date) + ",";
|
||
|
line += MyDateTime.Format(SwetTime, MyDateTimeType.Time3) + ",";
|
||
|
line += "\"" + drData["PartsFamily"].ToString() + "\",";
|
||
|
line += "\"" + drData["SupplyGroup"].ToString() + "\",";
|
||
|
line += drData["Variant1"].ToString() + ",";
|
||
|
line += partNumber + ",";
|
||
|
line += drData["description"].ToString() + ",";
|
||
|
line += drData["ColorName"].ToString() + "(" + drData["ColorCode"].ToString() + ")" + ",";
|
||
|
line += drData["quantity"].ToString() + ",";
|
||
|
line += CheckSequence + ",";
|
||
|
line += (partNumber.Length > 2 ? partNumber.Substring(partNumber.Length - 2, 2) : "") + ",";
|
||
|
line += "AAB" + ",";
|
||
|
line += drData["Variant"].ToString();
|
||
|
|
||
|
|
||
|
sw.WriteLine(line);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
MyLogger.Write(ex.Message);
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
if (sw != null) sw.Close();
|
||
|
}
|
||
|
|
||
|
return ID + ".csv";
|
||
|
|
||
|
}
|
||
|
|
||
|
private static void FtpMES(string filename)
|
||
|
{
|
||
|
Thread thread = new Thread(FtpMES);
|
||
|
thread.Start((object)filename);
|
||
|
}
|
||
|
|
||
|
private static void FtpMES(object filename)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string MES_AutoSend = MyAppconfig.ReadValue("MES_AutoSend").Trim();
|
||
|
string MES_Path = MyAppconfig.ReadValue("MES_Path").Trim();
|
||
|
|
||
|
if (MES_AutoSend == "是")
|
||
|
{
|
||
|
string path = MyIO.GetAppPath() + "\\MES_BAK";
|
||
|
|
||
|
File.Copy(path + "\\" + filename.ToString(), MES_Path + "\\" + filename.ToString());
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
MyLogger.Write(ex.Message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 处理ReOrder订单
|
||
|
|
||
|
private void timer2_Tick(object sender, EventArgs e)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
ReOrderUpdateGrid();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
MyMessageBox.ShowMessagePop(ex.Message);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
private void ReOrderUpdateGrid()
|
||
|
{
|
||
|
Entity_t_JIS_Seq5000_ReOrder t_JIS_Seq5000_ReOrder = new Entity_t_JIS_Seq5000_ReOrder();
|
||
|
DataSet dsReOrder = t_JIS_Seq5000_ReOrder.GetData("ID, OrderNumber, partNumber, PartName, SwetTime", "IsPrintAssemble=0 and PackageGroupName='" + PackageGroupName + "'", "[SwetTime] asc");
|
||
|
this.dgReOrder.DataSource = dsReOrder.Tables[0];
|
||
|
this.dgReOrder.Columns["ID"].Visible = false;
|
||
|
this.dgReOrder.Columns["OrderNumber"].HeaderText = "订单号";
|
||
|
this.dgReOrder.Columns["partNumber"].HeaderText = "零件号";
|
||
|
this.dgReOrder.Columns["PartName"].HeaderText = "描述";
|
||
|
this.dgReOrder.Columns["PartName"].Width = 260;
|
||
|
this.dgReOrder.Columns["SwetTime"].HeaderText = "时间";
|
||
|
this.dgReOrder.Columns["SwetTime"].Width = 180;
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
private void btnReOrder_Click(object sender, EventArgs e)
|
||
|
{
|
||
|
Gm_WMS.DataAccess.DataService.LocalDBService db = null;
|
||
|
try
|
||
|
{
|
||
|
if (this.dgReOrder.SelectedRows.Count == 0) throw new Exception("请选择一条ReOrder订单");
|
||
|
|
||
|
string OrderNumber = this.dgReOrder.SelectedRows[0].Cells["OrderNumber"].Value.ToString();
|
||
|
|
||
|
db = new Gm_WMS.DataAccess.DataService.LocalDBService();
|
||
|
db.BeginTrans();
|
||
|
|
||
|
Entity_t_JIS_Seq5000_ReOrder t_JIS_Seq5000_ReOrder = new Entity_t_JIS_Seq5000_ReOrder(db);
|
||
|
|
||
|
DataSet dsNow = t_JIS_Seq5000_ReOrder.GetData("top 1 *", "[OrderNumber]='" + OrderNumber + "' and [PackageGroupName]='" + PackageGroupName + "' ", "[ID] desc");
|
||
|
if (dsNow.Tables[0].Rows.Count == 0) throw new Exception(OrderNumber + " 不存在");
|
||
|
if (Convert.ToBoolean(dsNow.Tables[0].Rows[0]["IsPrintAssemble"]) == true) throw new Exception(OrderNumber + " 已经打印了");
|
||
|
|
||
|
t_JIS_Seq5000_ReOrder.Edit("[IsPrintAssemble]=1,[IsTransport]=1", "[ID]=" + dsNow.Tables[0].Rows[0]["ID"].ToString());
|
||
|
|
||
|
|
||
|
AddPrintAssemble(dsNow.Tables[0].Rows[0]["OrderNumber"].ToString(), db);
|
||
|
|
||
|
|
||
|
|
||
|
dsNow.Tables[0].TableName = "BillHead";
|
||
|
F_JIS5000_Print_ReOrder.PrintAssembly(dsNow);
|
||
|
F_JIS5000_Print_ReOrder.PrintAssemblyLabel(dsNow);
|
||
|
|
||
|
|
||
|
string filename = WriteMES(dsNow, true);
|
||
|
FtpMES(filename);
|
||
|
|
||
|
db.Commit();
|
||
|
|
||
|
ReOrderUpdateGrid();
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
if (db != null) db.Rollback();
|
||
|
MyMessageBox.ShowMessagePop(ex.Message);
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
if (db != null) db.EndTrans();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|