Exemplo n.º 1
0
        //public static void Init( AppConfig config)
        public static void Init()
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
            try
            {        
                    _config = new AppConfig();
                    queue.Clear();
                    cacheManager.Flush();
                    configAdapter.ConfigSectionChanged += new ConfigurationSectionAdapter.ConfigChangedHandler(configAdapter_ConfigSectionChanged);
                    watcher.EnableRaisingEvents = false;

                    
                    if (_config.IsNeesBackUpAfterCompleted)
                    {
                        CheckFileOnStart();
                    }

                    threadCount = new Semaphore(_config.ThreadCount, _config.ThreadCount);
                    watcher.Filter = _config.FileFilter;
                    logger.Debug(" watcher.Filter:" + _config.FileFilter);
                    watcher.Path = _config.FolderPath;
                    logger.Debug(" watcher.Path:" + _config.FolderPath);
                    watcher.IncludeSubdirectories =_config.IncludeSubdirectories;
                    logger.Debug("watcher.IncludeSubdirectories:" + _config.IncludeSubdirectories);
                    logger.Debug("_config.IsNeesBackUpAfterCompleted:" + _config.IsNeesBackUpAfterCompleted);

                    if (_config.IsNeesBackUpAfterCompleted)
                    {
                       
                        watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
                        watcher.Created += OnChanged;
                    }
                    else
                    {
                        watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName|NotifyFilters.LastWrite;
                        watcher.Changed += OnChanged;
                    }                  
                    
                    //watcher.Deleted += OnDeleted;
                    //watcher.Renamed += OnRenamed;
                    Thread dealWithData = new Thread(OnDealWithData);

                    if (_config.IsNeesBackUpAfterCompleted)
                    {
                        if (!Directory.Exists(_config.FailFileFolder))
                        {
                            Directory.CreateDirectory(_config.FailFileFolder);
                        }
                        if (!Directory.Exists(_config.SuccessFileFolder))
                        {
                            Directory.CreateDirectory(_config.SuccessFileFolder);
                        }
                    }

                    dealWithData.Start();
                    watcher.Disposed += OnDisposed;
                    watcher.Error += OnError;
                   
                    watcher.InternalBufferSize = _config.InternalBufferSize * 1024; // 64K
                    logger.Debug("Set watcher.InternalBufferSize = " + _config.InternalBufferSize.ToString() + "K");
                    watcher.EnableRaisingEvents = true;
                    logger.Debug("Set watcher.EnableRaisingEvents = true" );
            }
            catch(Exception e)
            {
                if (wicCdsi != null)
                {
                    Logon.Log_off(wicCdsi);
                }
                logger.Error(methodName, e);
                
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }

        }
Exemplo n.º 2
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);
            }


        }
Exemplo n.º 3
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);
            }
           

        }
Exemplo n.º 4
0
        static void configAdapter_ConfigSectionChanged()
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
             try
            {
                AppConfig config = new AppConfig();
                
                _config = config;
            }
             catch (Exception ex)
             {
                 logger.Error(methodName, ex);

             }
             finally
             {
                 logger.InfoFormat("END: {0}()", methodName);
             }
        }
Exemplo n.º 5
0
        static private void SendCDSIUpdateCmd(SqlConnection dbconnect,
                                                                           Log log,
                                                                           AppConfig config,
                                                                           ProductInfo productInfo,
                                                                           string po,
                                                                           bool isLinkPO,
                                                                           ref string msg)
        {
            string localmsg = "";
            // write link PO cmd in LocalSN2POFolder
            #region send CDSI Cmd
            WindowsImpersonationContext wicCdsi = null;
            if (isLinkPO)
            {
                if (!string.IsNullOrEmpty(config.CDSIServerUser))
                    wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                  config.CDSIDomain,
                                                                                  config.CDSIServerPassword,
                                                                                  log);

                CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder,
                                                                productInfo.CUSTSN,
                                                                po, config.CDSISN2POFolder);
                log.write(LogType.Info, 0, "Write Cmd", "SendCDSIUpdateCmd", "CDSIFile.LinkPO_Cmd1");

            }

            CDSIFile.SignUp_Cmd2(config.LocalMAILBOXFolder,
                                                            productInfo.CUSTSN,
                                                            productInfo.MAC,
                                                            config.CDSIMAILBOXFolder);
            log.write(LogType.Info, 0, "Write Cmd", "SendCDSIUpdateCmd", "CDSIFile.SignUp_Cmd2");
            //Thread.Sleep(config.CDSICmdInterval);

            CDSIFile.OMSUPDATE_Cmd3(config.LocalMAILBOXFolder,
                                                                         productInfo.CUSTSN,
                                                                         productInfo.MAC,
                                                                         productInfo.ATSNAV,
                                                                         productInfo.MN1,
                                                                         productInfo.SYSID,
                                                                         config.CDSIMAILBOXFolder);
            log.write(LogType.Info, 0, "Write Cmd", "SendCDSIUpdateCmd", " CDSIFile.OMSUPDATE_Cmd3");
            // don't sleep          
            //Vincent add check result
            enumCDSIResult result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                     config.CDSIMAILBOXFolder,
                                                                                   productInfo.CUSTSN,
                                                                                    productInfo.MAC);
            if (result1 == enumCDSIResult.NotFound)
            {
                #region retry again and sleep 5 sec               
                result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                              config.CDSIMAILBOXFolder,
                                                                              productInfo.CUSTSN,
                                                                              productInfo.MAC);
                #endregion
            }

            if (result1 == enumCDSIResult.Err || result1 == enumCDSIResult.NotFound)
            {
                #region write error message
                //send  error email
                localmsg = "<br/> OMSUPDATE_Cmd3 CDSIResultFile -- ProductID:" + productInfo.ProductID + "  CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" +
                            (result1 == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") +
                           " Please Check CDSI Server, Error Message:";

                msg = msg + localmsg;

                if (result1 == enumCDSIResult.Err)
                {
                    string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR");
                    msg = msg + "<br/>" + string.Join("<br/>", data);
                    localmsg = localmsg + "<br/>" + string.Join("<br/>", data);
                }

                log.write(LogType.error, AppDomain.CurrentDomain.Id, "SendCDSIUpdateCmd",
                               "OMSUPDATE_CDSIResultFile",
                               localmsg);

                #endregion
            }
            else
            {
                log.write(LogType.Info, AppDomain.CurrentDomain.Id, "SendCDSIUpdateCmd",
                              "OMSUPDATE_CDSIResultFile",
                              "Get Ack file");
            }

          

            #endregion

           

            #region SIGNOFF Cmd

            if (!string.IsNullOrEmpty(config.CDSIServerUser))
                wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                              config.CDSIDomain,
                                                                              config.CDSIServerPassword,
                                                                              log);

            CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder,
                                                           productInfo.CUSTSN,
                                                           productInfo.MAC,
                                                           config.CDSIMAILBOXFolder);
            log.write(LogType.Info, 0, "Write Cmd", "SendCDSIUpdateCmd", "CDSIFile.SIGNOFF_Cmd5");

            if (wicCdsi != null)
            {
                UTL.Logon.Log_off(wicCdsi);

            }
            //Disable sleep  Vincent
            //Thread.Sleep(config.CDSICmdInterval);
            #endregion
            



        }
