Esempio n. 1
0
        public static bool DecideUPSCDSI(UPSDatabase db, ProductInfo productInfo,CDSIPO poInfo, out UPSCombinePO combinePo)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
			logger.DebugFormat("BEGIN: {0}()", methodName);
			try	 
            {
                combinePo = null;
                
                if (db.UPSModelEntity.Any(x => x.Model== productInfo.Model && 
                                                                x.Status==EnumUPSModelStatus.Enable.ToString()))
                {
                    combinePo = db.UPSCombinePOEntity.Where(x => x.Model == productInfo.Model &&
                                                                             x.IECPO == poInfo.PO &&
                                                                           (x.Status == EnumUPSCombinePOStatus.Free.ToString() ||
                                                                            x.Status == EnumUPSCombinePOStatus.Release.ToString()))
                                                                            .OrderBy(x=>x.ID).FirstOrDefault();
                    return true;

                }
                else
                {

                    return false;
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
				throw;					
            }
			finally
			{
				logger.DebugFormat("END: {0}()", methodName);
			}
            
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        public static bool AssignCNRSPO(AppConfig config,
                                                       UPSDatabase db,
                                                       ProductInfo productInfo,
                                                       CDSIPO poInfo,
                                                       UPSCombinePO combinePo,                                                      
                                                       out string errorText)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                errorText = string.Empty;
                //Get AVPart Number
                string hpPo = combinePo.HPPO;
                IList<string> avPartNoList = db.UPSPOAVPartEntity.Where(x => x.HPPO == hpPo &&  x.IECPartNo!=null && x.IECPartNo!="" )
                                                            .Select(x=>x.AVPartNo).Distinct().ToList();
                if (avPartNoList == null || avPartNoList.Count == 0)
                {
                    errorText = string.Format("HPPO: {0} Not Find AV PartNo in UPS System", hpPo);
                    return false;
                }

                productInfo.ATSNAV = avPartNoList[0];
                logger.InfoFormat("HPPO: {0}  AVPartNo:{1}", hpPo, avPartNoList[0]);

                ATMStruct ret = GetATM(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO);
                if (ret.retcode < 0 || 
                    string.IsNullOrEmpty(ret.assetTagNum))
                {
                    errorText = string.Format("UPSATM Return:{0} AssetTag:{1}  Message:{2}", ret.retcode.ToString(),ret.assetTagNum??"", ret.message);
                    logger.ErrorFormat(errorText);
                    return false;
                }
                else
                {
                    logger.InfoFormat(" UPSATM Return:{0} Message:{1} Asset Tag:{2}", ret.retcode.ToString(), ret.message, ret.assetTagNum);
                }

                string astNum = ret.assetTagNum;    

                #region write db data
                DateTime now = DateTime.Now;
                SqlConnection dbconnect = (SqlConnection)db.Connection;
                if (dbconnect.State == System.Data.ConnectionState.Closed)
                {
                    dbconnect.Open();
                }
                SqlTransaction dbTxn = dbconnect.BeginTransaction();
                db.Transaction = dbTxn;

                //PoMO
                SQLStatement.InsertCNRSPoMo(dbconnect, dbTxn, poInfo);
               
                //int assignQty = poInfo.DeliveryQty - poInfo.RemainQty;
                //int specialRemainQty = demianOrder.Qty - assignQty;
                //if (specialRemainQty == 1)
                //{
                //    SQLStatement.UpdateSpecialOrderStatus(dbconnect, poInfo.PO, "Closed");
                //}
                //else if (demianOrder.Status.Equals("Created"))
                //{
                //    SQLStatement.UpdateSpecialOrderStatus(dbconnect, poInfo.PO, "Active");
                //}

                //CSIAST table
                SQLStatement.DeleteCDSIAST(dbconnect, dbTxn, productInfo.ProductID);
                SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "DID", "");
                SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "ASSET_TAG", astNum);
                SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "HPOrder", combinePo.HPPO);
                SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "PurchaseOrder", "");
                SQLStatement.WriteCDSIAST(dbconnect, dbTxn, productInfo.ProductID, "FactoryPO", combinePo.IECPO);
                SQLStatement.WriteProductAttr(dbconnect, dbTxn, productInfo.ProductID, "CNRSState", "OK", "CNRS", now); 
              
                //Update UPSCombinePO                        
                combinePo.ProductID = productInfo.ProductID;
                combinePo.CUSTSN = productInfo.CUSTSN;
                combinePo.Status = EnumUPSCombinePOStatus.Used.ToString();
                combinePo.IsShipPO = "CNRS";
                combinePo.Udt = now;
                combinePo.Editor = "UPS.CNRS";
                db.SubmitChanges();

                dbTxn.Commit();
                dbconnect.Close();
                #endregion
                return true;
            }
            catch (Exception e)
            {
                errorText = e.Message;
                logger.Error(e.Message, e);
                return false;
            }
            finally
            {
                if (db.Connection.State == System.Data.ConnectionState.Open)
                {
                    db.Connection.Close();
                }
                logger.DebugFormat("END: {0}()", methodName);
            }


        }
