private void ModifyInvoice()
        {
            ClientConversation.authenticate(_frmAuth.EllipseUser, _frmAuth.EllipsePswd);

            supplierInfo = new SupplierInvoiceInfo();

            var currentRow = TittleRow + 1;

            var proxySheet = new screen.ScreenService();
            var requestSheet = new screen.ScreenSubmitRequestDTO();

            proxySheet.Url = _eFunctions.GetServicesUrl(drpEnviroment.SelectedItem.Label) + "/ScreenService";

            var opSheet = new screen.OperationContext
            {
                district = _frmAuth.EllipseDsct,
                position = _frmAuth.EllipsePost,
                maxInstances = 100,
                maxInstancesSpecified = true,
                returnWarnings = _eFunctions.DebugWarnings
            };
            _cells.GetCell(1, currentRow).Select();

            while (_cells.GetNullIfTrimmedEmpty(_cells.GetCell(1, currentRow).Value) != null)
            {
                try
                {
                    _cells.GetCell(1, currentRow).Select();
                    supplierInfo.Supplier = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(1, currentRow).Value);
                    supplierInfo.Factura = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(2, currentRow).Value);
                    supplierInfo.Fechapagosolicitada = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(3, currentRow).Value);
                    supplierInfo.Fechapagooriginal = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(4, currentRow).Value);
                    supplierInfo.PmtStatus = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(5, currentRow).Value);
                    supplierInfo.Proveedor = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(6, currentRow).Value);
                    supplierInfo.CodigoBancoOriginal = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(7, currentRow).Value);
                    supplierInfo.St = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(8, currentRow).Value));
                    supplierInfo.Vrtotalfactura = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(9, currentRow).Value));
                    supplierInfo.VrBasedeDescuento = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(10, currentRow).Value));
                    supplierInfo.Diferencia = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(11, currentRow).Value));
                    supplierInfo.Descuentocalculado = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(12, currentRow).Value));
                    supplierInfo.Vrdescuentoaplicado = Convert.ToDouble(_cells.GetNullIfTrimmedEmpty(_cells.GetCell(13, currentRow).Value));
                    supplierInfo.Fechadepagomodificada = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(14, currentRow).Value);
                    supplierInfo.BancodePagoModificado = _cells.GetNullIfTrimmedEmpty(_cells.GetCell(15, currentRow).Value);

                    _eFunctions.RevertOperation(opSheet, proxySheet);

                    var replySheet = proxySheet.executeScreen(opSheet, "MSO261");

                    if (_eFunctions.CheckReplyError(replySheet))
                    {
                        _cells.GetCell(ResultColumn, currentRow).Style = StyleConstants.Error;
                        _cells.GetCell(ResultColumn, currentRow).Value = replySheet.message;
                    }
                    else
                    {
                        if (replySheet.mapName != "MSM261A") return;
                        var arrayFields = new ArrayScreenNameValue();
                        arrayFields.Add("OPTION1I", "1");
                        arrayFields.Add("DSTRCT_CODE1I", "ICOR");
                        arrayFields.Add("SUPPLIER_NO1I", supplierInfo.Supplier);
                        arrayFields.Add("INV_NO1I", supplierInfo.Factura);
                        requestSheet.screenFields = arrayFields.ToArray();

                        requestSheet.screenKey = "1";
                        replySheet = proxySheet.submit(opSheet, requestSheet);

                        while (_eFunctions.CheckReplyWarning(replySheet) || replySheet.functionKeys.Contains("XMIT-Confirm"))
                            replySheet = proxySheet.submit(opSheet, requestSheet);

                        if (_eFunctions.CheckReplyError(replySheet))
                        {
                            _cells.GetCell(ResultColumn, currentRow).Style = StyleConstants.Error;
                            _cells.GetCell(ResultColumn, currentRow).Value = replySheet.message;
                        }
                        else if (replySheet.mapName == "MSM261B")
                        {
                            arrayFields = new ArrayScreenNameValue();

                            arrayFields.Add("BRANCH_CODE2I", parameters.Branchcode);
                            arrayFields.Add("BANK_ACCT_NO2I", parameters.Bankaccount);
                            arrayFields.Add("SD_AMOUNT2I", supplierInfo.Descuentocalculado.ToString(CultureInfo.InvariantCulture));
                            arrayFields.Add("SD_DATE2I", supplierInfo.Fechapagosolicitada);
                            requestSheet.screenFields = arrayFields.ToArray();

                            requestSheet.screenKey = "1";
                            replySheet = proxySheet.submit(opSheet, requestSheet);

                            while (_eFunctions.CheckReplyWarning(replySheet) || replySheet.functionKeys.Contains("XMIT-Confirm"))
                                replySheet = proxySheet.submit(opSheet, requestSheet);

                            if (_eFunctions.CheckReplyError(replySheet) & !replySheet.message.Contains("X2:3730 - MODIFICATIONS MADE TO INVOICE"))
                            {
                                _cells.GetCell(ResultColumn, currentRow).Style = StyleConstants.Error;
                                _cells.GetCell(ResultColumn, currentRow).Value = replySheet.message;
                            }
                            else
                            {
                                _cells.GetCell(ResultColumn, currentRow).Style = StyleConstants.Success;
                                _cells.GetCell(ResultColumn, currentRow).Value = "Success";

                                _cells.GetCell(13, currentRow).Value = supplierInfo.Vrdescuentoaplicado = supplierInfo.Descuentocalculado;
                                _cells.GetCell(14, currentRow).Value = supplierInfo.Fechadepagomodificada = supplierInfo.Fechapagosolicitada;
                                _cells.GetCell(15, currentRow).Value = supplierInfo.BancodePagoModificado =  parameters.Branchcode+ " - " + parameters.Bankaccount ;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    _cells.GetCell(ResultColumn, currentRow).Style = StyleConstants.Error;
                    _cells.GetCell(ResultColumn, currentRow).Value = ex.Message;
                }
                finally
                {
                    currentRow++;
                }
            }
        }
        private void ManintainGeneralProfile(ref string option1I, ref ArrayScreenNameValue arrayFields,
            Screen.OperationContext opSheet, Screen.ScreenService proxySheet, Screen.ScreenSubmitRequestDTO requestSheet,
            ref Screen.ScreenDTO replySheet, int currentRow, out string profile, out string profileType,
            out string fuelOilType2I, out string fuelCapacity2I)
        {
            option1I = option1I.Substring(0, 1);
            profileType = "" + _cells.GetCell("B" + currentRow).Value;
            profile = "" + _cells.GetCell("C" + currentRow).Value;
            fuelOilType2I = "" + _cells.GetCell("D" + currentRow).Value;
            fuelCapacity2I = "" + _cells.GetCell("E" + currentRow).Value;

            _eFunctions.RevertOperation(opSheet, proxySheet);
            replySheet = proxySheet.executeScreen(opSheet, "MSO615");

            if (replySheet.mapName == "MSM615A" && _excelApp.ActiveWorkbook.ActiveSheet.Name == _sheetName01)
            {
                arrayFields = new ArrayScreenNameValue();
                arrayFields.Add("OPTION1I", option1I);

                if (profileType == "EGI")
                {
                    arrayFields.Add("GROUP_ID11I", profile);
                }
                else
                {
                    arrayFields.Add("PLANT_NO11I", profile);
                }

                requestSheet.screenFields = arrayFields.ToArray();
                requestSheet.screenKey = "1";
                replySheet = proxySheet.submit(opSheet, requestSheet);

                if (_eFunctions.CheckReplyWarning(replySheet))
                    replySheet = proxySheet.submit(opSheet, requestSheet);

                if (replySheet != null && replySheet.mapName == "MSM617B" && !_eFunctions.CheckReplyError(replySheet))
                {
                    arrayFields = new ArrayScreenNameValue();

                    arrayFields.Add("PLANT_NO2I", profile);
                    arrayFields.Add("FUEL_OIL_TYPE2I", fuelOilType2I);
                    arrayFields.Add("FUEL_CAPACITY2I", fuelCapacity2I);
                    arrayFields.Add("VAL_PROF_FLG2I", "N");

                    requestSheet.screenFields = arrayFields.ToArray();
                    requestSheet.screenKey = "1";
                    replySheet = proxySheet.submit(opSheet, requestSheet);

                    if (replySheet != null && replySheet.mapName == "MSM617B" &&
                        (replySheet.functionKeys.Contains("XMIT-Confirm") || _eFunctions.CheckReplyWarning(replySheet)))
                    {
                        replySheet = proxySheet.submit(opSheet, requestSheet);

                        if (replySheet != null && replySheet.mapName == "MSM615A" &&
                            !_eFunctions.CheckReplyWarning(replySheet) && !_eFunctions.CheckReplyError(replySheet))
                        {
                            _cells.GetCell("A" + currentRow + ":" + "C" + currentRow).Style =
                                _cells.GetStyle(StyleConstants.Success);
                        }
                    }
                    else if (_eFunctions.CheckReplyError(replySheet))
                    {
                        _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style =
                            _cells.GetStyle(StyleConstants.Error);
                        _cells.GetCell("A" + currentRow).AddComment(_cells.GetEmptyIfNull(replySheet.message));
                    }
                    else
                    {
                        _cells.GetCell("A" + currentRow + ":" + "C" + currentRow).Style =
                            _cells.GetStyle(StyleConstants.Success);
                    }
                }
                else if (_eFunctions.CheckReplyError(replySheet))
                {
                    _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style = _cells.GetStyle(StyleConstants.Error);
                    _cells.GetCell("A" + currentRow).AddComment(_cells.GetEmptyIfNull(replySheet.message));
                }
                else
                {
                    _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style = _cells.GetStyle(StyleConstants.Error);
                    _cells.GetCell("A" + currentRow).AddComment("NPI");
                }
            }
        }
        private void DeleteProfile(ref string OPTION1I, ref ArrayScreenNameValue arrayFields,
            Screen.OperationContext opSheet, Screen.ScreenService proxySheet, Screen.ScreenSubmitRequestDTO requestSheet,
            ref Screen.ScreenDTO replySheet, int currentRow, out string PROFILE, out string PROFILE_TYPE)
        {
            OPTION1I = "3";
            PROFILE_TYPE = "" + _cells.GetCell("B" + currentRow).Value;
            PROFILE = "" + _cells.GetCell("C" + currentRow).Value;

            _eFunctions.RevertOperation(opSheet, proxySheet);
            replySheet = proxySheet.executeScreen(opSheet, "MSO615");

            if (replySheet.mapName == "MSM615A" && _excelApp.ActiveWorkbook.ActiveSheet.Name == _sheetName01)
            {
                arrayFields = new ArrayScreenNameValue();
                arrayFields.Add("OPTION1I", OPTION1I);

                if (PROFILE_TYPE == "EGI")
                {
                    arrayFields.Add("GROUP_ID11I", PROFILE);
                }
                else
                {
                    arrayFields.Add("PLANT_NO11I", PROFILE);
                }

                requestSheet.screenFields = arrayFields.ToArray();
                requestSheet.screenKey = "1";
                replySheet = proxySheet.submit(opSheet, requestSheet);

                if (_eFunctions.CheckReplyWarning(replySheet))
                    replySheet = proxySheet.submit(opSheet, requestSheet);

                if (replySheet != null && replySheet.mapName == "MSM617A" && !_eFunctions.CheckReplyError(replySheet))
                {
                    arrayFields = new ArrayScreenNameValue();

                    arrayFields.Add("EQUIP_REF1I", PROFILE);

                    requestSheet.screenFields = arrayFields.ToArray();
                    requestSheet.screenKey = "9";
                    replySheet = proxySheet.submit(opSheet, requestSheet);

                    if (_eFunctions.CheckReplyWarning(replySheet))
                        replySheet = proxySheet.submit(opSheet, requestSheet);

                    while (replySheet.mapName == "MSM180B")
                    {
                        arrayFields = new ArrayScreenNameValue();
                        arrayFields.Add("DELETE_CONF2I", "Y");

                        requestSheet.screenFields = arrayFields.ToArray();
                        requestSheet.screenKey = "1";
                        replySheet = proxySheet.submit(opSheet, requestSheet);
                    }

                    if (replySheet != null && replySheet.mapName == "MSM615A" && !_eFunctions.CheckReplyError(replySheet))
                    {
                        _cells.GetCell("A" + currentRow + ":" + "C" + currentRow).Style =
                            _cells.GetStyle(StyleConstants.Success);
                    }
                    else if (_eFunctions.CheckReplyError(replySheet))
                    {
                        _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style =
                            _cells.GetStyle(StyleConstants.Error);
                        _cells.GetCell("A" + currentRow).AddComment(_cells.GetEmptyIfNull(replySheet.message));
                    }
                    else
                    {
                        _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style =
                            _cells.GetStyle(StyleConstants.Error);
                        _cells.GetCell("A" + currentRow).AddComment("NPI");
                    }
                }
            }
        }
        private void MaintainStatisticsProfile(ref string option1I, List<string> statType, List<string> statEntry,
            ref ArrayScreenNameValue arrayFields, Screen.OperationContext opSheet, Screen.ScreenService proxySheet,
            Screen.ScreenSubmitRequestDTO requestSheet, ref Screen.ScreenDTO replySheet, int currentRow,
            out string profile, out string profileType, out string prStatType1I)
        {
            option1I = option1I.Substring(0, 1);
            profileType = "" + _cells.GetCell("B" + currentRow).Value;
            profile = "" + _cells.GetCell("C" + currentRow).Value;
            prStatType1I = "" + _cells.GetCell("F" + currentRow).Value;

            statType = new List<string>();
            statEntry = new List<string>();

            const int startColumn = 7;
            for (var i = 0; i < 20; i++)
            {
                statType.Add(_cells.GetEmptyIfNull(_cells.GetCell(i*2 + startColumn, currentRow).Value));
                statEntry.Add(_cells.GetEmptyIfNull(_cells.GetCell(i*2 + startColumn + 1, currentRow).Value));
            }

            _eFunctions.RevertOperation(opSheet, proxySheet);
            replySheet = proxySheet.executeScreen(opSheet, "MSO615");

            if (replySheet.mapName != "MSM615A" || _excelApp.ActiveWorkbook.ActiveSheet.Name != _sheetName01) return;
            arrayFields = new ArrayScreenNameValue();
            arrayFields.Add("OPTION1I", option1I);
            arrayFields.Add(profileType == "EGI" ? "GROUP_ID11I" : "PLANT_NO11I", profile);

            requestSheet.screenFields = arrayFields.ToArray();
            requestSheet.screenKey = "1";
            replySheet = proxySheet.submit(opSheet, requestSheet);

            if (_eFunctions.CheckReplyWarning(replySheet))
                replySheet = proxySheet.submit(opSheet, requestSheet);

            if (replySheet != null && replySheet.mapName == "MSM617A")
            {
                arrayFields = new ArrayScreenNameValue();

                arrayFields.Add("EQUIP_REF1I", profile);
                arrayFields.Add("PR_STAT_TYPE1I", prStatType1I);

                double index = 0;
                double firstIndex;
                double secondIndex;
                foreach (var item in statType)
                {
                    firstIndex = (index%2) + 1;
                    secondIndex = Math.Ceiling((index + 1)/2);
                    arrayFields.Add("STAT_TYPE" + firstIndex + "1I" + secondIndex, item);
                    index++;
                }

                index = 0;
                foreach (var item in statEntry)
                {
                    firstIndex = (index%2) + 1;
                    secondIndex = Math.Ceiling((index + 1)/2);
                    arrayFields.Add("STAT_ENTRY" + firstIndex + "1I" + secondIndex, item);
                    index++;
                }

                requestSheet.screenFields = arrayFields.ToArray();
                requestSheet.screenKey = "1";
                replySheet = proxySheet.submit(opSheet, requestSheet);

                while (replySheet != null && replySheet.mapName == "MSM617A" &&
                       (replySheet.functionKeys.Contains("XMIT-Confirm") ||
                        replySheet.functionKeys.Contains("XMIT-Validate") ||
                        _eFunctions.CheckReplyWarning(replySheet)))
                {
                    replySheet = proxySheet.submit(opSheet, requestSheet);
                }

                if (replySheet != null && replySheet.mapName == "MSM615A")
                {
                    _cells.GetCell("A" + currentRow + ":" + "C" + currentRow).Style =
                        _cells.GetStyle(StyleConstants.Success);
                }
                else if (_eFunctions.CheckReplyError(replySheet))
                {
                    _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style =
                        _cells.GetStyle(StyleConstants.Error);
                    _cells.GetCell("A" + currentRow).AddComment(_cells.GetEmptyIfNull(replySheet.message));
                }
                else
                {
                    _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style =
                        _cells.GetStyle(StyleConstants.Error);
                    _cells.GetCell("A" + currentRow).AddComment("NPI");
                }
            }
            else if (_eFunctions.CheckReplyError(replySheet))
            {
                _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style = _cells.GetStyle(StyleConstants.Error);
                _cells.GetCell("A" + currentRow).AddComment(_cells.GetEmptyIfNull(replySheet.message));
            }
            else
            {
                _cells.GetCell("A" + currentRow + ":" + "B" + currentRow).Style = _cells.GetStyle(StyleConstants.Error);
                _cells.GetCell("A" + currentRow).AddComment("NPI");
            }
        }