Exemplo n.º 6
0
        private static void copyUnattend2ImgSrv(AppConfig config, string unattend, ProductInfo productInfo)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
			logger.DebugFormat("BEGIN: {0}()", methodName);
            WindowsImpersonationContext wicCdsi = null;

			try	 
            {

                if (!string.IsNullOrEmpty(config.IMGServerUser))
                {
                    wicCdsi = Logon.ImpersinateUser(config.IMGServerUser,
                                                                                  config.IMGDomain,
                                                                                  config.IMGServerPassword);
                }
                string srcPath = config.IMGFolder + productInfo.CUSTSN + "-" + productInfo.MAC + "\\";
                string destPathFile = srcPath + "unattend.xml";
                FileOperation.CreateDirectory(srcPath);
                logger.InfoFormat(" Copy imgServer File : {0}", destPathFile);
                File.WriteAllText(destPathFile, unattend);
             }
            catch (Exception e)
            {

                logger.Error(e.Message, e);
				throw;					
            }
			finally
			{
                if (wicCdsi != null)
                {
                    Logon.Log_off(wicCdsi);

                }
				logger.DebugFormat("END: {0}()", methodName);
			}
           

        }
Exemplo n.º 7
0
        static private void SendCDSIPOLinkCmd(SqlConnection dbconnect,
                                                   Log log,
                                                   AppConfig config,
                                                    ProductInfo productInfo,
                                                    string po,
                                                   ref string msg)
        {
            WindowsImpersonationContext wicCdsi = null;
            if (!string.IsNullOrEmpty(config.CDSIServerUser))
                wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                              config.CDSIDomain,
                                                                              config.CDSIServerPassword,
                                                                              log);

            CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder,
                                                            productInfo.CUSTSN,
                                                            po, config.CDSISN2POFolder);
            log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.LinkPO_Cmd1");

        }
Exemplo n.º 8
0
        public static  void SendCDSIPOLinkCmd(SqlConnection dbconnect,                                                
                                                  AppConfig config,
                                                   ProductInfo productInfo,
                                                   string po,
                                                  ref string msg)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                WindowsImpersonationContext wicCdsi = null;
                if (!string.IsNullOrEmpty(config.CDSIServerUser))
                    wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                  config.CDSIDomain,
                                                                                  config.CDSIServerPassword );

                CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder,
                                                                productInfo.CUSTSN,
                                                                po, config.CDSISN2POFolder);
                logger.Debug("CDSIFile.LinkPO_Cmd1");
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
            

        }
