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

249 lines
8.0 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 ICSEQPHandleDAL
{
#region 增加修改
public static void AddAndEdit(List<FormICSEQPCHECKLISTUIModel> checkInfoList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (FormICSEQPCHECKLISTUIModel checktInfo in checkInfoList)
{
bool isNew = false;
var line = db.ICSEQPCHECKLIST.SingleOrDefault(a => a.EQPID == checktInfo.EQPID && a.CKGROUP == checktInfo.CKGROUP);
if (line == null)
{
isNew = true;
line = new ICSEQPCHECKLIST();
line.EQPID = AppConfig.GetGuid();
}
line.EQPCode = checktInfo.EQPCode;
line.CKGROUP = checktInfo.CKGROUP;
line.MUSER = checktInfo.MUSER;
line.MUSERName = checktInfo.MUSERName;
line.MTIME = Convert.ToDateTime(checktInfo.MTIME);
line.WorkPoint = checktInfo.WorkPoint;
line.EATTRIBUTE1 = checktInfo.EATTRIBUTE1;
if (isNew)
db.ICSEQPCHECKLIST.InsertOnSubmit(line);
db.SubmitChanges();
}
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
#endregion
#region 班次代码是否存在
public static bool IsIncludingShiftCode(string shiftcode, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTCODE == shiftcode);
if (line == null)
return true;
else
return false;
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
//#region 班次次序是否存在
//public static bool IsIncludingInShiftSeq(int shiftsqe, string shifttypeid)
//{
// FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
// db.Connection.Open();
// db.Transaction = db.Connection.BeginTransaction();
// try
// {
// var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTSEQ == shiftsqe && a.SHIFTTYPEID == shifttypeid);
// if (line == null)
// return true;
// else
// return false;
// }
// catch (Exception ex)
// {
// db.Transaction.Rollback();
// throw ex;
// }
//}
//#endregion
public static List<FormICSEQPCHECKLISTUIModel> SearchCheckListInfoByEQPIDandCKGROUP(string id,string ckgroup, string dsconn)
{
List<FormICSEQPCHECKLISTUIModel> returnshift = new List<FormICSEQPCHECKLISTUIModel>();
string sql = @"select b.EQPID,b.EQPCode,c.CKGROUP,a.MUSERName,a.MTIME
from ICSEQPCHECKLIST a
left join ICSEquipment b on a.EQPCode=b.EQPCode
left join ICSOQCCKGROUP c on a.CKGROUP=c.CKGROUP
where b.EQPID='" + id + "' and c.CKGROUP='" + ckgroup + "'";
sql = string.Format(sql);
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
foreach (DataRow dr in dt.Rows)
{
FormICSEQPCHECKLISTUIModel checklistInfo = new FormICSEQPCHECKLISTUIModel();
checklistInfo.Equipment = new FormICSEquipmentUIModel();
checklistInfo.Equipment.EQPID = dr["EQPID"].ToString();
checklistInfo.Equipment.EQPCode = dr["EQPCode"].ToString();
checklistInfo.OQCCKGROUP = new FormICSOQCCKGROUPUIModel();
checklistInfo.OQCCKGROUP.CKGROUP = dr["CKGROUP"].ToString();
checklistInfo.MUSERName = dr["MUSERName"].ToString();
checklistInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
if (!returnshift.Contains(checklistInfo))
{
returnshift.Add(checklistInfo);
}
}
return returnshift;
}
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(List<String> guidList)
{
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var lines = db.ICSEQPCHECKLIST.Where(a => guidList.Contains(a.EQPCode) && guidList.Contains(a.CKGROUP));
db.ICSEQPCHECKLIST.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
#region update
public static void update(string guid, string status)
{
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var lines = db.ICSEquipment.SingleOrDefault(a => a.EQPID == guid);
lines.EQPStatus = status;
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;
// }
// }
}
}