Пример #1
0
 public MarketingDocument AddQuotation(MarketingDocument document, AppConnData oAppConnData)
 {
     return bizQuotation.Add(document, oAppConnData);
 }
Пример #2
0
 public MarketingDocument AddSalesOrder(MarketingDocument document, AppConnData oAppConnData)
 {
     return bizSalesOrder.Add(document, oAppConnData);
 }
        public MarketingDocument Add(SapDocumentType mktgDocType, MarketingDocument document, SAPConnection sapConn)
        {
            Documents doc = null;

            #region Document definition
            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oInvoices);
                    break;
                case SapDocumentType.SalesCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oCreditNotes);
                    break;
                case SapDocumentType.SalesDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oDeliveryNotes);
                    break;
                case SapDocumentType.SalesReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oReturns);
                    break;
                case SapDocumentType.SalesOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oOrders);
                    break;
                case SapDocumentType.PurchaseInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseInvoices);
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);
                    break;
                case SapDocumentType.PurchaseDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);
                    break;
                case SapDocumentType.PurchaseReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseReturns);
                    break;
                case SapDocumentType.PurchaseOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
                    break;
                case SapDocumentType.Quotation:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oQuotations);
                    break;
                default:
                    break;
            }
            #endregion

            #region Document header
            doc.Series = document.serie;
            doc.CardCode = document.cardCode;
            doc.DocDate = document.docDate;
            doc.DocDueDate = document.docDueDate;
            doc.TaxDate = document.taxDate;

            if (!string.IsNullOrEmpty(document.numAtCard))
                doc.NumAtCard = document.numAtCard;

            if (!string.IsNullOrEmpty(document.shipToCode))
                doc.ShipToCode = document.shipToCode;

            if (!string.IsNullOrEmpty(document.payToCode))
                doc.PayToCode = document.payToCode;

            if (document.groupNum != null)
                doc.GroupNumber = (int)document.groupNum;

            if (!string.IsNullOrEmpty(document.comments))
                doc.Comments = document.comments;

            if (document.slpCode != null)
                doc.SalesPersonCode = (int)document.slpCode;

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

            #endregion

            #region Document lines
            foreach (MarketingDocumentLine line in document.lines)
            {
                if (line.baseType != 202)
                    doc.Lines.ItemCode = line.itemCode;

                doc.Lines.Quantity = line.quantity;
                doc.Lines.WarehouseCode = line.whsCode;
                if (line.price != 0)
                    doc.Lines.UnitPrice = line.price;

                if (!string.IsNullOrEmpty(line.unitMsr))
                    doc.Lines.MeasureUnit = line.unitMsr;

                if (!string.IsNullOrEmpty(line.taxCode))
                    doc.Lines.TaxCode = line.taxCode;

                if (!string.IsNullOrEmpty(line.ocrCode))
                    doc.Lines.CostingCode = line.ocrCode;

                if (line.numPerMsr != 0)
                    doc.Lines.UnitsOfMeasurment = line.numPerMsr;

                if (line.baseEntry != 0)
                {
                    doc.Lines.BaseEntry = line.baseEntry;
                    doc.Lines.BaseLine = line.baseLine;
                    doc.Lines.BaseType = line.baseType;
                }

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

                #region Batchs
                if (line.batchNumbers != null)
                    foreach (BatchNumber batchNumber in line.batchNumbers)
                    {
                        doc.Lines.BatchNumbers.BatchNumber = batchNumber.DistNumber;
                        doc.Lines.BatchNumbers.Quantity = batchNumber.Quantity;
                        doc.Lines.BatchNumbers.ExpiryDate = batchNumber.ExpDate;
                        doc.Lines.BatchNumbers.Add();
                    }
                #endregion

                #region Series
                if (line.serialNumbers != null)
                    foreach (SerialNumber serie in line.serialNumbers)
                    {

                        doc.Lines.SerialNumbers.InternalSerialNumber = serie.DisNumber;
                        doc.Lines.SerialNumbers.Add();
                    }
                doc.Lines.Add();
                #endregion
            }
            #endregion

            if (doc.Add() != 0)
            {
                throw new SAPException(sapConn.company.GetLastErrorCode(), sapConn.company.GetLastErrorDescription());
            }
            document.docEntry = Convert.ToInt32(sapConn.company.GetNewObjectKey());
            return document;
        }
        public MarketingDocument Add(MarketingDocument document, 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();
                    SaleOrderAccess = new MarketingDocumentData(oAppConnData.adoConnString);
                    document = SaleOrderAccess.Add(SapDocumentType.Quotation, document, DataConnection.Conn);
                    DataConnection.EndTranAndRelease(BoWfTransOpt.wf_Commit);
                    return document;
                }

            }
            #region Catch
            catch (SAPException ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                BizUtilities.ProcessSapException(ex, "Gestión de Pagos");

            }
            catch (COMException ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                Exception outEx;
                try
                {
                    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 + " Descripción: " + ex.Message);
                        throw outEx;
                    }
                    else
                    {
                        throw;
                    }
                }
                catch (Exception)
                {
                }

                throw new Exception(ex.Message + "::" + ex.StackTrace);
            }
            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;
                }
                throw;
            }
            #endregion
            return document;
        }
        public List<MarketingDocument> GetWideList(SapDocumentType mktgDocType, DateTime startDate, DateTime endDate)
        {
            StringBuilder oSQL = new StringBuilder();

            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    break;
                case SapDocumentType.SalesCreditNote:
                    break;
                case SapDocumentType.SalesDelivery:
                    break;
                case SapDocumentType.SalesReturn:
                    break;
                case SapDocumentType.SalesOrder:
                    break;
                case SapDocumentType.PurchaseInvoice:
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    break;
                case SapDocumentType.PurchaseDelivery:
                    break;
                case SapDocumentType.PurchaseReturn:
                    break;
                case SapDocumentType.PurchaseOrder:
                    oSQL.Append("SELECT  T0.DocEntry, DocNum, CardCode, CardName, NumAtCard, T0.DocDate, DocStatus, Canceled, ");
                    oSQL.Append("ItemCode, Quantity, T1.WhsCode, WhsName, Dscription, LineStatus, T0.Doctype, T0.invntsttus, ");
                    oSQL.Append("T1.OpenCreQty, T1.OpenQty, T1.unitMsr, T1.NumPerMsr, T1.TargetType, T1.TrgetEntry, T1.LineNum, ");
                    oSQL.Append("T0.ObjType, T0.UpdateDate ");
                    oSQL.Append("FROM OPOR T0 ");
                    oSQL.Append("INNER JOIN POR1 T1 ");
                    oSQL.Append("ON T0.DocEntry = T1.DocEntry ");
                    oSQL.Append("LEFT JOIN OWHS T2 ");
                    oSQL.Append("ON T1.WhsCode = T2.WhsCode ");
                    oSQL.Append("Where T0.DocDate between @starDate and @endDate");
                    break;
                default:
                    break;
            }

            DbCommand dbCommand = this.dataBase.GetSqlStringCommand(oSQL.ToString());
            this.dataBase.AddInParameter(dbCommand, "starDate", DbType.Date, startDate);
            this.dataBase.AddInParameter(dbCommand, "endDate", DbType.Date, endDate);

            List<MarketingDocument> documentList = new List<MarketingDocument>();
            MarketingDocument document = new MarketingDocument();
            int DocEntryTemporal = 0;
            int contadorLineas = 0;

            using (this.reader = this.dataBase.ExecuteReader(dbCommand))
            {
                while (this.reader.Read())
                {
                    if (document.docEntry == 0 || Convert.ToInt32(this.reader.GetValue(0).ToString()) != DocEntryTemporal)
                    {
                        if (document.docEntry != 0)
                            documentList.Add(document);

                        document = new MarketingDocument();
                        document.docEntry = this.reader.IsDBNull(0) ? 0 : Convert.ToInt32(this.reader.GetValue(0).ToString());
                        document.docNum = this.reader.IsDBNull(1) ? 0 : Convert.ToInt32(this.reader.GetValue(1).ToString());
                        document.cardCode = this.reader.IsDBNull(2) ? "" : this.reader.GetValue(2).ToString();
                        document.cardName = this.reader.IsDBNull(3) ? "" : this.reader.GetValue(3).ToString();
                        document.numAtCard = this.reader.IsDBNull(4) ? "" : this.reader.GetValue(4).ToString();
                        document.docDate = this.reader.IsDBNull(5) ? DateTime.Now : Convert.ToDateTime(this.reader.GetValue(5).ToString());
                        document.docStatus = this.reader.IsDBNull(6) ? "" : this.reader.GetValue(6).ToString();
                        document.doctype = this.reader.IsDBNull(14) ? "" : this.reader.GetValue(14).ToString();
                        document.invntsttus = this.reader.IsDBNull(15) ? "" : this.reader.GetValue(15).ToString();
                        document.objtype = this.reader.IsDBNull(23) ? "" : this.reader.GetValue(23).ToString();
                        document.updateDate = this.reader.IsDBNull(24) ? DateTime.Now : Convert.ToDateTime(this.reader.GetValue(24).ToString());

                        if (this.reader.GetValue(7).ToString().Equals("Y"))
                            document.canceled = true;
                        else
                            document.canceled = false;
                        DocEntryTemporal = document.docEntry;
                    }
                    MarketingDocumentLine linea = new MarketingDocumentLine();
                    linea.itemCode = this.reader.IsDBNull(8) ? "" : this.reader.GetValue(8).ToString();
                    linea.quantity = this.reader.IsDBNull(9) ? 0 : Convert.ToDouble(this.reader.GetValue(9).ToString());
                    linea.whsCode = this.reader.IsDBNull(10) ? "" : this.reader.GetValue(10).ToString();
                    linea.whsName = this.reader.IsDBNull(11) ? "" : this.reader.GetValue(11).ToString();
                    linea.dscription = this.reader.IsDBNull(12) ? "" : this.reader.GetValue(12).ToString();
                    linea.lineStatus = this.reader.IsDBNull(13) ? "" : this.reader.GetValue(13).ToString();
                    linea.openCreQty = this.reader.IsDBNull(16) ? 0 : Convert.ToDouble(this.reader.GetValue(16).ToString());
                    linea.openQty = this.reader.IsDBNull(17) ? 0 : Convert.ToDouble(this.reader.GetValue(17).ToString());
                    linea.unitMsr = this.reader.IsDBNull(18) ? "" : this.reader.GetValue(18).ToString();
                    linea.numPerMsr = this.reader.IsDBNull(19) ? 0 : Convert.ToDouble(this.reader.GetValue(19).ToString());
                    linea.targetType = this.reader.IsDBNull(20) ? 0 : Convert.ToInt32(this.reader.GetValue(20).ToString());
                    linea.trgetEntry = this.reader.IsDBNull(21) ? 0 : Convert.ToInt32(this.reader.GetValue(21).ToString());
                    linea.lineNum = this.reader.IsDBNull(22) ? 0 : Convert.ToInt32(this.reader.GetValue(22).ToString());

                    document.lines.Add(linea);
                    contadorLineas++;
                }
                if (document.docEntry != 0)
                    documentList.Add(document);
            }
            return documentList;
        }
        public void Cancel(SapDocumentType mktgDocType, MarketingDocument document, SAPConnection sapConn)
        {
            Documents doc = null;

            #region Document definition
            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oInvoices);
                    break;
                case SapDocumentType.SalesCreditNote:
                    doc = doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oCreditNotes);
                    break;
                case SapDocumentType.SalesDelivery:
                    doc = doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oDeliveryNotes);
                    break;
                case SapDocumentType.SalesReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oReturns);
                    break;
                case SapDocumentType.SalesOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oOrders);
                    break;
                case SapDocumentType.PurchaseInvoice:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseInvoices);
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseCreditNotes);
                    break;
                case SapDocumentType.PurchaseDelivery:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseDeliveryNotes);
                    break;
                case SapDocumentType.PurchaseReturn:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseReturns);
                    break;
                case SapDocumentType.PurchaseOrder:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oPurchaseOrders);
                    break;
                case SapDocumentType.Quotation:
                    doc = (Documents)sapConn.company.GetBusinessObject(BoObjectTypes.oQuotations);
                    break;
                default:
                    break;
            }
            #endregion


            doc.GetByKey(document.docEntry);

            if (doc.DocumentStatus == BoStatus.bost_Close)
                throw new SAPException(-8900, "El pedido está cerrado");

            if (doc.Cancel() != 0)
                throw new SAPException(sapConn.company.GetLastErrorCode(), SAPConnection.conn.company.GetLastErrorDescription());
        }
        public MarketingDocument Add(SapDocumentType mktgDocType, MarketingDocument document)
        {
            StringBuilder cmd = new StringBuilder();
            string doc = string.Empty;

            #region Document definition
            switch (mktgDocType)
            {
                case SapDocumentType.SalesInvoice:
                    doc = "InvoicesService";
                    break;
                case SapDocumentType.SalesCreditNote:
                    doc = "CreditNotesService";
                    break;
                case SapDocumentType.SalesDelivery:
                    doc = "DeliveryNotesService";
                    break;
                case SapDocumentType.SalesReturn:
                    doc = "ReturnsService";
                    break;
                case SapDocumentType.SalesOrder:
                    doc = "OrdersService";
                    break;
                case SapDocumentType.PurchaseInvoice:
                    doc = "PurchaseInvoicesService";
                    break;
                case SapDocumentType.PurchaseCreditNote:
                    doc = "PurchaseCreditNotesService";
                    break;
                case SapDocumentType.PurchaseDelivery:
                    doc = "PurchaseDeliveryNotesService";
                    break;
                case SapDocumentType.PurchaseReturn:
                    doc = "PurchaseReturnsService";
                    break;
                case SapDocumentType.PurchaseOrder:
                    doc = "PurchaseOrdersService";
                    break;
                case SapDocumentType.Quotation:
                    doc = "QuotationsService";
                    break;
                case SapDocumentType.Draft:
                    doc = "DraftsService";
                    break;
                default:
                    break;
            }
            #endregion
            try
            {
                CreateSession();
                cmd.Append(@"<?xml version=""1.0"" encoding=""UTF-16""?>");
                cmd.Append(@"<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">");
                cmd.Append(string.Format("<env:Header><SessionID>{0}</SessionID></env:Header>", _sessionId));
                cmd.Append("<env:Body>");
                cmd.Append(@"<dis:Add xmlns:dis=""http://www.sap.com/SBO/DIS"">");
                cmd.Append(string.Format("<Service>{0}</Service>", doc));

                cmd.Append("<Document>");

                #region Document header
                cmd.Append(string.Format("<Series>{0}</Series>", document.serie));
                cmd.Append(string.Format("<CardCode>{0}</CardCode>", document.cardCode));
                cmd.Append(string.Format("<DocDate>{0}</DocDate>", document.docDate.ToString("yyyy-MM-dd")));
                cmd.Append(string.Format("<DocDueDate>{0}</DocDueDate>", document.docDueDate.ToString("yyyy-MM-dd")));
                cmd.Append(string.Format("<TaxDate>{0}</TaxDate>", document.taxDate.ToString("yyyy-MM-dd")));

                if (!string.IsNullOrEmpty(document.numAtCard))
                    cmd.Append(string.Format("<NumAtCard>{0}</NumAtCard>", document.numAtCard));

                if (!string.IsNullOrEmpty(document.shipToCode))
                    cmd.Append(string.Format("<ShipToCode>{0}</ShipToCode>", document.shipToCode));

                if (!string.IsNullOrEmpty(document.payToCode))
                    cmd.Append(string.Format("<PayToCode>{0}</PayToCode>", document.payToCode));

                if (document.groupNum != null)
                    cmd.Append(string.Format("<GroupNumber>{0}</GroupNumber>", document.groupNum.ToString()));

                if (!string.IsNullOrEmpty(document.comments))
                    cmd.Append(string.Format("<Comments>{0}</Comments>", document.comments));

                if (document.slpCode != null)
                    cmd.Append(string.Format("<SalesPersonCode>{0}</SalesPersonCode>", document.slpCode));

                #endregion

                #region Document lines
                cmd.Append("<DocumentLines>");
                foreach (MarketingDocumentLine line in document.lines)
                {
                    cmd.Append("<DocumentLine>");

                    if (line.baseType != 202)
                        cmd.Append(string.Format("<ItemCode>{0}</ItemCode>", line.itemCode));

                    cmd.Append(string.Format("<Quantity>{0}</Quantity>", line.quantity.ToString()));
                    cmd.Append(string.Format("<WarehouseCode>{0}</WarehouseCode>", line.whsCode));

                    if (line.price != 0)
                        cmd.Append(string.Format("<UnitPrice>{0}</UnitPrice>", line.price.ToString()));

                    if (!string.IsNullOrEmpty(line.unitMsr))
                        cmd.Append(string.Format("<MeasureUnit>{0}</MeasureUnit>", line.unitMsr));

                    if (!string.IsNullOrEmpty(line.taxCode))
                        cmd.Append(string.Format("<TaxCode>{0}</TaxCode>", line.taxCode));

                    if (!string.IsNullOrEmpty(line.ocrCode))
                        cmd.Append(string.Format("<CostingCode>{0}</CostingCode>", line.ocrCode));

                    if (line.numPerMsr != 0)
                        cmd.Append(string.Format("<UnitsOfMeasurment>{0}</UnitsOfMeasurment>", line.numPerMsr));

                    if (line.baseEntry != 0)
                    {
                        cmd.Append(string.Format("<BaseEntry>{0}</BaseEntry>", line.baseEntry));
                        cmd.Append(string.Format("<BaseLine>{0}</BaseLine>", line.baseLine));
                        cmd.Append(string.Format("<BaseType>{0}</BaseType>", line.baseType));
                    }

                    cmd.Append("</DocumentLine>");
                }

                cmd.Append("<DocumentLines>");
                #endregion

                cmd.Append("</Document>");
                cmd.Append("</dis:Add></env:Body></env:Envelope>");

                string AddDocument = node.BatchInteract(cmd.ToString());
                XmlDocument response = new XmlDocument();
                response.Load(AddDocument);

                int docEntry = -1;
                if (int.TryParse(response.DocumentElement.InnerText, out docEntry))
                    document.docEntry = docEntry;

                ReleaseSession();
            }
            catch (Exception ex)
            {
                ReleaseSession();
                throw ex;
            }

            return document;
        }
        public MarketingDocument Add(MarketingDocument document, 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))
                {
                    SaleOrderAccess = new MarketingDocumentData(oAppConnData.adoConnString);

                    UserDefinedField webDocument = document.userDefinedFields.Where(x => x.name == "U_orkWebDocument").FirstOrDefault();

                    if (webDocument != null)
                        if (!SaleOrderAccess.ExistWebDocument(SapDocumentType.SalesOrder, webDocument.value))
                        {
                            DataConnection.BeginTran();
                            document = SaleOrderAccess.Add(SapDocumentType.SalesOrder, document, DataConnection.Conn);
                            DataConnection.EndTranAndRelease(BoWfTransOpt.wf_Commit);
                        }
                        else
                        {
                            int docEntry = SaleOrderAccess.GetDocEntry(SapDocumentType.SalesOrder, int.Parse(webDocument.value));
                            document.docEntry = docEntry;
                        }
                    return document;
                }

                //***** prueba DIServer *****//
                //OrderAccess = new DocumentData(oAppConnData.dataBaseName, licenseServer, dbServer, oAppConnData.sapUser, oAppConnData.sapUserPassword, dbUser, dbUserPassword, serverType);
                //OrderAccess.Add(SapDocumentType.SalesOrder, document);
            }
            #region Catch
            catch (SAPException ex)
            {
                DataConnection.EndTranAndRelease(SAPbobsCOM.BoWfTransOpt.wf_RollBack);
                BizUtilities.ProcessSapException(ex, "Gestión de Pagos");

            }
            catch (COMException ex)
            {
                string[] error = ex.Message.Split(' ');

                if (error.Length == 2)
                    if (error[0] == "(-7)")
                    {
                        document.docEntry = Convert.ToInt32(error[1]);
                        return document;
                    }

                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 + " Descripción: " + ex.Message);
                    throw outEx;
                }
                else
                {
                    throw;
                }

                throw new Exception(ex.Message + "::" + ex.StackTrace);
            }
            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 + " Descripción: " + ex.Message);
                        throw outEx;

                    }
                }
                else
                {
                    throw ex;
                    //return 0;
                }
                throw;
            }
            #endregion
            return document;
        }
Пример #9
0
 public MarketingDocument AddSalesOrder(MarketingDocument document, AppConnData oAppConnData)
 {
     try
     {
         facade = new BizFacade(BusinessClass.BizSalesOrder);
         return facade.AddSalesOrder(document, 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");
     }
 }