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

278 lines
10 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 ICSEquipmentDAL
{
#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.ICSEquipment.SingleOrDefault(a => a.EQPID == equipmentInfo.EQPID);
if (line == null)
{
isNew = true;
line = new ICSEquipment();
line.EQPID = AppConfig.GetGuid();
}
var codes = db.ICSEquipment.Where(a => a.EQPCode == equipmentInfo.EQPCode && a.EQPID != line.EQPID && a.WorkPoint == equipmentInfo.WorkPoint);
if (codes.ToList().Count > 0)
{
throw new Exception("设备编号已存在");
}
line.EQPCode = equipmentInfo.EQPCode;
line.EQPName = equipmentInfo.EQPName;
line.Model = equipmentInfo.Model;
line.Type = equipmentInfo.Type;
line.EQPStatus = equipmentInfo.EQPStatus;
line.EQPDESC = equipmentInfo.EQPDESC;
line.EType = equipmentInfo.EType;
line.MTStatus = equipmentInfo.MTStatus;
line.Company = equipmentInfo.Company;
line.Address = equipmentInfo.Address;
line.TelPhone = equipmentInfo.TelPhone;
line.MUSER = equipmentInfo.MUSER;
line.MUSERName = equipmentInfo.MUSERName;
line.MTIME = Convert.ToDateTime(equipmentInfo.MTIME);
line.WorkPoint = equipmentInfo.WorkPoint;
line.USEStatus = equipmentInfo.USEStatus;
line.cClass = equipmentInfo.cClass;
line.cHandles = equipmentInfo.cHandles;
line.cAxis = equipmentInfo.cAxis;
line.cToolMagazine = equipmentInfo.cToolMagazine;
line.cMachinableProfiles = equipmentInfo.cMachinableProfiles;
line.cAccuracy = equipmentInfo.cAccuracy;
line.FIXOP = equipmentInfo.FIXOP;
line.EATTRIBUTE2 = equipmentInfo.EATTRIBUTE2;
line.MCCode = equipmentInfo.MCCode;
line.CXJD = equipmentInfo.CXJD;
line.CXType = equipmentInfo.CXType;
if (isNew)
db.ICSEquipment.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 a.EQPCode,a.EQPName,a.Model,a.Type,a.EQPStatus,a.EQPDESC,a.EType,
a.Company,a.Address,a.TelPhone,b.TypeCODE,
a.MUSERName,a.MTIME,
a.USEStatus,
a.cClass,a.cHandles,a.cAxis,a.cToolMagazine,a.cMachinableProfiles,a.cAccuracy,a.FIXOP,
a.EATTRIBUTE1,a.EATTRIBUTE2,a.mccode,a.cxtype,a.cxjd
from ICSEquipment a left join ICSEquipmentType b on a.EType=b.TypeCODE AND a.WorkPoint=b.WorkPoint where a.EQPID='{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.EQPID = id;
equipmentInfo.EQPCode = dr["EQPCode"].ToString();
equipmentInfo.EQPName = dr["EQPName"].ToString();
equipmentInfo.Model = dr["Model"].ToString();
equipmentInfo.Type = dr["Type"].ToString();
equipmentInfo.EQPStatus = dr["EQPStatus"].ToString();
equipmentInfo.EQPDESC = dr["EQPDESC"].ToString();
equipmentInfo.EType = dr["EType"].ToString();
equipmentInfo.Company = dr["Company"].ToString();
equipmentInfo.Address = dr["Address"].ToString();
equipmentInfo.TelPhone = dr["TelPhone"].ToString();
//equipmentInfo.SS = new FormICSSSUIModel();
//equipmentInfo.SS.SSCODE = dr["SSCODE"].ToString();
//equipmentInfo.SS.SSDESC = dr["SSDESC"].ToString();
equipmentInfo.MUSERName = dr["MUSERName"].ToString();
equipmentInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
equipmentInfo.MCCode = dr["mccode"].ToString();
if (string.IsNullOrEmpty(dr["mccode"].ToString()) || dr["mccode"].ToString() == "加工中心")
{
equipmentInfo.cClass = dr["cClass"].ToString();
equipmentInfo.cHandles = Convert.ToInt32(dr["cHandles"]);
equipmentInfo.cAxis = Convert.ToInt32(dr["cAxis"]);
equipmentInfo.cToolMagazine = Convert.ToInt32(dr["cToolMagazine"]);
equipmentInfo.cMachinableProfiles = Convert.ToInt32(dr["cMachinableProfiles"]);
equipmentInfo.cAccuracy = dr["cAccuracy"].ToString();
}
else {
equipmentInfo.CXType= dr["cxtype"].ToString();
equipmentInfo.CXJD = dr["CXJD"].ToString();
}
equipmentInfo.USEStatus = dr["USEStatus"].ToString();
equipmentInfo.FIXOP = dr["FIXOP"].ToString();
equipmentInfo.EATTRIBUTE2 = dr["EATTRIBUTE2"].ToString();
equipmentInfo.EATTRIBUTE1 = dr["EATTRIBUTE1"].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.ICSEquipment.Where(a => guidList.Contains(a.EQPID));
db.ICSEquipment.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;
// }
// }
}
}