华恒Mes鼎捷代码
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.

204 lines
7.8 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 ICSSoft.Base.Config.DBHelper;
namespace ICSSoft.Frame.Data.DAL
{
public class ICSStackDAL
{
public static void AddAndEdit(ICSStack Stack, string Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
bool isNew = false;
var line = db.ICSStack.SingleOrDefault(a => a.Serial == Stack.Serial);
if (line == null)
{
isNew = true;
line = new ICSStack();
line.Serial = AppConfig.GetGuid();
}
var codes = db.ICSStack.Where(a => a.StackCode == Stack.StackCode && a.Serial != line.Serial);
var names = db.ICSStack.Where(a => a.StackName == Stack.StackName && a.Serial != line.Serial);
//var StorageLotInfoLog = db.ICSStorageLotInfoLog.SingleOrDefault(a => a.Stack_Serial == Stack.Serial);
if (names.Count() > 0)
{
throw new Exception("库位名称已存在");
}
if (codes.Count() > 0)
{
throw new Exception("库位编号已存在");
}
//if (StorageLotInfoLog != null)
//{
// throw new Exception("库位正在使用中无法修改!!");
//}
line.StackCode = Stack.StackCode;
line.StackName = Stack.StackName;
line.Storage_Serial = Stack.Storage_Serial;
line.Storage_Name = Stack.Storage_Name;
line.MUSER = Stack.MUSER;
line.MUSERName = Stack.MUSERName;
line.WorkPoint = AppConfig.WorkPointCode;
line.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString());
if (isNew) db.ICSStack.InsertOnSubmit(line);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
public static void AddAndEditList(List<ICSStack> StackList, string Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
foreach (var Stack in StackList)
{
bool isNew = false;
var line = db.ICSStack.SingleOrDefault(a => a.Serial == Stack.Serial);
if (line == null)
{
isNew = true;
line = new ICSStack();
line.Serial = AppConfig.GetGuid();
}
var codes = db.ICSStack.Where(a => a.StackCode == Stack.StackCode && a.Serial != line.Serial);
var names = db.ICSStack.Where(a => a.StackName == Stack.StackName && a.Serial != line.Serial);
if (names.Count() > 0)
{
throw new Exception("库位名称已存在");
}
if (codes.Count() > 0)
{
throw new Exception("库位编号已存在");
}
line.StackCode = Stack.StackCode;
line.StackName = Stack.StackName;
line.Storage_Serial = Stack.Storage_Serial;
line.Storage_Name = Stack.Storage_Name;
line.MUSER = Stack.MUSER;
line.MUSERName = Stack.MUSERName;
line.WorkPoint = AppConfig.WorkPointCode;
line.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss").ToString());
if (isNew) db.ICSStack.InsertOnSubmit(line);
}
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
public static ICSStack select(String guid, String Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
//var StorageLotInfoLog = db.ICSStorageLotInfoLog.Where(a=>a.Stack_Serial==guid);
//if (StorageLotInfoLog.ToList().Count>0)
//{
// throw new Exception("库位正在使用中无法修改!!");
//}
var line = db.ICSStack.SingleOrDefault(a => a.Serial == guid);
return (ICSStack)line;
}
catch (Exception ex)
{
throw ex;
}
}
public static ICSStack selectByCode(String stackcode, String Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
ICSStack entity = new ICSStack();
try
{
var line = db.ICSStack.SingleOrDefault(a => a.StackCode == stackcode);
//entity.Serial = line.Serial;
//entity.StackCode = line.StackCode;
//entity.StackName = line.StackName;
//entity.Storage_Serial = line.Storage_Serial;
//entity.MUSER = line.MUSER;
//entity.MTIME = line.MTIME;
//entity.EATTRIBUTE1 = line.EATTRIBUTE1;
return (ICSStack)line;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
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.ICSStorageLotInfoLog.Where(a => guidList.Contains(a.Stack_Serial));
//if (line.ToList().Count > 0)
//{
// throw new Exception("库位正在使用中无法删除!!");
//}
var lines = db.ICSStack.Where(a => guidList.Contains(a.Serial));
db.ICSStack.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
public static DataTable SelectData() {
String WorkPoint = AppConfig.WorkPointCode;
string sql = @"SELECT [StorageCode] as '库房编号'
,[StorageName] as '库房名称'
FROM ICSStorage where WorkPoint='" + WorkPoint + "'";
object obj = AppConfig.InvokeWebservice(AppConfig.BaseServiceUri, "WebBaseService", "BaseService", "GetMainConnectString", new object[] { });
if (obj == null)
{
throw new Exception("ERP数据库连接失败!");
}
return DBHelper.ExecuteDataset(obj.ToString(), CommandType.Text, sql).Tables[0];
}
}
}