Example #1
0
        public List<NotifyStdWeightResponse> NotifyStdWeight(NotifyStdWeight[] StdWeightItems)
        {
            string connectionDB = "SD_DBServer";
            string connectionDB_EDI = "SD_DBServer_EDI";
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);

            try
            {            
                //1.檢查必要的input parameter
                Execute.ValidateParameter(connectionDB, StdWeightItems);

                //3.執行DB insert
                Execute.Process(connectionDB, connectionDB_EDI, StdWeightItems);

                //4.Build Response Message
                List<NotifyStdWeightResponse> pgiresponse = Execute.BuildResponseMsg(connectionDB, StdWeightItems);

                return pgiresponse;
            }
            catch (Exception e)
            {
                logger.Error(MethodBase.GetCurrentMethod(), e);
                //  UTL.SendMail("test", e.Message);
                //4.Build Response Error Message
                List<NotifyStdWeightResponse> ResponseList = new List<NotifyStdWeightResponse>();
                foreach (NotifyStdWeight item in StdWeightItems)
                {
                    NotifyStdWeightResponse response = new NotifyStdWeightResponse();
                    string SerialNumber = "";
                    string State = "F";
                    response.SerialNumber = SerialNumber;
                    response.Plant = item.Plant;
                    response.Model = item.Model;
                    response.Result = State;
                    ResponseList.Add(response);
                }
                return ResponseList;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }
        
        }
Example #2
0
        public static void UpdateStdWeight(string connectionDB, int dbIndex, NotifyStdWeight result)
        {
            string Model = (result.Model == null ? "":result.Model);
            string GrossWeight = (result.GrossWeight == null ? "":result.GrossWeight);

            string strSQL = @"if not exists(select * from PAK_SkuMasterWeight_FIS where Model=@Model)
                              begin
                                    insert into PAK_SkuMasterWeight_FIS(Model, Weight, Cdt)
                                    values (@Model, @GrossWeight, @Now)  
                              end
                              else
                              begin
                                     update PAK_SkuMasterWeight_FIS
                                     set Weight=@GrossWeight, Cdt=@Now
                                     where Model=@Model
                              end";

            SQLHelper.ExecuteNonQuery(SQLHelper.GetDBConnectionString(connectionDB, dbIndex),
                                                System.Data.CommandType.Text,
                                                strSQL,
                                                SQLHelper.CreateSqlParameter("@Model", 20, Model),
                                                SQLHelper.CreateSqlParameter("@GrossWeight", 20, GrossWeight),
                                                SQLHelper.CreateSqlParameter("@Now", DateTime.Now));
        }
Example #3
0
        //3.執行DB insert 
        public static void Process(string connectionDB, string connectionDB_EDI, NotifyStdWeight[] results)
        {
            int dbIndex = 0;
            string HPPlantCode = WebConfigurationManager.AppSettings["HPPlantCode"];
            string SyncEDIStdWeight = WebConfigurationManager.AppSettings["SyncEDIStdWeight"];
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            try
            {
                foreach (NotifyStdWeight item in results)
                {
                    string SerialNumber = item.SerialNumber;
                    if (item.Plant == HPPlantCode)
                    {
                        if (SyncEDIStdWeight == "Y")
                        {
                            //insert or update Grossweight to HPEDI.table for connection
                            SQL.UpdateStdWeight(connectionDB_EDI, dbIndex, item);

                            //insert or update Grossweight to HPEDI.table for connection 2
                            SQL.UpdateStdWeight(connectionDB, dbIndex, item);
                        }
                        else {
                            //insert or update Grossweight to HPEDI.table for connection
                            SQL.UpdateStdWeight(connectionDB_EDI, dbIndex, item);

                        }


                        //log success response record to TxnDataLog
                        SQL.InsertTxnDataLog_DB(connectionDB, dbIndex,
                                                EnumMsgCategory.Response,
                                                "NotifyStdWeightResponse",
                                                string.IsNullOrEmpty(item.Model) ? "" : item.Model,
                                                string.IsNullOrEmpty(item.GrossWeight) ? "" : item.GrossWeight,
                                                string.IsNullOrEmpty(item.SerialNumber) ? "" : item.SerialNumber,
                                                "",
                                                "",
                                                EnumMsgState.Success,
                                                string.IsNullOrEmpty(item.Plant) ? "" : item.Plant);
                    }
                }
                
            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }
        }