Exemplo n.º 9
0
        static void Main(string[] args)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                //if (File.Exists(@"\\10.99.183.50\fsm_com\Mailbox\CNU23090R7-28924AD3C1D7.ACK"))
                //{
                //    Console.WriteLine(@"CheckCDSIResult  find \\10.99.183.50\fsm_com\Mailbox\CNU23090R7-28924AD3C1D7.ACK Ack file!!");

                //}
                if (!ExecShell.CheckOneProcessRun())
                {
                    return;
                }

                AppConfig config = new AppConfig();
                string msg = "";
                string localmsg = "";

                //Log log = new Log(config.logPath, config.logPrefixName);
                //log.write(LogType.Info, 0, "Main" , "", "Start Program...");
                try
                {
                    SqlConnection dbconnect = new SqlConnection(config.DBConnectStr);
                    dbconnect.Open();
                    logger.DebugFormat("connected with HPIMES DB", "OK");

                    SqlConnection CdsiDbconnect = new SqlConnection(config.CDSIDBConnectStr);
                    CdsiDbconnect.Open();
                    logger.DebugFormat("connected with CDSI DB", "OK");

                    List<string> SnoIdList = SQLStatement.GetCDSISNList(dbconnect,  config.OffsetDay);
                    logger.DebugFormat("Send Link CDSI PO.........................");
                    List<ProductInfo> AssignedPOList = new List<ProductInfo>();
                    List<ProductInfo> UPSAssignedPOList = new List<ProductInfo>();

                    #region send PO Link to CDSI Server
                    foreach (string snoId in SnoIdList)
                    {
                        #region //0.Check ProductID info
                        ProductInfo productInfo = SQLStatement.GetProductInfo(dbconnect,  snoId);
                        if (string.IsNullOrEmpty(productInfo.CUSTSN) ||
                               string.IsNullOrEmpty(productInfo.MAC) ||
                               string.IsNullOrEmpty(productInfo.ATSNAV))
                        {
                            #region send  email not found PO need mantain PO data
                            string emptyDataMsg = "";
                            string DataMsg = "";

                            if (string.IsNullOrEmpty(productInfo.CUSTSN))
                                emptyDataMsg = emptyDataMsg + " CustomSN: ";
                            else
                                DataMsg = DataMsg + " CustomSN:" + productInfo.CUSTSN;

                            if (string.IsNullOrEmpty(productInfo.MAC))
                                emptyDataMsg = emptyDataMsg + " MAC: ";
                            else
                                DataMsg = DataMsg + " MAC:" + productInfo.MAC;

                            if (string.IsNullOrEmpty(productInfo.ATSNAV))
                                emptyDataMsg = emptyDataMsg + " ATSNAV: ";
                            else
                                DataMsg = DataMsg + " ATSNAV:" + productInfo.ATSNAV;

                            //localmsg = "<br/> CDSI ProductID:" + snoId + " CustomSN:" + (string.IsNullOrEmpty(productInfo.CUSTSN) ? "" : productInfo.CUSTSN) + " " +
                            //    " MAC:" + (string.IsNullOrEmpty(productInfo.MAC) ? "" : productInfo.MAC) + " " +
                            //    " ATSNAV:" + (string.IsNullOrEmpty(productInfo.ATSNAV) ? "" : productInfo.ATSNAV) + " " + " 為空!!! 請檢查設定!!" + "<br/>";

                            localmsg = "<br/> CDSI ProductID:" + snoId + DataMsg + ";" + emptyDataMsg + "為空!!! 請檢查設定或等過站分配" + emptyDataMsg + "值!!" + "<br/>";

                            msg = msg + localmsg;

                            logger.DebugFormat("Data is null or empty {0}",  localmsg);


                            #endregion
                            continue;
                        }
                        #endregion


                        #region //1.Get PO
                        string po = SQLStatement.GetSnoPoMo(dbconnect,  snoId);
                        if (string.IsNullOrEmpty(po))
                        {
                            #region assign PO
                            if (config.AutoAssignPO == 1)
                            {
                                CDSIPO poInfo = new CDSIPO();
                                poInfo.ProductID = snoId;
                                poInfo.MOId = productInfo.MOId;
                                poInfo.PO = "";
                                poInfo.DeliveryNo = "";

                                #region assign PO
                                if (SQLStatement.AssignPO(dbconnect,  config, productInfo, poInfo))
                                {
                                    logger.DebugFormat( "AssignPO " + poInfo.ProductID + " PO:" + poInfo.PO + " DeliveryNo:" + poInfo.DeliveryNo);


                                    //檢查UPS Device
                                    UPSDatabase  db= new UPSDatabase(config.DBConnectStr);
                                    UPSCombinePO combinePO =null;
                                    if (UPSData.DecideUPSCDSI(db, productInfo, poInfo, out combinePO))
                                    {
                                        #region UPS Device
                                        logger.DebugFormat("ProductID:{0} Model:{1} PO:{2} is UPS device!!", productInfo.ProductID, productInfo.Model, productInfo.PO); 
                                        string errorText=null;
                                        if (combinePO == null)
                                        {
                                            logger.ErrorFormat("ProductID:{0} Model:{1} PO:{2} is UPS device, no upload UPS PO!!", productInfo.ProductID, productInfo.Model, productInfo.PO); 

                                            localmsg = "<br/> CDSI ProductID:" + productInfo.ProductID +
                                                                           " CustomSN:" + productInfo.CUSTSN +
                                                                           " MAC:" + productInfo.MAC +
                                                                           " ATSNAV:" + productInfo.ATSNAV +
                                                                            " Model:" + productInfo.Model +
                                                                           " PO:" + productInfo.PO + " 未上傳 至UPS Server ,請上傳此PO至UPS Server <br/>";

                                            msg = msg + localmsg;
                                        }
                                        else
                                        {
                                            if (!UPSData.AssignUPSPO(config, db, productInfo, poInfo, combinePO, out errorText))
                                            {
                                                localmsg = "<br/> CDSI ProductID:" + productInfo.ProductID +
                                                                           " CustomSN:" + productInfo.CUSTSN +
                                                                           " MAC:" + productInfo.MAC +
                                                                           " ATSNAV:" + productInfo.ATSNAV +
                                                                            " Model:" + productInfo.Model +
                                                                           " PO:" + productInfo.PO + " 為 UPS Server 報錯 " + errorText + "<br/>";

                                                msg = msg + localmsg;
                                            }
                                        }
                                        #endregion
                                        continue;
                                    }
                                    else
                                    {
                                        logger.DebugFormat("ProductID:{0} Model:{1} PO:{2} is not UPS device!!", productInfo.ProductID, productInfo.Model, productInfo.PO); 
                                        #region CDSI SRV
                                        SQLStatement.InsertCDSIPoMo(dbconnect, poInfo);

                                        po = SQLStatement.GetSnoPoMo(dbconnect, snoId);

                                        //Thread.Sleep(config.CDSICmdInterval);

                                        //SendCDSIPOLinkCmd(dbconnect,
                                        //                                       log,
                                        //                                       config,
                                        //                                       productInfo,
                                        //                                       po,
                                        //                                        ref msg);
                                        string msgData = "";
                                        CDSIFile.SendCDSIUpdateCmd(dbconnect,
                                                                            config,
                                                                            productInfo,
                                                                            po,
                                                                            true,
                                                                            ref msgData);
                                        productInfo.PO = po;
                                        AssignedPOList.Add(productInfo);
                                        #endregion
                                    }
                                }
                                else
                                {
                                    #region send  email not found PO need upload PO data
                                    localmsg = "<br/>" + "CDSI ProductID:" + snoId +
                                                                     " CustomSN:" + productInfo.CUSTSN +
                                                                      " MAC:" + productInfo.MAC +
                                                                     " ATSNAV:" + productInfo.ATSNAV +
                                                                     " Model:" + productInfo.Model +
                                                                     " 找不到船務資料,請上傳船務資料!!" + "<br/>";
                                    msg = msg + "<br/>" + localmsg;

                                   logger.DebugFormat( "Not Found DN {0}" ,
                                                   localmsg);

                                    #endregion

                                    continue;
                                }
                                #endregion
                            }
                            else
                            {
                                #region send  email not found PO need upload PO data
                                localmsg = "<br/>" + "CDSI ProductID:" + snoId +
                                                                    " MAC:" + productInfo.MAC +
                                                                   " ATSNAV:" + productInfo.ATSNAV +
                                                                   " CustomSN:" + productInfo.CUSTSN +
                                                                   " Model:" + productInfo.Model +
                                                                   " 未設定PO, 請至iMES維護頁面CDSI PO" + "<br/>";
                                msg = msg + "<br/>" + localmsg;

                                logger.DebugFormat( "Not Found PO {0}",
                                               localmsg);

                                #endregion
                                continue;
                            }
                            #endregion
                        }
                        else
                        {
                            CDSIFile.SendCDSIPOLinkCmd(dbconnect,
                                                                           config,
                                                                           productInfo,
                                                                           po,
                                                                            ref msg);
                            productInfo.PO = po;
                            AssignedPOList.Add(productInfo);
                        }
                        #endregion
                    }
                    #endregion
                    Thread.Sleep(config.CDSICmdInterval);

                    logger.DebugFormat("Send CDSI Update & Retrive Asset Tag.........................");
                    #region Send OMSUpdate & Retrive ; used assigned PO for each send comand to CDSI Server
                    //foreach (string snoId in SnoIdList)
                    foreach (ProductInfo productInfo in AssignedPOList)
                    {
                        #region //0. Check CDSI Server FactoryPO
                        int cdsiCategory = SQLStatement.CheckCDSIFactoryPO(CdsiDbconnect,                                                                                                                   
                                                                                                                       productInfo.PO);
                        if (cdsiCategory == 0)   // not found CDSI FactoryPO
                        {
                            #region not found CDSI FactoryPO
                            localmsg = "<br/> CDSI ProductID:" + productInfo.ProductID +
                                " CustomSN:" + productInfo.CUSTSN +
                                " MAC:" + productInfo.MAC +
                                " ATSNAV:" + productInfo.ATSNAV +
                                 " Model:" + productInfo.Model +
                                " PO:" + productInfo.PO + " 在CDSI DB 找不到FactoryPO!!!" + "<br/>";

                            msg = msg + localmsg;

                            logger.DebugFormat( "not found CDSI FactoryPO {0}",
                                           localmsg);

                            #endregion

                            continue;

                        }
                        else
                        {
                            localmsg = "CDSI FactoryPO Category: " + (cdsiCategory == 1 ? "Shell PO" : " Nornal PO");
                            logger.DebugFormat( "CheckCDSIFactoryPO {0}",
                                          localmsg);
                        }
                        #endregion

                        CDSIFile.SendCDSICmd(dbconnect,                                                
                                                   config,
                                                   productInfo,
                                                   productInfo.PO,
                                                   false,
                                                   ref msg);


                    }

                    #endregion
                }
                catch (Exception e)
                {
                    #region exception handle
                    msg = e.StackTrace + " " + e.Message;
                    logger.Error(msg, e);
                    //log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "StackTrace", e.StackTrace);
                    //log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Message", e.Message);


                    SendMail.Send(config.FromAddress,
                                                          config.ToAddress,
                                                          config.CcAddress,
                                                          config.MailSubject + "program error",
                                                          msg,
                                                          config.EmailServer);
                    #endregion
                }
                finally
                {
                    #region error send email
                    if (!string.IsNullOrEmpty(msg))
                    {
                        SendMail.Send(config.FromAddress,
                                                          config.ToAddress,
                                                          config.CcAddress,
                                                          config.MailSubject + " 資料有誤!!",
                                                          msg,
                                                          config.EmailServer);
                    }

                    #endregion

                }

            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);                
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }          
               
        }     
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            //if (File.Exists(@"\\10.99.183.50\fsm_com\Mailbox\CNU23090R7-28924AD3C1D7.ACK"))
            //{
            //    Console.WriteLine(@"CheckCDSIResult  find \\10.99.183.50\fsm_com\Mailbox\CNU23090R7-28924AD3C1D7.ACK Ack file!!");
               
            //}
            
            AppConfig config = new AppConfig();
            string msg="";
            string localmsg = "";
                     
            Log log = new Log(config.logPath, config.logPrefixName);
            log.write(LogType.Info, 0, "Main" , "", "Start Program...");
            try 
            {
                SqlConnection dbconnect = new SqlConnection(config.DBConnectStr);
                dbconnect.Open();               
                log.write(LogType.Info, 0, "main", "connected with HPIMES DB", "OK");

                SqlConnection CdsiDbconnect = new SqlConnection(config.CDSIDBConnectStr);
                CdsiDbconnect.Open();
                log.write(LogType.Info, 0, "main", "connected with CDSI DB", "OK");

                List<string> SnoIdList = SQLStatement.GetCDSISNList(dbconnect, log, config.OffsetDay);
                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Start", "Send Link CDSI PO.........................");
                List<ProductInfo> AssignedPOList = new List<ProductInfo>();

                #region send PO Link to CDSI Server
                foreach (string snoId in SnoIdList)
                {
                    #region //0.Check ProductID info
                    ProductInfo productInfo = SQLStatement.GetProductInfo(dbconnect, log, snoId);
                     if (string.IsNullOrEmpty(productInfo.CUSTSN) ||
                            string.IsNullOrEmpty(productInfo.MAC) ||
                            string.IsNullOrEmpty(productInfo.ATSNAV))
                     {
                            #region send  email not found PO need mantain PO data
                            string emptyDataMsg = "";
                            string DataMsg = "";

                            if (string.IsNullOrEmpty(productInfo.CUSTSN))
                                emptyDataMsg = emptyDataMsg + " CustomSN: ";
                            else
                                DataMsg = DataMsg + " CustomSN:" + productInfo.CUSTSN;

                           if (string.IsNullOrEmpty(productInfo.MAC))
                               emptyDataMsg = emptyDataMsg + " MAC: ";
                           else
                               DataMsg = DataMsg + " MAC:" + productInfo.MAC;

                           if (string.IsNullOrEmpty(productInfo.ATSNAV))
                               emptyDataMsg = emptyDataMsg + " ATSNAV: ";
                           else
                               DataMsg = DataMsg + " ATSNAV:" + productInfo.ATSNAV;

                            //localmsg = "<br/> CDSI ProductID:" + snoId + " CustomSN:" + (string.IsNullOrEmpty(productInfo.CUSTSN) ? "" : productInfo.CUSTSN) + " " +
                            //    " MAC:" + (string.IsNullOrEmpty(productInfo.MAC) ? "" : productInfo.MAC) + " " +
                            //    " ATSNAV:" + (string.IsNullOrEmpty(productInfo.ATSNAV) ? "" : productInfo.ATSNAV) + " " + " 為空!!! 請檢查設定!!" + "<br/>";

                            localmsg = "<br/> CDSI ProductID:" + snoId + DataMsg +";" +emptyDataMsg + "為空!!! 請檢查設定或等過站分配" +emptyDataMsg +"值!!" + "<br/>";

                            msg = msg + localmsg;

                            log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                           "Data is null or empty",
                                           localmsg);

                           
                            #endregion
                            continue;
                     }
                    #endregion


                     #region //1.Get PO
                     string po = SQLStatement.GetSnoPoMo(dbconnect, log, snoId);
                    if (string.IsNullOrEmpty(po))
                    {
                        #region assign PO
                        if (config.AutoAssignPO == 1)
                        {
                            CDSIPO poInfo = new CDSIPO();
                            poInfo.ProductID = snoId;
                            poInfo.MOId = productInfo.MOId;
                            poInfo.PO = "";
                            poInfo.DeliveryNo = "";

                            #region assign PO
                            if (SQLStatement.AssignPO(dbconnect, log, config, productInfo, poInfo))
                            {
                                log.write(LogType.Info, 0, "AssignPO", poInfo.ProductID, "PO:" + poInfo.PO + " DeliveryNo:" + poInfo.DeliveryNo);

                                SQLStatement.InsertCDSIPoMo(dbconnect, log, poInfo);

                                po = SQLStatement.GetSnoPoMo(dbconnect, log, snoId);

                                //Thread.Sleep(config.CDSICmdInterval);

                                //SendCDSIPOLinkCmd(dbconnect,
                                //                                       log,
                                //                                       config,
                                //                                       productInfo,
                                //                                       po,
                                //                                        ref msg);
                                string msgData = "";
                                SendCDSIUpdateCmd(dbconnect,
                                                                    log,
                                                                    config,
                                                                    productInfo,
                                                                    po,
                                                                    true,
                                                                    ref msgData);
                                productInfo.PO =po;
                                AssignedPOList.Add(productInfo);
                            }
                            else
                            {
                                #region send  email not found PO need upload PO data
                                localmsg = "<br/>" + "CDSI ProductID:" + snoId + 
                                                                 " CustomSN:" + productInfo.CUSTSN +
                                                                  " MAC:" + productInfo.MAC +
                                                                 " ATSNAV:" + productInfo.ATSNAV +
                                                                 " Model:" + productInfo.Model + 
                                                                 " 找不到船務資料,請上傳船務資料!!" + "<br/>";
                                msg = msg + "<br/>" + localmsg;

                                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                               "Not Found DN",
                                               localmsg);

                                #endregion

                                continue;
                            }
                            #endregion
                        }
                        else
                        {
                            #region send  email not found PO need upload PO data
                            localmsg = "<br/>" + "CDSI ProductID:" + snoId +
                                                                " MAC:" + productInfo.MAC +
                                                               " ATSNAV:" + productInfo.ATSNAV + 
                                                               " CustomSN:" +  productInfo.CUSTSN  + 
                                                               " Model:" + productInfo.Model + 
                                                               " 未設定PO, 請至iMES維護頁面CDSI PO" + "<br/>";
                            msg = msg + "<br/>" + localmsg;

                            log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                           "Not Found PO",
                                           localmsg);

                            #endregion
                            continue;
                        }
                        #endregion
                    }
                    else
                    {
                        SendCDSIPOLinkCmd(dbconnect,
                                                                       log,
                                                                       config,
                                                                       productInfo,
                                                                       po,
                                                                        ref msg);
                        productInfo.PO = po;
                        AssignedPOList.Add(productInfo);
                    }
                     #endregion
                }
                #endregion
                Thread.Sleep(config.CDSICmdInterval);

                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Start", "Send CDSI Update & Retrive Asset Tag.........................");
                #region Send OMSUpdate & Retrive ; used assigned PO for each send comand to CDSI Server
                //foreach (string snoId in SnoIdList)
                foreach (ProductInfo productInfo in AssignedPOList)
                {                   
                        #region //0. Check CDSI Server FactoryPO
                        int cdsiCategory = SQLStatement.CheckCDSIFactoryPO(CdsiDbconnect,
                                                                                                                       log,
                                                                                                                       productInfo.PO);
                        if (cdsiCategory == 0)   // not found CDSI FactoryPO
                        {
                            #region not found CDSI FactoryPO
                            localmsg = "<br/> CDSI ProductID:" + productInfo.ProductID +
                                " CustomSN:" + productInfo.CUSTSN + 
                                " MAC:" + productInfo.MAC + 
                                " ATSNAV:" +productInfo.ATSNAV +
                                 " Model:" + productInfo.Model +
                                " PO:" + productInfo.PO + " 在CDSI DB 找不到FactoryPO!!!" + "<br/>";

                            msg = msg + localmsg;

                            log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                           "not found CDSI FactoryPO",
                                           localmsg);

                            #endregion

                            continue;

                        }
                        else
                        {
                            localmsg = "CDSI FactoryPO Category: " + (cdsiCategory== 1? "Shell PO" : " Nornal PO");
                            log.write(LogType.Info, AppDomain.CurrentDomain.Id, "Main",
                                          "CheckCDSIFactoryPO",
                                          localmsg);
                        }
                        #endregion
                        
                        SendCDSICmd(dbconnect,
                                                   log,
                                                   config,
                                                   productInfo,
                                                   productInfo.PO,
                                                   false,
                                                   ref msg);

                  
                }
                
                #endregion
            }
            catch (Exception e)
            {
                #region exception handle
                msg = e.StackTrace + " " +  e.Message;
                 log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "StackTrace", e.StackTrace);
                 log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Message", e.Message);
                         
               
                SendMail.Send(config.FromAddress,
                                                      config.ToAddress,
                                                      config.CcAddress,
                                                      config.MailSubject + "program error",
                                                      msg,
                                                      config.EmailServer,
                                                      log);
                #endregion
            }
            finally
            {
                #region error send email
                if (!string.IsNullOrEmpty(msg))
                {
                    SendMail.Send(config.FromAddress,
                                                      config.ToAddress,
                                                      config.CcAddress,
                                                      config.MailSubject + " 資料有誤!!",
                                                      msg,
                                                      config.EmailServer,
                                                      log);
                }
                
                #endregion
               
            }
               
        }
