Ejemplo n.º 1
0
        public static String ProcessCPShipto(String _so, String _sopo, Boolean _istesting)
        {
            System.Net.Mail.SmtpClient smtpClient1 = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["SMTPServer"]);

            Ship_to_Information ship_info = GetShipToInfo_BySOPO(_sopo).FirstOrDefault();

            DataAccess.SAPModel.SAPAccount s = new DataAccess.SAPModel.SAPAccount();

            s.SoldtoID        = "UZISCHE01";
            s.ShiptoID        = OrderBusinessLogic.GenerateNewUSShipToID(ship_info.ship_to_country_code, ship_info.ship_to_stateName, ship_info.ship_to_name, _istesting);
            s.CompanyName     = ship_info.ship_to_name;
            s.CountryCode     = ship_info.ship_to_country_code;
            s.OrgID           = "US01";
            s.City            = ship_info.ship_to_city;
            s.Address         = ship_info.ship_to_address;
            s.Region          = ship_info.ship_to_stateName;
            s.PostalCode      = ship_info.ship_to_postal_code;
            s.TEL             = ship_info.ship_to_telnumber;
            s.VatNumber       = ship_info.ship_to_country_code.Equals("US", StringComparison.CurrentCultureIgnoreCase) ? GetVATNumber(ship_info.ship_to_stateName) : " ";
            s.Currency        = GetSoDetail_Currency(_so);
            s.TaxJurisdiction = ship_info.ship_to_country_code.Equals("US", StringComparison.CurrentCultureIgnoreCase) ? ship_info.ship_to_stateName + ship_info.ship_to_postal_code.Substring(0, 5) : " ";
            s.Creator         = "VALERIE.MO";
            s.CreateDate      = DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.InvariantCulture);
            s.SalesGroupCode  = " ";
            s.SalesOfficeCode = "2200";
            s.ContactPerson   = ship_info.contact_person_first + ship_info.contact_person_last;

            DataAccess.SAPModel.SAPShipTo _objShipTo = CheckShiptoExistSAP(s.Address, s.ShiptoID);
            if (_objShipTo != null)
            {
                // Ship-to ID has already existed in SAP, return the exist one
                return(_objShipTo.SHIPTOID);
            }
            else
            {
                // Ship-to ID is not existed, need to create a new one.
                try
                {
                    DataAccess.SAPDAL.CreateUSShiptoAccount(s, _istesting); // Auto Creation
                    System.Threading.Thread.Sleep(3000);
                    DataAccess.SAPDAL.UpdateSAPSalesAreaData(s.SoldtoID, s.ShiptoID, s.OrgID, _istesting);

                    // Send Mail to Javian
                    smtpClient1.Send("*****@*****.**", "[email protected],[email protected],[email protected],[email protected]",
                                     string.Format("Check Point Auto-Create Shipto,  NewERPID: {0}", s.ShiptoID),
                                     string.Format("NewERPID: {0}", s.ShiptoID) + "\r\nTime: " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
                }
                catch (Exception ex)
                {
                    String errmsg = ex.ToString();
                }
                return(!String.IsNullOrEmpty(s.ShiptoID) ? s.ShiptoID : "");
            }
        }