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.
247 lines
8.0 KiB
247 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 ICSEquipmentTypeDAL
|
|
{
|
|
|
|
|
|
|
|
#region 增加修改
|
|
|
|
public static void AddAndEdit(List<FormICSEquipmentUIModel> equipmentInfoList, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSEquipmentUIModel equipmentInfo in equipmentInfoList)
|
|
{
|
|
|
|
bool isNew = false;
|
|
var line = db.ICSEquipmentType.SingleOrDefault(a =>a.TypeCODE == equipmentInfo.TypeCODE);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSEquipmentType();
|
|
line.ID = AppConfig.GetGuid();
|
|
|
|
}
|
|
var codes = db.ICSEquipmentType.Where(a => a.TypeCODE == equipmentInfo.TypeCODE && a.ID != line.ID);
|
|
if (codes.ToList().Count > 0)
|
|
{
|
|
throw new Exception("设备组代码已存在");
|
|
}
|
|
line.TypeCODE = equipmentInfo.TypeCODE;
|
|
line.TypeDESC = equipmentInfo.TypeDESC;
|
|
line.MUSER = equipmentInfo.MUSER;
|
|
line.SEGCODE = equipmentInfo.SEGCODE;
|
|
line.MUSERName = equipmentInfo.MUSERName;
|
|
line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
|
|
line.WorkPoint = equipmentInfo.WorkPoint;
|
|
line.EATTRIBUTE1 = equipmentInfo.EATTRIBUTE1;
|
|
|
|
if (isNew)
|
|
db.ICSEquipmentType.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<FormICSEquipmentUIModel> SearchEquipmentInfoByCode(string id, string dsconn)
|
|
{
|
|
List<FormICSEquipmentUIModel> returnshift = new List<FormICSEquipmentUIModel>();
|
|
string sql = @"select '' as isSelect,ID,TypeCODE,TypeDESC,SEGCODE,MUSERName,MTIME from ICSEquipmentType where ID='{0}'";
|
|
sql = string.Format(sql, id);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
FormICSEquipmentUIModel equipmentInfo = new FormICSEquipmentUIModel();
|
|
|
|
equipmentInfo.TypeCODE = dr["TypeCODE"].ToString();
|
|
equipmentInfo.TypeDESC = dr["TypeDESC"].ToString();
|
|
equipmentInfo.SEGCODE = dr["SEGCODE"].ToString();
|
|
equipmentInfo.MUSERName = dr["MUSERName"].ToString();
|
|
equipmentInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
|
|
|
|
if (!returnshift.Contains(equipmentInfo))
|
|
{
|
|
returnshift.Add(equipmentInfo);
|
|
}
|
|
|
|
}
|
|
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.ICSEquipmentType.Where(a => guidList.Contains(a.ID));
|
|
db.ICSEquipmentType.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 bool IncludingEquipment(List<string> idList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
bool flag = false;
|
|
var lines = db.ICSEquipment.Where(a => idList.Contains(a.EType));
|
|
if (lines.Count() != 0)
|
|
flag = true;
|
|
return flag;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|
|
|