锐腾搅拌上料功能
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.

248 lines
9.9 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 ICSStorageDAL
{
public static void AddAndEdit(ICSStorage Storage, string Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
bool isNew = false;
var line = db.ICSStorage.SingleOrDefault(a => a.Serial == Storage.Serial);
if(line==null){
isNew = true;
line = new ICSStorage();
line.Serial = AppConfig.GetGuid();
}
var names = db.ICSStorage.Where(a => a.StorageName == Storage.StorageName && a.Serial != line.Serial);
var codes = db.ICSStorage.Where(a => a.StorageCode == Storage.StorageCode && a.Serial != line.Serial);
//var StorageLotInfoLog = db.ICSStorageLotInfoLog.SingleOrDefault(a => a.Stack_Serial == Storage.Serial);
var SStack = db.ICSStack.SingleOrDefault(a => a.Storage_Serial == Storage.Serial);
if (names.Count() > 0)
{
throw new Exception("仓库名称已存在");
}
if (codes.Count() > 0)
{
throw new Exception("仓库编号已存在");
}
//if (StorageLotInfoLog != null || SStack != null)
//{
// throw new Exception("库房正在使用中无法修改!!");
//}
line.StorageCode = Storage.StorageCode;
line.StorageName = Storage.StorageName;
line.MUSER=Storage.MUSER;
line.MUSERName = Storage.MUSERName;
line.WorkPoint = AppConfig.WorkPointCode;
line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
if (isNew) db.ICSStorage.InsertOnSubmit(line);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
public static ICSStorage select(String guid, String Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
ICSStorage entity = new ICSStorage();
try
{
var line = db.ICSStorage.SingleOrDefault(a => a.Serial == guid);
//var StorageLotInfoLog = db.ICSStorageLotInfoLog.Where(a=>a.Storage_Serial==guid);
var Stack = db.ICSStack.Where(a =>a.Storage_Serial==guid);
//if (StorageLotInfoLog.ToList().Count > 0 || Stack.ToList().Count> 0)
//{
// throw new Exception("库房正在使用中无法修改");
//}
return (ICSStorage)line;
}
catch (Exception ex)
{
throw ex;
}
}
public static ICSStorage selectByID(String guid, String con)
{
FramDataContext db = new FramDataContext(con);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
ICSStorage entity = new ICSStorage();
try
{
var line = db.ICSStorage.SingleOrDefault(a => a.Serial == guid);
return (ICSStorage)line;
}
catch (Exception ex)
{
throw ex;
}
}
public static ICSStorage selectByCode(String storagecode, String Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var line = db.ICSStorage.SingleOrDefault(a => a.StorageCode == storagecode);
//entity.Serial = line.Serial;
//entity.StorageCode = line.StorageCode;
//entity.StorageName = line.StorageName;
//entity.MUSER = line.MUSER;
//entity.MTIME = line.MTIME;
//entity.EATTRIBUTE1 = line.EATTRIBUTE1;
return (ICSStorage)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.Storage_Serial));
var line1 = db.ICSStack.Where(a => guidList.Contains(a.Storage_Serial));
if (line1.Count() > 0)
{
throw new Exception("库房正在使用中无法删除!!");
}
var lines = db.ICSStorage.Where(a => guidList.Contains(a.Serial));
db.ICSStorage.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
public static void SelectERP(string ERPName)
{
string sql = @"UPDATE b SET b.StorageCode = a.cWhCode,
b.StorageName = a.cWhName,b.EATTRIBUTE1 = CONVERT(NVARCHAR(50),a.dModifyDate,21)
FROM (SELECT cWhCode,cWhName,a.dModifyDate,b.EATTRIBUTE1 FROM {1}.dbo.Warehouse a
LEFT JOIN [dbo].[ICSStorage] b ON a.cWhCode = b.StorageCode
AND a.dModifyDate = b.EATTRIBUTE1
WHERE dWhEndDate IS NULL AND b.StorageCode IS NULL) a
INNER JOIN [ICSStorage] b ON a.cWhCode = b.StorageCode
INSERT INTO [dbo].[ICSStorage]
SELECT NEWID(),cWhCode,cWhName,'',
'',GETDATE(),a.dModifyDate,'{0}' FROM {1}.dbo.Warehouse a
LEFT JOIN [dbo].[ICSStorage] b ON a.cWhCode = b.StorageCode
WHERE dWhEndDate IS NULL AND b.StorageCode IS NULL";
sql = string.Format(sql,AppConfig.WorkPointCode, ERPName);
DBHelper.ExecuteDataset(AppConfig.AppConnectString, CommandType.Text, sql);
//return DBHelper.ExecuteDataset(AppConfig.GetDataBaseConnectStringByKey("[DB.ERP]"), CommandType.Text, sql).Tables[0];
}
public static void SaveInfo(DataTable data, string Appconstr) {
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
for (int i = 0; i < data.Rows.Count; i++)
{
var StorageCode=data.Rows[i]["库房编号"].ToString();
var StorageName=data.Rows[i]["库房名称"].ToString();
ICSStorage code = new ICSStorage();
code.Serial = AppConfig.GetGuid();
code.StorageCode = StorageCode;
code.StorageName = StorageName;
code.MUSER = AppConfig.UserId;
code.MUSERName = AppConfig.UserName;
code.WorkPoint = AppConfig.WorkPointCode;
code.MTIME = Convert.ToDateTime(AppConfig.GetSeverDateTime("yyyy-MM-dd HH:mm:ss").ToString());
db.ICSStorage.InsertOnSubmit(code);
}
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
finally
{
db.Connection.Close();
}
}
public static void SaveConnect(string Connecting,string StorageSerial1,Dictionary<string ,string> ConnList)
{
FramDataContext db = new FramDataContext(Connecting);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
List<string> SerialList = new List<string>();
bool isNew = false;
//foreach (string Serial in ConnList.Keys)
//{
// //var line = db.ICSStorage2Storage.SingleOrDefault(a => a.Serial == Serial);
// //if (line == null)
// //{
// // isNew = true;
// // line = new ICSStorage2Storage();
// // line.Serial = Serial;
// //}
// line.Storage1Serial = StorageSerial1;
// line.Storage2Serial = ConnList[Serial];
// line.MTIME = DateTime.Now;
// line.MUSER = AppConfig.UserId;
// line.MUSERName = AppConfig.UserName;
// SerialList.Add(Serial);
// if (isNew) db.ICSStorage2Storage.InsertOnSubmit(line);
//}
//var lines = db.ICSStorage2Storage.Where(a => a.Storage1Serial == StorageSerial1 && !SerialList.Contains(a.Serial));
//db.ICSStorage2Storage.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
throw ex;
}
}
}
}