Example #1
0
        public static List<string> GetAvailableAV(AppConfig config)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            List<string> ret = new List<string>();
            //Get UPS available AV partNo
            try
            {
                if (string.IsNullOrEmpty(config.AVPartNo))
                {
                    logger.InfoFormat("Get UPS Support AV PartNo");

                    ret = RequestUPSGetSupportedAV();
                }
                else
                {
                    logger.InfoFormat("Manul assign AV PartNo: {0}", config.AVPartNo);
                   List<ConstValueTypeInfo> consttype=SQLStatement.GetConstValueType(config.DBConnectStr, "UPSAVPartNo");
                   ret = consttype.Select(x => x.Value).ToList();
                   // ret = config.AVPartNo.Split(new char[] { ',', '~' }).Select(x => x.Trim()).ToList();
                }
                return ret;
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {               
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #2
0
        public static List<UPSPOBOM> Parse(AppConfig config, List<string> supportAVList)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            List<UPSPOBOM> ret = new List<UPSPOBOM>();
            WindowsImpersonationContext wicCdsi = null;
            try
            {
                DateTime now = DateTime.Now;
                if (!string.IsNullOrEmpty(config.SAPServerUser))
                    wicCdsi = Logon.ImpersinateUser(config.SAPServerUser,
                                                                            config.SAPServerDomain,
                                                                           config.SAPServerPassword);
                FileInfo[] fileInfos = FileOperation.GetFilesByWildCard(config.SAPServerFolder,
                                                                                                       config.SAPPOFile);
                foreach (FileInfo file in fileInfos)
                {
                    string SrcFile = config.SAPServerFolder + file.Name;

                    string DestFile = config.SAPServerBckupFolder + file.Name + "." + now.ToString(config.TimeFormat);

                    //2.Rename SAP weight  file
                    logger.InfoFormat("Move SAP file: {0}", DestFile);
                    FileOperation.FileMove(SrcFile, DestFile, true);
                    logger.InfoFormat("Move file Completed");
                    List<UPSPOBOM> poList = ReadFile(DestFile, config, supportAVList);
                    if (ret.Count > 0)
                    {
                        ret = ret.Concat(poList).ToList();
                    }
                    else
                    {
                        ret = poList;
                    }
                }

                return filterPoNo(config, ret);
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {
                if (wicCdsi != null)
                {
                    Logon.Log_off(wicCdsi);
                }
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #3
0
        public static List<SAPPO> GetAstSapPo(AppConfig config,
                                                                          List<SAPPO> sapPOList, 
                                                                           List<string> supportAVList,
                                                                          out List<ModelBom> modelBomList)
        {
            var modelList=sapPOList.Select(x => x.IECSku).Distinct().ToList();
            modelBomList= SQLStatement.GetModelAVBom(config.DBConnectStr,
                                                                                                                    modelList).ToList();
            var modelAvPartList = modelBomList.GroupBy(x => x.Model)
                                                                    .Select((x, y) => new { Model = x.Key,
                                                                                                       AVPartList= x.Select(w=>w.AVPartNo).ToList()
                                                                                                     }).ToList();
            foreach (var po in sapPOList)
            {
                if (po.POType == "BTO")
                {
                    po.PartNoList = modelAvPartList.Where(x => x.Model == po.IECSku).Select(x => x.AVPartList).FirstOrDefault();
                    po.MESMatchAVPart = po.PartNoList; 
                    if (po.PartNoList == null || 
                        po.PartNoList.Count==0) //非資產標籤機器
                    {
                        po.CheckOK = true;
                        po.NeedSendBOM = false;
                        po.isAstTag = false;
                    }
                    else
                    {
                        #region BTO BOM 檢查AV Part 邏輯
                        po.isAstTag = true;
                        po.UPSMatchAVPart = supportAVList.Where(x => po.PartNoList.Contains(x)).Distinct().ToList();
                        po.DiffAVPart = po.PartNoList.Except(po.UPSMatchAVPart).ToList();
                        if (po.UPSMatchAVPart.Count == 0)
                        {
                            po.ErrorText = string.Format("PoType: {0} Model:{1} HPSKU:{2} HPPO:{3} UPS has no AV Part:{4}", 
                                                                         po.POType,  po.IECSku, po.HPSku, po.IECPO,  
                                                                         string.Join(",", po.MESMatchAVPart.ToArray()));
                            po.CheckOK = false;
                            po.NeedSendBOM = false;                           
                        }                      
                        else //UPS order 
                        {
                            po.CheckOK = true;
                            po.NeedSendBOM = true;
                            if (po.DiffAVPart.Count > 0)
                            {   //CIS Team Missing setup AV PartNo
                                po.ErrorText = string.Format("PoType: {0} Model:{1} HPSKU:{2} HPPO:{3} MES and UPS have different UPS AV Part:{4} , MES AV Part:{5}",
                                                                             po.POType, po.IECSku, po.HPSku, po.IECPO,
                                                                             string.Join(",", po.UPSMatchAVPart.ToArray()),
                                                                             string.Join(",", po.MESMatchAVPart.ToArray()));
                                po.CheckOK = false;

                            }else
                            {
                                po.CheckOK = true;
                            }
                        }
                        #endregion
                    }                    
                }
                else //CTO case
                {
                    if (po.PartNoList == null || po.PartNoList.Count == 0)
                    {
                        po.isAstTag = false;
                        po.CheckOK = true;
                        po.NeedSendBOM = false;
                    }
                    else
                    {
                        #region CTO BOM 檢查AV Part
                        var mesAVPartList= modelAvPartList.Where(x => x.Model == po.IECSku).Select(x => x.AVPartList).FirstOrDefault();
                        if (mesAVPartList == null || mesAVPartList.Count == 0)
                        {
                            po.MESMatchAVPart = new List<string>();
                        }
                        else
                        {
                            po.MESMatchAVPart = mesAVPartList.Where(x => po.PartNoList.Contains(x)).Distinct().ToList();
                        }
                        po.UPSMatchAVPart = supportAVList.Where(x => po.PartNoList.Contains(x)).Distinct().ToList();
                        po.DiffAVPart = po.MESMatchAVPart.Except(po.UPSMatchAVPart).ToList();

                        if (po.UPSMatchAVPart.Count == 0)  //UPS 沒有符合AV Part
                        {
                            if (po.MESMatchAVPart.Count > 0)
                            {
                                po.ErrorText = string.Format("PoType: {0} Model:{1} HPSKU:{2} HPPO:{3} UPS has no AV Part:{4}",
                                                                       po.POType, po.IECSku, po.HPSku, po.IECPO,
                                                                       string.Join(",", po.MESMatchAVPart.ToArray()));
                                po.CheckOK = false;
                            }
                            else
                            {
                                po.CheckOK = true;
                            }
                            po.NeedSendBOM = false;
                            po.isAstTag = false;
                        }
                        else   //UPS 有符合AV Part
                        {
                            po.NeedSendBOM = true;
                            po.isAstTag = true;
                            if (po.MESMatchAVPart.Count == 0)
                            {
                                po.ErrorText = string.Format("PoType: {0} Model:{1} HPSKU:{2} HPPO:{3} MES has no AV Part:{4}",
                                                                             po.POType, po.IECSku, po.HPSku, po.IECPO,
                                                                             string.Join(",", po.MESMatchAVPart.ToArray()));
                                po.CheckOK = false;                              
                            }
                            else if (po.DiffAVPart.Count > 0)
                            {   //CIS Team Missing setup AV PartNo
                                po.ErrorText = string.Format("PoType: {0} Model:{1} HPSKU:{2} HPPO:{3} MES and UPS have different UPS AV Part:{4} , MES AV Part:{5}",
                                                                             po.POType, po.IECSku, po.HPSku, po.IECPO,
                                                                             string.Join(",", po.UPSMatchAVPart.ToArray()),
                                                                             string.Join(",", po.MESMatchAVPart.ToArray()));
                                po.CheckOK = false;
                              
                            }
                            else //UPS order 
                            {
                                po.CheckOK = true;                               
                            }
                        }
                        #endregion
                    }
                }

            }
            if (string.IsNullOrEmpty(config.PONo))
            {                
                return sapPOList.Where(x => x.NeedSendBOM).ToList();
            }
            else
            {
                var poList = config.PONo.Split(new char[] { '~', ',', ';' });
                return sapPOList.Where(x => x.NeedSendBOM && poList.Contains(x.HPPO)).ToList();
            }            
        }
Example #4
0
        private static List<SAPPO> ReadFile(string file, AppConfig config)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);

            List<SAPPO> ret = new List<SAPPO>();
            try
            {
                string[] data = File.ReadAllLines(file);
                foreach (string s in data)
                {
                    try
                    {

                        string[] column = s.Split(new char[] { '~' });
                        if (column.Length < 8)
                        {
                            throw new Exception(string.Format("字串格式錯誤 '~' 字元只有幾:{0}", column.Length));
                        }

                         string avStr = column[7].Trim();
                        
                         IList<string> partList= avStr.Split(new char[] { ',' }).Select(x=>x.Trim()).ToList();
                        foreach(string partNo in partList)
                        {
                            SAPPO item = new SAPPO(); 
                            item.Plant= column[0].Trim();
                            item.POType = column[1].Trim();
                            item.HPPO= column[2].Trim();
                            item.CustPO = column[3].Trim();
                            item.HPSku = column[4].Trim();
                            item.IECSku = column[5].Trim();
                            item.Qty = int.Parse(column[6].Trim());
                            item.AVPartNo = partNo;

                            ret.Add(item);
                        }                            
                        
                    }
                    catch (Exception e)
                    {
                        logger.Info("Raw data =>" + s);
                        logger.Error(methodName, e);
                        throw e;
                    }
                }

                return ret;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }
        }
Example #5
0
        private static List<UPSPOBOM> ReadFile(string file, AppConfig config, List<string> supportAVList)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.InfoFormat("BEGIN: {0}()", methodName);

            List<UPSPOBOM> ret = new List<UPSPOBOM>();
            try
            {
                string[] data = File.ReadAllLines(file);
                foreach (string s in data)
                {
                    try
                    {

                        string[] column = s.Split(new char[] { '~' });
                        if (column.Length < 10)
                        {
                            throw new Exception(string.Format("字串格式錯誤 '~' 字元只有幾:{0}", column.Length));
                        }

                        UPSPOBOM item = new UPSPOBOM();
                        item.Plant = column[0].Trim();
                        item.POType = column[1].Trim();
                        item.HPPO = column[2].Trim();
                        item.CustPO = column[3].Trim();
                        item.IECPO = column[4].Trim();
                        item.CustPOItem = column[5].Trim();
                        item.HPSku = column[6].Trim();
                        item.IECSku = column[7].Trim();
                        item.Qty = (int)double.Parse(column[8].Trim());

                        string avStr = column[9].Trim();
                        if (!string.IsNullOrEmpty(avStr))
                        {
                            IList<string> partList = avStr.Split(new char[] { ',' }).Select(x => x.Trim()).ToList();

                            item.PartNoList = partList.Where(x => supportAVList.Contains(x)).ToList();
                        }
                        ret.Add(item);                      

                    }
                    catch (Exception e)
                    {
                        logger.Info("Raw data =>" + s);
                        logger.Error(methodName, e);
                        throw e;
                    }
                }

                return ret;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                logger.InfoFormat("END: {0}()", methodName);
            }
        }
Example #6
0
        private static List<UPSPOBOM> filterPoNo(AppConfig config, List<UPSPOBOM> sapPoList)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            
            try
            {
                logger.InfoFormat("Configure  Po No: {0}", config.PONo);
                if (string.IsNullOrEmpty( config.PONo))
                {
                    return sapPoList;
                }

                List<string> poList = config.PONo.Split(new char[] { ',', '~' }).ToList();
                var retPoList = (from p in sapPoList
                                 where poList.Contains(p.HPPO)
                                 select p).ToList();

                var filteredPoList = retPoList.Select(x => x.HPPO).ToArray();
                logger.InfoFormat("After filtered , need send  Po count: {0} Po List:{1}", retPoList.Count.ToString(), string.Join("~",filteredPoList));
                return retPoList;
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {
                
                logger.DebugFormat("END: {0}()", methodName);
            }


        }
Example #7
0
        public static List<UPSPOBOM> InsertBTOAvPartNo(AppConfig config, List<UPSPOBOM> poBOMList, List<string> supportAvList)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                var BTOModelList = (from p in poBOMList
                                    where p.POType == "BTO"
                                    select p.IECSku).Distinct().ToList();

                if (BTOModelList.Count > 0)
                {
                    List<ModelBom> modelAvPartList = SQLStatement.GetModelAVBom(config.DBConnectStr, BTOModelList).OrderBy(x => x.Model).ToList();

                    var btoPoList = (from bom in poBOMList
                                     where bom.POType == "BTO"
                                     select bom);

                    foreach (var po in btoPoList)
                    {
                        po.PartNoList  = (from av in modelAvPartList
                                                  where av.Model == po.IECSku &&
                                                             supportAvList.Contains(av.AVPartNo)
                                                 select av.AVPartNo).ToList();
                    }


                    //var poList = from bom in poBOMList
                    //             join modelPart in modelAvPartList on bom.IECSku equals modelPart.Model
                    //             where bom.POType == "BTO" && string.IsNullOrEmpty(bom.AVPartNo)
                    //             select new UPSPOBOM
                    //             {
                    //                 CustPO = bom.CustPO,
                    //                 POType = bom.POType,
                    //                 IECSku = bom.IECSku,
                    //                 HPPO = bom.HPPO,
                    //                 HPSku = bom.HPSku,
                    //                 Plant = bom.Plant,
                    //                 Qty = bom.Qty,
                    //                 AVPartNo = modelPart.AVPartNo,
                    //                 State = SendBOMState.CreatedPoBOM
                    //             };

                    //poBOMList = poBOMList.Concat(poList).ToList();

                }

                return poBOMList;
            } 
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {              
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #8
0
        public static void SendOSIStatus(AppConfig config, UPSPOBOM poBom)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                 logger.InfoFormat("Start UPSSendOSI PO:{0}", poBom.HPPO);
                 //5.UPSSendOSI 
                string osiSpec =UPSWS.ValidateGetOSIStatus(UPSWS.RequestUPSVerifyPOReady(poBom), poBom);
                if (poBom.State == SendBOMState.GetOSIOK)
                {
                    if (string.IsNullOrEmpty(osiSpec))
                    {
                        poBom.State = SendBOMState.SendOSIOK;
                    }
                    else
                    {
                        //產生OSI String ??????
                        //HP說目前OS只有CustomerPO欄位
                        //string osiString = "<CustomerPO>{0}</CustomerPO>";
                        //osiString = string.Format(osiString, poBom.CustPO);
                        string osiString = UPSWS.GenOSIString(poBom, osiSpec, config);
                        UPSWS.ValidateSendOSIStatus(UPSWS.RequestUPSSendOSI(poBom, osiString), poBom);
                    }
                }

                if (poBom.State == SendBOMState.SendBOMOK ||             
                    poBom.State == SendBOMState.SendOSIOK)
                {
                    //6.UPSVerifyPO
                    BomStatus validatePoStatus = UPSWS.RequestUPSVerifyPOReady(poBom);
                    //7.UPSGetRange
                    UPSWS.ValidatePoStatus(validatePoStatus, poBom, config);               
                    if (poBom.State == SendBOMState.VerifyOK)
                    {
                        //verify ok;
                    }
                    else
                    {
                        logger.ErrorFormat("Start UPSVerifyPOReady PO:{0} State:{1} !!", poBom.HPPO, poBom.State.ToString());
                    }
                }
                else   // Send email notify 
                {
                    logger.ErrorFormat("Start SendBOM PO:{0} State:{1} !!", poBom.HPPO, poBom.State.ToString());
                }          
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            } 
        }
