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

220 lines
9.0 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 System.Data.SqlClient;
namespace ICSSoft.Frame.Data.DAL
{
public class ICSINVENTORYDAL
{
#region AddandEdit
public static void AddandEdit(ICSINVENTORY inventoryLot, string Appconstr)
{
//FramDataContext db = new FramDataContext(Appconstr);
//db.Connection.Open();
//db.Transaction = db.Connection.BeginTransaction();
SqlConnection conn = new System.Data.SqlClient.SqlConnection(Appconstr);
conn.Open();
SqlTransaction sqlTran = conn.BeginTransaction();
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 180;
cmd.Transaction = sqlTran;
cmd.Connection = conn;
try
{
string sql = @"UPDATE ICSINVENTORY SET INVMACHINETYPE='{0}',INVCONTROLTYPE='{5}',MUSER='{1}',MUSERName='{2}',MTIME='{3}'
WHERE ID='{4}'";
sql = string.Format(sql, inventoryLot.INVMACHINETYPE, inventoryLot.MUSER, inventoryLot.MUSERName, inventoryLot.MTIME, inventoryLot.ID, inventoryLot.INVCONTROLTYPE);
cmd.CommandText = sql;
int result = cmd.ExecuteNonQuery();
if (result <= 0)
{
throw new Exception("修改失败");
}
cmd.Transaction.Commit();
//bool isNew = false;
//var line = db.ICSINVENTORY.SingleOrDefault(a => a.ID == inventoryLot.ID);
//if (line == null)
//{
// isNew = true;
// line = new ICSINVENTORY();
// line.ID = AppConfig.GetGuid();
//}
//var codes = db.ICSINVENTORY.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.INVDESC = inventoryLot.INVDESC;
//line.INVUOM = inventoryLot.INVUOM;
//line.INVTYPE = inventoryLot.INVTYPE;
//line.INVCLASS = inventoryLot.INVCLASS;
//line.INVMACHINETYPE = inventoryLot.INVMACHINETYPE;
//line.INVVOLUME = inventoryLot.INVVOLUME;
//line.INVMODELCODE = inventoryLot.INVMODELCODE;
//line.INVEXPORTIMPORT = inventoryLot.INVEXPORTIMPORT;
//line.INVMODELGROUP = inventoryLot.INVMODELGROUP;
//line.INVGROUP = inventoryLot.INVGROUP;
//line.INVGROUPDESC = inventoryLot.INVGROUPDESC;
//line.INVCONTROLTYPE = inventoryLot.INVCONTROLTYPE;
//line.MUSER = inventoryLot.MUSER;
//line.MUSERName = inventoryLot.MUSERName;
//line.MTIME = AppConfig.GetSeverDateTime("yyyy-MM-dd hh:mm:ss");
//line.WorkPoint = AppConfig.WorkPointCode;
//line.EATTRIBUTE1 = null;
//line.INVPARSETYPE = inventoryLot.INVPARSETYPE;
//line.CHECKSTATUS = inventoryLot.CHECKSTATUS;
//line.INVCHECKTYPE = inventoryLot.INVCHECKTYPE;
//line.SNLENGTH = inventoryLot.SNLENGTH;
//line.VENDORCODE = inventoryLot.VENDORCODE;
//line.ROHS = inventoryLot.ROHS;
//line.NeedVendor = inventoryLot.NeedVendor;
//line.INVShelfLife = inventoryLot.INVShelfLife;
//line.INVCARTONQTY = inventoryLot.INVCARTONQTY;
//line.ITEMBURNINQTY = inventoryLot.ITEMBURNINQTY;
//line.ELECTRICCURRENTMINVALUE = inventoryLot.ELECTRICCURRENTMINVALUE;
//line.ELECTRICCURRENTMAXVALUE = inventoryLot.ELECTRICCURRENTMAXVALUE;
//line.PCBACOUNT = inventoryLot.PCBACOUNT;
//line.CHKITEMOP = inventoryLot.CHKITEMOP;
//line.ISSMT = inventoryLot.ISSMT;
//if (isNew) db.ICSINVENTORY.InsertOnSubmit(line);
//db.SubmitChanges();
//db.Transaction.Commit();
}
catch (Exception ex)
{
cmd.Transaction.Rollback();
//db.Transaction.Rollback();
throw new Exception(ex.Message);
}
}
#endregion
#region select
public static ICSINVENTORY 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.ICSINVENTORY.SingleOrDefault(a => a.ID == guid);
return (ICSINVENTORY)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.ICSINVENTORY.Where(a => guidList.Contains(a.ID));
var line = db.ICSITEMROUTE2OP.Where(a => codeList.Contains(a.ITEMCODE));
if (line.Count() != 0)
{
throw new Exception("存货编码在产品、途程和工序的关系维护中已经使用,无法删除!");
}
var line1 = db.ICSITEM2ROUTE.Where(a => codeList.Contains(a.ITEMCODE));
if (line1.Count() != 0)
{
throw new Exception("存货编码在产品和途程的关系维护中已经使用,无法删除!");
}
var line2 = db.ICSSBOM.Where(a => codeList.Contains(a.ITEMCODE));
if (line2.Count() != 0)
{
throw new Exception("存货编码在标准BOM中已经使用,无法删除!");
}
var line3 = db.ICSOPBOM.Where(a => codeList.Contains(a.ITEMCODE));
if (line3.Count() != 0)
{
throw new Exception("存货编码在工序BOM中已经使用,无法删除!");
}
var line4 = db.ICSOPBOMDETAIL.Where(a => codeList.Contains(a.ITEMCODE));
if (line4.Count() != 0)
{
throw new Exception("存货编码在工序BOM详细信息中已经使用,无法删除!");
}
var line5 = db.ICSShipToStock.Where(a => codeList.Contains(a.ITEMCODE));
if (line5.Count() != 0)
{
throw new Exception("存货编码在免检物料表中已经使用,无法删除!");
}
var line6 = db.ICSINVReceiptDetail.Where(a => codeList.Contains(a.ITEMCODE));
if (line6.Count() != 0)
{
throw new Exception("存货编码在入库单详细表中已经使用,无法删除!");
}
var line7 = db.ICSWareHouseLotInfo.Where(a => codeList.Contains(a.INVCode));
if (line7.Count() != 0)
{
throw new Exception("存货编码在物料,产品批次的库存信息中已经使用,无法删除!");
}
var line8 = db.ICSInvTransferDetail.Where(a => codeList.Contains(a.ITEMCODE));
if (line8.Count() != 0)
{
throw new Exception("存货编码在库存移转单详细表中已经使用,无法删除!");
}
db.ICSINVENTORY.DeleteAllOnSubmit(lines);
db.SubmitChanges();
db.Transaction.Commit();
}
catch (Exception ex)
{
db.Transaction.Rollback();
throw ex;
}
}
#endregion
#region find
public static string find(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.ICSINVENTORY.SingleOrDefault(a => a.INVCODE == guid);
return line.INVCONTROLTYPE;
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
#endregion
}
}