Esempio n. 4
0
        public static bool AssignUPSPO(AppConfig config, 
                                                        UPSDatabase db, 
                                                        ProductInfo productInfo,
                                                        CDSIPO poInfo,    
                                                        UPSCombinePO combinePo,
                                                        out string errorText)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                errorText = string.Empty;
                //ATMStruct ret = GetATM(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO);
                //if (ret.retcode < 0 || string.IsNullOrEmpty(ret.assetTagNum))
                //{
                //    errorText = string.Format(" UPSATM Return:{0} Asset Tag:{1} Message:{2}", ret.retcode.ToString(),ret.assetTagNum??"", ret.message);
                //    logger.ErrorFormat(errorText);
                //    return false;
                //}
                //else
                //{
                //    logger.InfoFormat(" UPSATM Return:{0} Message:{1} Asset Tag:{2}", ret.retcode.ToString(), ret.message, ret.assetTagNum);
                //}
               
                var hppoData=db.UPSHPPOEntity.Where(x=>x.HPPO== combinePo.HPPO).FirstOrDefault();
                string hpSku =hppoData==null?null: hppoData.HPSKU;
                USIStruct returnUSI= GetUSI(productInfo.CUSTSN, productInfo.ATSNAV, combinePo.HPPO,hpSku);
                if (returnUSI.retcode < 0 || string.IsNullOrEmpty(returnUSI.unattend))
                {
                    errorText = string.Format(" UPSUSI Return:{0}  unattend:{1} Message:{2}", returnUSI.retcode.ToString(),returnUSI.unattend ??"", returnUSI.message);
                    logger.ErrorFormat(errorText);                    
                    return false;
                }
                else
                {
                    logger.InfoFormat(" UPSUSI Return:{0} Message:{1} unattend:{2}", returnUSI.retcode.ToString(), returnUSI.message, returnUSI.unattend);
                }

                string unattend = returnUSI.unattend;
                string astNum = null;
                XmlDocument doc =  new XmlDocument();
                doc.LoadXml(unattend);
                XmlNodeList assetTagNodList = doc.GetElementsByTagName("ComputerName");
                XmlNodeList userNodeList = doc.GetElementsByTagName("Credentials");
                XmlNodeList admNodeList = doc.GetElementsByTagName("AdministratorPassword");
                foreach (XmlNode node in assetTagNodList)
                {
                    if (!string.IsNullOrEmpty(node.InnerText))
                    {
                        astNum = node.InnerText;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(astNum))
                {
                    errorText = string.Format("Asset Tag is empty!");
                    logger.ErrorFormat(errorText);
                    return false;
                }
               
                copyUnattend2ImgSrv(config, unattend, productInfo);

                #region write db data
                DateTime now = DateTime.Now;     
               
                if (db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    db.Connection.Open();
                }
                db.Transaction = db.Connection.BeginTransaction();
                //SqlTransaction dbTxn= dbconnect.BeginTransaction();
                //db.Transaction = dbTxn;
                SqlConnection dbconnect = (SqlConnection)db.Connection;

                SqlTransaction transaction = (SqlTransaction)db.Transaction;
                //PoMO
                SQLStatement.InsertCDSIPoMo(dbconnect, transaction, poInfo);

                //CSIAST table
                SQLStatement.DeleteCDSIAST(dbconnect, transaction, productInfo.ProductID);
                SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "DID", "");
                SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "ASSET_TAG", astNum);
                SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "HPOrder", combinePo.HPPO);
                SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "PurchaseOrder", hppoData.EndCustomerPO ?? "");
                SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "FactoryPO", combinePo.IECPO);
                SQLStatement.WriteProductAttr(dbconnect, transaction, productInfo.ProductID, "CDSIState", "OK", "CDSI", now);

                foreach (XmlNode node in userNodeList)
                {
                    foreach (XmlNode cnode in node.ChildNodes)
                    {
                        SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, cnode.Name, cnode.InnerText);                      
                    }          
                }

                foreach (XmlNode node in admNodeList)
                {
                    foreach (XmlNode cnode in node.ChildNodes)
                    {
                        if (cnode.Name.ToLower() == "value")
                        {
                            SQLStatement.WriteCDSIAST(dbconnect, transaction, productInfo.ProductID, "AdministratorPassword", cnode.InnerText);
                        }
                    }
                }


                //Update UPSCombinePO                        
                combinePo.ProductID = productInfo.ProductID;
                combinePo.CUSTSN = productInfo.CUSTSN;
                combinePo.Status = EnumUPSCombinePOStatus.Used.ToString();
                combinePo.IsShipPO = "CDSI";
                combinePo.Udt = now;               
                combinePo.Editor = "UPS.CDSI";
                db.SubmitChanges();

                db.Transaction.Commit();
                db.Connection.Close(); 
               
                #endregion
                return true;
            }
            catch (Exception e)
            {
                errorText = e.Message;
                logger.Error(e.Message, e);
                return false;
            }
            finally
            {
               if (db.Connection.State == System.Data.ConnectionState.Open)
                {
                    db.Connection.Close();
                }
                logger.DebugFormat("END: {0}()", methodName);
            }
           

        }