Example #9
0
        public static void SendVerifyPOStatus(AppConfig config, UPSPOBOM poBom)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                logger.InfoFormat("Start UPSVerifyPOReady PO:{0}", poBom.HPPO);

                //6.UPSVerifyPO
                BomStatus validatePoStatus = UPSWS.RequestUPSVerifyPOReady(poBom);
                UPSWS.ValidatePoStatus(validatePoStatus, poBom, config);

                if (poBom.State == SendBOMState.VerifyOK)
                {
                    //verify ok;
                }
                else
                {
                    logger.ErrorFormat("Start UPSVerifyPOReady PO:{0} State:{1} !!", poBom.HPPO, poBom.State.ToString());
                }
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }  
        }
Example #10
0
        public static void ValidateSendBomStatus(BomStatus status, UPSPOBOM poBom, AppConfig config)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                logger.InfoFormat("Reply SendBomStatus PO:{0} retCode:{1} message:{2} datastring:{3}", poBom.HPPO, status.retcode.ToString(), status.message, status.datastring);
                if (status.retcode == 0) //Holding process need waiting time
                {
                    poBom.State = SendBOMState.SendBOMHolding;
                    
                }
                else if (status.retcode == 1) // Send OSI 
                {
                    
                    poBom.State = SendBOMState.NeedSendOSI;
                  

                    //產生OSI String ??????
                    //HP說目前OS只有CustomerPO欄位
                    //string osiString = "<CustomerPO>{0}</CustomerPO>";
                    //osiString = string.Format(osiString, poBom.CustPO);
                   string osiString = GenOSIString(poBom, status.datastring, config);

                    ValidateSendOSIStatus(RequestUPSSendOSI(poBom, osiString), poBom);
                }
                else if (status.retcode == 2)
                {                  
                   poBom.State = SendBOMState.SendBOMOK;                  
                }
                else if (status.retcode == 4)
                {                    
                    poBom.State = SendBOMState.SendBOMUnSupportedAV;
                    poBom.ErrorText = string.Format("Reply SendBomStatus  PO:{0} Code:{1} DataString:{2} Message:{3}", poBom.HPPO, status.retcode, status.datastring, status.message);
                }
                else if (status.retcode == 3)
                {
                    poBom.State = SendBOMState.AlreadySendBOM;
                    poBom.ErrorText = string.Format("Reply SendBomStatus PO:{0} Code:{1} DataString:{2} Message:{3}", poBom.HPPO, status.retcode, status.datastring, status.message);
                }
                else
                {
                    poBom.State = SendBOMState.SendBOMFail;
                    poBom.ErrorText = string.Format("Reply SendBomStatus  PO:{0} Code:{1} DataString:{2} Message:{3}", poBom.HPPO, status.retcode, status.datastring, status.message);
                }
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #11
0
        public static void SendCreatePOStatus(AppConfig config, UPSPOBOM poBom)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                logger.InfoFormat("Start SendBOM PO:{0} CustomPO:{1}", poBom.HPPO, poBom.CustPO);
                //5.UPSSendBOM/UPSSendOSI
                BomStatus SendBomstatus = UPSWS.RequestUPSSendBOM(poBom, poBom.PartNoList);
                UPSWS.ValidateSendBomStatus(SendBomstatus, poBom, config);
               
                if (poBom.State == SendBOMState.SendBOMHolding)
                {
                    logger.InfoFormat("Start SendBOM PO:{0} Waiting {1} seconds ...", poBom.HPPO, config.DelayVerifyPo.ToString());
                    return;
                }

                if (poBom.State == SendBOMState.SendBOMOK ||
                    poBom.State == SendBOMState.SendBOMHolding ||
                    poBom.State == SendBOMState.SendOSIOK)
                {
                    //6.UPSVerifyPO
                    BomStatus validatePoStatus = UPSWS.RequestUPSVerifyPOReady(poBom);
                    //7.UPSGetRange
                    UPSWS.ValidatePoStatus(validatePoStatus, poBom, config);                   
                    if (poBom.State == SendBOMState.VerifyOK)
                    {
                        //verify ok;
                    }
                    else
                    {
                        logger.ErrorFormat("Start UPSVerifyPOReady PO:{0} State:{1} !!", poBom.HPPO, poBom.State.ToString());
                    }
                }
                else   // Send email notify 
                {
                    logger.ErrorFormat("Start SendBOM PO:{0} State:{1} !!", poBom.HPPO, poBom.State.ToString());
                }

            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }         
        }
