Ejemplo n.º 1
0
        /// *****************************************************************************************
        /// General files process - Only NIS XML valid Files are processed here:
        ///     (1) - Select orders to process depending on WasImported status.
        ///     (2) - Route process to the corresponding import process using delegates.
        ///     (3) - NIS table reading errors are detected here.
        ///     (4) - Errors are logged in service log and reported through web services.
        /// -----------------------------------------------------------------------------------------
        public void ProcessOrder(int order, EtlTimer sync)
        {
            /// Initialize Error messages object basic information
            ServiceResponse errMsg = new ServiceResponse();

            errMsg.FileType   = "1";
            errMsg.FileName   = "Order: " + order.ToString();
            errMsg.NISOrderId = "0";
            errMsg.Status     = "Not Processed";
            errMsg.Message    = string.Empty;
            try
            {
                /// *********************************************************************************
                /// Select files acceptable to be process, all other file types (extension) will not
                /// be processed (they stay in the newFiles folder) and an error message is generated
                /// to the WebServices.
                /// Only NIS (1) row are processed by entry.
                /// ---------------------------------------------------------------------------------
                NisTables NisOrder = new NisTables();
                NisOrder = Inr.getNisOrder(order);

                if (NisOrder != null && NisOrder.items != null)
                {
                    /// Instanciate NBI Tables methods delegate
                    Del handler = null;
                    // Declare a class instance xml:
                    ImportProcedure_NIS_V2.BuildJason.ImportProcess table = new ImportProcedure_NIS_V2.BuildJason.ImportProcess();
                    /// Declare an interface instance Table:
                    ImportProcedure_NIS_V2.BuildJason.INISTables orderClass = (ImportProcedure_NIS_V2.BuildJason.INISTables)table;
                    /// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    /// Route to the corresponding NIS import procedure
                    ///  ----------------------------------------------------------------------------
                    handler = orderClass.ProcessNisOrder;
                    bool ok = false;
                    ok = handler(NisOrder, order, sync);                  //  Process file and WebService
                }
                else
                {   //  update error order - set imported on and import problem on
                    int ret = Inr.updNisOrder(order, 0, 1, 0);
                    icr.writeSyncLog(1, sync.MwEtlTimerId, 1, sync.ServiceName, "Table reading error order header or no items found, order " + order);
                }
            }
            catch (Exception fle)
            {
                int res = icr.updImportControl(sync.MwEtlTimerId, 0);     //  set EtlTimer for this service to not Running (isRunning = false)
                errMsg.Message = "(NIS ProcessFile) Table reading error - in order " + errMsg.FileName + ". " + fle;
                icr.writeSyncLog(1, sync.MwEtlTimerId, 1, sync.ServiceName, errMsg.Message);
                int resp = Inr.updNisOrder(Convert.ToInt32(errMsg.FileName), 0, 1, 0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Retreive the complete order information (header and all depending items) for an specific order.
        /// </summary>
        /// <param name="order"></param>
        /// <returns>Nis tables class</returns>
        public NisTables getNisOrder(int order)
        {
            SqlDataReader   dr    = null;
            NisTables       ord   = new NisTables();
            List <NisItems> list  = new List <NisItems>();
            int             items = 0;

            try
            {
                System.Collections.Specialized.NameValueCollection args = new NameValueCollection();
                args.Add("@Order", order.ToString());
                DBContext.DBAccess access = new DBContext.DBAccess();
                //
                dr = access.ExecuteReader("[MW_GetNisOrder]", DBContext.DBAccess.DBConnection.NameSys, args);
                //
                while (dr != null && dr.Read())
                {
                    NisHeader head = new NisHeader();
                    head.HeaderId            = (Int32)(dr["ID"].ToString().Length > 0 ? Int32.Parse(dr["ID"].ToString()) : 0);
                    head.HeaderUserId        = (Int32)(dr["userID"].ToString().Length > 0 ? Int32.Parse(dr["userID"].ToString()) : 0);
                    head.HeaderUserEmail     = dr["email"].ToString().Length > 0 ? dr["email"].ToString() : "";
                    head.HeaderOrderDate     = dr["orderDate"].ToString().Length > 0 ? DateTime.Parse(dr["orderDate"].ToString()) : DateTime.Now;
                    head.HeaderDateRequested = dr["dateReq"].ToString().Length > 0 ? DateTime.Parse(dr["dateReq"].ToString()) : DateTime.Now;
                    head.HeaderPO            = dr["PO"].ToString().Length > 0 ? dr["PO"].ToString() : "";
                    head.HeaderDescription   = dr["description"].ToString().Length > 0 ? dr["description"].ToString() : "";
                    head.HeaderShipVia1      = dr["shippingViaID"].ToString().Length > 0 ? dr["shippingViaID"].ToString() : "";
                    head.HeaderShipVia2      = dr["shippingViaID2"].ToString().Length > 0 ? dr["shippingViaID2"].ToString() : "";
                    head.HeaderShipToId1     = dr["shippingToID"].ToString().Length > 0 ? dr["shippingToID"].ToString() : "";
                    head.HeaderShipToId2     = dr["shippingToID2"].ToString().Length > 0 ? dr["shippingToID2"].ToString() : "";
                    head.HeaderComments      = dr["comments"].ToString().Length > 0 ? dr["comments"].ToString() : "";
                    head.FileName            = "Db Source";
                    head.HeaderSentDate      = dr["sentDate"].ToString().Length > 0 ? DateTime.Parse(dr["sentDate"].ToString()) : DateTime.Now;
                    ord.header = head;      //  Store order header information
                    //
                    dr.NextResult();        //  Move to the second select result set
                    //
                    while (dr != null && dr.Read())
                    {   //  Get all order items (From second select result set)
                        NisItems itm = new NisItems();
                        items++;
                        itm.NisOrderId  = items;            //  set item sequence
                        itm.Itemid      = (int)(dr["Id"].ToString().Length > 0 ? int.Parse(dr["Id"].ToString()) : 0);
                        itm.OrderId     = (int)(dr["orderID"].ToString().Length > 0 ? int.Parse(dr["orderID"].ToString()) : 0);
                        itm.SkuId       = (int)(dr["SKU_ID"].ToString().Length > 0 ? int.Parse(dr["SKU_ID"].ToString()) : 0);
                        itm.LineId      = (int)(dr["lineID"].ToString().Length > 0 ? int.Parse(dr["lineID"].ToString()) : 0);
                        itm.Quantity1   = (int)(dr["Qty1"].ToString().Length > 0 ? int.Parse(dr["Qty1"].ToString()) : 0);
                        itm.Quantity2   = (int)(dr["Qty2"].ToString().Length > 0 ? int.Parse(dr["Qty2"].ToString()) : 0);
                        itm.Line1       = dr["line1"].ToString().Length > 0 ? dr["line1"].ToString() : "";
                        itm.Line2       = dr["line2"].ToString().Length > 0 ? dr["line2"].ToString() : "";
                        itm.Line3       = dr["line3"].ToString().Length > 0 ? dr["line3"].ToString() : "";
                        itm.Description = dr["description"].ToString().Length > 0 ? dr["description"].ToString() : "";
                        itm.SkuClient   = dr["SKU_client"].ToString().Length > 0 ? dr["SKU_client"].ToString() : "";
                        itm.SkuWe       = dr["SKU_WE"].ToString().Length > 0 ? dr["SKU_WE"].ToString() : "";
                        itm.AccountCode = dr["accountID"].ToString().Length > 0 ? dr["accountID"].ToString() : "";
                        list.Add(itm);
                    }
                    ord.items = list;   //  Store order Items information
                }
            }
            finally
            {
                if ((dr != null) && (!dr.IsClosed))
                {
                    dr.Close();
                }
            }
            return(ord);
        }
Ejemplo n.º 3
0
        /// *************************************************************************************************
        /// <summary>
        ///     07/27/2017 11:27 version
        ///     NIS Orders process, Order data come as an object splited into order header/detail sections.
        ///     Each section is send to WebServices as a JSON string if header/detail information is complete,
        ///     when detail info.
        ///     All errors are send to a Webservice (Error) and included in the Service log.
        /// </summary>
        /// <param name="doc">Imported order content as a NisTables class</param>
        /// <param name="oNumber">Order number</param>
        /// <param name="fName">EtlTimer sync control data)</param>
        /// <returns>Process status true if procees was completed ok, else false</returns>
        /// -------------------------------------------------------------------------------------------------
        bool INISTables.ProcessNisOrder(NisTables doc, int oNumber, EtlTimer syncRow)
        {
            /// Response from MW api
            ServiceResponse rStatus = new ServiceResponse();

            DAL.SupportServices.SupportServices       wsm = new DAL.SupportServices.SupportServices(); //  Set WebService methods pointer
            DAL.ImportControl.ImportControlRepository icr = new DAL.ImportControl.ImportControlRepository();
            ///  Create error message object and initialice it
            ServiceResponse errMsg = new ServiceResponse();

            errMsg.FileType   = "1";    //  Set Nis Type
            errMsg.FileName   = "NIS Table";
            errMsg.NISOrderId = oNumber.ToString();
            errMsg.Status     = "Not Processed";
            errMsg.Message    = "No items found for this order header";
            /// *********************************************************************************************
            //  Order header section
            /// ---------------------------------------------------------------------------------------------
            string jsonHead = "{ \"nisOrderSummary\":" + Newtonsoft.Json.JsonConvert.SerializeObject(doc.header);

            /// *********************************************************************************************
            ///  Order Detail Section
            ///  --------------------------------------------------------------------------------------------
            /// ===============================================================================
            /// Send Imported files data content to webServices - information must be complete
            /// Order Header + all related Order Items.
            /// -------------------------------------------------------------------------------
            if (doc.items.Count > 0)
            {
                /// Serialize Items list and complete json string for Header and Items
                string json2 = jsonHead + ", \"nisOrderItems\" : " + Newtonsoft.Json.JsonConvert.SerializeObject(doc.items) + "}";
                /// ******************************************************************************
                /// Call Web Service
                /// <param name="json2">        Header/detail object Json serialized string.</param>
                /// <param name="fname">        Xml file name </param>
                /// <param name="syncRow.WebServiceOrders">File Type, route to web service(url)</param>
                /// <param name="syncRow">      EtlTimer control data.
                /// <returns>"rStatus" true if WebService was processed, else false</returns>
                /// *** Web service url is defined in the App.Config file key 'NisOrder'.
                /// ------------------------------------------------------------------------------
                /// ==============> save order data through the defined web service
                rStatus = wsm.ConsumeWebService(json2, oNumber.ToString(), syncRow.WebServiceOrders, syncRow);   //"OrderData", syncRow); //// TEMPORARY UNCOMMENT TO SEND JSON INFO
                ///
                //rStatus.IsOk = true;          /// set order process to ok TEMPORARY, UNCOMMENT IF WEB SERVICE IS USED TO SEND JSON INFO
                ///
                string apiMsg   = "";
                int    resp     = 0;            ///  Order update response
                int    uOption  = 0;
                int    impProb  = 0;
                int    navOrder = 0;
                DAL.ImportControl.ImportControlRepository ikr = new DAL.ImportControl.ImportControlRepository();
                DAL.ImportControl.ImportNISRepository     inr = new DAL.ImportControl.ImportNISRepository();
                //
                if (rStatus.Status == "OK")
                {   //  set order condition to imported
                    apiMsg       = " Imported";
                    uOption      = 1;
                    rStatus.IsOk = true;
                    navOrder     = Convert.ToInt32(rStatus.NISOrderId);
                    ///
                    /// Save processed files log - May16-2017
                    ///
                    int res = ikr.writeImportLog(syncRow.MwEtlTimerId, "NIS", doc.header.HeaderId.ToString());
                }
                else
                {   //  Set order contion to imported with errors.
                    impProb      = 1;
                    apiMsg       = " Not Imported - API errors";
                    rStatus.IsOk = false;
                }
                resp = inr.updNisOrder(oNumber, uOption, impProb, navOrder);   // ************  MUST UPDATE NIS ORDER    *******************
                //
                string ret = ikr.writeSyncLog(1, syncRow.MwEtlTimerId, 1, syncRow.ServiceName, "> " + syncRow.Description + " NIS Order: <" + doc.header.HeaderId + "> " + apiMsg + ".");
                //  <==============
                //  <==============
            }
            else
            {   /// Incomplete order (No order items included and no xls file Name reported in orderHeader)
                jsonHead = jsonHead + " }";
                /// Send Message to WebService
                wsm.WriteErrorFile(errMsg, syncRow);    //// TEMPORARY UNCOMMENT TO SEND JSON INFO
            }
            return(rStatus.IsOk);
        }