Exemplo n.º 11
0
        public static IList<UPSHPPO> GetUPSHPPO(AppConfig config,List<string> poList)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);
            try
            {
                UPSDatabase db = new UPSDatabase(config.DBConnectStr);

                return (from po in db.UPSHPPOEntity
                                           join d in poList on po.HPPO equals d
                                           select po).ToList();

            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }
        }
Exemplo n.º 12
0
        static public bool AssignMO(SqlConnection connect,                                                    
                                                        AppConfig config,
                                                        ProductInfo prodInfo,
                                                       CDSIPO poInfo)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                bool selectedMo = false;

                List<MO> moList = GetAvailableMO(connect,                                                                         
                                                                               prodInfo,
                                                                                config.MOStartDateOffSetDay,
                                                                                config.MOUdtOffSetDay);
                if (moList.Count == 0) return selectedMo;

                int availableQty = 0;

                foreach (MO mo in moList)
                {
                    availableQty = mo.Qty - GetAssignMOQty(connect,  mo.MOId);
                    if (availableQty > 0)
                    {

                        poInfo.MOId = mo.MOId;
                        selectedMo = true;
                        break;
                    }
                }

                return selectedMo;
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
           

        }
Exemplo n.º 13
0
        public  static  void SendCDSIUpdateCmd(SqlConnection dbconnect,                                                                        
                                                                           AppConfig config,
                                                                           ProductInfo productInfo,
                                                                           string po,
                                                                           bool isLinkPO,
                                                                           ref string msg)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                string localmsg = "";
                // write link PO cmd in LocalSN2POFolder
                #region send CDSI Cmd
                WindowsImpersonationContext wicCdsi = null;
                if (isLinkPO)
                {
                    if (!string.IsNullOrEmpty(config.CDSIServerUser))
                        wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                      config.CDSIDomain,
                                                                                      config.CDSIServerPassword);

                    CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder,
                                                                    productInfo.CUSTSN,
                                                                    po, config.CDSISN2POFolder);
                    logger.DebugFormat("SendCDSIUpdateCmd {0}", "CDSIFile.LinkPO_Cmd1");

                }

                CDSIFile.SignUp_Cmd2(config.LocalMAILBOXFolder,
                                                                productInfo.CUSTSN,
                                                                productInfo.MAC,
                                                                config.CDSIMAILBOXFolder);
                logger.DebugFormat( "SendCDSIUpdateCmd {0}", "CDSIFile.SignUp_Cmd2");
                //Thread.Sleep(config.CDSICmdInterval);

                CDSIFile.OMSUPDATE_Cmd3(config.LocalMAILBOXFolder,
                                                                             productInfo.CUSTSN,
                                                                             productInfo.MAC,
                                                                             productInfo.ATSNAV,
                                                                             productInfo.MN1,
                                                                             productInfo.SYSID,
                                                                             config.CDSIMAILBOXFolder);
                logger.DebugFormat("SendCDSIUpdateCmd {0}", " CDSIFile.OMSUPDATE_Cmd3");
                // don't sleep          
                //Vincent add check result
                enumCDSIResult result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                         config.CDSIMAILBOXFolder,
                                                                                       productInfo.CUSTSN,
                                                                                        productInfo.MAC);
                if (result1 == enumCDSIResult.NotFound)
                {
                    #region retry again and sleep 5 sec
                    result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                  config.CDSIMAILBOXFolder,
                                                                                  productInfo.CUSTSN,
                                                                                  productInfo.MAC);
                    #endregion
                }

                if (result1 == enumCDSIResult.Err || result1 == enumCDSIResult.NotFound)
                {
                    #region write error message
                    //send  error email
                    localmsg = "<br/> OMSUPDATE_Cmd3 CDSIResultFile -- ProductID:" + productInfo.ProductID + "  CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" +
                                (result1 == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") +
                               " Please Check CDSI Server, Error Message:";

                    msg = msg + localmsg;

                    if (result1 == enumCDSIResult.Err)
                    {
                        string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR");
                        msg = msg + "<br/>" + string.Join("<br/>", data);
                        localmsg = localmsg + "<br/>" + string.Join("<br/>", data);
                    }

                    logger.DebugFormat("SendCDSIUpdateCmd {0} {1}",
                                   "OMSUPDATE_CDSIResultFile",
                                   localmsg);

                    #endregion
                }
                else
                {
                    logger.DebugFormat("SendCDSIUpdateCmd {0} {1}",
                                  "OMSUPDATE_CDSIResultFile",
                                  "Get Ack file");
                }



                #endregion



                #region SIGNOFF Cmd

                if (!string.IsNullOrEmpty(config.CDSIServerUser))
                    wicCdsi = Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                  config.CDSIDomain,
                                                                                  config.CDSIServerPassword);

                CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder,
                                                               productInfo.CUSTSN,
                                                               productInfo.MAC,
                                                               config.CDSIMAILBOXFolder);
                logger.DebugFormat("SendCDSIUpdateCmd {0}" , "CDSIFile.SIGNOFF_Cmd5");

                if (wicCdsi != null)
                {
                    Logon.Log_off(wicCdsi);

                }
                //Disable sleep  Vincent
                //Thread.Sleep(config.CDSICmdInterval);
                #endregion
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
          
        }