Example #12
0
        public static void UpdateUPSModel(AppConfig config,
                                                                UPSDatabase db,
                                                                HPPO dbPo,
                                                                 UPSPOBOM poBom,
                                                                 string editor)
        {

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

                db.Transaction.Commit();
                //db.Connection.Close();
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                if (db.Transaction != null && db.Transaction.Connection != null)
                {
                    db.Transaction.Rollback();
                }
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #13
0
        public static void TestDB(AppConfig config,
                                     UPSDatabase db)
        {
            //UPSDatabase db = new UPSDatabase(config.DBConnectStr);
            DateTime now = DateTime.Now;

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

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

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



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

            db.Transaction.Commit();
           
            //db.Connection.Close();
        }
Example #14
0
        public static void UpdateUPSHPPO(AppConfig config, 
                                                                UPSDatabase db, 
                                                                HPPO dbPo, 
                                                                 UPSPOBOM poBom, 
                                                                 string editor)
        {
            DateTime now = DateTime.Now;
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                //UPSDatabase db = new UPSDatabase(config.DBConnectStr);

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

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

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

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

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

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

                    DataTableHelper.BulkCopyToDatabase(UPSCombinePOList,
                                                                                "UPSCombinePO",
                                                                                (SqlConnection)db.Connection,
                                                                                (SqlTransaction)db.Transaction);
                }
               
                db.SubmitChanges(System.Data.Linq.ConflictMode.ContinueOnConflict);
                
                db.Transaction.Commit();
                // db.Connection.Close();
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                if (db.Transaction != null && db.Transaction.Connection != null)
                {
                    db.Transaction.Rollback();
                }
                
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #15
0
        public static List<HPPO> GetUPSHPPO(AppConfig config, 
                                                                    UPSDatabase db,  
                                                                    DateTime receiveDate)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                List<HPPO> upspoList = new List<HPPO>();

                //UPSDatabase db = new UPSDatabase(config.DBConnectStr);
                if (db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    db.Connection.Open();
                }

                var mesPoList = (from x in db.UPSHPPOEntity
                                 where x.ReceiveDate >= receiveDate
                                 select x).ToList();
                var poNumList = mesPoList.Select(x => x.HPPO).ToList();
                var mesIecPoList = (from x in db.UPSIECPOEntity
                                    where poNumList.Contains(x.HPPO)
                                    select x).ToList();

                var mesPoPartList = (from x in db.UPSPOAVPartEntity
                                     where poNumList.Contains(x.HPPO)
                                     select x).ToList();

                foreach (var po in mesPoList)
                {
                    HPPO hppo = new HPPO();
                    hppo.PO = po;
                    hppo.IECPOList = mesIecPoList.Where(x => x.HPPO == po.HPPO).ToList();
                    hppo.PartNoList = mesPoPartList.Where(x => x.HPPO == po.HPPO).ToList();
                    hppo.isWithdraw = mesIecPoList.Any(x => x.HPPO == po.HPPO && x.Editor == "Withdraw");
                    if (hppo.isWithdraw)
                    {
                        hppo.WithdrawIECPOList = mesIecPoList.Where(x => x.HPPO == po.HPPO && x.Editor == "Withdraw").ToList();
                        hppo.WithdrawPartNoList = mesPoPartList.Where(x => x.HPPO == po.HPPO && x.Editor == "Withdraw").ToList();
                        hppo.PO.WithdrawQty = hppo.WithdrawIECPOList.Sum(x => x.Qty);                       
                    }
                    hppo.Insert = false;
                    upspoList.Add(hppo);
                }

                return upspoList;
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
          
        }
