锐腾搅拌上料功能
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.

355 lines
15 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSSoft.Frame.Data.Entity;
using ICSSoft.Base.Config.DBHelper;
using System.Data;
using System.Data.SqlClient;
using ICSSoft.Base.Config.AppConfig;
namespace ICSSoft.Frame.Data.DAL
{
public class FormICSPurchaseLOTDAL
{
#region 新增和修改
public static void Add(List<ICSITEMLot> InfoList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (ICSITEMLot info in InfoList)
{
bool isNew = false;
var line = db.ICSITEMLot.SingleOrDefault(a => a.ID == info.ID && a.WorkPoint == AppConfig.WorkPointCode);
if (line == null)
{
isNew = true;
line = new ICSITEMLot();
line.ID = AppConfig.GetGuid();
}
line.LotNO = info.LotNO;
line.ItemCode = info.ItemCode;
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.TYPE = "到货";
line.EATTRIBUTE1 = info.EATTRIBUTE1;
line.MUSER = AppConfig.UserCode;
line.MUSERName = AppConfig.UserName;
line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss");
line.WorkPoint = AppConfig.WorkPointCode;
if (isNew)
{
db.ICSITEMLot.InsertOnSubmit(line);
}
db.SubmitChanges();
}
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
#region 更新打印信息
public static void updatePrint(List<ICSITEMLot> InfoList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (ICSITEMLot info in InfoList)
{
var line = db.ICSITEMLot.SingleOrDefault(a => a.LotNO == info.LotNO && a.WorkPoint == AppConfig.WorkPointCode);
if (line == null)
{
continue;
}
if (line.PrintTimes == null)
line.PrintTimes = 1;
else
line.PrintTimes ++;
line.lastPrintUSERID = info.lastPrintUSERID;
line.lastPrintTime = info.lastPrintTime;
db.SubmitChanges();
}
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
#region 通过代码、行号查询
public static FormICSRdrecord2LOTUIModel SearchInfo(string CODE, string RowNo, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
#region
try
{
FormICSRdrecord2LOTUIModel info = new FormICSRdrecord2LOTUIModel();
info.rdrecord = db.ICSINVReceiptDetail.SingleOrDefault(a => a.ReceiptNO == CODE && a.ReceiptLine == Convert.ToInt32(RowNo) && a.WorkPoint == AppConfig.WorkPointCode);
if(info.rdrecord!=null)
info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.rdrecord.ITEMCODE && a.WorkPoint == AppConfig.WorkPointCode);
var infos = db.ICSITEMLot.Where(a => a.TransNO == CODE && a.TransLine == RowNo && a.WorkPoint == AppConfig.WorkPointCode);
info.SumQty = Convert.ToDecimal(infos.AsEnumerable().Sum(a => a.LOTQTY));
info.SumNo = infos.Count();
var infoMaxs = db.ICSITEMLot.Where(a => a.LotNO.Contains(info.rdrecord.MOCODE + info.rdrecord.MOSEQ) && a.WorkPoint == AppConfig.WorkPointCode);
if (infoMaxs.Count() == 0)
info.MaxNo = 0;
else
{
string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
info.MaxNo =Convert.ToInt32(lotno.Substring(lotno.Length - 5));
}
if (infos != null && infos.Count() > 0)
{
var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
if (VenderLotNO != null && VenderLotNO.Count()>0)
{
info.VenderLotNO = VenderLotNO.ToList()[0];
return info;
}
}
var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
info.TodayMOCount = infoTodays.Distinct().Count();
return info;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
public static FormICSPurchaseLOTUIModelX Search_Info(string CODE, string RowNo, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
#region
try
{
string Row_NO = RowNo.ToString();
FormICSPurchaseLOTUIModelX info = new FormICSPurchaseLOTUIModelX();
info.pomain = db.ICSPO_PoMain.SingleOrDefault(a => a.POCode == CODE && a.PORow == Row_NO && a.WorkPoint == AppConfig.WorkPointCode);
if (info.pomain != null)
info.inventory = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.pomain.InvCode && a.WorkPoint == AppConfig.WorkPointCode);
info.icsitems = db.ICSITEMLot.Where(a => a.ItemCode == info.pomain.InvCode && a.WorkPoint == AppConfig.WorkPointCode && a.TransNO == info.pomain.POCode && a.TransLine == info.pomain.PORow).FirstOrDefault();
var infos = db.ICSITEMLot.Where(a => a.ItemCode == info.pomain.InvCode && a.WorkPoint == AppConfig.WorkPointCode);
info.SumQty = Convert.ToDecimal(info.pomain.Quantity);
//info.SumNo = infos.Count();
try
{
string sql = @"SELECT count(B.ItemCode) as num, b.ItemCode, B.LOTQTY FROM ICSPO_PoMain M
LEFT JOIN ICSITEMLot B ON M.InvCode = B.ItemCode AND M.WorkPoint=B.WorkPoint AND M.POCode = B.TransNO AND CONVERT(int, M.PORow) = B.TransLine
LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
WHERE M.POCode = '{0}'
AND M.PORow = '{1}'
AND M.WorkPoint = '{2}' AND B.ItemCode = '{3}'
group by b.ItemCode, B.LOTQTY
";
sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode, info.pomain.InvCode);
DataTable ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
if (ds.Rows.Count == 0 || ds == null)
{
info.SumNo = 0;
}
else
{
info.SumNo = 0;
for (int i = 0; i < ds.Rows.Count; i++)
{
info.SumNo += Int32.Parse(ds.Rows[i]["num"].ToString());
}
}
}
catch (Exception ex)
{
throw ex;
}
var infoMaxs = db.ICSITEMLot.Where(a => a.TransNO == info.pomain.POCode && a.TransLine == info.pomain.PORow && a.WorkPoint == AppConfig.WorkPointCode);
if (infoMaxs.Count() == 0)
info.MaxNo = 0;
else
{
string lotno = infoMaxs.OrderByDescending(a => a.LotNO).FirstOrDefault().LotNO;
info.MaxNo = Convert.ToInt32(lotno.Substring(lotno.Length - 5));
}
if (infos != null && infos.Count() > 0)
{
var VenderLotNO = infos.Where(a => a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.VenderLotNO).Distinct();
if (VenderLotNO != null && VenderLotNO.Count() > 0)
{
info.VenderLotNO = VenderLotNO.ToList()[0];
return info;
}
}
var infoTodays = db.ICSITEMLot.Where(a => a.WorkPoint == AppConfig.WorkPointCode && a.PRODUCTDATE == AppConfig.GetSeverDateTime("yyyy-MM-dd")).Select(a => a.TransNO);
info.TodayMOCount = infoTodays.Distinct().Count();
return info;
}
catch (Exception ex)
{
throw ex;
}
#endregion
}
#endregion
#region 通过主表行和子表
#region 原逻辑
//public static DataSet SearchData(string CODE, int RowNo, string dsconn)
//{
// try
// {
// string sql = @"SELECT
// a.ReceiptNO,
// a.ReceiptLine,
// a.RECSTATUS,
// a.TYPE,
// a.InvCode,
// a.PLANQTY,
// b.INVNAME,
// b.INVSTD
// FROM
// ICSINVReceiptDetail a
// LEFT JOIN ICSINVENTORY b ON a.InvCode=b.INVCODE
// WHERE
// a.ReceiptNO='{0}'
// AND ReceiptLine='{1}'
// AND a.WorkPoint = '{2}'
// AND b.WorkPoint = '{2}'
// ";
// sql += @"SELECT
// CASE WHEN c.LotNO IS NULL THEN 'Y' ELSE '' END AS isSelect,
// a.ID,
// b.POCode,
// b.PORow,
// a.TransNO,
// a.TransLine,
// a.LOTNO,
// CAST(CASE WHEN c.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
// a.LOTQTY,
// a.VenderLotNO,
// a.PRODUCTDATE,
// a.MUSERName
// FROM
// ICSITEMLot a
// LEFT JOIN ICSINVReceiptDetail b ON a.TransNO=b.ReceiptNO AND a.TransLine=b.ReceiptLine AND a.WorkPoint=b.WorkPoint
// LEFT JOIN ICSWareHouseLotInfo c ON a.LOTNO=c.LotNO AND a.WorkPoint=c.WorkPoint
// WHERE
// a.TransNO = '{0}'
// AND a.TransLine = '{1}'
// AND a.WorkPoint = '{2}'
// ORDER BY
// a.LOTNO
// ";
// sql = string.Format(sql,CODE,RowNo,AppConfig.WorkPointCode);
// DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
// return ds;
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
#endregion
public static DataSet SearchData(string CODE, string RowNo, string dsconn)
{
try
{
string sql = @"SELECT
A.POCode,
A.PORow,
'' as RECSTATUS,
'' as TYPE,
C.INVCODE,
A.Quantity,
C.INVNAME,
C.INVSTD
FROM ICSPO_PoMain A
LEFT JOIN ICSINVENTORY C ON A.InvCode = C.INVCODE
WHERE
A.POCode='{0}'
AND A.PORow='{1}'
AND A.WorkPoint = '{2}'
";
sql += @"SELECT
CASE WHEN C.LOTNO IS NULL THEN 'Y' ELSE '' END AS isSelect,
B.ID,
M.POCode,
M.PORow,
B.TransNO,
B.TransLine,
B.LOTNO,
CAST(CASE WHEN C.LotNO IS NOT NULL THEN '1' ELSE '0' END AS BIT) AS isInput,
B.LOTQTY,
B.VenderLotNO,
B.PRODUCTDATE,
A.MUSERName,
A.INVUOM
FROM ICSPO_PoMain M
LEFT JOIN ICSINVENTORY A ON M.InvCode = A.INVCODE
LEFT JOIN ICSITEMLot B ON M.InvCode = B.ItemCode AND M.WorkPoint=B.WorkPoint AND M.POCode = B.TransNO AND CONVERT(int, M.PORow) = B.TransLine
LEFT JOIN ICSWareHouseLotInfo C ON B.LOTNO=C.LotNO AND B.WorkPoint=C.WorkPoint
WHERE M.POCode = '{0}'
AND M.PORow = '{1}'
AND M.WorkPoint = '{2}' AND B.LOTNO !=''
ORDER BY M.POCode
";
sql = string.Format(sql, CODE, RowNo, AppConfig.WorkPointCode);
DataSet ds = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql);
return ds;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
public static void deleteInfo(List<string> codeList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var lines = db.ICSITEMLot.Where(a => codeList.Contains(a.ID));
db.ICSITEMLot.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
}
}