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.
579 lines
21 KiB
579 lines
21 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using System.Data.Linq;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
|
|
public class ICSMO2LotDAL
|
|
{
|
|
|
|
|
|
|
|
#region 增加修改
|
|
|
|
public static void AddAndEdit(List<FormICSMO2LotUIModel> equipmentInfoList, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSMO2LotUIModel equipmentInfo in equipmentInfoList)
|
|
{
|
|
|
|
bool isNew = false;
|
|
var line = db.ICSITEMLot.SingleOrDefault(a =>a.LotNO==equipmentInfo.LotNO);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSITEMLot();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.LotNO = equipmentInfo.LotNO;
|
|
|
|
}
|
|
//9.4
|
|
|
|
line.MOPLANENDDATE = equipmentInfo.MOPLANENDDATE;
|
|
line.MOPLANSTARTDATE = equipmentInfo.MOPLANSTARTDATE;
|
|
|
|
line.MCODE = equipmentInfo.MCODE;
|
|
line.TransNO = equipmentInfo.TransNO;
|
|
line.TransLine = equipmentInfo.TransLine;
|
|
line.VENDORITEMCODE = equipmentInfo.VENDORITEMCODE;
|
|
line.VENDORCODE = equipmentInfo.VENDORCODE;
|
|
line.VenderLotNO = equipmentInfo.VenderLotNO;
|
|
line.PRODUCTDATE = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss"); ;
|
|
line.LOTQTY = equipmentInfo.LOTQTY;
|
|
line.ACTIVE = "Y";//传入固定值
|
|
line.Exdate = Convert.ToDateTime("2999-12-31 00:00:00.000");//传入固定值
|
|
line.WorkPoint = "6000";//传入固定值
|
|
line.MUSER = equipmentInfo.MUSER;
|
|
line.MUSERName = equipmentInfo.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
|
|
line.TYPE = equipmentInfo.TYPE;
|
|
line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
|
|
line.PrintTimes = equipmentInfo.PrintTimes;
|
|
line.lastPrintUSERID = equipmentInfo.lastPrintUSERID;
|
|
line.lastPrintTime = equipmentInfo.lastPrintTime;
|
|
line.VoucherNO = equipmentInfo.VoucherNO;
|
|
line.VoucherRow = equipmentInfo.VoucherRow;
|
|
|
|
line.EATTRIBUTE3 = equipmentInfo.EATTRIBUTE3;
|
|
line.EATTRIBUTE6 = equipmentInfo.EATTRIBUTE6;
|
|
line.EATTRIBUTE7 = equipmentInfo.EATTRIBUTE7;
|
|
|
|
// line.EATTRIBUTE2 = "已分批";
|
|
#region 修改ICSMO表EATTRIBUTE2栏位将该行工单标记为已分批
|
|
|
|
var lines = db.ICSMO.SingleOrDefault(a => a.MOCODE == line.TransNO && a.MOSEQ == line.TransLine);
|
|
if (lines != null)
|
|
{
|
|
lines.EATTRIBUTE2 = "已分批";
|
|
//db.SubmitChanges();
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
if (isNew)
|
|
db.ICSITEMLot.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
|
|
|
|
}
|
|
//foreach (WM_BarCode barcode in barcodeList)
|
|
//{
|
|
// WM_BarCode line1 = new WM_BarCode();
|
|
// line1.guid = barcode.guid;
|
|
// line1.SrcType = barcode.SrcType;
|
|
// line1.Srcguid = barcode.Srcguid;
|
|
// line1.RCVShipguid = barcode.RCVShipguid;
|
|
// line1.BarCodeNo = barcode.BarCodeNo;
|
|
// line1.BarCodeQty = barcode.BarCodeQty;
|
|
// line1.ItemGuid = barcode.ItemGuid;
|
|
// line1.ItemCode = barcode.ItemCode;
|
|
// line1.ItemName = barcode.ItemName;
|
|
// line1.MUSERCode = barcode.MUSERCode;
|
|
// line1.MUSERName = barcode.MUSERName;
|
|
// line1.MTIME = Convert.ToDateTime(barcode.MTIME);
|
|
// line1.WorkPointCode = barcode.WorkPointCode;
|
|
// line1.BarCodeStatus = barcode.BarCodeStatus;
|
|
|
|
|
|
// //db.WM_BarCode.InsertOnSubmit(line1);
|
|
// db.SubmitChanges();
|
|
|
|
|
|
//}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
public static void AddAndEditList(List<ICSITEMROUTE2OPLot> equipmentInfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (ICSITEMROUTE2OPLot equipmentInfo in equipmentInfoList)
|
|
{
|
|
var op = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPCODE == equipmentInfo.OPCODE && a.ID != equipmentInfo.ID);
|
|
if (op!=null)
|
|
{
|
|
throw new Exception("工序代码:" + equipmentInfo.OPCODE + "已存在!");
|
|
}
|
|
var seq = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.LotNo == equipmentInfo.LotNo && a.OPSEQ == equipmentInfo.OPSEQ && a.ID != equipmentInfo.ID);
|
|
if (seq != null)
|
|
{
|
|
throw new Exception("工序次序:" + equipmentInfo.OPSEQ + "已存在!");
|
|
}
|
|
|
|
bool isNew = false;
|
|
//var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.OPCODE == equipmentInfo.OPCODE && a.OPSEQ == equipmentInfo.OPSEQ && a.ROUTECODE == equipmentInfo.ROUTECODE && a.LotNo == equipmentInfo.LotNo);
|
|
var line = db.ICSITEMROUTE2OPLot.SingleOrDefault(a => a.ID == equipmentInfo.ID);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSITEMROUTE2OPLot();
|
|
line.ID = AppConfig.GetGuid();
|
|
//line.LotNo = equipmentInfo.LotNo;
|
|
line.OPCONTROL = equipmentInfo.OPCONTROL;
|
|
line.OPTIONALOP = equipmentInfo.OPTIONALOP;
|
|
line.IDMERGETYPE = equipmentInfo.IDMERGETYPE;
|
|
}
|
|
|
|
line.ROUTECODE = equipmentInfo.ROUTECODE;
|
|
line.OPSEQ = equipmentInfo.OPSEQ;
|
|
line.OPCODE = equipmentInfo.OPCODE;
|
|
line.LotNo = equipmentInfo.LotNo;
|
|
line.IDMERGERULE = equipmentInfo.IDMERGERULE;
|
|
line.ITEMCODE = equipmentInfo.ITEMCODE;
|
|
line.WorkPoint = equipmentInfo.WorkPoint;//传入固定值
|
|
line.MUSER = equipmentInfo.MUSER;
|
|
line.MUSERName = equipmentInfo.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
|
|
line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
|
|
|
|
|
|
|
|
|
|
if (isNew)
|
|
db.ICSITEMROUTE2OPLot.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region delete
|
|
public static void delete(List<String> guidList)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
|
|
var tempLines = db.ICSMO2User.Where(a => guidList.Contains(a.LOTNO));
|
|
if (tempLines != null && tempLines.ToList().Count > 0)
|
|
{
|
|
throw new Exception("工单已有派工信息,无法删除!");
|
|
}
|
|
|
|
var lines = db.ICSITEMLot.Where(a => guidList.Contains(a.LotNO));
|
|
db.ICSITEMLot.DeleteAllOnSubmit(lines);
|
|
|
|
//删除 ICSITEMROUT2OPLot表中数据删除20190717ZM
|
|
var _lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
|
|
db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(_lines);
|
|
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
//删除ICSITEMROUTE2OPLot表中数据ZM
|
|
public static void deleteLot(List<String> guidList)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
//var tempLines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.LotNo));
|
|
//if (tempLines != null && tempLines.ToList().Count > 0)
|
|
//{
|
|
// throw new Exception("工单已有派工信息,无法删除!");
|
|
//}
|
|
|
|
var lines = db.ICSITEMROUTE2OPLot.Where(a => guidList.Contains(a.ID));
|
|
|
|
db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
//删除ICSITEMROUTE2OPLot表中数据ZM
|
|
public static void deleteLot(List<ICSITEMROUTE2OPLot> guidList)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (var item in guidList)
|
|
{
|
|
var users = db.ICSMO2User.Where(a => a.LOTNO == item.LotNo && a.OPCODE == item.OPCODE);
|
|
db.ICSMO2User.DeleteAllOnSubmit(users);
|
|
|
|
var lines = db.ICSITEMROUTE2OPLot.Where(a => a.LotNo==item.LotNo && a.OPCODE==item.OPCODE);
|
|
db.ICSITEMROUTE2OPLot.DeleteAllOnSubmit(lines);
|
|
}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
#region 工单是否已生成批次
|
|
public static bool IsIncludingInMO2Lot(string moid)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
//var line = db.ICSITEMLot.Where(a => a.ID == moid);
|
|
var line = from a in db.ICSITEMLot
|
|
join b in db.ICSMO on new { MOCODE = a.TransNO, MOSEQ=a.TransLine } equals new { b.MOCODE, b.MOSEQ }
|
|
where b.ID==moid
|
|
select a;
|
|
if (line.ToList().Count > 0)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
public static DataTable searchForItem(string itemcode, string dsconn)
|
|
{
|
|
|
|
string sql = @"select guid,ItemName
|
|
from Base_Inventory
|
|
where ItemCode='{0}'";
|
|
sql = string.Format(sql, itemcode);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
|
|
return dt;
|
|
|
|
}
|
|
|
|
public static DataTable SelectShiftTypeCode()
|
|
{
|
|
string sql = @"select SHIFTTYPECODE as [班制代码]
|
|
from dbo.ICSSHIFTTYPE
|
|
where 1=1";
|
|
sql = string.Format(sql);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
return dt;
|
|
}
|
|
|
|
public static DataTable SelectShiftTypeId(string str)
|
|
{
|
|
string sql = @"select ID
|
|
from dbo.ICSSHIFTTYPE
|
|
where SHIFTTYPECODE='" + str + "'";
|
|
sql = string.Format(sql);
|
|
DataTable dt = DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
return dt;
|
|
}
|
|
|
|
|
|
#region delete
|
|
public static void delete(string moid)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.ICSITEMLot.Where(a => a.ID == moid);
|
|
db.ICSITEMLot.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
public static DataTable GetShiftCode()
|
|
{
|
|
try
|
|
{
|
|
string sql = @"select TOP 1 [SHIFTCODE]
|
|
FROM [dbo].[ICSSHIFT] order by SHIFTCODE desc";
|
|
return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
public static DataTable GetShiftSeqCode()
|
|
{
|
|
try
|
|
{
|
|
string sql = @"select TOP 1 [SHIFTSEQ]
|
|
FROM [dbo].[ICSSHIFT] order by [SHIFTTYPEID] desc";
|
|
return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 工单是否已生成批次
|
|
public static DataTable IsUsingMO(string MOCode, string MOSEQ)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
string sql = @"SELECT COUNT(*) FROM ICSMOPickLog
|
|
WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "'";
|
|
return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 工单是否已生下发
|
|
public static DataTable IsSendMO(string MOCode, string MOSEQ)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
string sql = @"SELECT MOSTATUS FROM ICSMO
|
|
WHERE MOCODE='" + MOCode + "' AND MOSEQ='" + MOSEQ + "'";
|
|
return DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 一键分批 8.19
|
|
public static void OP2LotAddAndEdit(List<ICSITEMLot> lotinfolist, List<ICSITEMROUTE2OPLot> oplotinfolist, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
#region 新增ICSITEMLot表
|
|
foreach (ICSITEMLot info in lotinfolist)
|
|
{
|
|
bool isNew = false;
|
|
var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSITEMLot();
|
|
line.ID = info.ID;
|
|
line.LotNO = info.LotNO;
|
|
}
|
|
// line.ItemCODE = info.ItemCODE;
|
|
|
|
line.MCODE = info.MCODE;
|
|
//line.MCODE = "";
|
|
line.TransNO = info.TransNO;
|
|
line.TransLine = info.TransLine;
|
|
line.VENDORITEMCODE = info.VENDORITEMCODE;
|
|
line.VENDORCODE = info.VENDORCODE;
|
|
line.VenderLotNO = info.VenderLotNO;
|
|
line.PRODUCTDATE = info.PRODUCTDATE;
|
|
line.LOTQTY = info.LOTQTY;
|
|
line.ACTIVE = info.ACTIVE;//传入固定值
|
|
line.Exdate = info.Exdate;//传入固定值
|
|
line.WorkPoint = info.WorkPoint;
|
|
line.MUSER = info.MUSER;
|
|
line.MUSERName = info.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(info.MTIME);
|
|
line.TYPE = info.TYPE;
|
|
line.EATTRIBUTE1 = info.EATTRIBUTE1;
|
|
line.MOPLANSTARTDATE = info.MOPLANSTARTDATE;
|
|
line.MOPLANENDDATE = info.MOPLANENDDATE;
|
|
if (isNew)
|
|
db.ICSITEMLot.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
#endregion
|
|
|
|
#region 新增ICSItemRoute2OPLot表
|
|
foreach (ICSITEMROUTE2OPLot info in oplotinfolist)
|
|
{
|
|
var line = new ICSITEMROUTE2OPLot();
|
|
line.ID = info.ID;
|
|
line.LotNo = info.LotNo;
|
|
line.ITEMCODE = info.ITEMCODE;
|
|
line.ROUTECODE = info.ROUTECODE;
|
|
line.OPCODE = info.OPCODE;
|
|
line.OPSEQ = info.OPSEQ;
|
|
line.OPCONTROL = info.OPCONTROL;
|
|
line.OPTIONALOP = info.OPTIONALOP;
|
|
line.IDMERGERULE = info.IDMERGERULE;
|
|
line.IDMERGETYPE = info.IDMERGETYPE;
|
|
line.WorkPoint = info.WorkPoint;
|
|
line.MUSER = info.MUSER;
|
|
line.MUSERName = info.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(info.MTIME);
|
|
line.EATTRIBUTE1 = info.EATTRIBUTE1;
|
|
db.ICSITEMROUTE2OPLot.InsertOnSubmit(line);
|
|
}
|
|
#endregion
|
|
|
|
#region 修改ICSMO表EATTRIBUTE2栏位将该行工单标记为已分批
|
|
foreach (ICSITEMLot info in lotinfolist)
|
|
{
|
|
var line = db.ICSMO.SingleOrDefault(a => a.MOCODE == info.TransNO && a.MOSEQ == info.TransLine);
|
|
if (line != null)
|
|
{
|
|
line.EATTRIBUTE2 = "已分批";
|
|
db.SubmitChanges();
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public static bool IsPG(string mocode,string moseq) {
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
ICSMO2User user = db.ICSMO2User.Where(a => a.MOCODE == mocode&&a.MOSEQ==Convert.ToInt32(moseq)).FirstOrDefault();
|
|
if (user!=null) {
|
|
return true;
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
public static bool IsKG(string mocode,string moseq)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
ICSLOTSIMULATION user = db.ICSLOTSIMULATION.Where(a => a.MOCODE == mocode&& a.MOSEQ == Convert.ToInt32(moseq)).FirstOrDefault();
|
|
if (user != null)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
|