Example #16
0
        public static List<HPPO> AddUPSHPPO(AppConfig config, 
                                                                        UPSDatabase db,    
                                                                        IList<SAPPO> sapPoList, 
                                                                        List<ModelBom> modelBomList, 
                                                                        string editor)
        {
            string methodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                List<HPPO> upspoList = new List<HPPO>();
                DateTime now = DateTime.Now;
                List<String> poNumList = sapPoList.Select(x => x.HPPO).Distinct().ToList();
                //UPSDatabase db = new UPSDatabase(config.DBConnectStr);

                var mesPoList = (from x in db.UPSHPPOEntity
                                 where poNumList.Contains(x.HPPO)
                                 select x).ToList();

                var mesIecPoList = (from x in db.UPSIECPOEntity
                                    where poNumList.Contains(x.HPPO)
                                    select x).ToList();

                var mesPoPartList = (from x in db.UPSPOAVPartEntity
                                     where poNumList.Contains(x.HPPO)
                                     select x).ToList();

                foreach (var poId in poNumList)
                {
                    var poList = sapPoList.Where(x => x.HPPO == poId).ToList();
                    var first = poList[0];
                    var po = mesPoList.Where(x => x.HPPO == poId).FirstOrDefault();                   
 
                    if (po == null) //新增
                    {
                        #region 新增
                        HPPO hppo = new HPPO();
                        hppo.PO = new UPSHPPO
                        {
                            HPPO = poId,
                            Plant = first.Plant,
                            POType = first.POType,
                            HPSKU = first.HPSku,
                            EndCustomerPO = first.CustPO,
                            Status = SendBOMState.CreatedPoBOM.ToString(),
                            Qty = poList.Sum(x => x.Qty),
                            Editor = editor,
                            ErrorText = string.Empty,
                            ReceiveDate = new DateTime(now.Year, now.Month, now.Day),
                            Cdt = now,
                            Udt = now
                        };



                        hppo.IECPOList = new List<UPSIECPO>();
                        hppo.PartNoList = new List<UPSPOAVPart>();
                        foreach (var sappo in poList)
                        {
                            UPSIECPO iecpo = new UPSIECPO
                            {
                                HPPO = poId,
                                IECPO = sappo.IECPO,
                                IECPOItem = sappo.IECPOItem,
                                Model = sappo.IECSku,
                                Qty = sappo.Qty,
                                //Status = SendBOMState.Waiting.ToString(),
                                Cdt = now,
                                Udt = now,
                                Editor = editor,
                                Status ="New"
                            };
                            hppo.IECPOList.Add(iecpo);


                         
                            //有2笔HPPO,且机型不同,AV 也不同,会导致漏赛UPSPOAVPart。
                           // foreach (var partNo in first.UPSMatchAVPart)
                            foreach (var partNo in sappo.UPSMatchAVPart)
                            {
                                var modelBom = modelBomList.Where(x => x.AVPartNo == partNo).FirstOrDefault();
                                UPSPOAVPart part = new UPSPOAVPart
                                {
                                    HPPO = poId,
                                    AVPartNo = partNo,
                                    IECPartNo = modelBom == null ? string.Empty : modelBom.IECPartNo,
                                    IECPartType = modelBom == null ? string.Empty : modelBom.IECPartType,
                                    Editor = editor,
                                    Remark = string.Empty,
                                    Udt = now,
                                    Cdt = now
                                };

                                hppo.PartNoList.Add(part);
                            }

                        }

                       
                        hppo.Insert = true;
                        upspoList.Add(hppo);
                        #endregion
                    }                    
                    else //查詢 需考慮Cancel PO,再產生新的IECPO case
                    {
                        HPPO hppo = new HPPO();
                        bool isWithdraw = false;
                        #region 檢查及計算是否有拉單Case
                        var hpIECPOList = mesIecPoList.Where(x => x.HPPO == poId).ToList();
                        var hpAvPOList = mesPoPartList.Where(x => x.HPPO == poId).ToList();
                        var withdrawPOList =poList.Where(x => !hpIECPOList.Any(y => x.IECPO == y.IECPO && x.IECPOItem == y.IECPOItem)).ToList();
                        if (withdrawPOList.Count > 0)
                        {
                            hppo.WithdrawIECPOList = new List<UPSIECPO>();
                            foreach (var sappo in withdrawPOList)
                            {
                                UPSIECPO iecpo = new UPSIECPO
                                {
                                    HPPO = poId,
                                    IECPO = sappo.IECPO,
                                    IECPOItem = sappo.IECPOItem,
                                    Model = sappo.IECSku,
                                    Qty = sappo.Qty,
                                    //Status = SendBOMState.Waiting.ToString(),
                                    Cdt = now,
                                    Udt = now,
                                    Status ="Withdraw",
                                    Editor = "Withdraw"
                                };
                                hppo.WithdrawIECPOList.Add(iecpo);
                            }
                            
                            hppo.WithdrawPartNoList = new List<UPSPOAVPart>();
                            foreach (var partNo in withdrawPOList[0].UPSMatchAVPart)
                            {
                                var modelBom = modelBomList.Where(x => x.AVPartNo == partNo).FirstOrDefault();
                                UPSPOAVPart part = new UPSPOAVPart
                                {
                                    HPPO = poId,
                                    AVPartNo = partNo,
                                    IECPartNo = modelBom == null ? string.Empty : modelBom.IECPartNo,
                                    IECPartType = modelBom == null ? string.Empty : modelBom.IECPartType,
                                    Editor = "Withdraw",
                                    Remark ="Withdraw",
                                    Udt = now,
                                    Cdt = now
                                };

                                hppo.WithdrawPartNoList.Add(part);
                            }
                            isWithdraw = true;
                            po.Status = SendBOMState.CreatedWithdrawPoBOM.ToString();
                            po.WithdrawQty = withdrawPOList.Sum(x => x.Qty);
                            po.Qty = po.Qty + po.WithdrawQty;
                        }                        
                        #endregion
                        
                        hppo.PO = po;
                        hppo.IECPOList = mesIecPoList.Where(x => x.HPPO == poId).ToList();
                        hppo.PartNoList = mesPoPartList.Where(x => x.HPPO == poId).ToList();
                        hppo.isWithdraw = isWithdraw;
                        hppo.Insert = false;
                        upspoList.Add(hppo);
                    }
                }

                var insertDataList = upspoList.Where(x => x.Insert || x.isWithdraw ).ToList();
                if (insertDataList.Count > 0)
                {
                    #region insert MES db data case
                    if (db.Connection.State == System.Data.ConnectionState.Closed)
                    {
                        db.Connection.Open();
                    }


                    db.Transaction = db.Connection.BeginTransaction();
                    var hppoList = insertDataList.Where(x=>x.Insert).Select(x => x.PO).ToList();
                    DataTableHelper.BulkCopyToDatabase(hppoList, "UPSHPPO", (SqlConnection)db.Connection, (SqlTransaction)db.Transaction);
                    //db.UPSHPPOEntity.InsertAllOnSubmit(hppoList);

                    var iecpoList = new List<UPSIECPO>();

                    insertDataList.ForEach(x => {
                        if (x.Insert)
                        {
                            iecpoList = iecpoList.Union(x.IECPOList).ToList();
                        }
                        else
                        {
                            iecpoList = iecpoList.Union(x.WithdrawIECPOList).ToList();
                        }
                    });

                    DataTableHelper.BulkCopyToDatabase(iecpoList, "UPSIECPO", (SqlConnection)db.Connection, (SqlTransaction)db.Transaction);
                    //db.UPSIECPOEntity.InsertAllOnSubmit(iecpoList);

                    var avPartList = new List<UPSPOAVPart>();
                    insertDataList.ForEach(x =>
                    {
                        if (x.Insert)
                        {
                            avPartList = avPartList.Concat(x.PartNoList).ToList();
                        }
                        else
                        {
                            avPartList = avPartList.Concat(x.WithdrawPartNoList).ToList();
                        }
                    });
                    //db.UPSPOAVPartEntity.InsertAllOnSubmit(avPartList);
                    DataTableHelper.BulkCopyToDatabase(avPartList, "UPSPOAVPart", (SqlConnection)db.Connection, (SqlTransaction)db.Transaction);
                    //db.SubmitChanges();

                    if (insertDataList.Any(x => x.isWithdraw))
                    {
                        db.SubmitChanges();
                    }

                    db.Transaction.Commit();
                    db.Connection.Close();

                    //重新get data
                    var mesPoList1 = (from x in db.UPSHPPOEntity
                                      where poNumList.Contains(x.HPPO)
                                      select x).ToList();

                    var mesIecPoList1 = (from x in db.UPSIECPOEntity
                                         where poNumList.Contains(x.HPPO)
                                         select x).ToList();

                    var mesPoPartList1 = (from x in db.UPSPOAVPartEntity
                                          where poNumList.Contains(x.HPPO)
                                          select x).ToList();
                    upspoList = new List<HPPO>();
                    foreach (var poId in poNumList)
                    {
                        HPPO hppo = new HPPO();
                        hppo.PO = mesPoList1.Where(x => x.HPPO == poId).First();
                        hppo.IECPOList = mesIecPoList1.Where(x => x.HPPO == poId).ToList();
                        hppo.PartNoList = mesPoPartList1.Where(x => x.HPPO == poId).ToList();
                        var withdrawDataList= insertDataList.Where(x => x.PO.HPPO == poId && x.isWithdraw).FirstOrDefault();
                        if (withdrawDataList!=null)
                        {
                            hppo.WithdrawIECPOList = withdrawDataList.WithdrawIECPOList;
                            hppo.isWithdraw = true;
                            hppo.WithdrawPartNoList = withdrawDataList.WithdrawPartNoList;
                            hppo.PO.WithdrawQty = withdrawDataList.PO.WithdrawQty;
                        }
                        hppo.Insert = false;
                        upspoList.Add(hppo);
                    }
                    #endregion
                }
                return upspoList;
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                if (db.Transaction != null && db.Transaction.Connection != null)
                {
                    db.Transaction.Rollback();
                }
                throw;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
            
        }
