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.
323 lines
11 KiB
323 lines
11 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
//using ZHCSoft.Base.Config.DBHelper;
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
|
|
using System.Data.Linq;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
//using ZHCSoft.Base.Config.AppConfig;
|
|
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSOP2UserDAL
|
|
{
|
|
|
|
#region 新增和修改
|
|
public static void Add(int flag,List<FormICSOP2UserUIModel> ITEM2ROUTEInfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSOP2UserUIModel info in ITEM2ROUTEInfoList)
|
|
{
|
|
bool isNew = false;
|
|
var line = db.ICSOP2User.SingleOrDefault(a => a.OPCODE == info.op.OPCODE && a.USERCODE == info.user.UserCode);
|
|
if (line != null && flag == 0)
|
|
{
|
|
throw new Exception("工序与人员关系已存在");
|
|
|
|
}
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSOP2User();
|
|
}
|
|
line.OPID = info.op.ID;
|
|
line.OPCODE = info.op.OPCODE;
|
|
line.USERCODE = info.user.UserCode;
|
|
|
|
line.USERName = info.user.UserName;
|
|
|
|
line.MUSER = AppConfig.UserId;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.MTIME = DateTime.Now;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
line.Level = info.Level;
|
|
if (isNew)
|
|
{
|
|
db.ICSOP2User.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
}
|
|
|
|
db.SubmitChanges();
|
|
|
|
}
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 新增和修改List
|
|
public static string AddList(List<FormICSOP2UserUIModel> ITEM2ROUTEInfoList, string dsconn)
|
|
{
|
|
string str = "";
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSOP2UserUIModel info in ITEM2ROUTEInfoList)
|
|
{
|
|
var op = db.ICSOP.SingleOrDefault( a => a.OPCODE == info.OPCODE);
|
|
if (op == null)
|
|
{
|
|
str += "工序代码:" + info.OPCODE + " 不存在!\n";
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
info.op = new FormICSOPUIModel();
|
|
info.op.ID = op.ID;
|
|
info.op.OPCODE = op.OPCODE;
|
|
}
|
|
var user = db.Sys_User.SingleOrDefault(a => a.UserCode == info.USERCODE);
|
|
if (user == null)
|
|
{
|
|
str += "人员代码:" + info.USERCODE + " 不存在!\n";
|
|
continue;
|
|
}
|
|
else
|
|
{
|
|
info.user = new FormICSUserUIModel();
|
|
info.user.UserCode = user.UserCode;
|
|
info.user.UserName = user.UserName;
|
|
}
|
|
|
|
//bool isNew = false;
|
|
var line1 = db.ICSOP2User.SingleOrDefault(a => a.OPCODE == info.op.OPCODE && a.USERCODE == info.user.UserCode);
|
|
if (line1 != null)
|
|
{
|
|
str += "工序代码:" + info.op.OPCODE + ",人员代码:" + info.user.UserCode + " 已存在!\n";
|
|
continue;
|
|
}
|
|
ICSOP2User line = new ICSOP2User();
|
|
line.OPID = info.op.ID;
|
|
line.OPCODE = info.op.OPCODE;
|
|
line.USERCODE = info.user.UserCode;
|
|
|
|
line.USERName = info.user.UserName;
|
|
|
|
line.MUSER = AppConfig.UserId;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.MTIME = DateTime.Now;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
|
|
db.ICSOP2User.InsertOnSubmit(line);
|
|
|
|
db.SubmitChanges();
|
|
|
|
}
|
|
|
|
db.Transaction.Commit();
|
|
if (string.IsNullOrEmpty(str))
|
|
str = "数据导入成功!";
|
|
return str;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
|
|
public static void Addop(List<FormICSITEM2ROUTEUIModel> ITEM2ROUTEInfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
string routecode;
|
|
foreach (FormICSITEM2ROUTEUIModel info in ITEM2ROUTEInfoList)
|
|
{
|
|
List<ICSITEMROUTE2OP> listmodel = new List<ICSITEMROUTE2OP>();
|
|
routecode = info.route.ROUTECODE;
|
|
string sql = @"select [OPID],[OPCODE],[OPSEQ],[OPCONTROL]
|
|
from [ICSROUTE2OP]
|
|
where ROUTECODE='{0}'";
|
|
sql = string.Format(sql, routecode);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
ICSITEMROUTE2OP model = new ICSITEMROUTE2OP();
|
|
model.ITEMID = info.item.ID;
|
|
model.ITEMCODE = info.item.INVCODE;
|
|
model.ROUTEID = info.route.ID;
|
|
model.ROUTECODE = info.route.ROUTECODE;
|
|
model.OPID = dr["OPID"].ToString();
|
|
model.OPCODE = dr["OPCODE"].ToString();
|
|
model.OPSEQ = Convert.ToInt32(dr["OPSEQ"].ToString());
|
|
model.OPCONTROL = dr["OPCONTROL"].ToString();
|
|
model.OPTIONALOP = "";
|
|
model.IDMERGETYPE = "";
|
|
model.IDMERGERULE = 0;
|
|
|
|
model.MUSER = AppConfig.UserId;
|
|
model.MUSERName = AppConfig.UserName;
|
|
model.MTIME = DateTime.Now;
|
|
model.WorkPoint = AppConfig.WorkPointCode;
|
|
|
|
listmodel.Add(model);
|
|
}
|
|
foreach (ICSITEMROUTE2OP test in listmodel)
|
|
{
|
|
db.ICSITEMROUTE2OP.InsertOnSubmit(test);
|
|
|
|
}
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#region 代码是否存在
|
|
public static bool IsIncluding(string itemCODE,string routeCODE, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var line = db.ICSITEM2ROUTE.SingleOrDefault(a => a.ITEMCODE == itemCODE && a.ROUTECODE == routeCODE);
|
|
if (line == null)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#region 产品是否有使用的途程
|
|
public static bool IsIncludingISREF(string itemCODE, string routeCODE, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var line = db.ICSITEM2ROUTE.SingleOrDefault(a => a.ITEMCODE == itemCODE && a.ROUTECODE != routeCODE && a.ISREF.Equals("是"));
|
|
if (line == null)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 通过产品代码和途程代码查询
|
|
public static List<FormICSOP2UserUIModel> SearchInfoByCode(string opCode, string userCode, string dsconn)
|
|
{
|
|
List<FormICSOP2UserUIModel> returnir = new List<FormICSOP2UserUIModel>();
|
|
string sql = @"select [OPID]
|
|
,[OPCODE]
|
|
,[USERCODE]
|
|
,[USERName]
|
|
,[MUSER]
|
|
,[MUSERName]
|
|
,[MTIME]
|
|
,[WorkPoint]
|
|
,[EATTRIBUTE1]
|
|
,[Level]
|
|
from ICSOP2User
|
|
where OPCODE='" + opCode + "' and USERCODE='" + userCode + "'";
|
|
sql = string.Format(sql, opCode, userCode);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
FormICSOP2UserUIModel returnInfo = new FormICSOP2UserUIModel();
|
|
returnInfo.OPID = dr["OPID"].ToString();
|
|
returnInfo.OPCODE = dr["OPCODE"].ToString();
|
|
returnInfo.USERCODE = dr["USERCODE"].ToString();
|
|
returnInfo.USERName = dr["USERName"].ToString();
|
|
returnInfo.Level = dr["Level"].ToString();
|
|
if (!returnir.Contains(returnInfo))
|
|
{
|
|
returnir.Add(returnInfo);
|
|
}
|
|
|
|
|
|
}
|
|
return returnir;
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 删除
|
|
public static void deleteInfo(List<ICSOP2User> op2userList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (ICSOP2User op2user in op2userList)
|
|
{
|
|
var lines = db.ICSOP2User.Where(a => a.OPCODE == op2user.OPCODE && a.USERCODE == op2user.USERCODE);
|
|
db.ICSOP2User.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
}
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
}
|
|
}
|