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.
143 lines
4.6 KiB
143 lines
4.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
using ICSSoft.Base.Config.AppConfig;
|
|
using System.Data;
|
|
using System.Data.Sql;
|
|
using System.Data.Linq;
|
|
using ICSSoft.Base.Config.DBHelper;
|
|
namespace ICSSoft.Frame.Data.DAL
|
|
{
|
|
public class ICSRESDAL
|
|
{
|
|
#region AddandEdit
|
|
public static void AddandEdit(ICSRES ItemLot, string Appconstr)
|
|
{
|
|
FramDataContext db = new FramDataContext(Appconstr);
|
|
db.Connection.Open();
|
|
db.Transaction = db.Connection.BeginTransaction();
|
|
try
|
|
{
|
|
bool isNew = false;
|
|
var line = db.ICSRES.SingleOrDefault(a => a.ID == ItemLot.ID);
|
|
|
|
if (line == null)
|
|
{
|
|
isNew = true;
|
|
line = new ICSRES();
|
|
line.ID = AppConfig.GetGuid();
|
|
}
|
|
|
|
var codes = db.ICSRES.Where(a => a.RESCODE == ItemLot.RESCODE && a.ID != line.ID);
|
|
if (codes.ToList().Count > 0)
|
|
{
|
|
throw new Exception("资源代码已存在");
|
|
}
|
|
|
|
line.RESCODE = ItemLot.RESCODE;
|
|
line.RESDESC = ItemLot.RESDESC;
|
|
line.RESTYPE = ItemLot.RESTYPE;
|
|
line.SEGID = ItemLot.SEGID;
|
|
if (!(ItemLot.SEGID.Equals("")))
|
|
{
|
|
var lineone = db.ICSSEG.SingleOrDefault(a => a.ID == ItemLot.SEGID);
|
|
line.SEGCODE = lineone.SEGCODE;
|
|
}
|
|
line.SSID = ItemLot.SSID;
|
|
if (!(ItemLot.SSID.Equals("")))
|
|
{
|
|
var linetwo = db.ICSSS.SingleOrDefault(a => a.ID == ItemLot.SSID);
|
|
line.SSCODE = linetwo.SSCODE;
|
|
}
|
|
line.SHIFTTYPEID = ItemLot.SHIFTTYPEID;
|
|
if (!(ItemLot.SHIFTTYPEID.Equals("")))
|
|
{
|
|
var linethree = db.ICSSHIFTTYPE.SingleOrDefault(a => a.ID == ItemLot.SHIFTTYPEID);
|
|
line.SHIFTTYPECODE = linethree.SHIFTTYPECODE;
|
|
}
|
|
line.DCTCODE = ItemLot.DCTCODE;
|
|
line.CREWCODE = ItemLot.CREWCODE;
|
|
|
|
line.MUSER = ItemLot.MUSER;
|
|
line.MUSERName = ItemLot.MUSERName;
|
|
line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
|
|
line.WorkPoint = AppConfig.WorkPointCode;
|
|
|
|
if (isNew) db.ICSRES.InsertOnSubmit(line);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region select
|
|
public static DataTable select(String guid, String Appconstr)
|
|
{
|
|
try
|
|
{
|
|
string sql = @"SELECT a.[RESCODE]
|
|
,a.[RESDESC]
|
|
,a.[RESGROUP]
|
|
,a.[RESTYPE]
|
|
,a.[SEGID]
|
|
,a.[SSID]
|
|
,a.[SHIFTTYPEID]
|
|
,a.[DCTCODE]
|
|
,a.[CREWCODE]
|
|
,a.[MUSER]
|
|
,a.[MUSERName]
|
|
,a.[MTIME]
|
|
,a.[WorkPoint],
|
|
b.SEGCODE,
|
|
c.SSCODE,
|
|
d.SHIFTTYPECODE
|
|
FROM dbo.ICSRES a LEFT JOIN ICSSEG b ON a.SEGID=b.ID
|
|
LEFT JOIN [dbo].[ICSSS] c ON a.SSID=c.ID
|
|
LEFT JOIN dbo.ICSSHIFTTYPE d ON a.SHIFTTYPEID=d.ID
|
|
where a.id='{0}'";
|
|
sql = string.Format(sql, guid);
|
|
return DBHelper.ExecuteDataset(Appconstr, CommandType.Text, sql).Tables[0];
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception(ex.Message);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#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 line = db.ICSOP2RES.Where(a => guidList.Contains(a.RESID));
|
|
if(line.Count()>0){
|
|
throw new Exception("资源已经关联工序无法删除!!!");
|
|
}
|
|
var lines = db.ICSRES.Where(a => guidList.Contains(a.ID));
|
|
db.ICSRES.DeleteAllOnSubmit(lines);
|
|
|
|
db.SubmitChanges();
|
|
db.Transaction.Commit();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
db.Transaction.Rollback();
|
|
throw ex;
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|