Example #17
0
        public static string GenOSIString(UPSPOBOM poBOM, string osiSpec, AppConfig config)
        {
            string osiString = "";
            string osiFormat = "<{0}>{1}</{0}>";
            int index = 0;
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                logger.InfoFormat("UPS OSI Spec:{0}, Config OSI Tag Name:{1} Config OSI Map Value:{2}",
                                            osiSpec, 
                                            string.Join (",",config.OSITagName),
                                            string.Join(",",config.OSITagNameMapValue));
                foreach (string name in config.OSITagName)
                {
                    if (!string.IsNullOrEmpty(name) && osiSpec.Contains(name))
                    {
                        string value="";
                        if (config.OSITagNameMapValue.Length > index)
                        {
                            if (config.OSITagNameMapValue[index].ToLower() == "customerpo")
                            {
                                value = poBOM.CustPO;
                            }
                            else
                            {
                                value = config.OSITagNameMapValue[index];
                            }
                        }
                        osiString = osiString + string.Format(osiFormat, name, value);

                    }

                    index++;
                }
                logger.InfoFormat("OSI String:{0}", osiString);
                return osiString;
            }
            catch (Exception e)
            {
                logger.Error(methodName, e);
                throw e;
            }
            finally
            {
                logger.DebugFormat("END: {0}()", methodName);
            }
        }
