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.
148 lines
5.0 KiB
148 lines
5.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSEQPShutdownDAL
|
|
{
|
|
public static void AddAndEdit(List<Entity.FormICSEQPShutdownUIModel> listInfo, bool add)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSEQPShutdownUIModel info in listInfo)
|
|
{
|
|
var line = db.ICSEquipmentShutdown.SingleOrDefault(a => a.EQPID == info.EQPID && a.WorkPoint == AppConfig.WorkPointCode);
|
|
if (add)
|
|
{
|
|
if (line != null)
|
|
{
|
|
throw new Exception(info.EQPCode + "," + info.EQPName + "已维护");
|
|
}
|
|
line = new ICSEquipmentShutdown();
|
|
}
|
|
else
|
|
{
|
|
if (line == null)
|
|
{
|
|
throw new Exception(info.EQPCode + "," + info.EQPName + "已被移除,无法修改");
|
|
}
|
|
}
|
|
|
|
line.EQPID = info.EQPID;
|
|
line.TStart = Convert.ToDateTime(info.TStart);
|
|
line.TEnd = Convert.ToDateTime(info.TEnd);
|
|
line.MUSER = info.MUSER;
|
|
line.MUSERName = info.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(info.MTIME);
|
|
line.WorkPoint = info.WorkPoint;
|
|
line.Reason = info.Reason;
|
|
line.EATTRIBUTE1 = "SHUTDOWN";
|
|
|
|
if (add)
|
|
db.ICSEquipmentShutdown.InsertOnSubmit(line);
|
|
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
|
|
public static void Delete(List<string> listID)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.ICSEquipmentShutdown.Where(a => listID.Contains(a.EQPID) && a.WorkPoint == AppConfig.WorkPointCode);
|
|
db.ICSEquipmentShutdown.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static FormICSEQPShutdownUIModel Select(string id)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
try
|
|
{
|
|
//var lines = db.ICSEquipmentShutdown.Where(a => a.EQPID==id && a.WorkPoint == AppConfig.WorkPointCode).ToArray();
|
|
string sql = @"
|
|
SELECT
|
|
A.EQPID,
|
|
B.EQPCode,
|
|
B.EQPName,
|
|
B.EQPDESC,
|
|
B.Model,
|
|
B.[Type],
|
|
B.EType,
|
|
B.EATTRIBUTE1,
|
|
A.TStart,
|
|
A.TEnd,
|
|
A.Reason
|
|
FROM [dbo].[ICSEquipmentShutdown] A
|
|
LEFT JOIN dbo.ICSEquipment B
|
|
ON A.EQPID = B.EQPID
|
|
AND A.WorkPoint = B.WorkPoint
|
|
WHERE 1 = 1 AND A.EQPID='" + id + "'AND A.WorkPoint = '" + AppConfig.WorkPointCode + "';";
|
|
List<FormICSEQPShutdownUIModel> lines = db.ExecuteQuery<FormICSEQPShutdownUIModel>(sql).ToList();
|
|
if (lines.Count() == 0)
|
|
{
|
|
return null;
|
|
}
|
|
return lines[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Connection.Close();
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
public static ICSEquipmentShutdown SelectSuspendInfo(string lot, string route, string op, string user)
|
|
{
|
|
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.ICSEquipmentShutdown.Where(a => a.LOTNO == lot
|
|
&& a.ROUTECODE == route
|
|
&& a.OPCODE == op
|
|
&& a.OPUserCode == user
|
|
&& a.EATTRIBUTE1.ToUpper() == "SUSPEND"
|
|
&& a.TEnd == null
|
|
&& a.WorkPoint == AppConfig.WorkPointCode).ToList<ICSEquipmentShutdown>();
|
|
return lines[0];
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|