Exemplo n.º 14
0
        static public bool  AssignMO(SqlConnection connect,
                                                       Log log,
                                                        AppConfig config,
                                                        ProductInfo prodInfo, 
                                                       CDSIPO poInfo)
        {
            bool selectedMo = false;

            List<MO> moList=  GetAvailableMO(connect,
                                                                           log,
                                                                           prodInfo,
                                                                            config.MOStartDateOffSetDay,
                                                                            config.MOUdtOffSetDay);
            if (moList.Count == 0) return selectedMo;
            
            int availableQty=0;
           
            foreach (MO mo in moList)
            {
                availableQty = mo.Qty- GetAssignMOQty(connect, log, mo.MOId);
                if (availableQty > 0)
                {
                   
                    poInfo.MOId = mo.MOId;
                    selectedMo = true;
                    break;
                }
            }

            return selectedMo;

        }
Exemplo n.º 15
0
        static private void SendCDSICmd(SqlConnection dbconnect,
                                                                Log log,
                                                                AppConfig config,
                                                                ProductInfo productInfo,
                                                                string po,
                                                                bool isLinkPO,
                                                                ref string msg)
        {
            string localmsg="";
             // write link PO cmd in LocalSN2POFolder
             #region send CDSI Cmd
                            WindowsImpersonationContext wicCdsi = null;
                            if (isLinkPO)
                            {
                                if (!string.IsNullOrEmpty(config.CDSIServerUser))
                                    wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                                  config.CDSIDomain,
                                                                                                  config.CDSIServerPassword,
                                                                                                  log);

                                CDSIFile.LinkPO_Cmd1(config.LocalSN2POFolder,
                                                                                productInfo.CUSTSN,
                                                                                po, config.CDSISN2POFolder);
                                log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.LinkPO_Cmd1");

                            }

                            CDSIFile.SignUp_Cmd2(config.LocalMAILBOXFolder,
                                                                            productInfo.CUSTSN,
                                                                            productInfo.MAC,
                                                                            config.CDSIMAILBOXFolder);
                            log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.SignUp_Cmd2");
                            //Thread.Sleep(config.CDSICmdInterval);

                            CDSIFile.OMSUPDATE_Cmd3(config.LocalMAILBOXFolder,
                                                                                         productInfo.CUSTSN,
                                                                                         productInfo.MAC,
                                                                                         productInfo.ATSNAV,
                                                                                         productInfo.MN1,
                                                                                         productInfo.SYSID,
                                                                                         config.CDSIMAILBOXFolder);
                            log.write(LogType.Info, 0, "Write Cmd", "", " CDSIFile.OMSUPDATE_Cmd3");
                            // don't sleep
                            Thread.Sleep(config.CDSICmdInterval);
                            //Vincent add check result
                            enumCDSIResult result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                                     config.CDSIMAILBOXFolder,
                                                                                                   productInfo.CUSTSN,
                                                                                                    productInfo.MAC);
                            if (result1 == enumCDSIResult.NotFound)
                            {
                                #region retry again and sleep 5 sec
                                System.Threading.Thread.Sleep(config.CDSICmdInterval);
                                result1 = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                              config.CDSIMAILBOXFolder,
                                                                                              productInfo.CUSTSN,
                                                                                              productInfo.MAC);
                                #endregion
                            }

                            if (result1 == enumCDSIResult.Err || result1 == enumCDSIResult.NotFound)
                            {
                                #region write error message
                                //send  error email
                                localmsg = "<br/> OMSUPDATE_Cmd3 CDSIResultFile -- ProductID:" + productInfo.ProductID + "  CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" +
                                            (result1 == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") +
                                           " Please Check CDSI Server, Error Message:";

                                msg = msg + localmsg;

                                if (result1 == enumCDSIResult.Err)
                                {
                                    string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR");
                                    msg = msg + "<br/>" + string.Join("<br/>", data);
                                    localmsg = localmsg + "<br/>" + string.Join("<br/>", data);
                                }
                               
                                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                               "OMSUPDATE_CDSIResultFile",
                                               localmsg);

                                #endregion

                                #region SIGNOFF Cmd

                                if (!string.IsNullOrEmpty(config.CDSIServerUser))
                                    wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                                  config.CDSIDomain,
                                                                                                  config.CDSIServerPassword,
                                                                                                  log);

                                CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder,
                                                                               productInfo.CUSTSN,
                                                                               productInfo.MAC,
                                                                               config.CDSIMAILBOXFolder);
                                log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.SIGNOFF_Cmd5");

                                if (wicCdsi != null)
                                {
                                    UTL.Logon.Log_off(wicCdsi);

                                }
                                //Disable sleep  Vincent
                                //Thread.Sleep(config.CDSICmdInterval);
                                #endregion
                                return;
                            }

                            CDSIFile.RETRIEVE_Cmd4(config.LocalMAILBOXFolder,
                                                                            productInfo.CUSTSN,
                                                                            productInfo.MAC,
                                                                            config.CDSIMAILBOXFolder);
                            log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.RETRIEVE_Cmd4");
                            

                            if (wicCdsi != null)
                            {
                                UTL.Logon.Log_off(wicCdsi);

                            }

                            Thread.Sleep(config.CDSICmdInterval);

                            #endregion

            //Get ACK/ERR file
            enumCDSIResult result = CDSIFile.CheckCDSIResult(config.LocalMAILBOXFolder,
                                                                                                      config.CDSIMAILBOXFolder,
                                                                                                    productInfo.CUSTSN,
                                                                                                     productInfo.MAC);
            log.write(LogType.Info, 0, "CheckCDSIResult", "", "CDSIFile.CheckCDSIResult");
           if (result == enumCDSIResult.NotFound)
           {
                #region retry again and sleep 5 sec
                                Thread.Sleep(config.CDSICmdInterval);
                                result = CDSIFile.CheckCDSIResult(   config.LocalMAILBOXFolder,
                                                                                                config.CDSIMAILBOXFolder,
                                                                                                   productInfo.CUSTSN,
                                                                                                    productInfo.MAC);
                                #endregion
           }

           if (result == enumCDSIResult.Ack)
           {
               log.write(LogType.Info, AppDomain.CurrentDomain.Id, "Main",
                                           "CheckCDSIResult",
                                           "OK");
                #region  Copy CDSI Result XML file to local Result folder & Read CDSI XML file
                                CDSIFile.CopyCDSIResultFolder(config.CDSIResultFolder,
                                                                                                  config.LocalResultFolder,
                                                                                                  productInfo.CUSTSN,
                                                                                                  productInfo.MAC);
                                log.write(LogType.Info, 0, "CopyCDSIResultFolder", " Copy to Result File", "CDSIFile.CopyCDSIResultFolder");

                                enumCDSIResult OMSresult = CDSIFile.CheckCDSIResultByOMS(config.LocalResultFolder,
                                                                                                                                                 productInfo.CUSTSN,
                                                                                                                                                 productInfo.MAC,
                                                                                                                                                 productInfo.ATSNAV);
                                log.write(LogType.Info, 0, "CheckCDSIResultByOMS", "Check Result", "CDSIFile.CheckCDSIResultByOMS");
                                                               
                                if (OMSresult == enumCDSIResult.Ack)
                                {
                                    string xmlName = productInfo.CUSTSN + "-" + productInfo.MAC + "\\" + productInfo.ATSNAV + ".DAT";

                                    string srcXmlPath = config.LocalResultFolder + xmlName;
                                    SQLStatement.ReadXMLCDSIAST(dbconnect,
                                                                                               log,
                                                                                               productInfo.ProductID,
                                                                                               srcXmlPath);
                                    log.write(LogType.Info, AppDomain.CurrentDomain.Id, "ReadXMLCDSIAST",
                                               "Parse XML",
                                              "ReadXMLCDSIAST");

                                }
                                else
                                {

                                    //send  error email
                                    localmsg = "<br/>CDSI " + " ProductID:" + productInfo.ProductID + "  PO:" + po + "  " + productInfo.ATSNAV +
                                                ".OMS File -- " +
                                                (OMSresult == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") +
                                               " Please Check CDSI Server!!" + "<br/>";

                                    msg = msg + localmsg;                                  
                                    
                                  
                                }


                                #endregion


                  #region Copy CDSI file to Image download server

                                if (OMSresult == enumCDSIResult.Ack)
                                {
                                    if (!string.IsNullOrEmpty(config.IMGServerUser))
                                    {
                                        WindowsImpersonationContext wic = UTL.Logon.ImpersinateUser(config.IMGServerUser, config.IMGDomain, config.IMGServerPassword, log);
                                        log.write(LogType.Info, AppDomain.CurrentDomain.Id, "CopyCDSIResultFolder",
                                             "Copy Image Server start",
                                            "CopyCDSIResultFolder");
                                        CDSIFile.CopyCDSIResultFolder(config.LocalResultFolder,
                                                                                                      config.IMGFolder,
                                                                                                      productInfo.CUSTSN,
                                                                                                      productInfo.MAC);
                                        log.write(LogType.Info, AppDomain.CurrentDomain.Id, "CopyCDSIResultFolder",
                                             "Copy Image Server end",
                                            "CopyCDSIResultFolder");
                                        UTL.Logon.Log_off(wic);
                                    }
                                    else
                                    {
                                        log.write(LogType.Info, AppDomain.CurrentDomain.Id, "CopyCDSIResultFolder",
                                            "Copy Image Server start (none login)",
                                           "CopyCDSIResultFolder");

                                        CDSIFile.CopyCDSIResultFolder(config.LocalResultFolder, 
                                                                                                config.IMGFolder, 
                                                                                                productInfo.CUSTSN, 
                                                                                                productInfo.MAC);
                                        
                                        log.write(LogType.Info, AppDomain.CurrentDomain.Id, "CopyCDSIResultFolder",
                                            "Copy Image Server end(none login)",
                                           "CopyCDSIResultFolder");
                                    }
                                }

                                #endregion
             }
             else
            {
                  #region CDSI Result Error & not found then send email
                                //send  error email
                                localmsg = "<br/> RETRIEVE_Cmd4 CDSIResultFile -- ProductID:" + productInfo.ProductID + "  CUSTSN:" + productInfo.CUSTSN + " PO:" + po + "<br/>" +
                                            (result == enumCDSIResult.Err ? "Error Result" : "Not Found Result file") +
                                           " Please Check CDSI Server, Error Message:";

                                msg = msg + localmsg;

                                
                                string[] data = File.ReadAllLines(config.LocalMAILBOXFolder + productInfo.CUSTSN + "-" + productInfo.MAC + ".ERR");
                                msg = msg + "<br/>" + string.Join("<br/>", data);
                                localmsg = localmsg + "<br/>" + string.Join("<br/>", data);
                                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                               "RETRIEVE_CDSIResultFile",
                                               localmsg);
                               
                                #endregion
             }

             #region SIGNOFF Cmd

                            if (!string.IsNullOrEmpty(config.CDSIServerUser))
                                wicCdsi = UTL.Logon.ImpersinateUser(config.CDSIServerUser,
                                                                                              config.CDSIDomain,
                                                                                              config.CDSIServerPassword,
                                                                                              log);

                            CDSIFile.SIGNOFF_Cmd5(config.LocalMAILBOXFolder,
                                                                           productInfo.CUSTSN,
                                                                           productInfo.MAC,
                                                                           config.CDSIMAILBOXFolder);
                            log.write(LogType.Info, 0, "Write Cmd", "", "CDSIFile.SIGNOFF_Cmd5");

                            if (wicCdsi != null)
                            {
                                UTL.Logon.Log_off(wicCdsi);

                            }
                            //Disable sleep  Vincent
                            //Thread.Sleep(config.CDSICmdInterval);
                            #endregion
             //Delete Local File
                       


        }
Exemplo n.º 16
0
        static public bool AssignPO(SqlConnection connect,
                                                      Log log,
                                                      AppConfig config,
                                                      ProductInfo prodInfo, 
                                                      CDSIPO poInfo)
        {

            bool selectedPo = false;

            List<Delivery> poList = GetAvailableDelivery(connect,
                                                                                     log,
                                                                                     prodInfo,
                                                                                      config.ShipDateOffSetDay);
            if (poList.Count == 0)
            {
                poList = GetAvailableDeliveryByCustPo(connect,
                                                                                                     log,
                                                                                                     prodInfo,
                                                                                                      config.ShipDateOffSetDay);
            }

            if (poList.Count == 0)    return selectedPo;

            int availableQty = 0;

            foreach (Delivery po in poList)
            {
                availableQty = po.Qty - GetAssignPOQty(connect, log, po.DeliveryNo, po.PO);
                if (availableQty > 0)
                {                    
                    poInfo.PO= po.PO;
                    poInfo.DeliveryNo = po.DeliveryNo;
                    poInfo.DeliveryQty = po.Qty;
                    poInfo.RemainQty = availableQty;
                    poInfo.CustPo = po.CustPo;
                    poInfo.HpPo = po.HpPo;
                    poInfo.isCustPo = po.isCustPo;
                    selectedPo = true;
                    break;
                }
            }

            return selectedPo;
        }
