示例#1
0
文件: MESData.cs 项目: wra222/testgit
        public static void UpdateUPSModel(AppConfig config,
                                                                UPSDatabase db,
                                                                HPPO dbPo,
                                                                 UPSPOBOM poBom,
                                                                 string editor)
        {

            DateTime now = DateTime.Now;
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                if (db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    db.Connection.Open();
                }
               db.Transaction = db.Connection.BeginTransaction();
               dbPo.IECPOList.ForEach(n =>
                    {
                        n.Udt = now;
                        var upsModel = db.UPSModelEntity.Where(x => x.Model == n.Model).FirstOrDefault();
                        if (upsModel == null)
                        {
                            upsModel = new UPSModel
                            {
                                Model = n.Model,
                                FirstReceiveDate = dbPo.PO.ReceiveDate,
                                LastReceiveDate = dbPo.PO.ReceiveDate,
                                Remark = "NEW",
                                Status = EnumUPSModelStatus.Enable.ToString(),
                                Editor = dbPo.PO.Editor,
                                Cdt = now,
                                Udt = now
                            };
                            db.UPSModelEntity.InsertOnSubmit(upsModel);
                            db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                        }
                        //else
                        //{
                        //    upsModel.LastReceiveDate = dbPo.PO.ReceiveDate;
                        //    upsModel.Udt = now;
                        //}
                    });
                

                db.Transaction.Commit();
                //db.Connection.Close();
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                if (db.Transaction != null && db.Transaction.Connection != null)
                {
                    db.Transaction.Rollback();
                }
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
示例#2
0
文件: MESData.cs 项目: wra222/testgit
        public static void TestDB(AppConfig config,
                                     UPSDatabase db)
        {
            //UPSDatabase db = new UPSDatabase(config.DBConnectStr);
            DateTime now = DateTime.Now;

            var upsModelList = db.UPSModelEntity.Where(x => x.Remark == "NEW").ToList();
            db.Connection.Close();

            if (db.Connection.State == System.Data.ConnectionState.Closed)
            {
                db.Connection.Open();
            }

            db.Transaction = db.Connection.BeginTransaction();
            foreach (var item in upsModelList)
            {
                item.Udt = now;
            }



            var upsModel = db.UPSModelEntity.Where(x => x.Model == "testModel").FirstOrDefault();
            if (upsModel == null)
            {
                upsModel = new UPSModel
                {
                    Model = "testModel",
                    FirstReceiveDate = now,
                    LastReceiveDate = now,
                    Remark = "NEW",
                    Status = EnumUPSModelStatus.Enable.ToString(),
                    Editor = string.Empty,
                    Cdt = now,
                    Udt = now
                };
                db.UPSModelEntity.InsertOnSubmit(upsModel);
                db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
            }
            db.Transaction.Commit();
            if (db.Transaction == null)
            {
                Console.WriteLine("null transaction!!");
            }
            db.Transaction = db.Connection.BeginTransaction();
            var upsModel1 = db.UPSModelEntity.Where(x => x.Model == "testModel").FirstOrDefault();
            if (upsModel1 == null)
            {
                upsModel1 = new UPSModel
                {
                    Model = "testModel",
                    FirstReceiveDate = now,
                    LastReceiveDate = now,
                    Remark = "NEW",
                    Status = EnumUPSModelStatus.Enable.ToString(),
                    Editor = string.Empty,
                    Cdt = now,
                    Udt = now
                };
                db.UPSModelEntity.InsertOnSubmit(upsModel1);
                db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
            }

            db.Transaction.Commit();
           
            //db.Connection.Close();
        }
示例#3
0
文件: MESData.cs 项目: wra222/testgit
        public static void UpdateUPSHPPO(AppConfig config, 
                                                                UPSDatabase db, 
                                                                HPPO dbPo, 
                                                                 UPSPOBOM poBom, 
                                                                 string editor)
        {
            DateTime now = DateTime.Now;
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                //UPSDatabase db = new UPSDatabase(config.DBConnectStr);

                if (db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    db.Connection.Open();
                }
                
                db.Transaction = db.Connection.BeginTransaction();

                if (dbPo.PO.Status != poBom.State.ToString())
                {
                    dbPo.PO.Status = poBom.State.ToString();
                    dbPo.PO.ErrorText = poBom.ErrorText;
                    dbPo.PO.Udt = now;
                    //db.UPSHPPOEntity.Attach(dbPo.PO, true);
                }

                if (poBom.State == SendBOMState.VerifyOK)
                {
                    //產生UPSCombinePO
                    List<UPSCombinePO> UPSCombinePOList = new List<UPSCombinePO>();
                    List<UPSIECPO> IECPOList = null;
                    if (dbPo.isWithdraw)
                    {
                        IECPOList = dbPo.WithdrawIECPOList;
                        foreach (UPSIECPO iecpo in dbPo.IECPOList)
                        {
                            if (iecpo.Editor == "Withdraw")
                            {
                                iecpo.Editor = "UPS-" + iecpo.Editor;
                                iecpo.Udt = now;
                            }
                        }

                        foreach (UPSPOAVPart avpart in dbPo.PartNoList)
                        {
                            if (avpart.Editor == "Withdraw")
                            {
                                avpart.Editor = "UPS-" + avpart.Editor;
                                avpart.Udt = now;
                            }
                        }
                    }
                    else
                    {
                        IECPOList = dbPo.IECPOList;
                    }

                    IECPOList.ForEach(n =>
                    {
                        //n.Status = SendBOMState.VerifyOK.ToString();
                        n.Udt = now;
                        var upsModel = db.UPSModelEntity.Where(x => x.Model == n.Model).FirstOrDefault();
                        if (upsModel == null)
                        {
                            upsModel = new UPSModel
                            {
                                Model = n.Model,
                                FirstReceiveDate = dbPo.PO.ReceiveDate,
                                LastReceiveDate = dbPo.PO.ReceiveDate,
                                Remark = string.Empty,
                                Status = EnumUPSModelStatus.Enable.ToString(),
                                Editor = dbPo.PO.Editor,
                                Cdt = now,
                                Udt = now
                            };
                            db.UPSModelEntity.InsertOnSubmit(upsModel);
                        }
                        else
                        {
                            upsModel.LastReceiveDate = dbPo.PO.ReceiveDate;
                            upsModel.Udt = now;
                        }

                        int qty = n.Qty;
                        for (int i = 0; i < qty; i++)
                        {
                            UPSCombinePO combinePO = new UPSCombinePO
                            {
                                HPPO = dbPo.PO.HPPO,
                                IECPO = n.IECPO,
                                IECPOItem = n.IECPOItem,
                                Model = n.Model,
                                ReceiveDate = dbPo.PO.ReceiveDate,
                                ProductID = string.Empty,
                                CUSTSN = string.Empty,
                                Station = string.Empty,
                                IsShipPO = "N",
                                Status = EnumCombinePoState.Free.ToString(),
                                Remark = string.Empty,
                                Editor = editor,
                                Cdt = now,
                                Udt = now
                            };
                            UPSCombinePOList.Add(combinePO);
                        }
                    });

                    DataTableHelper.BulkCopyToDatabase(UPSCombinePOList,
                                                                                "UPSCombinePO",
                                                                                (SqlConnection)db.Connection,
                                                                                (SqlTransaction)db.Transaction);
                }
               
                db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                
                db.Transaction.Commit();
                // db.Connection.Close();
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                if (db.Transaction != null && db.Transaction.Connection != null)
                {
                    db.Transaction.Rollback();
                }
                
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }