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.

433 lines
16 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 Gm_WMS.DataAccess.DataService;
using System.IO;
namespace Stone.WinModule.JISAdmin
{
public partial class frmEdiPrintAssemble : Stone.WinModule.frmBase
{
public frmEdiPrintAssemble()
{
InitializeComponent();
}
private void frmEdiPrintAssemble_Load(object sender, EventArgs e)
{
if (User.UserInfo.UserName == "admin")
{
this.btnPrintHand.Visible = true;
}
this.cbFields.SelectedIndex = 0;
this.timer1.Interval = Convert.ToInt32(MyAppconfig.ReadValue("EDI显示刷新时间")) * 1000;
this.timer1.Enabled = true;
}
private void btnQuery_Click(object sender, EventArgs e)
{
try
{
string PackageGroupName = ""; if (rbType1.Checked) PackageGroupName = rbType1.Text; if (rbType2.Checked) PackageGroupName = rbType2.Text; if (rbType3.Checked) PackageGroupName = rbType3.Text; if (rbType4.Checked) PackageGroupName = rbType4.Text; if (rbType5.Checked) PackageGroupName = rbType5.Text;
string Fields = this.cbFields.SelectedItem.ToString();
string value = this.txtKey.Text.Trim();
string d1 = MyDateTime.Format(this.dateTimePicker1.Value, MyDateTimeType.Date) + " 00:00:00";
string d2 = MyDateTime.Format(this.dateTimePicker2.Value, MyDateTimeType.Date) + " 23:59:59";
string strWhere = "[IsFix]=1 and [PackageGroupName]='{4}' and [IsPrintAssemble]={0} and [SwetTime]>='{1}' and [SwetTime]<='{2}' {3}";
object[] obj = new object[10];
obj[0] = rbPrint1.Checked ? "1" : "0";
obj[1] = d1;
obj[2] = d2;
obj[3] = " and " + Fields + "='" + value + "'";
obj[4] = PackageGroupName;
if (value == "") obj[3] = "";
strWhere = string.Format(strWhere, obj);
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000();
this.dgrdView1.DataSource = t_JIS_Seq5000.GetData("", strWhere, "[SequenceNumber] asc, [SwetTime] asc").Tables[0];
MyGridViewStyle.SetDataGridRowNumber(this.dgrdView1);
MyGridViewStyle.SetDataGridMenuCommon(this.dgrdView1);
MyGridViewStyle.GetGridViewState(this.dgrdView1, "JIS装配单");
this.dgrdView1.Columns["ID"].Visible = false;
this.dgrdView1.Columns["SequenceNumber"].HeaderText = "EINSTEIN Seq";
this.lblState.Text = "记录:" + this.dgrdView1.Rows.Count.ToString();
}
catch (Exception ex)
{
this.lblShow.Text = ex.Message;
}
}
private void btnPrintHand_Click(object sender, EventArgs e)
{
string PackageGroupName = ""; if (rbType1.Checked) PackageGroupName = rbType1.Text; if (rbType2.Checked) PackageGroupName = rbType2.Text; if (rbType3.Checked) PackageGroupName = rbType3.Text; if (rbType4.Checked) PackageGroupName = rbType4.Text; if (rbType5.Checked) PackageGroupName = rbType5.Text;
LocalDBService db = null;
try
{
if (!MyMessageBox.ShowQuestion("请按Sift或Ctrl键选择需要手动打印的多条记录,是否要手动打印?")) return;
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择需要打印的多条记录!");
string ids = "";
for (int i = 0; i < this.dgrdView1.SelectedRows.Count; i++)
{
ids += this.dgrdView1.SelectedRows[i].Cells["ID"].Value.ToString() + ",";
}
if (ids.Length > 0) ids = ids.Substring(0, ids.Length - 1);
string strWhere = "[ID] in (" + ids + ")";
string PackageGroupName_New = this.dgrdView1.SelectedRows[0].Cells["PackageGroupName"].Value.ToString();
if (PackageGroupName != PackageGroupName_New)
{
throw new Exception("数据和类型不正确");
}
db = new LocalDBService();
db.BeginTrans();
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000(db);
DataSet dsData = t_JIS_Seq5000.GetData("", strWhere, "[SwetTime], [CheckSequence] ASC");
if (dsData.Tables[0].Select("[IsPrintAssemble]=1").Length > 0)
throw new Exception("选择的记录中有已经打印的数据,请刷新数据!");
dsData.Tables[0].TableName = "BillHead";
string filename = WriteMES(dsData, false);
FtpMES(filename);
t_JIS_Seq5000.Edit("[IsPrintAssemble]=1, [PrintTimeAssemble]=getdate(), [IsTransport]=1", strWhere);
string BillNo = F_JIS5000_Print.GetPackingListNumber(db, PackageGroupName_New);
string PagerNumber = F_JIS5000_Print.GetNumber(db, PackageGroupName_New, 2);
for (int j = 0; j < dsData.Tables[0].Rows.Count; j++)
{
//throw new Exception("OK");
t_JIS_Seq5000.Edit("[IsPrintPackingList]=1, [PackingListNumber]='" + BillNo + "', [PagerNumber]='" + PagerNumber + "'", "[ID]=" + dsData.Tables[0].Rows[j]["ID"].ToString());
}
F_JIS5000_Print.PrintAssembly(dsData);
F_JIS5000_Print.PrintAssemblyLabel(dsData);
db.Commit();
btnQuery_Click(new object(), new EventArgs());
}
catch (Exception ex)
{
if (db != null) db.Rollback();
MyMessageBox.ShowErrorMessage(ex.Message);
}
finally
{
if (db != null) db.EndTrans();
}
}
private void btnRePrint_Click(object sender, EventArgs e)
{
try
{
if (!MyMessageBox.ShowQuestion("是否要补打装配单?")) return;
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择需要补打的多条记录!");
string ids = "";
for (int i = 0; i < this.dgrdView1.SelectedRows.Count; i++)
{
ids += this.dgrdView1.SelectedRows[i].Cells["ID"].Value.ToString() + ",";
}
if (ids.Length > 0) ids = ids.Substring(0, ids.Length - 1);
string strWhere = "[ID] in (" + ids + ")";
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000();
DataSet dsData = t_JIS_Seq5000.GetData("", strWhere, "[SequenceNumber] asc, [SwetTime] asc");
if (dsData.Tables[0].Select("[IsPrintAssemble]=0").Length > 0)
throw new Exception("没有可打印的数据");
dsData.Tables[0].TableName = "BillHead";
F_JIS5000_Print.PrintAssembly(dsData);
btnQuery_Click(new object(), new EventArgs());
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void btnPrintLabel_Click(object sender, EventArgs e)
{
try
{
if (!MyMessageBox.ShowQuestion("是否要补打零件标签?")) return;
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择需要补打的多条记录!");
string ids = "";
for (int i = 0; i < this.dgrdView1.SelectedRows.Count; i++)
{
ids += this.dgrdView1.SelectedRows[i].Cells["ID"].Value.ToString() + ",";
}
if (ids.Length > 0) ids = ids.Substring(0, ids.Length - 1);
string strWhere = "[ID] in (" + ids + ")";
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000();
DataSet dsData = t_JIS_Seq5000.GetData("", strWhere, "[SequenceNumber] asc, [SwetTime] asc");
if (dsData.Tables[0].Select("[IsPrintAssemble]=0").Length > 0)
throw new Exception("没有可打印的数据");
dsData.Tables[0].TableName = "BillHead";
F_JIS5000_Print.PrintAssemblyLabel(dsData);
btnQuery_Click(new object(), new EventArgs());
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void btnSet_Click(object sender, EventArgs e)
{
MyGridViewStyle.Show(this.dgrdView1, "JIS装配单");
}
private void btnOutPut_Click(object sender, EventArgs e)
{
try
{
Stone.Common.MyExport.ShowExport(this.dgrdView1);
}
catch (Exception ex)
{
MyMessageBox.ShowInfoMessage(ex.Message);
}
}
private void frmEdiPrintAssemble_FormClosing(object sender, FormClosingEventArgs e)
{
try
{
MyGridViewStyle.SaveGridViewState(this.dgrdView1, "JIS装配单");
}
catch
{
}
}
private void chkAuto_CheckedChanged(object sender, EventArgs e)
{
AutoUpdate();
}
private void AutoUpdate()
{
if (chkAuto.Checked)
{
this.lblShow.Text = "自动刷新中...";
this.Update();
btnQuery_Click(new object(), new EventArgs());
this.lblShow.Text = DateTime.Now.ToString() + " 自动刷新完成,下次刷新 " + Convert.ToString(this.timer1.Interval / 1000) + " 秒以后";
}
else
{
this.lblShow.Text = "自动刷新关闭";
}
}
private void timer1_Tick(object sender, EventArgs e)
{
AutoUpdate();
}
private void btnPrintReA_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择要补打的记录");
if (!MyMessageBox.ShowQuestion("是否要补打选择的记录?")) return;
string ID = this.dgrdView1.SelectedRows[0].Cells["ID"].Value.ToString();
F_JIS5000_Print.PrintCallShipRe(ID, "SMA");
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void btnPrintReB_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择要补打的记录");
if (!MyMessageBox.ShowQuestion("是否要补打选择的记录?")) return;
string ID = this.dgrdView1.SelectedRows[0].Cells["ID"].Value.ToString();
F_JIS5000_Print.PrintCallShipRe(ID, "SMB");
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
if (this.dgrdView1.SelectedRows.Count == 0) throw new Exception("请选择一条要插单的记录!");
if (!MyMessageBox.ShowQuestion("是否要线下插单?")) return;
string ID = this.dgrdView1.SelectedRows[0].Cells["ID"].Value.ToString();
Entity_t_JIS_Seq5000 t_JIS_Seq5000 = new Entity_t_JIS_Seq5000();
DataSet dsData = t_JIS_Seq5000.GetData("[ID]=" + ID);
if (dsData.Tables[0].Rows.Count == 0)
{
throw new Exception("插单的记录不存在");
}
if (Convert.ToInt32(dsData.Tables[0].Rows[0]["IsAssemble"]) == 0)
{
throw new Exception("只有装配完成的才能线下插单");
}
Gm_WMS.DataAccess.DataService.LocalDBService db = new Gm_WMS.DataAccess.DataService.LocalDBService();
db.Exec_NonQuery("UPDATE t_JIS_Seq5000 SET [IsInsert]=1, [IsPrintAssemble]=0, [IsAssemble]=0, [IsTransport]=0 WHERE [ID]=" + ID);
btnQuery_Click(new object(), new EventArgs());
MyMessageBox.ShowInfoMessage("插单完成");
}
catch (Exception ex)
{
MyMessageBox.ShowErrorMessage(ex.Message);
}
}
#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(), "JisMajor desc, seqnum asc");
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);
string PrintTime = MyDateTime.Format(MyDateTimeType.DateTime);
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();// +",";
//line += PrintTime;
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)
{
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(), true);
}
}
#endregion
}
}