Exemplo n.º 17
0
        static void Main(string[] args)
        {        
            
            AppConfig config = new AppConfig();
            string msg="";
            string localmsg = "";
                     
            Log log = new Log(config.logPath, config.logPrefixName);
            log.write(LogType.Info, 0, "Main" , "", "Start Program...");
            try 
            {
                SqlConnection dbconnect = new SqlConnection(config.DBConnectStr);
                dbconnect.Open();               
                log.write(LogType.Info, 0, "main", "connected with HPIMES DB", "OK");

              

                List<string> SnoIdList = SQLStatement.GetCNRSSNList(dbconnect, log, config.OffsetDay);
                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Start", "Send Link CNRS PO.........................");
                List<ProductInfo> AssignedPOList = new List<ProductInfo>();

                #region send PO Link to CNRS Table
                foreach (string snoId in SnoIdList)
                {
                    #region //0.Check ProductID info
                    ProductInfo productInfo = SQLStatement.GetProductInfo(dbconnect, log, snoId);
                     if (string.IsNullOrEmpty(productInfo.CUSTSN) ||
                            string.IsNullOrEmpty(productInfo.MAC) ||
                            productInfo.IsCNRS!="Y" ||
                            productInfo.IsPO!="Y")
                     {
                            #region send  email not found PO need mantain PO data
                            string emptyDataMsg = "";
                            string DataMsg = "";

                            if (string.IsNullOrEmpty(productInfo.CUSTSN))
                                emptyDataMsg = emptyDataMsg + " CustomSN: ";
                            else
                                DataMsg = DataMsg + " CustomSN:" + productInfo.CUSTSN;

                           if (string.IsNullOrEmpty(productInfo.MAC))
                               emptyDataMsg = emptyDataMsg + " MAC: ";
                           else
                               DataMsg = DataMsg + " MAC:" + productInfo.MAC;

                           if (productInfo.IsCNRS != "Y")
                               emptyDataMsg = emptyDataMsg + " ModelInfo.Name='CNRS'  ModelInfo.Value!=Y ";

                           if (productInfo.IsPO != "Y")
                               emptyDataMsg = emptyDataMsg + " ModelInfo.Name='PO'  ModelInfo.Value!=Y ";

                            //localmsg = "<br/> CDSI ProductID:" + snoId + " CustomSN:" + (string.IsNullOrEmpty(productInfo.CUSTSN) ? "" : productInfo.CUSTSN) + " " +
                            //    " MAC:" + (string.IsNullOrEmpty(productInfo.MAC) ? "" : productInfo.MAC) + " " +
                            //    " ATSNAV:" + (string.IsNullOrEmpty(productInfo.ATSNAV) ? "" : productInfo.ATSNAV) + " " + " 為空!!! 請檢查設定!!" + "<br/>";

                            localmsg = "<br/> CNRS ProductID:" + snoId + DataMsg +";" +emptyDataMsg + "為空!!! 請檢查ModelInfo設定或等過站分配" +emptyDataMsg +"值!!" + "<br/>";

                            msg = msg + localmsg;

                            log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                           "Data is null or empty",
                                           localmsg);

                           
                            #endregion
                            continue;
                     }
                    #endregion

                     #region //1.Get PO
                     string po = SQLStatement.GetSnoPoMo(dbconnect, log, snoId);
                    if (string.IsNullOrEmpty(po))
                    {
                        #region assign PO
                       
                        CDSIPO poInfo = new CDSIPO();
                        poInfo.ProductID = snoId;
                        poInfo.MOId = productInfo.MOId;
                        poInfo.PO = "";
                        poInfo.DeliveryNo = "";
                        poInfo.DeliveryQty=0;
                        poInfo.RemainQty=0;

                        #region assign PO
                        if (SQLStatement.AssignPO(dbconnect, log, config, productInfo, poInfo))
                        {
                            log.write(LogType.Info, 0, "AssignPO", poInfo.ProductID, "PO:" + poInfo.PO + " DeliveryNo:" + poInfo.DeliveryNo);

                            SpecialOrder demianOrder = SQLStatement.GetSpecialOrder(dbconnect, log, poInfo.PO);
                            if (demianOrder != null && demianOrder.Category.Equals("CNRS"))
                            {  
                                if (demianOrder.Qty != poInfo.DeliveryQty && config.bCheckQty)
                                {
                                    #region send  email Delivery Qty is not equal SpecialOrder Qty 
                                    localmsg = "<br/>" + "CNRS ProductID:" + snoId +
                                                                     " CustomSN:" + productInfo.CUSTSN +
                                                                      " MAC:" + productInfo.MAC +
                                                                     " Model:" + productInfo.Model +
                                                                     "FactoryPO:" + demianOrder.FactoryPO+
                                                                     " SpecialOrder Qty: " + demianOrder.Qty + " Delivery Qty:" +poInfo.DeliveryQty + ",請檢查SpecialOrder, Delivery資料!!" + "<br/>";
                                    msg = msg + "<br/>" + localmsg;

                                    log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                                   "Qty is not same",
                                                   localmsg);

                                    #endregion

                                    continue;
                                }

                                if (!demianOrder.Status.Equals("Active") && !demianOrder.Status.Equals("Created"))
                                {
                                    #region send  email Delivery Qty is not equal SpecialOrder Qty
                                    localmsg = "<br/>" + "CNRS ProductID:" + snoId +
                                                                     " CustomSN:" + productInfo.CUSTSN +
                                                                      " MAC:" + productInfo.MAC +
                                                                     " Model:" + productInfo.Model +
                                                                     "FactoryPO:" + demianOrder.FactoryPO +
                                                                     " SpecialOrder Status: " + demianOrder.Status + "不是Active or Created Status,請檢查SpecialOrder 資料!!" + "<br/>";
                                    msg = msg + "<br/>" + localmsg;

                                    log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                                   "Wrong SpecialOrder Status ",
                                                   localmsg);

                                    #endregion
                                    continue;
                                }
                                string assetTag = demianOrder.AssetTag;
                                #region 若 SpecialOrder Qty>1 or AssetTag="" 則分配重AssetRange 分配Asset Tag
                                if (demianOrder.Qty>1 || string.IsNullOrEmpty(demianOrder.AssetTag))
                                {
                                   IOnlineGenerateAST onlineAst= ServiceAgent.getInstance().GetObjectByName<IOnlineGenerateAST>("IMESService.OnlineGenerateAST");
                                   if (onlineAst == null)
                                   {
                                       throw new Exception("Remoting call FA  Generate AST Number Service Fail, Please check FA Remoting Port and IP setting value in app.config file !!!");
                                   }
                                   assetTag=onlineAst.GenAstNumberByAstHPPo(snoId,demianOrder.FactoryPO, config.ASTStation, "CNRS", "CNRS", "HP");
                                   if (string.IsNullOrEmpty(assetTag))
                                   {
                                       throw new Exception("Generate AST Number is null !!!");
                                   }
                                }
                                #endregion
                                SQLStatement.InsertCNRSPoMo(dbconnect, log, poInfo);
                                int assignQty = poInfo.DeliveryQty - poInfo.RemainQty;
                                int specialRemainQty =demianOrder.Qty  - assignQty;
                                if (specialRemainQty==1)
                                {
                                    SQLStatement.UpdateSpecialOrderStatus(dbconnect, log, poInfo.PO, "Closed");
                                }
                                else if (demianOrder.Status.Equals("Created"))
                                {
                                    SQLStatement.UpdateSpecialOrderStatus(dbconnect, log, poInfo.PO, "Active");
                                }

                                SQLStatement.WriteCDSIAST(dbconnect, log, poInfo.ProductID, "ASSET_TAG", assetTag);
                               
                                 SQLStatement.WriteCDSIAST(dbconnect, log, poInfo.ProductID, "HPOrder", poInfo.CustPo);
                                 SQLStatement.WriteCDSIAST(dbconnect, log, poInfo.ProductID, "FactoryPO", poInfo.HpPo);
                                 //SQLStatement.WriteCDSIAST(dbconnect, log, poInfo.ProductID, "FactoryPO", demianOrder.FactoryPO);
                                
                                SQLStatement.WriteProductAttr(dbconnect, log, poInfo.ProductID, "CNRSState", "OK", "CNRS", DateTime.Now);
                                productInfo.PO = po;
                                AssignedPOList.Add(productInfo);
                            }
                            else
                            {
                                #region send  email not found SpecialPO need upload PO data
                                localmsg = "<br/>" + "CNRS ProductID:" + snoId +
                                                                 " CustomSN:" + productInfo.CUSTSN +
                                                                  " MAC:" + productInfo.MAC +
                                                                 " Model:" + productInfo.Model +
                                                                 " 找不到SpecialOrder 資料,請上傳FactoryPO資料!!" + "<br/>";
                                msg = msg + "<br/>" + localmsg;

                                log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                               "Not Special order",
                                               localmsg);

                                #endregion
                                continue;
                            }
                        }
                        else
                        {
                            #region send  email not found PO need upload PO data
                            localmsg = "<br/>" + "CNRS ProductID:" + snoId + 
                                                             " CustomSN:" + productInfo.CUSTSN +
                                                              " MAC:" + productInfo.MAC +                                                             
                                                             " Model:" + productInfo.Model +
                                                             " 找不到船務的HP PO 對應SpecialOrder FactoryPO 資料,請上傳船務資料 或是上傳FactoryPO資料!!" + "<br/>";
                            msg = msg + "<br/>" + localmsg;

                            log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                           "Not Found DN",
                                           localmsg);

                            #endregion

                            continue;
                        }
                        #endregion
                       
                        #endregion
                    }
                    else //Manual assign PO
                    {
                        #region send  email Not Allow Manual Assigned PO
                        localmsg = "<br/>" + "CNRS ProductID:" + snoId +
                                                         " CustomSN:" + productInfo.CUSTSN +
                                                          " MAC:" + productInfo.MAC +
                                                         " Model:" + productInfo.Model +
                                                         "FactoryPO:" + po +
                                                         " 不允許收動分配PO,請檢查SnoDet_PoMo資料!!" + "<br/>";
                        msg = msg + "<br/>" + localmsg;

                        log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main",
                                       "Not Allow Manual Assigned PO ",
                                       localmsg);

                        #endregion
                        continue;
                    }
                     #endregion
                }
                #endregion
                Thread.Sleep(config.AssignedPOCmdInterval);
               
            }
            catch (Exception e)
            {
                #region exception handle
                msg = e.StackTrace + " " +  e.Message;
                 log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "StackTrace", e.StackTrace);
                 log.write(LogType.error, AppDomain.CurrentDomain.Id, "Main", "Message", e.Message);
                         
               
                SendMail.Send(config.FromAddress,
                                                      config.ToAddress,
                                                      config.CcAddress,
                                                      config.MailSubject + "program error",
                                                      msg,
                                                      config.EmailServer,
                                                      log);
                #endregion
            }
            finally
            {
                #region error send email
                if (!string.IsNullOrEmpty(msg))
                {
                    SendMail.Send(config.FromAddress,
                                                      config.ToAddress,
                                                      config.CcAddress,
                                                      config.MailSubject + " 資料有誤!!",
                                                      msg,
                                                      config.EmailServer,
                                                      log);
                }
                
                #endregion
               
            }
               
        }