private CatService.CatalogueServiceResult DeleteStock(CatService.CatalogueService catalogueServiceProxy,
     CatService.CatalogueServiceResult catalogueServiceReply, CatService.CatalogueDTO catalogue,
     CatService.OperationContext catalogueOp, int currentRow)
 {
     try
     {
         catalogueServiceReply = new CatService.CatalogueServiceResult();
         catalogueServiceReply = catalogueServiceProxy.delete(catalogueOp, catalogue);
     }
     catch (Exception errordelete)
     {
         _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
         _cells.GetCell(resultColumn, currentRow).Value = "ERROR: " + errordelete.Message;
         ErrorLogger.LogError("RibbonEllipse.cs:CreateStock()", errordelete.Message, _eFunctions.DebugErrors);
     }
     return catalogueServiceReply;
 }
        /// <summary>
        ///     Funcion para crear, editar y asociar al Parte Numero al Stock Code.
        /// </summary>
        private void CreateStock()
        {
            var catalogueServiceProxy = new CatService.CatalogueService();
            var catalogueOp = new CatService.OperationContext();
            catalogueServiceProxy.Url = _eFunctions.GetServicesUrl(drpEnviroment.SelectedItem.Label) +
                                        "/CatalogueService";

            var productServiceProxy = new CatProdService.CatalogueProductService();
            var product = new CatProdService.CatalogueProductDTO();
            var productServiceOp = new CatProdService.OperationContext();
            productServiceProxy.Url = _eFunctions.GetServicesUrl(drpEnviroment.SelectedItem.Label) +
                                      "/CatalogueProductService";

            var currentRow = tittleRow + 1;

            catalogueOp.district = _frmAuth.EllipseDsct;
            catalogueOp.position = _frmAuth.EllipsePost;
            catalogueOp.maxInstances = 100;
            catalogueOp.returnWarnings = _eFunctions.DebugWarnings;

            productServiceOp.district = _frmAuth.EllipseDsct;
            productServiceOp.position = _frmAuth.EllipsePost;
            productServiceOp.maxInstances = 100;
            productServiceOp.returnWarnings = _eFunctions.DebugWarnings;

            ClientConversation.authenticate(_frmAuth.EllipseUser, _frmAuth.EllipsePswd);

            while (!string.IsNullOrEmpty("" + _cells.GetCell(2, currentRow).Value))
            {
                try
                {
                    var catalogue = new CatService.CatalogueDTO
                    {
                        stockCode = _cells.GetNullOrTrimmedValue(_cells.GetCell(1, currentRow).Value),
                        isItemNameEnabled = true,
                        stockStatus = "D",
                        trackingIndicator = "N",
                        externallyManagedIndicator = false,
                        isExistedInventory = false,
                        itemName = "98008",
                        assetInd = false,
                        isExcludedFromRequirementDetermination = false,
                        isGloballyMaintained = false,
                        consumeAtSupplyCustomerAccount = false,
                        isEntitlementCheckingRequired = false,
                        isInspectionRequired = false,
                        unitOfIssue = _cells.GetNullOrTrimmedValue(_cells.GetCell(3, currentRow).Value),
                        batchLotManagementIndicator = false,
                        isRelifeAllowed = false,
                        isQualityDocumentationRequired = false,
                        isPackagingOrTreatmentRequired = false,
                        repairOrderFlag = false,
                        isAutoGenerateRepairOrder = false
                    };

                    var catalogueServiceReply = catalogueServiceProxy.create(catalogueOp, catalogue);

                    if (catalogueServiceReply.errors.Length > 0)
                    {
                        foreach (var t in catalogueServiceReply.errors)
                        {
                            _cells.GetCell(resultColumn, currentRow).Value += " - " + t.messageText;
                        }
                        _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
                    }
                    else
                    {
                        _cells.GetCell(1, currentRow).Value = catalogueServiceReply.catalogueDTO.stockCode;

                        catalogue = new CatService.CatalogueDTO
                        {
                            stockCode = catalogueServiceReply.catalogueDTO.stockCode,
                            unitOfIssue = _cells.GetNullOrTrimmedValue(_cells.GetCell(3, currentRow).Value),
                            volume = Convert.ToDecimal(0),
                            weight = Convert.ToDecimal(0),
                            isExistedInventory = false,
                            externallyManagedIndicator = false,
                            productServiceCategoryId = "9999",
                            description = _cells.GetNullOrTrimmedValue(_cells.GetCell(2, currentRow).Value),
                            classification = "T",
                            stockType = "T",
                            assetInd = false,
                            isExcludedFromRequirementDetermination = false,
                            isGloballyMaintained = false,
                            consumeAtSupplyCustomerAccount = false,
                            trackingIndicator = "N",
                            isEntitlementCheckingRequired = false,
                            isInspectionRequired = false,
                            batchLotManagementIndicator = false,
                            isRelifeAllowed = false,
                            isQualityDocumentationRequired = false,
                            isPackagingOrTreatmentRequired = false,
                            repairOrderFlag = false,
                            isAutoGenerateRepairOrder = false
                        };

                        try
                        {
                            catalogueServiceReply = new CatService.CatalogueServiceResult();
                            catalogueServiceReply = catalogueServiceProxy.update(catalogueOp, catalogue);

                            //Si existe algun error en la actualizacion del Stock se muestran los mensajes de Error y se procede a Eliminar el Registro
                            if (catalogueServiceReply.errors.Length > 0)
                            {
                                foreach (var t in catalogueServiceReply.errors)
                                {
                                    _cells.GetCell(resultColumn, currentRow).Value += " - " + t.messageText;
                                }
                                _cells.GetCell(1, currentRow).Style = StyleConstants.Error;

                                catalogueServiceReply = DeleteStock(catalogueServiceProxy, catalogueServiceReply,
                                    catalogue, catalogueOp, currentRow);
                            }
                            else
                            {
                                try
                                {
                                    product.stockCode = catalogue.stockCode;
                                    product.partNumber =
                                        _cells.GetNullOrTrimmedValue(_cells.GetCell(4, currentRow).Value);
                                    product.manufacturerMnemonic = "MINSTAL";
                                    product.preferredPartIndicator = "01";
                                    product.partStatus1 = "V";

                                    productServiceProxy.create(productServiceOp, product);

                                    //Activar Stock
                                    try
                                    {
                                        catalogueServiceReply = new CatService.CatalogueServiceResult();
                                        catalogueServiceReply = catalogueServiceProxy.activate(catalogueOp, catalogue);

                                        if (catalogueServiceReply.errors.Length > 0)
                                        {
                                            foreach (var t in catalogueServiceReply.errors)
                                            {
                                                _cells.GetCell(resultColumn, currentRow).Value += " - " + t.messageText;
                                            }
                                            _cells.GetCell(1, currentRow).Style = StyleConstants.Error;

                                            catalogueServiceReply = DeleteStock(catalogueServiceProxy,
                                                catalogueServiceReply, catalogue, catalogueOp, currentRow);
                                        }
                                        else
                                        {
                                            _cells.GetCell(1, currentRow).Style = StyleConstants.Success;
                                        }
                                    }
                                    catch (Exception errorActivate)
                                    {
                                        _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
                                        _cells.GetCell(resultColumn, currentRow).Value = "ERROR: " +
                                                                                         errorActivate.Message;
                                        ErrorLogger.LogError("RibbonEllipse.cs:CreateStock()", errorActivate.Message,
                                            _eFunctions.DebugErrors);

                                        catalogueServiceReply = DeleteStock(catalogueServiceProxy, catalogueServiceReply,
                                            catalogue, catalogueOp, currentRow);
                                    }
                                }
                                catch (Exception errorCreatePn)
                                {
                                    _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
                                    _cells.GetCell(resultColumn, currentRow).Value = "ERROR: " + errorCreatePn.Message;
                                    ErrorLogger.LogError("RibbonEllipse.cs:CreateStock()", errorCreatePn.Message,
                                        _eFunctions.DebugErrors);

                                    catalogueServiceReply = DeleteStock(catalogueServiceProxy, catalogueServiceReply,
                                        catalogue, catalogueOp, currentRow);
                                }
                            }
                        }
                        catch (Exception errorUpdate)
                        {
                            _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
                            _cells.GetCell(resultColumn, currentRow).Value = "ERROR: " + errorUpdate.Message;
                            ErrorLogger.LogError("RibbonEllipse.cs:CreateStock()", errorUpdate.Message,
                                _eFunctions.DebugErrors);

                            DeleteStock(catalogueServiceProxy, catalogueServiceReply, catalogue, catalogueOp, currentRow);
                        }
                    }
                }
                catch (Exception errorCreate)
                {
                    _cells.GetCell(1, currentRow).Style = StyleConstants.Error;
                    _cells.GetCell(resultColumn, currentRow).Value = "ERROR: " + errorCreate.Message;
                    ErrorLogger.LogError("RibbonEllipse.cs:CreateStock()", errorCreate.Message, _eFunctions.DebugErrors);
                }
                finally
                {
                    currentRow++;
                }
            }
        }