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.
173 lines
5.6 KiB
173 lines
5.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
using System.Data;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using System.Data.Linq;
|
|
using System.Data.SqlClient;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSFACTORYDAL
|
|
{
|
|
#region 新增和修改
|
|
public static void Add(List<FormICSFactoryUIModel> factoryInfoList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSFactoryUIModel factoryinfo in factoryInfoList)
|
|
{
|
|
bool isNew = false;
|
|
var line = db.ICSFACTORY.SingleOrDefault(a => a.FACCODE == factoryinfo.FACCODE && a.WorkPoint == factoryinfo.WorkPoint);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSFACTORY();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.FACCODE = factoryinfo.FACCODE;
|
|
|
|
}
|
|
line.FACDESC = factoryinfo.FACDESC;
|
|
line.MUSER = AppConfig.UserId;
|
|
line.MUSERName = AppConfig.UserName;
|
|
line.MTIME = DateTime.Now;
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
if (isNew)
|
|
db.ICSFACTORY.InsertOnSubmit(line);
|
|
db.SubmitChanges();
|
|
|
|
}
|
|
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 通过工厂代码查询
|
|
public static List<FormICSFactoryUIModel> SearchFactoryInfoByCode(string FACCODE, string dsconn)
|
|
{
|
|
List<FormICSFactoryUIModel> returnfactory = new List<FormICSFactoryUIModel>();
|
|
string sql = @"select [FACCODE],[FACDESC],[MUSERName],[MTIME]
|
|
from ICSFACTORY
|
|
where FACCODE='{0}'";
|
|
sql = string.Format(sql, FACCODE);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
FormICSFactoryUIModel returnInfo = new FormICSFactoryUIModel();
|
|
|
|
returnInfo.FACCODE = dr["FACCODE"].ToString();
|
|
returnInfo.FACDESC = dr["FACDESC"].ToString();
|
|
returnInfo.MUSERName = dr["MUSERName"].ToString();
|
|
returnInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
|
|
returnfactory.Add(returnInfo);
|
|
|
|
}
|
|
return returnfactory;
|
|
|
|
}
|
|
#endregion
|
|
#region 工厂代码是否存在
|
|
public static bool IsIncluding(string FACCODE, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var line = db.ICSFACTORY.SingleOrDefault(a => a.FACCODE == FACCODE);
|
|
if (line == null)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
#region 删除
|
|
public static void deleteInfo(List<string> codeList, string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
var lines = db.ICSFACTORY.Where(a => codeList.Contains(a.FACCODE));
|
|
db.ICSFACTORY.DeleteAllOnSubmit(lines);
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 判断是否在车间维护中已存在该工厂
|
|
|
|
public static bool isIncludingInSeg(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.ICSSEG.Where(a => idList.Contains(a.FACID));
|
|
if (lines.Count() != 0)
|
|
flag = true;
|
|
|
|
return flag;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
#region 查询最大的工厂代码
|
|
public static string SearchMaxCode(string dsconn)
|
|
{
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
string lines = db.ICSFACTORY.Max(a => a.FACCODE);
|
|
return lines;
|
|
//db.ICSSHIFTTYPE.DeleteAllOnSubmit(lines);
|
|
//db.SubmitChanges();
|
|
//db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|