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.
1342 lines
61 KiB
1342 lines
61 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Data.Linq;
|
|
using System.Linq;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using DevExpress.XtraEditors;
|
|
using DevExpress.XtraGrid.Views.BandedGrid;
|
|
using DevExpress.XtraGrid.Columns;
|
|
using DevExpress.XtraGrid;
|
|
using System.IO;
|
|
using System.Threading;
|
|
using ICSSoft.Base.Language.Tool;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using ICSSoft.Base.UserControl.MessageControl;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.Report.Filter;
|
|
using ICSSoft.Base.UserControl.FormControl;
|
|
using ICSSoft.Base.Report.GridReport;
|
|
using ICSSoft.Base.ReferForm.AppReferForm;
|
|
using ICSSoft.Frame.Data.BLL;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Log;
|
|
using ICSSoft.Frame.Common;
|
|
|
|
namespace ICSSoft.Frame.APP
|
|
{
|
|
public partial class FormICSDataCollectForWWAGV : DevExpress.XtraEditors.XtraForm
|
|
{
|
|
private string sqltxt = "";
|
|
private string sqlconn = "";
|
|
String guid = AppConfig.GetGuid();
|
|
private DataTable dataSource = null;
|
|
private DataTable grvdt = new DataTable();
|
|
List<ICSPO_PoMain> polist = new List<ICSPO_PoMain>();
|
|
List<ICSWareHouseLotInfoLog> loglist = new List<ICSWareHouseLotInfoLog>();
|
|
|
|
|
|
#region 构造函数
|
|
public FormICSDataCollectForWWAGV()
|
|
{
|
|
InitializeComponent();
|
|
this.MaximumSize = new Size(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height);
|
|
this.WindowState = FormWindowState.Maximized;
|
|
grvDetail.Columns[0].Visible = false;
|
|
}
|
|
#endregion
|
|
|
|
#region 操作权限
|
|
public DataTable RightOfExute()
|
|
{
|
|
DataTable rData = new DataTable();
|
|
rData.Columns.Add("BtnName");
|
|
rData.Columns.Add("ActionName");
|
|
//查看权限(必须有)
|
|
DataRow seeRow = rData.NewRow();
|
|
seeRow["BtnName"] = "see";
|
|
seeRow["ActionName"] = "查看";
|
|
rData.Rows.Add(seeRow);
|
|
|
|
List<Control> ControlList = new List<Control>();
|
|
ControlList.Add(btnWWSubmit);
|
|
foreach (Control ctr in ControlList)
|
|
{
|
|
|
|
if (ctr.GetType() == typeof(SimpleButton))
|
|
{
|
|
DataRow dr = rData.NewRow();
|
|
dr["BtnName"] = ctr.Name;
|
|
dr["ActionName"] = ctr.Text;
|
|
rData.Rows.Add(dr);
|
|
}
|
|
}
|
|
|
|
rData.AcceptChanges();
|
|
return rData;
|
|
}
|
|
public DataTable RightOfData()// 数据权限
|
|
{
|
|
DataTable rData = new DataTable();
|
|
rData.Columns.Add("BodyName");
|
|
rData.Columns.Add("ControlName");
|
|
rData.Columns.Add("ControlCaption");
|
|
|
|
rData.AcceptChanges();
|
|
return rData;
|
|
}
|
|
#endregion
|
|
|
|
#region 退出
|
|
private void btnClose_Click(object sender, EventArgs e)
|
|
{
|
|
AppConfig.CloseFormShow(this.Text);
|
|
this.Close();
|
|
}
|
|
|
|
private void btnExit_Click(object sender, EventArgs e)
|
|
{
|
|
AppConfig.CloseFormShow(this.Text);
|
|
this.Close();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 移动窗体
|
|
private const int WM_NCHITTEST = 0x84;
|
|
private const int HTCLIENT = 0x1;
|
|
private const int HTCAPTION = 0x2;
|
|
//首先必须了解Windows的消息传递机制,当有鼠标活动消息时,
|
|
//系统发送WM_NCHITTEST 消息给窗体作为判断消息发生地的根据。 nchittest
|
|
//假如你点击的是标题栏,窗体收到的消息值就是 HTCAPTION ,
|
|
//同样地,若接受到的消息是 HTCLIENT,说明用户点击的是客户区,也就是鼠标消息发生在客户区。
|
|
|
|
//重写窗体,使窗体可以不通过自带标题栏实现移动
|
|
protected override void WndProc(ref Message m)
|
|
{
|
|
|
|
|
|
//当重载窗体的 WndProc 方法时,可以截获 WM_NCHITTEST 消息并改些该消息,
|
|
//当判断鼠标事件发生在客户区时,改写改消息,发送 HTCAPTION 给窗体,
|
|
//这样,窗体收到的消息就时 HTCAPTION ,在客户区通过鼠标来拖动窗体就如同通过标题栏来拖动一样。
|
|
//注意:当你重载 WndProc 并改写鼠标事件后,整个窗体的鼠标事件也就随之改变了。
|
|
switch (m.Msg)
|
|
{
|
|
case WM_NCHITTEST:
|
|
base.WndProc(ref m);
|
|
if ((int)m.Result == HTCLIENT)
|
|
m.Result = (IntPtr)HTCAPTION;
|
|
return;
|
|
}
|
|
//拦截双击标题栏、移动窗体的系统消息
|
|
if (m.Msg != 0xA3)
|
|
{
|
|
base.WndProc(ref m);
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 列表
|
|
private void grvDetail_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
|
|
{
|
|
if (e.Info.IsRowIndicator && e.RowHandle >= 0)
|
|
e.Info.DisplayText = (e.RowHandle + 1).ToString();
|
|
}
|
|
#endregion
|
|
|
|
#region 分页
|
|
private void rptPage_PageIndexChanged(object Sender, EventArgs e)
|
|
{
|
|
|
|
DataTable data = AppConfig.GetPageData(dataSource, rptPage.PageIndex, rptPage.PageSize).Copy();
|
|
//DataTable data = AppConfig.GetPageDataByDb(tempTableName, "pagerowindex", rptPage.PageSize, rptPage.PageIndex, dataSource.Rows.Count);
|
|
grdDetail.DataSource = data;
|
|
}
|
|
#endregion
|
|
|
|
#region 全选
|
|
private void btnSelectAll_Click(object sender, EventArgs e)
|
|
{
|
|
grvDetail.PostEditor();
|
|
this.Validate();
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
grvDetail.SetRowCellValue(i, colisSelect, "Y");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 全消
|
|
private void btnCancelAll_Click(object sender, EventArgs e)
|
|
{
|
|
grvDetail.PostEditor();
|
|
this.Validate();
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
grvDetail.SetRowCellValue(i, colisSelect, "");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 双击
|
|
private void grvDetail_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
if (grvDetail.FocusedRowHandle < 0)
|
|
{
|
|
return;
|
|
}
|
|
if (grvDetail.FocusedColumn == colisSelect)
|
|
{
|
|
if (grvDetail.GetRowCellValue(grvDetail.FocusedRowHandle, colisSelect).ToString() == "")
|
|
{
|
|
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "Y");
|
|
}
|
|
else
|
|
{
|
|
grvDetail.SetRowCellValue(grvDetail.FocusedRowHandle, colisSelect, "");
|
|
}
|
|
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 新增
|
|
private void btnCreate_Click(object sender, EventArgs e)
|
|
{
|
|
//SimpleButton btntemp = (SimpleButton)sender;
|
|
//if (AppConfig.GetUserExcuteRight(this.Tag.ToString(), btntemp.Name) == false)
|
|
//{
|
|
// ICSBaseSimpleCode.AppshowMessageBox("对不起您没有:" + btntemp.Text + "权限,请联系系统管理员!");
|
|
// return;
|
|
//}
|
|
//FormICSONWIPCheckAdd add = new FormICSONWIPCheckAdd();
|
|
//add.ShowDialog();
|
|
//btnRefresh_Click(null, null);
|
|
}
|
|
#endregion
|
|
private void FormICSCREW_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnSearch_Click(object sender, EventArgs e)
|
|
{
|
|
//if (SendType.Checked == true)
|
|
//{
|
|
// if (txtPOCode.Text != "")
|
|
// {
|
|
// GetSendGrvDT("MOCODE");
|
|
// }
|
|
// if (txtLotNo.Text != "")
|
|
// {
|
|
// GetSendGrvDT("LOTNO");
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// if (txtPOCode.Text != "")
|
|
// {
|
|
// GetReceiveDT("MOCODE");
|
|
// }
|
|
// if (txtLotNo.Text != "")
|
|
// {
|
|
// GetReceiveDT("LOTNO");
|
|
// }
|
|
//}
|
|
}
|
|
private void GetSendGrvDT(string CodeType)
|
|
{
|
|
string sql = @" select '' as isSelected
|
|
,A.LOTNO AS LOTNO
|
|
,B.MCODE AS INVCODE
|
|
,C.INVNAME AS INVNAME
|
|
,C.INVSTD AS INVSTD
|
|
,ISNULL(B.LOTQTY,0) AS LOTQTY
|
|
,C.INVUOM AS INVUOM
|
|
,Convert(decimal(18,2),ISNULL(B.LOTQTY,0))*Convert(decimal(18,2),ISNULL(B.EATTRIBUTE3,0)) AS AssQTY
|
|
,C.INVEXPORTIMPORT AS INVAssUOM
|
|
,D.ROUTECODE AS ROUTECODE
|
|
,D.OPSEQ AS OPSEQ
|
|
,D.OPCODE AS OPCODE
|
|
,E.OPDESC AS OPDESC
|
|
,G.TypeCODE AS TypeCode
|
|
,G.TypeDESC AS TypeDESC
|
|
,A.EQPCode AS EQPCode
|
|
,A.PRLineID AS LOTPRID
|
|
,'' AS LotPOCode
|
|
,'' AS LotPORow
|
|
,B.VenderLotNO
|
|
from ICSMO2User A
|
|
LEFT JOIN ICSITEMLot B
|
|
ON B.LotNO=A.LOTNO
|
|
LEFT JOIN ICSINVENTORY C
|
|
ON C.INVCODE=B.MCODE
|
|
LEFT JOIN ICSITEMROUTE2OPLot D
|
|
ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE
|
|
LEFT JOIN ICSOP E
|
|
ON E.OPCODE=D.OPCODE
|
|
LEFT JOIN ICSEquipment F
|
|
ON F.EQPCode=A.EQPCode
|
|
LEFT JOIN ICSEquipmentType G
|
|
ON G.TypeCODE=F.Type
|
|
where A.LOTNO = '{0}'
|
|
AND A.EATTRIBUTE1='1'
|
|
AND A.WorkPoint='{1}'
|
|
AND A.LOTNO+A.OPCODE NOT IN
|
|
(SELECT LotNO+OPCODE FROM ICSLOTONWIP AND A.LOTNO='{0}')
|
|
ORDER BY A.LOTNO,D.OPSEQ";
|
|
sql = string.Format(sql, txtLotNo.Text, AppConfig.WorkPointCode);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
//新增判断是否已发料
|
|
if (dt.Rows.Count <= 0) {
|
|
ICSBaseSimpleCode.AppshowMessageBox("未获取到该流转单未发料的委外工序!");
|
|
return;
|
|
}
|
|
|
|
int chkCount = 0;
|
|
bool canSend = false;
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
for (int j = 0; j < gridViewCG.RowCount; j++)
|
|
{
|
|
if (dt.Rows[i]["LOTPRID"].ToString() == gridViewCG.GetRowCellValue(j, PRID).ToString())
|
|
{
|
|
chkCount++;
|
|
}
|
|
}
|
|
}
|
|
if (chkCount <= gridViewCG.RowCount)
|
|
{
|
|
canSend = true;
|
|
}
|
|
for (int i = dt.Rows.Count - 1; i >= 0; i--)
|
|
{
|
|
sql = @"select * from ICSITEMROUTE2OPLot
|
|
where LotNo='{0}' AND OPSEQ<'{1}'";
|
|
sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
|
|
DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (chkdt.Rows.Count != 0)
|
|
{
|
|
sql = @"SELECT * FROM ICSLOTONWIPCheck A
|
|
INNER JOIN ICSLOTONWIP B
|
|
ON B.ID=A.ONWIPID
|
|
INNER JOIN ICSLOTSIMULATION C
|
|
ON C.LOTNO=B.LOTNO AND C.SEQ=B.SEQ
|
|
WHERE C.LOTNO='{0}' AND C.OPCODE=
|
|
(SELECT TOP 1 OPCODE FROM ICSITEMROUTE2OPLot
|
|
WHERE LOTNO='{0}' AND OPSEQ<'{1}'
|
|
ORDER BY OPSEQ DESC) ";
|
|
sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
|
|
chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (chkdt.Rows.Count == 0)
|
|
{
|
|
dt.Rows.Remove(dt.Rows[i]);
|
|
}
|
|
else
|
|
{
|
|
if ((chkdt.Rows[0]["Result"].ToString() == "不合格" && chkdt.Rows[0]["TResult"].ToString() == "报废")
|
|
|| (chkdt.Rows[0]["Result"].ToString() == "不合格" && chkdt.Rows[0]["TResult"] == null))
|
|
{
|
|
dt.Rows.Remove(dt.Rows[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("上一道工序未检验或检验不合格,无法委外发料,请确认!");
|
|
return;
|
|
}
|
|
for (int i = dt.Rows.Count - 1; i >= 0; i--)
|
|
{
|
|
bool isexsist = false;
|
|
for (int j = 0; j < gridViewCG.RowCount; j++)
|
|
{
|
|
if (dt.Rows[i]["LOTPRID"].ToString() == gridViewCG.GetRowCellValue(j, PRID).ToString())
|
|
{
|
|
isexsist = true;
|
|
}
|
|
}
|
|
if (isexsist == false)
|
|
{
|
|
dt.Rows.Remove(dt.Rows[i]);
|
|
}
|
|
}
|
|
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("生成的请购单PR号和ERP内不一致或该PR单行对应采购订单行未生成,无法委外发料,请确认!");
|
|
return;
|
|
}
|
|
if (canSend == false)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("MES连续委外道数(" + chkCount + ")和ERP内的采购订单(" + gridViewCG.RowCount + ")不一致,请确认!");
|
|
return;
|
|
}
|
|
if (grvdt == null || grvdt.Rows.Count == 0)
|
|
{
|
|
decimal POTotalQTY = 0;
|
|
decimal LotTotalQTY = 0;
|
|
for (int i = 0; i < gridViewCG.RowCount; i++)
|
|
{
|
|
string POInvCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
|
|
decimal POPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
|
|
decimal POSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
|
|
decimal POCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
|
|
string PRLineID = gridViewCG.GetRowCellValue(i, PRID).ToString();
|
|
for (int j = 0; j < dt.Rows.Count; j++)
|
|
{
|
|
if (POInvCode == dt.Rows[j]["INVCODE"].ToString() + "_" + dt.Rows[j]["OPCODE"].ToString() && PRLineID == dt.Rows[j]["LOTPRID"].ToString())
|
|
{
|
|
POTotalQTY = POTotalQTY + (POPlanQTY - POSendQTY - POCurrentQTY);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
LotTotalQTY = LotTotalQTY + Convert.ToDecimal(dt.Rows[i]["LOTQTY"]);
|
|
}
|
|
if (POTotalQTY < LotTotalQTY)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超过采购订单行数量!!");
|
|
return;
|
|
}
|
|
grvdt = dt.Copy();
|
|
}
|
|
else
|
|
{
|
|
if (dt.Rows.Count != 0)
|
|
{
|
|
grvdt = GetGrvDTADD(grvdt, dt);
|
|
}
|
|
}
|
|
if (grvdt.Rows.Count != 0)
|
|
{
|
|
if (grvdt.Rows.Count > 1)
|
|
{
|
|
for (int i = 0; i < grvdt.Rows.Count; i++)
|
|
{
|
|
if (grvdt.Rows[i]["LOTNO"].ToString() == txtLotNo.Text.Trim())
|
|
{
|
|
DataRow dr = grvdt.Select("LOTNO='" + txtLotNo.Text.Trim() + "'")[0];
|
|
DataRow newdr = grvdt.NewRow();
|
|
newdr.ItemArray = dr.ItemArray;
|
|
grvdt.Rows.Remove(dr);
|
|
grvdt.Rows.InsertAt(newdr, 0);
|
|
}
|
|
}
|
|
}
|
|
grdDetail.DataSource = grvdt;
|
|
}
|
|
}
|
|
private void GetReceiveDT(string CodeType)
|
|
{
|
|
DataTable tempdt = new DataTable();
|
|
string FLLotNo = "";
|
|
string FLOPCode = "";
|
|
string FLItemCode = "";
|
|
tempdt.TableName = "IcsItemLotANDOP";
|
|
tempdt.Columns.Add("LotNo", typeof(string));
|
|
tempdt.Columns.Add("OPCode", typeof(string));
|
|
tempdt.Columns.Add("ItemCode", typeof(string));
|
|
string sql = @" select A.LOTNO AS LOTNO
|
|
,D.OPSEQ AS OPSEQ
|
|
,D.OPCODE AS OPCODE
|
|
from ICSMO2User A
|
|
LEFT JOIN ICSITEMROUTE2OPLot D
|
|
ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE";
|
|
if (CodeType == "LOTNO")
|
|
{
|
|
sql += @" WHERE A.LOTNO = '{0}'";
|
|
}
|
|
else
|
|
{
|
|
sql += @" WHERE A.MOCODE = '{0}'";
|
|
}
|
|
sql += @"AND A.EATTRIBUTE1='1'
|
|
AND A.WorkPoint='{1}'
|
|
AND A.LOTNO+A.OPCODE IN
|
|
(SELECT LotNO+OPCODE FROM ICSLOTSIMULATION
|
|
WHERE CollectStatus='COLLECT_BEGIN')
|
|
ORDER BY A.LOTNO,D.OPSEQ";
|
|
if (CodeType == "LOTNO")
|
|
{
|
|
sql = string.Format(sql, txtLotNo.Text, AppConfig.WorkPointCode);
|
|
}
|
|
else
|
|
{
|
|
sql = string.Format(sql, txtPOCode.Text, AppConfig.WorkPointCode);
|
|
}
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
sql = @"SELECT
|
|
a.LotNo AS LOTNO
|
|
,a.ITEMCODE
|
|
,a.OPSEQ AS OPSEQ
|
|
,a.OPCODE AS OPCODE
|
|
,c.EATTRIBUTE1 AS ISWW
|
|
,b.OPSEQ AS NOPSEQ
|
|
,b.OPCODE AS NOPCODE
|
|
,d.EATTRIBUTE1 AS NISWW
|
|
FROM ICSITEMROUTE2OPLot a
|
|
LEFT JOIN ICSITEMROUTE2OPLot b ON a.LotNo=b.LotNo AND b.OPSEQ=(SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OPLot WHERE LotNo=a.LotNo AND OPSEQ>a.OPSEQ)
|
|
LEFT JOIN ICSMO2User c ON a.LotNo=c.LOTNO AND a.OPCODE=c.OPCODE
|
|
LEFT JOIN ICSMO2User d ON b.LotNo=d.LOTNO AND b.OPCODE=d.OPCODE
|
|
WHERE c.LotNo = '{0}'
|
|
AND a.OPSEQ>='{1}'
|
|
ORDER BY a.LotNo,a.OPSEQ";
|
|
sql = string.Format(sql, dt.Rows[i]["LOTNO"].ToString(), dt.Rows[i]["OPSEQ"].ToString());
|
|
DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
FLLotNo = chkdt.Rows[0]["LotNo"].ToString();
|
|
FLOPCode = chkdt.Rows[0]["OPCODE"].ToString();
|
|
FLItemCode = chkdt.Rows[0]["ITEMCODE"].ToString();
|
|
for (int j = 0; j < chkdt.Rows.Count; j++)
|
|
{
|
|
if (chkdt.Rows[j]["ISWW"].ToString() == "1")
|
|
{
|
|
DataRow dr = tempdt.NewRow();
|
|
dr["LotNo"] = chkdt.Rows[j]["LOTNO"].ToString();
|
|
dr["OPCode"] = chkdt.Rows[j]["OPCODE"].ToString();
|
|
dr["ItemCode"] = chkdt.Rows[j]["ITEMCODE"].ToString();
|
|
tempdt.Rows.Add(dr);
|
|
}
|
|
if (chkdt.Rows[j]["NISWW"].ToString() != "1")
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
string FLSql = @"select POCode,PORow,InvCode
|
|
from ICSPO_PoMain A
|
|
LEFT JOIN ICSWareHouseLotInfoLog B
|
|
ON B.TransNO=A.POCode and a.PORow=b.TransLine
|
|
where LotNO='{0}' AND BusinessCode='委外发料'
|
|
AND TransType='发' and a.POCode=(select pocode from ICSWareHouseLotInfoLog where Lotno='{0}' and memo='{1}')
|
|
--AND Memo='{1}'
|
|
AND B.WorkPoint='{2}'";
|
|
FLSql = string.Format(FLSql, FLLotNo, FLOPCode, AppConfig.WorkPointCode);
|
|
DataTable fldt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, FLSql).Tables[0];
|
|
for (int i = tempdt.Rows.Count - 1; i >= 0; i--)
|
|
{
|
|
bool needReceive = false;
|
|
for (int j = 0; j < fldt.Rows.Count; j++)
|
|
{
|
|
if (fldt.Rows[j]["InvCode"].ToString() ==
|
|
tempdt.Rows[i]["ITEMCODE"].ToString() + "_" + tempdt.Rows[i]["OPCODE"].ToString())
|
|
{
|
|
needReceive = true;
|
|
}
|
|
}
|
|
if (needReceive == false)
|
|
{
|
|
tempdt.Rows.Remove(tempdt.Rows[i]);
|
|
}
|
|
}
|
|
//留下最后一道委外工序进行批量收料
|
|
for (int i = tempdt.Rows.Count - 1; i >= 0; i--)
|
|
{
|
|
if (i != tempdt.Rows.Count - 1)
|
|
{
|
|
tempdt.Rows.Remove(tempdt.Rows[i]);
|
|
}
|
|
}
|
|
for (int i = 0; i < tempdt.Rows.Count; i++)
|
|
{
|
|
string receivesql = @"select '' as isSelected
|
|
,A.LOTNO AS LOTNO
|
|
,B.MCODE AS INVCODE
|
|
,C.INVNAME AS INVNAME
|
|
,C.INVSTD AS INVSTD
|
|
,ISNULL(B.LOTQTY,0) AS LOTQTY
|
|
,C.INVUOM AS INVUOM
|
|
,Convert(decimal(18,2),ISNULL(B.LOTQTY,0))*Convert(decimal(18,2),ISNULL(B.EATTRIBUTE3,0)) AS AssQTY
|
|
,C.INVEXPORTIMPORT AS INVAssUOM
|
|
,D.ROUTECODE AS ROUTECODE
|
|
,D.OPSEQ AS OPSEQ
|
|
,D.OPCODE AS OPCODE
|
|
,E.OPDESC AS OPDESC
|
|
,G.TypeCODE AS TypeCode
|
|
,G.TypeDESC AS TypeDESC
|
|
,A.EQPCode AS EQPCode
|
|
,B.VenderLotNO
|
|
from ICSMO2User A
|
|
LEFT JOIN ICSITEMLot B
|
|
ON B.LotNO=A.LOTNO
|
|
LEFT JOIN ICSINVENTORY C
|
|
ON C.INVCODE=B.MCODE
|
|
LEFT JOIN ICSITEMROUTE2OPLot D
|
|
ON D.LotNo=A.LOTNO AND D.OPCODE=A.OPCODE
|
|
LEFT JOIN ICSOP E
|
|
ON E.OPCODE=D.OPCODE
|
|
LEFT JOIN ICSEquipment F
|
|
ON F.EQPCode=A.EQPCode
|
|
LEFT JOIN ICSEquipmentType G
|
|
ON G.TypeCODE=F.Type
|
|
where A.LOTNO='{0}'
|
|
AND A.OPCODE='{1}'";
|
|
receivesql = string.Format(receivesql, tempdt.Rows[i]["LotNo"].ToString()
|
|
, tempdt.Rows[i]["OPCode"].ToString());
|
|
DataTable receivedt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, receivesql).Tables[0];
|
|
if (grvdt == null || grvdt.Rows.Count == 0)
|
|
{
|
|
grvdt = receivedt.Copy();
|
|
}
|
|
else
|
|
{
|
|
grvdt = GetGrvDTADD(grvdt, receivedt);
|
|
}
|
|
}
|
|
if (grvdt.Rows.Count != 0)
|
|
{
|
|
if (grvdt.Rows.Count > 1)
|
|
{
|
|
for (int i = 0; i < grvdt.Rows.Count; i++)
|
|
{
|
|
if (grvdt.Rows[i]["LOTNO"].ToString() == txtLotNo.Text.Trim())
|
|
{
|
|
DataRow dr = grvdt.Select("LOTNO='" + txtLotNo.Text.Trim() + "'")[0];
|
|
DataRow newdr = grvdt.NewRow();
|
|
newdr.ItemArray = dr.ItemArray;
|
|
grvdt.Rows.Remove(dr);
|
|
grvdt.Rows.InsertAt(newdr, 0);
|
|
}
|
|
}
|
|
}
|
|
grdDetail.DataSource = grvdt;
|
|
}
|
|
else
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("工单或条码下不存在符合收料条件的工序!!");
|
|
return;
|
|
}
|
|
}
|
|
private DataTable GetGrvDTADD(DataTable GRVDT, DataTable DT)
|
|
{
|
|
if (SendType.Checked == true)
|
|
{
|
|
decimal POTotalQTY = 0;
|
|
decimal LotTotalQTY = 0;
|
|
for (int i = 0; i < gridViewCG.RowCount; i++)
|
|
{
|
|
string POInvCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
|
|
decimal POPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
|
|
decimal POSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
|
|
decimal POCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
|
|
string PRLineID = gridViewCG.GetRowCellValue(i, PRID).ToString();
|
|
for (int j = 0; j < DT.Rows.Count; j++)
|
|
{
|
|
if (POInvCode == DT.Rows[j]["INVCODE"].ToString() + "_" + DT.Rows[j]["OPCODE"].ToString() && PRLineID == DT.Rows[j]["LOTPRID"].ToString())
|
|
{
|
|
POTotalQTY = POTotalQTY + (POPlanQTY - POSendQTY - POCurrentQTY);
|
|
}
|
|
}
|
|
}
|
|
for (int i = 0; i < DT.Rows.Count; i++)
|
|
{
|
|
LotTotalQTY = LotTotalQTY + Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
|
|
}
|
|
if (POTotalQTY < LotTotalQTY)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超过采购订单行数量!!");
|
|
return GRVDT;
|
|
}
|
|
}
|
|
for (int i = 0; i < DT.Rows.Count; i++)
|
|
{
|
|
bool isexsist = false;
|
|
for (int j = 0; j < GRVDT.Rows.Count; j++)
|
|
{
|
|
if (DT.Rows[i]["LOTNO"].ToString() == GRVDT.Rows[j]["LOTNO"].ToString())
|
|
{
|
|
isexsist = true;
|
|
}
|
|
}
|
|
if (isexsist == false)
|
|
{
|
|
if (SendType.Checked == true)
|
|
{
|
|
DataRow dr = GRVDT.NewRow();
|
|
dr["isSelected"] = DT.Rows[i]["isSelected"].ToString();
|
|
dr["VenderLotNO"] = DT.Rows[i]["VenderLotNO"].ToString();
|
|
dr["LOTNO"] = DT.Rows[i]["LOTNO"].ToString();
|
|
dr["INVCODE"] = DT.Rows[i]["INVCODE"].ToString();
|
|
dr["INVNAME"] = DT.Rows[i]["INVNAME"].ToString();
|
|
dr["INVSTD"] = DT.Rows[i]["INVSTD"].ToString();
|
|
dr["LOTQTY"] = Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
|
|
dr["INVUOM"] = DT.Rows[i]["INVUOM"].ToString();
|
|
dr["AssQTY"] = Convert.ToDecimal(DT.Rows[i]["AssQTY"]);
|
|
dr["INVAssUOM"] = DT.Rows[i]["INVAssUOM"].ToString();
|
|
dr["ROUTECODE"] = DT.Rows[i]["ROUTECODE"].ToString();
|
|
dr["OPSEQ"] = Convert.ToDecimal(DT.Rows[i]["OPSEQ"]);
|
|
dr["OPCODE"] = DT.Rows[i]["OPCODE"].ToString();
|
|
dr["OPDESC"] = DT.Rows[i]["OPDESC"].ToString();
|
|
dr["EQPCode"] = DT.Rows[i]["EQPCode"].ToString();
|
|
dr["TypeCode"] = DT.Rows[i]["TypeCode"].ToString();
|
|
dr["TypeDESC"] = DT.Rows[i]["TypeDESC"].ToString();
|
|
dr["LOTPRID"] = DT.Rows[i]["LOTPRID"].ToString();
|
|
dr["LotPOCode"] = DT.Rows[i]["LotPOCode"].ToString();
|
|
dr["LotPORow"] = DT.Rows[i]["LotPORow"].ToString();
|
|
GRVDT.Rows.Add(dr);
|
|
}
|
|
else
|
|
{
|
|
DataRow dr = GRVDT.NewRow();
|
|
dr["isSelected"] = DT.Rows[i]["isSelected"].ToString();
|
|
dr["VenderLotNO"] = DT.Rows[i]["VenderLotNO"].ToString();
|
|
dr["LOTNO"] = DT.Rows[i]["LOTNO"].ToString();
|
|
dr["INVCODE"] = DT.Rows[i]["INVCODE"].ToString();
|
|
dr["INVNAME"] = DT.Rows[i]["INVNAME"].ToString();
|
|
dr["INVSTD"] = DT.Rows[i]["INVSTD"].ToString();
|
|
dr["LOTQTY"] = Convert.ToDecimal(DT.Rows[i]["LOTQTY"]);
|
|
dr["INVUOM"] = DT.Rows[i]["INVUOM"].ToString();
|
|
dr["AssQTY"] = Convert.ToDecimal(DT.Rows[i]["AssQTY"]);
|
|
dr["INVAssUOM"] = DT.Rows[i]["INVAssUOM"].ToString();
|
|
dr["ROUTECODE"] = DT.Rows[i]["ROUTECODE"].ToString();
|
|
dr["OPSEQ"] = Convert.ToDecimal(DT.Rows[i]["OPSEQ"]);
|
|
dr["OPCODE"] = DT.Rows[i]["OPCODE"].ToString();
|
|
dr["OPDESC"] = DT.Rows[i]["OPDESC"].ToString();
|
|
dr["EQPCode"] = DT.Rows[i]["EQPCode"].ToString();
|
|
dr["TypeCode"] = DT.Rows[i]["TypeCode"].ToString();
|
|
dr["TypeDESC"] = DT.Rows[i]["TypeDESC"].ToString();
|
|
GRVDT.Rows.Add(dr);
|
|
}
|
|
}
|
|
}
|
|
return GRVDT;
|
|
}
|
|
#region 全选
|
|
private void btnSelectAll_Click_1(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
grvDetail.SetRowCellValue(i, colisSelect, "Y");
|
|
}
|
|
}
|
|
#endregion
|
|
#region 全消
|
|
private void btnCancelAll_Click_1(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
grvDetail.SetRowCellValue(i, colisSelect, "");
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
private void btnClear_Click(object sender, EventArgs e)
|
|
{
|
|
txtPOCode.Text = "";
|
|
txtLotNo.Text = "";
|
|
grvdt.Clear();
|
|
grdDetail.DataSource = null;
|
|
gridControlCG.DataSource = null;
|
|
loglist.Clear();
|
|
polist.Clear();
|
|
}
|
|
|
|
private void SendType_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (SendType.Checked == true)
|
|
{
|
|
btnWWSubmit.Text = "委外发料";
|
|
txtPOCode.Enabled = true;
|
|
grvDetail.Columns[0].Visible = false;
|
|
txtPOCode.Text = "";
|
|
txtLotNo.Text = "";
|
|
grvdt.Clear();
|
|
grdDetail.DataSource = null;
|
|
gridControlCG.DataSource = null;
|
|
loglist.Clear();
|
|
polist.Clear();
|
|
}
|
|
}
|
|
|
|
private void ReceiveType_CheckedChanged(object sender, EventArgs e)
|
|
{
|
|
if (ReceiveType.Checked == true)
|
|
{
|
|
btnWWSubmit.Text = "委外收料";
|
|
txtPOCode.Enabled = false;
|
|
grvDetail.Columns[0].Visible = true;
|
|
gridControlCG.DataSource = null;
|
|
txtPOCode.Text = "";
|
|
txtLotNo.Text = "";
|
|
grvdt.Clear();
|
|
grdDetail.DataSource = null;
|
|
gridControlCG.DataSource = null;
|
|
loglist.Clear();
|
|
polist.Clear();
|
|
}
|
|
}
|
|
|
|
private void btnWWSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
List<ICSLOTSIMULATION> infolist = new List<ICSLOTSIMULATION>();
|
|
if (SendType.Checked == true)
|
|
{
|
|
if (txtPOCode.Text == "" && txtLotNo.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < gridViewCG.RowCount; i++)
|
|
{
|
|
|
|
decimal PlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY));
|
|
decimal OutQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY));
|
|
decimal NowQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY));
|
|
if (PlanQTY < OutQTY + NowQTY)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("发料数量不能超出采购订单行数量!!");
|
|
return;
|
|
}
|
|
}
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
|
|
simulation.MUSER = AppConfig.UserCode;
|
|
simulation.LOTNO = grvDetail.GetRowCellValue(i, LOTNO).ToString();
|
|
simulation.OPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
|
|
simulation.EQPCODE = grvDetail.GetRowCellValue(i, EQPCode).ToString();
|
|
simulation.EATTRIBUTE1 = "COLLECT_BEGIN";
|
|
simulation.CHECKLOTNO = "WW";
|
|
|
|
infolist.Add(simulation);
|
|
}
|
|
if (infolist.Count <= 0) {
|
|
ICSBaseSimpleCode.AppshowMessageBox("请先输入产品跟踪单号!");
|
|
return;
|
|
}
|
|
|
|
string errormessage = ICSCollectBLL.SaveList(AppConfig.AppConnectString, infolist, polist, loglist);
|
|
if (errormessage != "")
|
|
{
|
|
MessageBox.Show(errormessage);
|
|
}
|
|
else
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("发料成功!!");
|
|
btnClear_Click(null, null);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (txtLotNo.Text == "")
|
|
{
|
|
return;
|
|
}
|
|
int count = 0;
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
if (count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行操作!!");
|
|
return;
|
|
}
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
|
|
{
|
|
bool opisallend = false;
|
|
string EndLotNo = grvDetail.GetRowCellValue(i, LOTNO).ToString();
|
|
#region 判断当前收料工序是否是最后一道工序
|
|
string chksql = @"select Top 1 OPCODE from ICSITEMROUTE2OPLot
|
|
where LotNo='{0}' AND WorkPoint='{1}'
|
|
order by OPSEQ DESC";
|
|
chksql = string.Format(chksql, EndLotNo, AppConfig.WorkPointCode);
|
|
DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
|
|
if (chkdt.Rows.Count != 0)
|
|
{
|
|
if (chkdt.Rows[0]["OPCODE"].ToString() == grvDetail.GetRowCellValue(i, OPCODE).ToString())
|
|
{
|
|
opisallend = true;
|
|
}
|
|
}
|
|
#endregion
|
|
ICSLOTSIMULATION simulation = new ICSLOTSIMULATION();
|
|
simulation.MUSER = AppConfig.UserCode;
|
|
simulation.LOTNO = grvDetail.GetRowCellValue(i, LOTNO).ToString();
|
|
simulation.OPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
|
|
simulation.EQPCODE = grvDetail.GetRowCellValue(i, EQPCode).ToString();
|
|
simulation.ITEMCODE = grvDetail.GetRowCellValue(i, INVCODE).ToString();
|
|
simulation.EATTRIBUTE1 = "COLLECT_END";
|
|
if (opisallend == true)
|
|
{
|
|
simulation.ISCOM = "1";
|
|
simulation.EndTime = DateTime.Now;
|
|
}
|
|
else
|
|
{
|
|
simulation.ISCOM = "";
|
|
simulation.EndTime = null;
|
|
}
|
|
infolist.Add(simulation);
|
|
}
|
|
}
|
|
ICSCollectBLL.SaveListEnd(AppConfig.AppConnectString, infolist);
|
|
ICSCollectBLL.CheckListEnd(AppConfig.AppConnectString, infolist);//验证该条码所有发料未收料的工序,进行收料处理,下道工序收料了,上面没有收料的都收料
|
|
StringBuilder errores =new StringBuilder("");
|
|
foreach (var Lot in infolist)
|
|
{
|
|
if (ICSAGVBLL.IsCanToAGV(Lot.LOTNO, Lot.OPCODE, "AGV是否开启", AppConfig.AppConnectString, AppConfig.WorkPointCode))
|
|
{
|
|
|
|
try
|
|
{
|
|
|
|
ICSAGVTASKLOG Log = new ICSAGVTASKLOG();
|
|
Log.ID = AppConfig.GetGuid();
|
|
Log.Lotno = Lot.LOTNO;
|
|
Log.Opcode = Lot.OPCODE;
|
|
bool Islastop = ICSAGVBLL.IsLastOP(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
|
|
bool NextOpIsWW = ICSAGVBLL.NextOPisWW(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
|
|
bool NextOpIsWG = ICSAGVBLL.NextOPisWG(Log.Lotno, Log.Opcode, AppConfig.AppConnectString, AppConfig.WorkPointCode);
|
|
string Area = ICSAGVBLL.GetAreaCode("00088", "8", AppConfig.AppConnectString, AppConfig.WorkPointCode);
|
|
Log.TaskType = "委外收料";
|
|
string BeginArea = Area.Split('@')[0].Split(':')[0];
|
|
string EndArea = Area.Split('@')[1].Split(':')[0];
|
|
AgvAreaToAreaModel Model = new AgvAreaToAreaModel();
|
|
Model.trackingNumber =Lot.LOTNO;
|
|
Model.area = EndArea;
|
|
Log.Area = BeginArea;
|
|
Log.EndArea = EndArea;
|
|
Log.Mtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
Log.MuserName = AppConfig.UserName;
|
|
ICSAGVBLL.AgvAreaToArea(Model, Log, AppConfig.AppConnectString, AppConfig.WorkPointCode);
|
|
}
|
|
|
|
catch (Exception ex)
|
|
{
|
|
errores.Append("AGV任务异常:" + ex.Message + "已跳过\r\n");
|
|
continue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ICSBaseSimpleCode.AppshowMessageBox("收料成功!!");
|
|
btnClear_Click(null, null);
|
|
}
|
|
}
|
|
|
|
private void txtPOCode_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
grvdt.Clear();
|
|
grdDetail.DataSource = null;
|
|
gridControlCG.DataSource = null;
|
|
loglist.Clear();
|
|
polist.Clear();
|
|
string POCode = txtPOCode.Text.Trim().ToString();
|
|
string sql = @"select ROW_NUMBER() OVER(ORDER BY A.ID) SEQ,
|
|
POCode AS POCODE,
|
|
PORow AS POROW,
|
|
A.InvCode AS ITEMCODE,
|
|
B.INVNAME AS ITEMNAME,
|
|
ISNULL(Quantity,0) AS QTY,
|
|
ISNULL(qty,0) AS SendQTY,
|
|
0 AS CurrentQTY,
|
|
Free1 AS PRID
|
|
from ICSPO_PoMain A
|
|
left join ICSINVENTORY B
|
|
ON B.INVCODE=A.InvCode
|
|
left join (select sum(TransQTY) as qty,TransNO,TransLine from ICSWareHouseLotInfoLog where TransType='发' and BusinessCode='委外发料' group by TransNO,TransLine)c
|
|
on c.TransNO=a.POCode and c.TransLine=a.PORow
|
|
where A.POCode='{0}'
|
|
AND A.WorkPoint='{1}'";
|
|
sql = string.Format(sql, POCode, AppConfig.WorkPointCode);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (dt.Rows.Count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("输入的采购条码不存在!!");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
gridControlCG.DataSource = dt;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void txtLotNo_KeyDown(object sender, KeyEventArgs e)
|
|
{
|
|
if (e.KeyCode == Keys.Enter)
|
|
{
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (txtLotNo.Text == grvDetail.GetRowCellValue(i, LOTNO).ToString())
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("扫描的产品产品跟踪单号已存在!!");
|
|
txtLotNo.SelectAll();
|
|
return;
|
|
}
|
|
}
|
|
if (SendType.Checked == true)
|
|
{
|
|
if (gridControlCG.DataSource == null)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("请先扫描采购订单号!!");
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
#region 20210125新增判断(判断条码上一道工序是否检验合格)
|
|
string chksql = @"select TOP 1 ID from ICSLOTONWIP
|
|
where LOTNO='{0}' and WorkPoint='{1}'
|
|
order by MTIME DESC";
|
|
chksql = string.Format(chksql, txtLotNo.Text.Trim(), AppConfig.WorkPointCode);
|
|
DataTable chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
|
|
if (chkdt.Rows.Count != 0)
|
|
{
|
|
string ONWIPID = chkdt.Rows[0]["ID"].ToString();
|
|
chksql = @"select Result,ISNULL(TResult,'') AS TResult from ICSLOTONWIPCheck
|
|
where ONWIPID='{0}' AND WorkPoint='{1}'";
|
|
chksql = string.Format(chksql, ONWIPID, AppConfig.WorkPointCode);
|
|
chkdt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, chksql).Tables[0];
|
|
if (chkdt.Rows.Count != 0)
|
|
{
|
|
if (chkdt.Rows[0]["Result"].ToString() == "不合格"
|
|
&& (chkdt.Rows[0]["TResult"].ToString() == "" || chkdt.Rows[0]["TResult"].ToString() == "报废"))
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("跟踪单:" + txtLotNo.Text.Trim() + ",上道工序不合格且不是让步或返工状态,不能开始该工序!\n\r");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region 20200820新增防呆
|
|
//20210709卡控拿掉
|
|
// string sql = @"select ISNULL(EATTRIBUTE6,'') AS EATTRIBUTE6 from ICSITEMLot
|
|
// where LotNO='{0}' AND WorkPoint='{1}'";
|
|
// sql = string.Format(sql, txtLotNo.Text.Trim(), AppConfig.WorkPointCode);
|
|
// DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
// if (dt.Rows.Count == 0)
|
|
// {
|
|
// ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号不存在!!");
|
|
// return;
|
|
// }
|
|
//else
|
|
//{
|
|
// if (dt.Rows[0]["EATTRIBUTE6"].ToString() == "")
|
|
// {
|
|
// ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未绑定零件号,请先绑定再发料!!");
|
|
// return;
|
|
// }
|
|
//}
|
|
#endregion
|
|
//右侧跟踪单详情显示的方法
|
|
GetSendGrvDT("LOTNO");
|
|
//左侧采购订单本次数量计算的方法
|
|
GetSendQTY(txtLotNo.Text.Trim().ToString());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
GetReceiveDT("LOTNO");
|
|
}
|
|
txtLotNo.SelectAll();
|
|
}
|
|
}
|
|
|
|
public void GetSendQTY(string PRLotNo)
|
|
{
|
|
string PRINVCODE = "";
|
|
string PROPCODE = "";
|
|
decimal PRLOTQTY = 0;
|
|
string PRLotOP = "";
|
|
string LotPRID = "";
|
|
decimal TotalSendQTY = 0;
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (PRLotNo == grvDetail.GetRowCellValue(i, LOTNO).ToString())
|
|
{
|
|
PRINVCODE = grvDetail.GetRowCellValue(i, INVCODE).ToString();
|
|
PROPCODE = grvDetail.GetRowCellValue(i, OPCODE).ToString();
|
|
PRLOTQTY = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY).ToString());
|
|
PRLotOP = grvDetail.GetRowCellValue(i, OPCODE).ToString();
|
|
LotPRID = grvDetail.GetRowCellValue(i, LOTPRID).ToString();
|
|
}
|
|
}
|
|
for (int i = 0; i < gridViewCG.RowCount; i++)
|
|
{
|
|
string PRITEMCode = gridViewCG.GetRowCellValue(i, ITEMCODE).ToString();
|
|
decimal PRPlanQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, QTY).ToString());
|
|
decimal PRSendQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, SendQTY).ToString());
|
|
decimal PRCurrentQTY = Convert.ToDecimal(gridViewCG.GetRowCellValue(i, CurrentQTY).ToString());
|
|
string PRCODE = gridViewCG.GetRowCellValue(i, POCODE).ToString();
|
|
string PRROW = gridViewCG.GetRowCellValue(i, POROW).ToString();
|
|
string POPRID = gridViewCG.GetRowCellValue(i, PRID).ToString();
|
|
if (PRITEMCode == PRINVCODE + "_" + PROPCODE && PRLOTQTY != 0 && PRPlanQTY - PRSendQTY - PRCurrentQTY != 0
|
|
&& LotPRID == POPRID)
|
|
{
|
|
#region 获取连续委外的后续工序
|
|
DataTable dt = GetNextWWInfo(PRLotNo, PRLotOP);
|
|
#endregion
|
|
if (PRPlanQTY - PRSendQTY - PRCurrentQTY >= PRLOTQTY)
|
|
{
|
|
grvDetail.SetRowCellValue(i, LotPOCode, PRCODE);
|
|
grvDetail.SetRowCellValue(i, LotPORow, PRROW);
|
|
gridViewCG.SetRowCellValue(i, CurrentQTY, PRLOTQTY + PRCurrentQTY);
|
|
ICSPO_PoMain poinfo = new ICSPO_PoMain();
|
|
poinfo.POCode = PRCODE;
|
|
poinfo.PORow = PRROW;
|
|
poinfo.INQty = PRLOTQTY;
|
|
polist.Add(poinfo);
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
if (dr["ISWW"].ToString() == "1")
|
|
{
|
|
bool lotisexsist = false;
|
|
for (int k = 0; k < gridViewCG.RowCount; k++)
|
|
{
|
|
if (gridViewCG.GetRowCellValue(k, ITEMCODE).ToString() ==
|
|
dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString())
|
|
{
|
|
lotisexsist = true;
|
|
}
|
|
}
|
|
|
|
if (lotisexsist == true)
|
|
{
|
|
ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
|
|
loginfo.ID = AppConfig.GetGuid();
|
|
loginfo.TransNO = PRCODE;
|
|
loginfo.TransLine = dr["PORow"].ToString();
|
|
loginfo.ITEMCODE = dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString();
|
|
loginfo.LotNO = PRLotNo;
|
|
loginfo.TransQTY = PRLOTQTY;
|
|
loginfo.TransType = "发";
|
|
loginfo.BusinessCode = "委外发料";
|
|
loginfo.Memo = dr["OPCODE"].ToString();
|
|
loginfo.MUSER = AppConfig.UserCode;
|
|
loginfo.MUSERName = AppConfig.UserName;
|
|
loginfo.MTIME = DateTime.Now;
|
|
loginfo.WorkPoint = AppConfig.WorkPointCode;
|
|
if (loginfo.TransLine == "")
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未关联到对应采购订单行,请联系开发人员!!");
|
|
btnClear_Click(null, null);
|
|
return;
|
|
}
|
|
loglist.Add(loginfo);
|
|
}
|
|
}
|
|
if (dr["NISWW"].ToString() == "0")
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
PRLOTQTY = 0;
|
|
}
|
|
else
|
|
{
|
|
grvDetail.SetRowCellValue(i, LotPOCode, PRCODE);
|
|
grvDetail.SetRowCellValue(i, LotPORow, PRROW);
|
|
gridViewCG.SetRowCellValue(i, CurrentQTY, PRPlanQTY - PRSendQTY - PRCurrentQTY);
|
|
ICSPO_PoMain poinfo = new ICSPO_PoMain();
|
|
poinfo.POCode = PRCODE;
|
|
poinfo.PORow = PRROW;
|
|
poinfo.INQty = PRPlanQTY - PRSendQTY - PRCurrentQTY;
|
|
polist.Add(poinfo);
|
|
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
if (dr["ISWW"].ToString() == "1")
|
|
{
|
|
bool lotisexsist = false;
|
|
for (int k = 0; k < gridViewCG.RowCount; k++)
|
|
{
|
|
if (gridViewCG.GetRowCellValue(k, ITEMCODE).ToString() ==
|
|
dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString())
|
|
{
|
|
lotisexsist = true;
|
|
}
|
|
}
|
|
if (lotisexsist == true)
|
|
{
|
|
ICSWareHouseLotInfoLog loginfo = new ICSWareHouseLotInfoLog();
|
|
loginfo.ID = AppConfig.GetGuid();
|
|
loginfo.TransNO = PRCODE;
|
|
loginfo.TransLine = dr["PORow"].ToString();
|
|
loginfo.ITEMCODE = dr["ITEMCODE"].ToString() + "_" + dr["OPCODE"].ToString(); ;
|
|
loginfo.LotNO = PRLotNo;
|
|
loginfo.TransQTY = PRPlanQTY - PRSendQTY - PRCurrentQTY;
|
|
loginfo.TransType = "发";
|
|
loginfo.BusinessCode = "委外发料";
|
|
loginfo.Memo = dr["OPCODE"].ToString();
|
|
loginfo.MUSER = AppConfig.UserCode;
|
|
loginfo.MUSERName = AppConfig.UserName;
|
|
loginfo.MTIME = DateTime.Now;
|
|
loginfo.WorkPoint = AppConfig.WorkPointCode;
|
|
if (loginfo.TransLine == "")
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("产品跟踪单号未关联到对应采购订单行,请联系开发人员!!");
|
|
btnClear_Click(null, null);
|
|
return;
|
|
}
|
|
loglist.Add(loginfo);
|
|
}
|
|
}
|
|
if (dr["NISWW"].ToString() == "0")
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
PRLOTQTY = PRLOTQTY - (PRPlanQTY - PRSendQTY - PRCurrentQTY);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnDelete_Click(object sender, EventArgs e)
|
|
{
|
|
int count = 0;
|
|
for (int i = 0; i < grvDetail.RowCount; i++)
|
|
{
|
|
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
if (count == 0)
|
|
{
|
|
ICSBaseSimpleCode.AppshowMessageBox("请至少选择一条数据进行删除!!");
|
|
return;
|
|
}
|
|
for (int i = grvDetail.RowCount - 1; i >= 0; i--)
|
|
{
|
|
if (grvDetail.GetRowCellValue(i, colisSelect).ToString() == "Y")
|
|
{
|
|
string pocode = grvDetail.GetRowCellValue(i, LotPOCode).ToString();
|
|
string porow = grvDetail.GetRowCellValue(i, LotPORow).ToString();
|
|
decimal poqty = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY));
|
|
string lotno = grvDetail.GetRowCellValue(i, LOTNO).ToString();
|
|
#region 左侧采购订单列表中的本次数量扣减
|
|
for (int j = 0; j < gridViewCG.RowCount; j++)
|
|
{
|
|
if (gridViewCG.GetRowCellValue(j, POCODE).ToString() == pocode
|
|
&& gridViewCG.GetRowCellValue(j, POROW).ToString() == porow && poqty > 0)
|
|
{
|
|
if (poqty >= Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY)))
|
|
{
|
|
poqty = poqty - Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY));
|
|
gridViewCG.SetRowCellValue(j, CurrentQTY, 0);
|
|
}
|
|
else
|
|
{
|
|
gridViewCG.SetRowCellValue(j, CurrentQTY, Convert.ToDecimal(gridViewCG.GetRowCellValue(j, CurrentQTY)) - poqty);
|
|
poqty = 0;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region PO_PoMain实体对象中的本次数量扣减
|
|
poqty = Convert.ToDecimal(grvDetail.GetRowCellValue(i, LOTQTY));
|
|
foreach (ICSPO_PoMain info in polist)
|
|
{
|
|
if (info.POCode == pocode && info.PORow == porow && poqty > 0)
|
|
{
|
|
if (poqty > info.INQty)
|
|
{
|
|
poqty = poqty - Convert.ToDecimal(info.INQty);
|
|
info.INQty = 0;
|
|
}
|
|
else
|
|
{
|
|
info.INQty = Convert.ToDecimal(info.INQty) - poqty;
|
|
poqty = 0;
|
|
}
|
|
}
|
|
}
|
|
#endregion
|
|
#region ICSWareHouseInfoLog实体对象中的对象删除
|
|
foreach (ICSWareHouseLotInfoLog info in loglist)
|
|
{
|
|
if (lotno == info.LotNO)
|
|
{
|
|
loglist.Remove(info);
|
|
}
|
|
}
|
|
#endregion
|
|
grvDetail.DeleteRow(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
//获取连续委外后续工序的信息
|
|
private DataTable GetNextWWInfo(string LotNO, string OPCode)
|
|
{
|
|
string sql = @"SELECT e.POCode,e.PORow,
|
|
a.LotNo AS LOTNO
|
|
,a.ITEMCODE
|
|
,a.OPSEQ AS OPSEQ
|
|
,a.OPCODE AS OPCODE
|
|
,c.EATTRIBUTE1 AS ISWW
|
|
,b.OPSEQ AS NOPSEQ
|
|
,b.OPCODE AS NOPCODE
|
|
,d.EATTRIBUTE1 AS NISWW
|
|
FROM ICSITEMROUTE2OPLot a
|
|
LEFT JOIN ICSITEMROUTE2OPLot b ON a.LotNo=b.LotNo AND b.OPSEQ=(SELECT MIN(OPSEQ) FROM ICSITEMROUTE2OPLot WHERE LotNo=a.LotNo AND OPSEQ>a.OPSEQ)
|
|
LEFT JOIN ICSMO2User c ON a.LotNo=c.LOTNO AND a.OPCODE=c.OPCODE
|
|
LEFT JOIN ICSMO2User d ON b.LotNo=d.LOTNO AND b.OPCODE=d.OPCODE
|
|
inner JOIN ICSPO_PoMain e ON e.InvCode=a.ITEMCODE+'_'+a.OPCODE AND e.POCode='{2}' AND e.Free1=c.PRLineID AND Quantity!=ISNULL(INQty,0)
|
|
WHERE c.LotNo = '{0}'
|
|
AND a.OPSEQ>=(select OPSEQ from ICSITEMROUTE2OPLot
|
|
where ROUTECODE=(
|
|
select TOP 1 RouteCode from ICSMO2User
|
|
where LOTNO='{0}')
|
|
AND OPCODE='{1}' AND LOTNO='{0}')
|
|
ORDER BY a.LotNo,a.OPSEQ";
|
|
|
|
sql = string.Format(sql, LotNO, OPCode, txtPOCode.Text.ToString());
|
|
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
dt.AcceptChanges();
|
|
string NextOpseq = "";
|
|
//排除不是连续的工序
|
|
for (int i = 0; i < dt.Rows.Count; i++)
|
|
{
|
|
if (NextOpseq != dt.Rows[i]["OPSEQ"].ToString() && NextOpseq != "") {
|
|
dt.Rows[i].Delete();
|
|
//删除剩余所有不连续的工序
|
|
if (i < dt.Rows.Count - 1) {
|
|
for (int j = i + 1; j <= dt.Rows.Count - 1; j++) {
|
|
dt.Rows[j].Delete();
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
sql = "select top 1 opseq from ICSITEMROUTE2OPLot where lotno='" + LotNO + "' and opseq>"+dt.Rows[i]["OPSEQ"].ToString()+" order by opseq";
|
|
DataTable optable = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
if (optable.Rows.Count > 0) {
|
|
NextOpseq=optable.Rows[0]["opseq"].ToString();
|
|
}
|
|
|
|
}
|
|
dt.AcceptChanges();
|
|
|
|
|
|
|
|
return dt;
|
|
}
|
|
|
|
|
|
}
|
|
}
|