コード例 #1
0
ファイル: Order.cs プロジェクト: QYFS2018/VC2
        public override ReturnValue UpdateShipment()
        {
            ReturnValue _result = new ReturnValue();

            Common.Connect();

            #region get order list

            TOrder _tOrder = new TOrder();
            _result = _tOrder.getShimentOrderList();
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "getShimentOrderList failed. \r\n " + _result.ErrMessage;

                Common.Log("getShimentOrderList---ER \r\n" + _result.ErrMessage);

                return(_result);
            }

            EntityList orderList = _result.ObjectList;

            VCBusiness.Model.TProgram_Email _tProgram_Email = Common.CreateObject(this.Owner, "TProgram_Email") as VCBusiness.Model.TProgram_Email;
            _result = _tProgram_Email.getEmailTemplate("SHIP_CONFIRMATION");
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "getEmailTemplate failed. \r\n " + _result.ErrMessage;

                Common.Log("getEmailTemplate---ER \r\n" + _result.ErrMessage);

                return(_result);
            }

            _tProgram_Email = _result.Object as TProgram_Email;



            #endregion

            #region update shipment

            foreach (TOrder order in orderList)
            {
                Common.Log("Order : " + order.OrderId);

                #region GetOrderShipmentInfo

                EntityList productList = new EntityList();

                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    #region test


                    TOrder_Line_Item orderline = new TOrder_Line_Item();
                    _result = orderline.getOrderLineItemsByOrderId(order.OrderId);

                    foreach (TOrder_Line_Item item in _result.ObjectList)
                    {
                        item.ShipCarrier    = "UPS";
                        item.ShipMethod     = "STD";
                        item.TrackingNumber = "123456789";
                        item.ShippedDate    = System.DateTime.Now;
                        productList.Add(item);
                    }

                    #endregion
                }
                else
                {
                    #region call Veracore

                    _result = VeraCore.GetOrderShipmentInfo(order.OrderId.ToString());
                    if (_result.Success == false)
                    {
                        if (_result.ErrMessage.IndexOf("Invalid Order ID") > -1)
                        {
                            _result.ErrMessage = "Can't find the order";
                        }
                        else
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;
                        }
                        Common.Log("Order : " + order.OrderId + "  GetOrderShipmentInfo---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    productList = _result.ObjectList;

                    if (productList.Count() == 0)
                    {
                        Common.Log("Order : " + order.OrderId + "---Unshipped");

                        continue;
                    }

                    #endregion
                }

                #endregion

                Transaction _tran = new Transaction();

                #region update order line



                foreach (TOrder_Line_Item item in productList)
                {
                    order.ShipCarrier    = item.ShipCarrier;
                    order.ShipMethod     = item.ShipMethod;
                    order.TrackingNumber = item.TrackingNumber;
                    order.ShippedDate    = item.ShippedDate.Value;

                    _result = item.updateOrderLineItemShipment(order.OrderId, item.PartNumber, item.ShippedDate.Value, item.TrackingNumber, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  updateOrderLineItemShipment---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    if (this.Owner.OwnerInfo["ImportDM"].ToString() == "Y")
                    {
                        TDM_Order_Detail _tDM_Order_Detail = new TDM_Order_Detail();
                        _tDM_Order_Detail.DataConnectProviders = "ZoytoPH";
                        _result = _tDM_Order_Detail.updateDMShipingInfo(order.OrderId, item.PartNumber, order.ShippedDate.Value, order.TrackingNumber);
                        if (_result.Success == false)
                        {
                            _tran.RollbackTransaction();
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  updateDMShipingInfo---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                    }
                }

                #endregion

                #region update carton & ASN

                #region get release list

                TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
                _result = _tOrder_Line_Item.getOrderReleaseByOrderId(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  getOrderReleaseByOrderId---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                EntityList _releaseList = _result.ObjectList;

                #endregion

                #region delete cartion and ASN

                TOrder_Line_Shipment_Carton _tOrder_Line_Shipment_Carton = new TOrder_Line_Shipment_Carton();
                _result = _tOrder_Line_Shipment_Carton.deleteOrderLineShipmentCartonByOrderID(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  deleteOrderLineShipmentCartonByOrderID---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                TOrder_Line_Shipment_ASN _tOrder_Line_Shipment_ASN = new TOrder_Line_Shipment_ASN();
                _result = _tOrder_Line_Shipment_ASN.deleteOrderLineShipmentASNByOrderID(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  deleteOrderLineShipmentASNByOrderID---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                #endregion

                int releaseID = 1;
                foreach (TOrder_Line_Item item in _releaseList)
                {
                    #region update release number && carton && ASN

                    _result = item.updateOrderReleaseByTracking(order.OrderId, item.TrackingNumber, releaseID, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  updateOrderReleaseByTracking---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    _tOrder_Line_Shipment_Carton                  = new TOrder_Line_Shipment_Carton();
                    _tOrder_Line_Shipment_Carton.ORDER_ID         = order.OrderId;
                    _tOrder_Line_Shipment_Carton.RELEASE_NUM      = releaseID;
                    _tOrder_Line_Shipment_Carton.CARTON_ID_FROM   = releaseID.ToString();
                    _tOrder_Line_Shipment_Carton.CARRIER_ID       = order.ShipCarrier;
                    _tOrder_Line_Shipment_Carton.SHIP_METHOD      = order.ShipMethod;
                    _tOrder_Line_Shipment_Carton.PACKAGE_TRACE_ID = item.TrackingNumber;
                    _tOrder_Line_Shipment_Carton.Ship_date        = item.ShippedDate.Value;

                    _result = _tOrder_Line_Shipment_Carton.Save(_tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  _tOrder_Line_Shipment_Carton.Save---ER \r\n" + _result.ErrMessage);

                        continue;
                    }


                    _result = item.createASN(order.OrderId, releaseID, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + " createASN---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    #endregion

                    releaseID++;
                }

                #endregion

                #region update phontom item

                _result = _tOrder.updateOrderPhontomOrderStatus(order.OrderId, order.ShippedDate.Value, order.TrackingNumber, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  updateOrderPhontomOrderStatus---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                #endregion

                #region customerEventPostShipmentUpdate

                _result = this.customerEventPostShipmentUpdate(order, productList, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  customerEventPostShipmentUpdate---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                #endregion

                _tran.CommitTransaction();

                #region sent confirm email

                if (Owner.OwnerInfo["ShipConfirmation"].ToString() == "Y")
                {
                    #region check already sent email

                    App_Log_Mail _app_Log_Mail = new App_Log_Mail();
                    _result = _app_Log_Mail.getEmailLog(order.OrderId, releaseID - 1);
                    if (_result.Success == false)
                    {
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  getEmailLog---ER \r\n" + _result.ErrMessage);

                        continue;
                    }
                    _app_Log_Mail = _result.Object as App_Log_Mail;

                    #endregion

                    if (_app_Log_Mail.ID == 0)
                    {
                        #region sent shipment email

                        #region get email content

                        VCBusiness.EmailFactory EmailFactory = Common.CreateObject(this.Owner, "EmailFactory") as VCBusiness.EmailFactory;
                        _result = EmailFactory.GetMailContent(order.OrderId, releaseID - 1, _tProgram_Email);
                        if (_result.Success == false)
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  GetMailContent---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                        EmailMessage email = _result.ObjectValue as EmailMessage;

                        #endregion

                        #region sent email

                        _result = EmailFactory.SentEmail(order.OrderId, releaseID - 1, email);
                        if (_result.Success == false)
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  SentEmail---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                        #endregion

                        #endregion
                    }
                }

                #endregion

                successfulRecord++;
                Common.Log("Order : " + order.OrderId + "---OK");
            }

            #endregion

            #region update Order Status SH

            _result = _tOrder.updateOrderStatusSH();
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "updateOrderStatusSH failed. \r\n " + _result.ErrMessage;

                Common.Log("updateOrderStatusSH---ER \r\n" + _result.ErrMessage);

                return(_result);
            }


            #endregion

            Common.SentAlterEmail(failedRecord, errorNotes);

            _result.Success = true;


            return(_result);
        }
コード例 #2
0
        public ReturnValue Run(string ownerCode, string action, string oid)
        {
            ReturnValue _result = new ReturnValue();

            #region get Owner List

            Controler Controler = new Controler();
            _result = Controler.getControler();
            if (_result.Success == false)
            {
                Common.ProcessError(_result, true);

                return(_result);
            }

            #endregion

            foreach (Owner owner in Controler.Owners)
            {
                if (ownerCode == "999" || ownerCode == owner.OwnerCode.ToString())
                {
                    #region check and set onwer setting

                    bool enableRun = false;
                    if (owner.Actions.ContainsKey(action.ToUpper()) == true)
                    {
                        enableRun = Convert.ToBoolean(owner.Actions[action.ToUpper()].ToString());
                    }

                    if (enableRun == false)
                    {
                        continue;
                    }

                    Common.OwnerCode  = owner.OwnerCode;
                    WComm.ConInfo.Url = owner.RegSubKey;
                    VCBusiness.BaseOrder Order = Common.CreateObject(owner, "Order") as VCBusiness.BaseOrder;
                    Order.Owner = owner;
                    VCBusiness.BaseProduct Product = Common.CreateObject(owner, "Product") as VCBusiness.BaseProduct;
                    Product.Owner      = owner;
                    Common.ProcessType = action;

                    #endregion

                    #region Run function

                    if (action.ToUpper() == "OrderDownload".ToUpper())
                    {
                        Common.Log("Start OrderDownload");
                        _result = Order.Download();
                    }

                    if (action.ToUpper() == "UpdateShipment".ToUpper())
                    {
                        Common.Log("Start Update Shipment");
                        _result = Order.UpdateShipment();
                    }

                    if (action.ToUpper() == "ProductDownload".ToUpper())
                    {
                        Common.Log("Start Product Download");
                        _result = Product.ProductDownload();
                    }

                    if (action.ToUpper() == "UpdateInventoryStatus".ToUpper())
                    {
                        Common.Log("Start UpdateInventoryStatus");
                        _result = Product.UpdateInventoryStatus();
                    }

                    if (action.ToUpper() == "ShipConfirmEmail".ToUpper())
                    {
                        #region ShipConfirmEmail

                        Common.Log("Start ShipConfirmEmail");

                        VCBusiness.Model.TProgram_Email _tProgram_Email = Common.CreateObject(owner, "TProgram_Email") as VCBusiness.Model.TProgram_Email;
                        _result = _tProgram_Email.getEmailTemplate("SHIP_CONFIRMATION");
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        _tProgram_Email = _result.Object as TProgram_Email;


                        VCBusiness.EmailFactory EmailFactory = Common.CreateObject(owner, "EmailFactory") as VCBusiness.EmailFactory;
                        _result = EmailFactory.GetMailContent(int.Parse(oid), 1, _tProgram_Email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }
                        EmailMessage email = _result.ObjectValue as EmailMessage;

                        _result = EmailFactory.SentEmail(int.Parse(oid), 1, email);
                        if (_result.Success == false)
                        {
                            return(_result);
                        }

                        #endregion
                    }



                    if (action.ToUpper() == "ImportDMOrderDetail".ToUpper())
                    {
                        _result = Order.ImportDMOrderDetail(int.Parse(oid));
                    }

                    if (action.ToUpper() == "GenerateInvoicePDF".ToUpper())
                    {
                        VCBusiness.TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                        _result = TecnifibreInvoicePDF.PrintInvoice(int.Parse(oid));
                    }

                    if (action.ToUpper() == "InvoiceEmail".ToUpper())
                    {
                        VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();
                        _result = EmailFactory.ReSentInvoiceEmail();
                    }

                    #region Tecnifibre

                    Tecnifibre Tecnifibre = new Tecnifibre();

                    if (action.ToUpper() == "TFDueInvoices".ToUpper())
                    {
                        Common.Log("Start TFDueInvoices");
                        _result = Tecnifibre.DueInvoices();
                    }

                    if (action.ToUpper() == "TFPastDue".ToUpper())
                    {
                        Common.Log("Start TFPastDue");
                        _result = Tecnifibre.PastDue();
                    }

                    if (action.ToUpper() == "TFCancelOrder".ToUpper())
                    {
                        Common.Log("Start TFCancelOrder");
                        _result = Tecnifibre.CancelHDOrder();
                    }

                    if (action.ToUpper() == "TFWishList".ToUpper())
                    {
                        Common.Log("Start TFWishList");
                        _result = Tecnifibre.WishList();
                    }


                    #endregion


                    #endregion

                    if (_result.Success == false)
                    {
                        Common.ProcessError(_result, false);
                    }

                    Common.Log("Finish");
                }
            }

            return(_result);
        }