using System; using System.Collections.Generic; using System.Linq; using System.Text; using ICSSoft.Frame.Data.DAL; using ICSSoft.Frame.Data.Entity; namespace ICSSoft.Frame.Data.BLL { public class ICSCollectBLL { public static void Save(string Appconstr, ICSLOTSIMULATION simulation) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //校验传入数据是否符合采集要求 ICSCollectDAL.CheckInfo(db, simulation); //保存数据 ICSCollectDAL.Save(db, simulation); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static string SaveList(string Appconstr, List onwiplist, List polist, List loglist) { string errormessage = ""; FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); foreach (ICSLOTONWIP info in onwiplist) { //校验传入数据是否符合采集要求 string opmessage = ICSCollectDAL.CheckInfoWW(db, info); //校验工艺路线是否有新增工序且未派工 string routemessage = ICSCollectDAL.CheckRoute(db, info); if (opmessage == "" && routemessage == "") { //保存数据 ICSCollectDAL.Save(db, info); } else { errormessage += opmessage + routemessage; } } if (errormessage == "") { //采购订单已发数量更新 foreach (ICSPO_PoMain info in polist) { ICSCollectDAL.UpdatePOInfo(db, info); } //日志表条码对应采购订单信息记录 foreach (ICSWareHouseLotInfoLog info in loglist) { ICSCollectDAL.AddLogInfo(db, info); } } db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); return errormessage; } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static string SaveList(string Appconstr, List infolist, List listOnwip, List polist, List loglist) { string errormessage = ""; FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); foreach (ICSLOTONWIP info in listOnwip) { //校验传入数据是否符合采集要求 string opmessage = ICSCollectDAL.CheckInfoWW(db, info); //校验工艺路线是否有新增工序且未派工 string routemessage = ICSCollectDAL.CheckRoute(db, info); if (opmessage == "" && routemessage == "") { //保存数据 ICSCollectDAL.Save(db, info); } else { errormessage += opmessage + routemessage; } } if (errormessage == "") { //采购订单已发数量更新 foreach (ICSPO_PoMain info in polist) { ICSCollectDAL.UpdatePOInfo(db, info); } //日志表条码对应采购订单信息记录 foreach (ICSWareHouseLotInfoLog info in loglist) { ICSCollectDAL.AddLogInfo(db, info); } } db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); return errormessage; } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void CheckListEnd(string Appconstr, List infolist) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //foreach (ICSLOTSIMULATION info in infolist) //{ // //校验传入数据是否符合采集要求 // ICSCollectDAL.CheckInfo(db, info); // //保存数据 // ICSCollectDAL.Save(db, info); //} //批量委外自动开工完工 ICSCollectDAL.CheckListEnd(db, infolist); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void SaveListEnd(string Appconstr, List infolist) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //foreach (ICSLOTSIMULATION info in infolist) //{ // //校验传入数据是否符合采集要求 // ICSCollectDAL.CheckInfo(db, info); // //保存数据 // ICSCollectDAL.Save(db, info); //} //批量委外自动开工完工 ICSCollectDAL.CheckAutoOP(db, infolist); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void Transfer(string Appconstr, ICSLOTSIMULATION simulation) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //校验传入数据是否符合采集要求 ICSCollectDAL.CheckTransferInfo(db, simulation); //保存数据 ICSCollectDAL.Transfer(db, simulation); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void SaveItem(string Appconstr, ICSLOTONWIPITEM simulation) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //校验传入数据是否符合采集要求 ICSCollectDAL.CheckItemInfo(db, simulation); //保存数据 ICSCollectDAL.SaveItem(db, simulation); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void Pause(string Appconstr, ICSLOTSIMULATION simulation) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //校验传入数据是否符合采集要求 ICSLOTSIMULATION sim = db.ICSLOTSIMULATION.SingleOrDefault(a => a.LOTNO == simulation.LOTNO && a.OPCODE == simulation.OPCODE); if (sim == null) { throw new Exception("该批次工序不是在制品不可暂停!"); } else if (sim.CollectStatus.Equals("COLLECT_END")) { throw new Exception("该工序已经完工,不能暂停!"); } else if (sim.LOTStatus.Equals("暂停")) { throw new Exception("该批次工序已经暂停!"); } //保存数据 ICSCollectDAL.Pause(db, sim); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } public static void CancelPause(string Appconstr, ICSLOTSIMULATION simulation) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //保存数据 ICSCollectDAL.CancelPause(db, simulation); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } //结算料费 public static void Calculate(string Appconstr, List list) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); //保存数据 ICSCollectDAL.Calculate(db, list, "不合格"); db.SubmitChanges(); db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } //第一次判定 //public static void FirstResult(string Appconstr, List list, List idList) //{ // FramDataContext db = new FramDataContext(Appconstr); // db.Connection.Open(); // db.Transaction = db.Connection.BeginTransaction(); // try // { // if (string.IsNullOrWhiteSpace(Appconstr)) // throw new Exception("连接字符串不能为空!"); // //保存数据 // ICSCollectDAL.FirstResult(db, list, idList); // db.SubmitChanges(); // db.Transaction.Commit(); // db.Connection.Close(); // } // catch (Exception ex) // { // db.Transaction.Rollback(); // db.Connection.Close(); // throw ex; // } //} ////第二次判定 //public static void SecondResult(string Appconstr, List list, List idList) //{ // FramDataContext db = new FramDataContext(Appconstr); // db.Connection.Open(); // db.Transaction = db.Connection.BeginTransaction(); // try // { // if (string.IsNullOrWhiteSpace(Appconstr)) // throw new Exception("连接字符串不能为空!"); // //保存数据 // ICSCollectDAL.SecondResult(db, list, idList); // db.SubmitChanges(); // db.Transaction.Commit(); // db.Connection.Close(); // } // catch (Exception ex) // { // db.Transaction.Rollback(); // db.Connection.Close(); // throw ex; // } //} #region 获取跟踪单当前的采集信息 public static ICSLOTSIMULATION GetSimInfoByLotNo(string LotNo, string dsconn) { try { return ICSCollectDAL.GetSimInfoByLotNo(LotNo, dsconn); } catch (Exception ex) { throw ex; } } #endregion #region 检查当前检验的工序是否是委外工(True:委外,Flase:非委外) public static bool GetLotOPInfoByCode(string LotNo, string OPCode, string dsconn) { try { return ICSCollectDAL.GetLotOPInfoByCode(LotNo, OPCode, dsconn); } catch (Exception ex) { throw ex; } } #endregion //public static void TResult(string Appconstr, List list) //{ // FramDataContext db = new FramDataContext(Appconstr); // db.Connection.Open(); // db.Transaction = db.Connection.BeginTransaction(); // try // { // if (string.IsNullOrWhiteSpace(Appconstr)) // throw new Exception("连接字符串不能为空!"); // //保存数据 // ICSCollectDAL.TResult(db, list); // db.SubmitChanges(); // db.Transaction.Commit(); // db.Connection.Close(); // } // catch (Exception ex) // { // db.Transaction.Rollback(); // db.Connection.Close(); // throw ex; // } //} #region GetModel //public static ICSLOTONWIPCheck GetModel(string id, string dsconn) //{ // try // { // return ICSCollectDAL.GetModel(id, dsconn); // } // catch (Exception ex) // { // throw ex; // } //} #endregion #region AddPDF public static void AddPDF(string id, string fname, string dsconn) { try { ICSCollectDAL.AddPDF(id, fname, dsconn); } catch (Exception ex) { throw ex; } } #endregion //public static void RResult(string Appconstr, List list) //{ // FramDataContext db = new FramDataContext(Appconstr); // db.Connection.Open(); // db.Transaction = db.Connection.BeginTransaction(); // try // { // if (string.IsNullOrWhiteSpace(Appconstr)) // throw new Exception("连接字符串不能为空!"); // //保存数据 // ICSCollectDAL.RResult(db, list); // db.SubmitChanges(); // db.Transaction.Commit(); // db.Connection.Close(); // } // catch (Exception ex) // { // db.Transaction.Rollback(); // db.Connection.Close(); // throw ex; // } //} //删除开工未完工的记录 public static void DataDelete(string Appconstr, List infolist, List wwinfolist) { FramDataContext db = new FramDataContext(Appconstr); db.Connection.Open(); db.Transaction = db.Connection.BeginTransaction(); try { if (string.IsNullOrWhiteSpace(Appconstr)) throw new Exception("连接字符串不能为空!"); if (infolist.Count != 0) { ICSCollectDAL.DataDelete(db, infolist); } if (wwinfolist.Count != 0) { ICSCollectDAL.DataDeleteForWW(db, wwinfolist); } db.Transaction.Commit(); db.Connection.Close(); } catch (Exception ex) { db.Transaction.Rollback(); db.Connection.Close(); throw ex; } } #region 判断第二次检验是否与第一次检验相同(True:相同;False:不同) //public static string CheckFSDifferent(string Appconstr, List infolist, List LotNO, List OPCode) //{ // FramDataContext db = new FramDataContext(Appconstr); // db.Connection.Open(); // db.Transaction = db.Connection.BeginTransaction(); // try // { // string Result = ICSCollectDAL.CheckFSDifferent(db, infolist, LotNO, OPCode); // db.Connection.Close(); // return Result; // } // catch (Exception ex) // { // db.Connection.Close(); // throw new Exception(ex.Message); // } //} #endregion /// /// 委外发料/收料 /// /// 是否是发料 /// ds中的dt为每个跟踪单连续委外工序信息 /// 套接字 public static void OutsourceSubmit(bool send, System.Data.DataSet ds, string conn) { ICSCollectDAL.OutsourceSubmit(send, ds, conn); } public static void DeleteWW(System.Data.DataSet ds, string conn) { ICSCollectDAL.DeleteWW(ds, conn); } } }