Пример #1
0
 public void AddBusinessPartnerAddress(BusinessPartnerAddress address, AppConnData oAppConnData)
 {
     try
     {
         facade = new BizFacade(BusinessClass.BizBusinessPartner);
         facade.AddBusinessPartnerAddress(address, oAppConnData);
     }
     catch (Exception ex)
     {
         DataAccessFault detalleError = new DataAccessFault();
         foreach (string valores in ex.Data.Keys)
         {
             switch (valores)
             {
                 case "1": detalleError.ErrorID = ex.Data[valores].ToString();
                     break;
                 case "2": detalleError.ErrorSAP = ex.Data[valores].ToString();
                     break;
                 case "3": detalleError.Description = ex.Data[valores].ToString();
                     break;
                 default: detalleError.ErrorID = ex.Data[valores].ToString();
                     break;
             }
         }
         throw new FaultException<DataAccessFault>(detalleError, "Error al Procesar la solicitud");
     }
 }
Пример #2
0
 public void AddBusinessPartnerAddress(BusinessPartnerAddress address, AppConnData oAppConnData)
 {
     bizBusinessPartner.AddAddress(address, oAppConnData);
 }
        public List<BusinessPartnerAddress> GetAddressList(string cardCode, AddressType addressType)
        {
            StringBuilder oSQL = new StringBuilder();
            oSQL.Append(string.Format("SELECT Address, Street FROM CRD1 T0 WHERE cardCode = '{0}' ", cardCode));

            switch (addressType)
            {
                case AddressType.ShipTo:
                    oSQL.Append(string.Format("AND  adresType = '{0}' ", "S"));
                    break;
                case AddressType.BillTo:
                    oSQL.Append(string.Format("AND  adresType = '{0}' ", "B"));
                    break;
                default:
                    break;
            }

            DbCommand myCommand = this.dataBase.GetSqlStringCommand(oSQL.ToString());

            List<BusinessPartnerAddress> contacts = new List<BusinessPartnerAddress>();

            using (this.reader = this.dataBase.ExecuteReader(myCommand))
            {
                while (this.reader.Read())
                {
                    BusinessPartnerAddress contact = new BusinessPartnerAddress();
                    //contact.addressType = this.reader.GetValue(0).ToString() == "S" ? AddressType.ShipTo : AddressType.BillTo;
                    contact.address = this.reader.IsDBNull(0) ? "" : this.reader.GetValue(0).ToString();
                    contact.street = this.reader.IsDBNull(1) ? "" : this.reader.GetValue(1).ToString();

                    contacts.Add(contact);
                }
            }
            return contacts;
        }
        public void AddAddress(BusinessPartnerAddress address, SAPConnection sapConn)
        {
            int addressQty = GetAddressList(address.cardCode, AddressType.BillTo).Count() + GetAddressList(address.cardCode, AddressType.ShipTo).Count();

            BusinessPartners bp; //= new BusinessPartners();
            bp = (BusinessPartners)sapConn.company.GetBusinessObject(BoObjectTypes.oBusinessPartners);
            bp.GetByKey(address.cardCode);

            bp.Addresses.Add();
            bp.Addresses.SetCurrentLine(addressQty);

            bp.Addresses.AddressType = address.addressType == AddressType.BillTo ? BoAddressType.bo_BillTo : BoAddressType.bo_ShipTo;
            bp.Addresses.AddressName = address.address;

            if (!string.IsNullOrEmpty(address.street))
                bp.Addresses.Street = address.street;

            if (!string.IsNullOrEmpty(address.block))
                bp.Addresses.Block = address.block;

            if (!string.IsNullOrEmpty(address.zipCode))
                bp.Addresses.ZipCode = address.zipCode;

            if (!string.IsNullOrEmpty(address.city))
                bp.Addresses.City = address.city;

            if (!string.IsNullOrEmpty(address.country))
                bp.Addresses.Country = address.country;

            if (!string.IsNullOrEmpty(address.county))
                bp.Addresses.County = address.county;

            if (!string.IsNullOrEmpty(address.taxCode))
                bp.Addresses.TaxCode = address.taxCode;

            if (!string.IsNullOrEmpty(address.streetNo))
                bp.Addresses.StreetNo = address.streetNo;

            if (!string.IsNullOrEmpty(address.state))
                bp.Addresses.State = address.state;

            #region UDF's
            if (address.UserDefinedFields != null)
                foreach (UserDefinedField item in address.UserDefinedFields)
                {
                    if (!string.IsNullOrEmpty(item.value))
                        switch (item.type)
                        {
                            case UdfType.Alphanumeric:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            case UdfType.Integer:
                                bp.UserFields.Fields.Item(item.name).Value = int.Parse(item.value);
                                break;
                            case UdfType.Double:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Datetime:
                                bp.UserFields.Fields.Item(item.name).Value = DateTime.Parse(item.value);
                                break;
                            case UdfType.Price:
                                bp.UserFields.Fields.Item(item.name).Value = double.Parse(item.value);
                                break;
                            case UdfType.Text:
                                bp.UserFields.Fields.Item(item.name).Value = item.value;
                                break;
                            default:
                                break;
                        }
                }
            #endregion

            bp.Update();
        }
        public bool AddAddress(BusinessPartnerAddress address, AppConnData oAppConnData)
        {
            try
            {
                if (!BizUtilities.ValidateServiceConnection(oAppConnData))
                    throw new BusinessException(15, "Nombre de Usuario o Contraseña incorrecta para el Servicio");

                oAppConnData = BizUtilities.GetDataConnection(oAppConnData);

                string licenseServer = Cryptography.Decrypt(HexSerialization.HexToString(ConfigurationManager.AppSettings["licenseServer"]));
                string dbServer = Cryptography.Decrypt(HexSerialization.HexToString(ConfigurationManager.AppSettings["dbServer"]));
                string dbUser = Cryptography.Decrypt(HexSerialization.HexToString(ConfigurationManager.AppSettings["dbUser"]));
                string dbUserPassword = Cryptography.Decrypt(HexSerialization.HexToString(ConfigurationManager.AppSettings["dbUserPassword"]));
                string serverType = ConfigurationManager.AppSettings["serverType"];

                DataConnection = new SAPConnectionData(oAppConnData.dataBaseName, licenseServer, dbServer, oAppConnData.sapUser, oAppConnData.sapUserPassword, dbUser, dbUserPassword, serverType);

                if (DataConnection.ConnectCompany(oAppConnData.dataBaseName, oAppConnData.sapUser, oAppConnData.sapUserPassword))
                {
                    DataConnection.BeginTran();
                    BusinessPartnerAccess = new BusinessPartnerData(oAppConnData.adoConnString);
                    BusinessPartnerAccess.AddAddress(address, DataConnection.Conn);
                    DataConnection.EndTranAndRelease(BoWfTransOpt.wf_Commit);
                    return true;
                }
            }
            #region Catch
            catch (SAPException ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                BizUtilities.ProcessSapException(ex, "Gestión de Pagos");
                return false;
            }
            catch (COMException ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                Exception outEx;
                if (ExceptionPolicy.HandleException(ex, "Politica_Excepcion_Com", out outEx))
                {
                    outEx.Data.Add("1", "3");
                    outEx.Data.Add("2", "NA");
                    outEx.Data.Add("3", outEx.Message);
                    throw outEx;
                }
                else
                {
                    throw;
                }

            }
            catch (DbException ex)
            {
                Exception outEx;
                if (ExceptionPolicy.HandleException(ex, "Politica_SQLServer", out outEx))
                {
                    outEx.Data.Add("1", "14");
                    outEx.Data.Add("2", "NA");
                    //outEx.Data.Add("3", outEx.Message);
                    outEx.Data.Add("3", outEx.Message + " Descripción: " + ex.Message);
                    throw outEx;
                }
                else
                {
                    throw ex;
                }
            }
            catch (BusinessException ex)
            {
                ex.Data.Add("1", ex.ErrorId);
                ex.Data.Add("2", "NA");
                ex.Data.Add("3", ex.Message);
                throw ex;
            }
            catch (Exception ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                Exception outEx;
                if (ex.Data["1"] == null)
                {
                    if (ExceptionPolicy.HandleException(ex, "Politica_ExcepcionGenerica", out outEx))
                    {
                        outEx.Data.Add("1", "3");
                        outEx.Data.Add("2", "NA");
                        outEx.Data.Add("3", outEx.Message);
                        throw outEx;

                    }
                }
                else
                {
                    throw ex;
                    //return 0;
                }
                return false;
            }
            #endregion
            return false;
        }