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

219 lines
8.1 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSSoft.Frame.Data.Entity;
using System.Data;
using ICSSoft.Base.Config.DBHelper;
namespace ICSSoft.Frame.Data.DAL
{
public class ICSLOTONWIPInspectionDAL
{
public static string Add(Entity.ICSLOTONWIPInspection info, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
if (info.TransNO == null)
{
string flag = DateTime.Now.ToString("yyyyMMdd");
int flowLen = 5;
int flow = 1;
string maxFlow = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(flag)).Max(a => a.TransNO);
if (!string.IsNullOrEmpty(maxFlow))
{
if (maxFlow.Length < flag.Length + flowLen)
{
throw new Exception(maxFlow + "最新单号规则错误!流水码应是" + flowLen.ToString() + "位");
}
bool b = Int32.TryParse(maxFlow.Substring(flag.Length, flowLen), out flow);
if (!b)
{
throw new Exception(maxFlow + "最新单号流水码不是数字");
}
flow++;
}
info.TransNO = flag + flow.ToString().PadLeft(flowLen, '0');
}
else
{
//int Again = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO.Split('-').Length <= 1 ? 0 : Convert.ToInt32(a.TransNO.Split('-')[1]));
int f = 0;
string s = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO);
if (!s.Contains("-"))
{
f = 0;
}
else
{
f = Convert.ToInt32(s.Split('-')[1]);
}
info.TransNO = info.TransNO + "-" + (f + 1).ToString();
}
db.ICSLOTONWIPInspection.InsertOnSubmit(info);
db.SubmitChanges();
db.Transaction.Commit();
return info.TransNO;
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
public static void AddList(List<ICSLOTONWIPInspection> infos, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (var info in infos)
{
if (info.TransNO == null)
{
string flag = DateTime.Now.ToString("yyyyMMdd");
int flowLen = 5;
int flow = 1;
string maxFlow = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(flag)).Max(a => a.TransNO);
if (!string.IsNullOrEmpty(maxFlow))
{
if (maxFlow.Length < flag.Length + flowLen)
{
throw new Exception(maxFlow + "最新单号规则错误!流水码应是" + flowLen.ToString() + "位");
}
bool b = Int32.TryParse(maxFlow.Substring(flag.Length, flowLen), out flow);
if (!b)
{
throw new Exception(maxFlow + "最新单号流水码不是数字");
}
flow++;
}
info.TransNO = flag + flow.ToString().PadLeft(flowLen, '0');
}
else
{
//int Again = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO.Split('-').Length <= 1 ? 0 : Convert.ToInt32(a.TransNO.Split('-')[1]));
int f = 0;
string s = db.ICSLOTONWIPInspection.Where(a => a.TransNO.StartsWith(info.TransNO)).Max(a => a.TransNO);
if (!s.Contains("-"))
{
f = 0;
}
else
{
f = Convert.ToInt32(s.Split('-')[1]);
}
info.TransNO = info.TransNO + "-" + (f + 1).ToString();
}
db.ICSLOTONWIPInspection.InsertOnSubmit(info);
db.SubmitChanges();
}
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
public static DataTable QueryInspectionInfo(string LOTNO, string conn)
{
string sql = @"
SELECT
WIP.LOTNO,
WIP.OPSEQ,
WIP.OPCODE,
OP.OPDESC,
WIPD.MUSERName 报工人,
A.TransNO,
A.CheckMode,
A.IsCalc,
A.Quantity,
A.MUSERName 送检人,
B.Enable,
B.Status,
B.BeginDateTime,
B.EndDateTime,
B.OKQuantity,
B.NGQuantity,
B.MUSERName AS 检验人,
B.EqpCode,
C.UNIT
FROM dbo.ICSLOTONWIP WIP
LEFT JOIN dbo.ICSOP OP ON OP.OPCODE=WIP.OPCODE AND OP.WorkPoint=WIP.WorkPoint
LEFT JOIN dbo.ICSLOTONWIPDetail WIPD ON WIPD.LOTNO=WIP.LOTNO AND WIPD.OPCODE=WIP.OPCODE
LEFT JOIN dbo.ICSLOTONWIPInspection A ON A.DetailID=WIPD.ID
LEFT JOIN dbo.ICSLOTONWIPCheck B ON B.FORTRANID=A.ID
LEFT JOIN dbo.ICSLOTONWIPCheckDetail C ON C.FORTRANID=B.ID AND C.TYPE='不良'
WHERE A.TransNO IS NOT NULL {0}
ORDER BY WIP.OPSEQ,A.MTIME,B.BeginDateTime
";
if (string.IsNullOrEmpty(LOTNO))
{
sql = string.Format(sql, "");
}
else
{
sql = string.Format(sql, " AND WIP.LOTNO='" + LOTNO + "'");
}
return DBHelper.ExecuteDataset(conn, CommandType.Text, sql).Tables[0];
}
public static DataTable QueryXunjian(string WIPDetail_ID, string WorkPoint, string dsconn)
{
string sql = @"
SELECT
wip.MOCODE,
wip.MOSEQ,
det.ID AS DetailID,
det.LOTNO,
det.ROUTECODE,
wip.OPSEQ,
det.OPCODE,
OP.OPDESC,
det.ITEMCODE,
inv.INVMODELGROUP AS CustITEMCODE,
inv.[version] AS ItemVersion,
det.MUSERName AS OPUser,
det.EQPCode AS EQPCODE,
e.TransNO,
ROUND(ISNULL(e.Quantity,0),0) AS Quantity,
Convert(int,0) as CurrentQTY,
e.MUSERName AS xjUser,
e.MTIME AS LastXJTIME,
chk.MUSERName AS chkUser,
chk.BeginDateTime,
chk.EndDateTime,
chk.Status
FROM ICSLOTONWIPDetail det
INNER JOIN ICSLOTONWIP wip ON wip.LOTNO=det.LOTNO AND wip.ROUTECODE=det.ROUTECODE AND wip.OPCODE=det.OPCODE AND wip.WorkPoint=det.WorkPoint
LEFT JOIN ICSLOTONWIPInspection e ON det.ID=e.DetailID AND det.WorkPoint=e.WorkPoint AND e.CheckMode='巡检'
LEFT JOIN ICSLOTONWIPCheck chk ON e.ID=chk.FORTRANID AND e.WorkPoint=chk.WorkPoint AND chk.Enable='1'
LEFT JOIN dbo.ICSOP OP ON OP.OPCODE=det.OPCODE AND OP.WorkPoint=det.WorkPoint
LEFT JOIN dbo.ICSINVENTORY inv ON inv.INVCODE=det.ITEMCODE AND inv.WorkPoint=det.WorkPoint
WHERE det.CollectStatus='COLLECT_BEGIN'
AND det.WorkPoint='{0}'
AND ISNULL(e.MTIME,'')=ISNULL((SELECT MAX(MTIME) FROM ICSLOTONWIPInspection WHERE DetailID=DET.ID AND WorkPoint=det.WorkPoint AND CheckMode='巡检'),'')
AND det.BeginDateTime >'2022-03-29'
";
sql = string.Format(sql, WorkPoint);
if (!string.IsNullOrEmpty(WIPDetail_ID))
{
sql += " AND det.ID='" + WIPDetail_ID + "'";
}
return DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
}
}
}