Example #4
0
        //1.檢查必要的input parameter
        public static void ValidateParameter(string connectionDB, NotifyStdWeight[] results)
        {
            int dbIndex = 0;
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            try
            {
                List<string> NotNullItemList = new List<string> {"SerialNumber",
                                                                 "Plant",
                                                                 "Model",
                                                                 "GrossWeight",
                                                                 "Unit"};
                foreach (NotifyStdWeight item in results)
                {
                    logger.DebugFormat("NotifyStdWeight: \r\n{0}", ObjectTool.ObjectTostring(item));
                    //log receive record to TxnDataLog
                    SQL.InsertTxnDataLog_DB(connectionDB, dbIndex,
                                            EnumMsgCategory.Receive,
                                            "NotifyStdWeight",
                                            string.IsNullOrEmpty(item.Model) ? "" : item.Model,
                                            string.IsNullOrEmpty(item.GrossWeight) ? "" : item.GrossWeight,
                                            string.IsNullOrEmpty(item.SerialNumber) ? "" : item.SerialNumber,
                                            "",
                                            "",
                                            EnumMsgState.Received,
                                            string.IsNullOrEmpty(item.Plant) ? "" : item.Plant);
                }

                foreach (NotifyStdWeight item in results)
                {
                    //Check null data
                    string className = item.GetType().BaseType.Name;
                    if (className == "Object")
                    { className = item.GetType().Name; }
                    string title = "These columns of " + className + " are null or no data : ";
                    string error = "";
                    foreach (string itemcolumn in NotNullItemList)
                    {
                        if (string.IsNullOrEmpty(GetValueByType(itemcolumn, item).Trim()))
                        { error = error + itemcolumn + ","; }
                    }

                    if (error != "")
                    {
                        error = title + error;

                        //log fail response record to TxnDataLog
                        SQL.InsertTxnDataLog_DB(connectionDB, dbIndex,
                                                EnumMsgCategory.Response,
                                                "NotifyStdWeightResponse",
                                                string.IsNullOrEmpty(item.Model) ? "" : item.Model,
                                                string.IsNullOrEmpty(item.GrossWeight) ? "" : item.GrossWeight,
                                                string.IsNullOrEmpty(item.SerialNumber) ? "" : item.SerialNumber,
                                                "",
                                                "",
                                                EnumMsgState.Fail,
                                                string.IsNullOrEmpty(item.Plant) ? "" : item.Plant);
                    }            
                }

            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }
            
        }
Example #5
0
        //4.Build Response message structure
        public static List<NotifyStdWeightResponse> BuildResponseMsg(string connectionDB, NotifyStdWeight[] results)
        {
            int dbIndex = 0;
            string methodName = MethodBase.GetCurrentMethod().Name;
            BaseLog.LoggingBegin(logger, methodName);
            List<NotifyStdWeightResponse> ResponseList = new List<NotifyStdWeightResponse>();
            try
            {
                foreach (NotifyStdWeight item in results)
                {
                    BaseLog.LoggingInfo(logger, "SerialNumber: \r\n{0}", ObjectTool.ObjectTostring(item.SerialNumber));

                    NotifyStdWeightResponse response = new NotifyStdWeightResponse();
                    string SerialNumber = item.SerialNumber;
                    string State = SQL.GetStdWeightState(connectionDB, dbIndex, SerialNumber);
                    if (State == "N") State = "F";
                    response.SerialNumber = item.SerialNumber;
                    response.Plant = item.Plant;
                    response.Model = item.Model; 
                    response.Result = State;
                    ResponseList.Add(response);
                }

                return ResponseList;
            }
            catch (Exception e)
            {
                BaseLog.LoggingError(logger, MethodBase.GetCurrentMethod(), e);
                throw e;
            }
            finally
            {
                BaseLog.LoggingEnd(logger, methodName);
            }                 

        }