Example #18
0
        public static void ValidatePoStatus(BomStatus status, UPSPOBOM poBom, AppConfig config)
        {
            string methodName = MethodBase.GetCurrentMethod().Name;
            logger.DebugFormat("BEGIN: {0}()", methodName);
            try
            {
                logger.InfoFormat("Reply ValidatePoStatus retCode:{0} message:{1} datastring:{2}", status.retcode.ToString(), status.message, status.datastring);
                if (status.retcode == 0) //Holding process need waiting time
                {                    
                     poBom.State = SendBOMState.VerifyOK;                 
                }
                else if (status.retcode == 1) //need send OSI
                {
                    if (!string.IsNullOrEmpty(status.datastring))
                    {
                        poBom.State = SendBOMState.NeedSendOSI;


                        //產生OSI String ??????
                        //HP說目前OS只有CustomerPO欄位
                        //string osiString = "<CustomerPO>{0}</CustomerPO>";
                        //osiString = string.Format(osiString, poBom.CustPO);
                        string osiString = GenOSIString(poBom, status.datastring, config);

                        ValidateSendOSIStatus(RequestUPSSendOSI(poBom, osiString), poBom);
                        if (poBom.State == SendBOMState.SendOSIOK)
                        {
                            //6.UPSVerifyPO
                            BomStatus validatePoStatus = UPSWS.RequestUPSVerifyPOReady(poBom);
                            //7.UPSGetRange
                            UPSWS.ValidatePoStatus(validatePoStatus, poBom, config);
                        }
                    }
                    else
                    {
                        poBom.State = SendBOMState.VerifyFail;
                         poBom.ErrorText = string.Format("Return Code:{0} DataString:{1} Message:{2}", status.retcode, status.datastring, status.message);
                    }
                }
                else
                {
                    poBom.State = SendBOMState.VerifyFail;
                    poBom.ErrorText = string.Format("Return Code:{0} DataString:{1} Message:{2}", status.retcode, status.datastring, status.message);

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