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.
262 lines
8.7 KiB
262 lines
8.7 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 ICSShiftDAL
|
|
{
|
|
|
|
|
|
|
|
#region 增加修改
|
|
|
|
public static void AddAndEdit(List<FormICSShiftUIModel> shiftInfoList, string dsconn)
|
|
{
|
|
|
|
FramDataContext db = new FramDataContext(dsconn);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
foreach (FormICSShiftUIModel shiftInfo in shiftInfoList)
|
|
{
|
|
|
|
bool isNew = false;
|
|
var line = db.ICSSHIFT.SingleOrDefault(a => a.SHIFTCODE == shiftInfo.SHIFTCODE);
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSSHIFT();
|
|
line.ID = AppConfig.GetGuid();
|
|
line.SHIFTCODE = shiftInfo.SHIFTCODE;
|
|
|
|
}
|
|
var codes = db.ICSSHIFT.Where(a => a.SHIFTSEQ == shiftInfo.SHIFTSEQ &&a.SHIFTTYPEID==shiftInfo.SHIFTTYPEID&& a.ID != line.ID);
|
|
if (codes.ToList().Count > 0)
|
|
{
|
|
throw new Exception("班次次序在该班制中已存在");
|
|
}
|
|
line.SHIFTTYPEID = shiftInfo.SHIFTTYPEID;
|
|
line.SHIFTSEQ=shiftInfo.SHIFTSEQ;
|
|
line.SHIFTDESC=shiftInfo.SHIFTDESC;
|
|
line.SHIFTBTIME=shiftInfo.SHIFTBTIME;
|
|
line.SHIFTETIME=shiftInfo.SHIFTETIME;
|
|
line.ISOVERDAY=shiftInfo.ISOVERDAY;
|
|
line.MUSER=shiftInfo.MUSER;
|
|
line.MUSERName=shiftInfo.MUSERName;
|
|
line.MTIME =Convert.ToDateTime(shiftInfo.MTIME);
|
|
line.WorkPoint = shiftInfo.WorkPoint;
|
|
line.EATTRIBUTE1 = shiftInfo.EATTRIBUTE1;
|
|
|
|
if (isNew)
|
|
db.ICSSHIFT.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
|
|
|
|
#region 班次代码是否在时段维护中使用
|
|
public static bool isIncludingInICSTP(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.ICSTP.Where(a => idList.Contains(a.SHIFTID));
|
|
if (lines.Count() != 0)
|
|
flag = true;
|
|
|
|
return flag;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
//db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
|
|
}
|
|
#endregion
|
|
|
|
|
|
public static List<FormICSShiftUIModel> SearchShiftInfoByCode(string SHIFTCODE, string dsconn)
|
|
{
|
|
List<FormICSShiftUIModel> returnshift = new List<FormICSShiftUIModel>();
|
|
string sql = @"select a.SHIFTCODE,b.ID,b.SHIFTTYPECODE,a.SHIFTSEQ,a.SHIFTDESC,a.SHIFTBTIME,a.SHIFTETIME,a.ISOVERDAY,a.MUSERName,a.MTIME
|
|
from ICSSHIFT a
|
|
left join ICSSHIFTTYPE b on a.SHIFTTYPEID=b.ID
|
|
where SHIFTCODE='{0}'";
|
|
sql = string.Format(sql, SHIFTCODE);
|
|
DataTable dt = DBHelper.ExecuteDataset(dsconn, CommandType.Text, sql).Tables[0];
|
|
foreach (DataRow dr in dt.Rows)
|
|
{
|
|
FormICSShiftUIModel shiftInfo = new FormICSShiftUIModel();
|
|
shiftInfo.SHIFTCODE = dr["SHIFTCODE"].ToString();
|
|
shiftInfo.shifttype = new FormICSShifTypeUIModel();
|
|
//shiftInfo.SHIFTTYPEID = dr["ID"].ToString();
|
|
shiftInfo.shifttype.SHIFTTYPECODE = dr["SHIFTTYPECODE"].ToString();
|
|
shiftInfo.SHIFTSEQ = Convert.ToInt32(dr["SHIFTSEQ"]);
|
|
shiftInfo.SHIFTDESC = dr["SHIFTDESC"].ToString();
|
|
shiftInfo.SHIFTBTIME = int.Parse(dr["SHIFTBTIME"].ToString());
|
|
shiftInfo.SHIFTETIME = int.Parse(dr["SHIFTETIME"].ToString());
|
|
shiftInfo.ISOVERDAY = dr["ISOVERDAY"].ToString();
|
|
shiftInfo.MUSERName = dr["MUSERName"].ToString();
|
|
shiftInfo.MTIME = System.DateTime.Parse(dr["MTIME"].ToString());
|
|
|
|
if (!returnshift.Contains(shiftInfo))
|
|
{
|
|
returnshift.Add(shiftInfo);
|
|
}
|
|
|
|
}
|
|
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.ICSSHIFT.Where(a => guidList.Contains(a.ID));
|
|
db.ICSSHIFT.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;
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
}
|
|
}
|
|
|