华恒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.

159 lines
5.2 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;
namespace ICSSoft.Frame.Data.DAL
{
public class ICSINVInfoDAL
{
#region AddandEdit
public static void AddandEdit(ICSINVInfo inventoryLot, string Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
bool isNew = false;
var line = db.ICSINVInfo.SingleOrDefault(a => a.ID == inventoryLot.ID);
if (line == null)
{
isNew = true;
line = new ICSINVInfo();
line.ID = AppConfig.GetGuid();
}
var codes = db.ICSINVInfo.Where(a => a.INVCODE == inventoryLot.INVCODE && a.ID != line.ID);
if (codes.ToList().Count > 0)
{
throw new Exception("存货编码已存在");
}
line.INVCODE = inventoryLot.INVCODE;
line.INVNAME = inventoryLot.INVNAME;
line.EATTRIBUTE6 = inventoryLot.EATTRIBUTE6;
line.MUSER = inventoryLot.MUSER;
line.MUSERName = inventoryLot.MUSERName;
line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
line.WorkPoint = AppConfig.WorkPointCode;
if (isNew) db.ICSINVInfo.InsertOnSubmit(line);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
#endregion
#region 新增和修改List
public static string AddList(List<ICSINVInfo> InfoList, string dsconn)
{
FramDataContext db = new FramDataContext(dsconn);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
string str = "";
foreach (ICSINVInfo info in InfoList)
{
var code = db.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == info.INVCODE);
if (code==null)
{
str += "存货编码:" + info.INVCODE + "不存在" + "\r\n";
continue;
}
bool isNew = false;
var line = db.ICSINVInfo.SingleOrDefault(a => a.INVCODE == info.INVCODE);
if (line == null)
{
isNew = true;
line = new ICSINVInfo();
line.ID = AppConfig.GetGuid();
}
line.INVCODE = info.INVCODE;
line.INVNAME = info.INVNAME;
line.EATTRIBUTE1 = info.EATTRIBUTE1;
line.EATTRIBUTE4 = info.EATTRIBUTE4;
line.EATTRIBUTE6 = info.EATTRIBUTE6;
line.MUSER = AppConfig.UserCode;
line.MUSERName = AppConfig.UserName;
line.MTIME = DateTime.Now;
line.WorkPoint = AppConfig.WorkPointCode;
if (isNew)
db.ICSINVInfo.InsertOnSubmit(line);
db.SubmitChanges();
}
db.Transaction.Commit();
return str;
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
#region select
public static ICSINVInfo select(String guid, String Appconstr)
{
FramDataContext db = new FramDataContext(Appconstr);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
ICSINVENTORY entity = new ICSINVENTORY();
try
{
var line = db.ICSINVInfo.SingleOrDefault(a => a.ID == guid);
return (ICSINVInfo)line;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion
#region delete
public static void delete(List<String> guidList,List<string> codeList)
{
FramDataContext db = new FramDataContext(AppConfig.AppConnectString);
db.Connection.Open();
db.Transaction = db.Connection.BeginTransaction();
try
{
var lines = db.ICSINVInfo.Where(a => guidList.Contains(a.ID));
db.ICSINVInfo.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
}
}