public void CargarTablaImportes(bool edit)
        {
            ITarifariosFleteZonaTopeCol zonasTopes = tariFlete.ZonasTopesCol;
            ITarifariosFleteTopeCol     tariTopes  = tariFlete.TopesCol;
            ITarifariosFleteZonaCol     tariZonas  = tariFlete.ZonasCol;

            if (zonasTopes.getCount() > 0)
            {
                HtmlTable     tblTabla = (HtmlTable)FindControl("tblImportesTarifario");
                HtmlTableRow  rowFila  = new HtmlTableRow();
                HtmlTableCell celCelda = new HtmlTableCell();

                TextBox     txt1, txt2;
                Label       lbl1, lbl2;
                PlaceHolder ph1, ph2;

                celCelda.InnerText = "";
                celCelda.Attributes.Add("Class", "TituloGrilla");
                rowFila.Cells.Add(celCelda);

                for (int i = 0; i < tariZonas.getCount(); i++)
                {
                    celCelda = new HtmlTableCell();
                    celCelda.Attributes.Add("Class", "TituloGrillaFijo");
                    if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                    {
                        celCelda.Attributes.Add("Colspan", "2");
                    }
                    celCelda.InnerText = ((ITarifarioFleteZona)tariZonas.GetTarifarioFleteZona(i)).Zona.ZonaDescrip;
                    rowFila.Controls.Add(celCelda);
                }
                tblTabla.Rows.Add(rowFila);
                //Si la valorizacion del Tarifario es Bulto-kilogramo agrego los subtitulos Primer Bulto y Bulto Exc
                if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                {
                    rowFila = new HtmlTableRow();

                    celCelda           = new HtmlTableCell();
                    celCelda.InnerText = "";
                    celCelda.Attributes.Add("Class", "TituloGrilla");
                    rowFila.Cells.Add(celCelda);

                    for (int i = 0; i < tariZonas.getCount(); i++)
                    {
                        celCelda = new HtmlTableCell();
                        celCelda.Attributes.Add("Class", "TituloGrillaFijo");
                        celCelda.Attributes.Add("Colspan", "1");
                        celCelda.InnerText = "Primer Bulto";
                        rowFila.Controls.Add(celCelda);

                        celCelda = new HtmlTableCell();
                        celCelda.Attributes.Add("Class", "TituloGrillaFijo");
                        celCelda.Attributes.Add("Colspan", "1");
                        celCelda.InnerText = "Bulto Exc";
                        rowFila.Controls.Add(celCelda);
                    }
                    tblTabla.Rows.Add(rowFila);
                }
                for (int i = 0; i < tariTopes.getCount(); i++)
                {
                    ITarifarioFleteTope oTope = (ITarifarioFleteTope)tariTopes.GetTarifarioFleteTope(i);

                    rowFila            = new HtmlTableRow();
                    celCelda           = new HtmlTableCell();
                    celCelda.InnerText = oTope.Tope.TopeKgHasta.ToString();
                    celCelda.Attributes.Add("Class", "TituloGrilla");
                    rowFila.Cells.Add(celCelda);

                    for (int j = 0; j < tariZonas.getCount(); j++)
                    {
                        ITarifarioFleteZona     oZona     = (ITarifarioFleteZona)tariZonas.GetTarifarioFleteZona(j);
                        ITarifarioFleteZonaTope oZonaTope = zonasTopes.ConsultarExiste(oTope.TarifarioFleteTopeID, oZona.TarifarioFleteZonaID);

                        celCelda           = new HtmlTableCell();
                        celCelda.InnerText = "";

                        HtmlTableCell celCelda1 = new HtmlTableCell();
                        celCelda1.InnerText = "";

                        if (oZonaTope != null)
                        {
                            if (edit)
                            {
                                txt1                 = new TextBox();
                                txt1.CssClass        = "CampoChicoFijo";
                                txt1.ID              = "txtImporte_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID;
                                txt1.EnableViewState = false;
                                txt1.Text            = oZonaTope.Importe.ToString("0.###");
                                txt1.MaxLength       = 12;
                                celCelda.Controls.Add(txt1);

                                ph1 = new PlaceHolder();
                                ph1.Controls.Add(GenerarValidadores.DecimalPositivo(txt1.ID, this.TraducirTexto("Errores.Invalidos.Importe"), true, "valImporte_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID));
                                celCelda.Controls.Add(ph1);
                                //rowFila.Cells.Add(celCelda);

                                if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    txt2                 = new TextBox();
                                    txt2.CssClass        = "CampoChicoFijo";
                                    txt2.ID              = "txtImporteBulto_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID;
                                    txt2.EnableViewState = false;
                                    txt2.Text            = oZonaTope.ImporteBultoExc.ToString("0.###");
                                    txt2.MaxLength       = 12;
                                    celCelda1.Controls.Add(txt2);

                                    ph2 = new PlaceHolder();                                    //VER
                                    ph2.Controls.Add(GenerarValidadores.DecimalPositivo(txt2.ID, this.TraducirTexto("Errores.Invalidos.Importe"), true, "valImporteBulto_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID));
                                    celCelda1.Controls.Add(ph2);
                                    //rowFila.Cells.Add(celCelda1);
                                }
                            }
                            else
                            {
                                lbl1          = new Label();
                                lbl1.CssClass = "TextoChicoFijo";
                                lbl1.ID       = "lblImporte_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID;
                                lbl1.Text     = oZonaTope.Importe.ToString("0.###");
                                /*SFE Mostrar en la tabla el texto "/Kg" si es Kilogramo Variable o "%" si es Por Valor Declarado*/
                                if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Kilogramo)
                                {
                                    if (oTope.KgVariable)
                                    {
                                        lbl1.Text = lbl1.Text + "  / Kg.";
                                    }
                                }
                                else if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.ValorDeclarado)
                                {
                                    lbl1.Text = lbl1.Text + "  %";
                                }

                                celCelda.Controls.Add(lbl1);
                                //rowFila.Cells.Add(celCelda);

                                if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    //HtmlTableCell celCelda1 = new HtmlTableCell();
                                    //celCelda1.InnerText = "";
                                    lbl2          = new Label();
                                    lbl2.CssClass = "TextoChicoFijo";
                                    lbl2.ID       = "lblImporteBulto_" + oZona.Zona.ZonaID + "_" + oTope.Tope.TopeID;
                                    lbl2.Text     = oZonaTope.ImporteBultoExc.ToString("0.###");
                                    celCelda1.Controls.Add(lbl2);

                                    //rowFila.Cells.Add(celCelda1);
                                }
                            }
                        }
                        rowFila.Cells.Add(celCelda);
                        if (tariFlete.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                        {
                            rowFila.Cells.Add(celCelda1);
                        }
                    }
                    tblTabla.Rows.Add(rowFila);
                }
                if ((this.txtAccion.Text == "E") || (this.txtAccion.Text == "G"))
                {
                    this.SetearBotones("GuardarCancelar");
                }
                else
                {
                    this.SetearBotones("Editar");
                }
            }
            else
            {
                this.SetearBotones("Ninguno");
            }
        }
        /// <summary>
        /// Método para recalcular importes: de zonas (Importe por Kg Excedente) e importes de zonas y topes
        /// </summary>
        /// <param name="tariFleteNuevo"></param>
        /// <returns>Devuelve un booleano indicando el éxito de la operación</returns>
        public static bool RecalcularImportes(ITarifarioFlete tariFleteNuevo, int usuarioID)
        {
            ITarifarioFlete             tariRef    = TarifarioFleteFactory.GetTarifarioFlete();
            ITarifariosFleteZonaTopeCol zonasTopes = tariFleteNuevo.ZonasTopesCol;

            //Solo me interesa consultar los importes del tarifario de referencia
            tariRef.ZonasTopesCol.TarifarioFleteID = tariFleteNuevo.TarifarioFleteRefID;
            tariRef.ZonasTopesCol.Consultar();

            tariRef.ZonasCol.TarifarioFleteID = tariFleteNuevo.TarifarioFleteRefID;
            tariRef.ZonasCol.Consultar();

            bool esPorcentaje;

            if (tariFleteNuevo.PorcentajeAjuste != 0)
            {
                esPorcentaje = true;
            }
            else
            {
                esPorcentaje = false;
            }

            //Iterar por la coleccion de importes de zonas y asignar el importe que corresponda.

            ITarifariosFleteZonaCol zonasCol = tariFleteNuevo.ZonasCol;

            for (int i = 0; i < zonasCol.getCount(); i++)
            {
                //Recuperar el importe de Kg. Excedente de la zona de referencia
                ITarifarioFleteZona oZona    = zonasCol.GetTarifarioFleteZona(i);
                ITarifarioFleteZona oZonaRef = tariRef.ZonasCol.GetTarifarioFleteZonaByZonaID(oZona.Zona.ZonaID);

                if (tariFleteNuevo.FactorAjuste != "")
                {
                    if (esPorcentaje)
                    {
                        if (tariFleteNuevo.FactorAjuste == "+")
                        {
                            oZona.ImporteKgExcedente = oZonaRef.ImporteKgExcedente + (oZonaRef.ImporteKgExcedente * (tariFleteNuevo.PorcentajeAjuste / 100));
                        }
                        else
                        {
                            oZona.ImporteKgExcedente = oZonaRef.ImporteKgExcedente - (oZonaRef.ImporteKgExcedente * (tariFleteNuevo.PorcentajeAjuste / 100));
                            if (oZona.ImporteKgExcedente < 0)
                            {
                                oZona.ImporteKgExcedente = 0;
                            }
                        }
                    }
                    else
                    {
                        if (tariFleteNuevo.FactorAjuste == "+")
                        {                               //Modificacion del nuevo txtImporteAjusKgExcedente (Bety)
                            oZona.ImporteKgExcedente = oZonaRef.ImporteKgExcedente + tariFleteNuevo.ImporteAjusteKgExcedente;
                        }
                        else
                        {
                            oZona.ImporteKgExcedente = oZonaRef.ImporteKgExcedente - tariFleteNuevo.ImporteAjusteKgExcedente;
                            if (oZona.ImporteKgExcedente < 0)
                            {
                                oZona.ImporteKgExcedente = 0;
                            }
                        }
                    }
                }
                else
                {
                    oZona.ImporteKgExcedente = oZonaRef.ImporteKgExcedente;
                }
            }

            /*try
             * {
             *
             *              return true;
             *      else
             *              return false;
             * }
             * catch(Exception)
             * {
             *      return false;
             * }*/
            //Recalcular los importes del tarifario
            //Recorrer la col de zonastopes. Por cada Zona y tope, recuperar el importe del padre y aplicar
            for (int i = 0; i < zonasTopes.getCount(); i++)
            {
                ITarifarioFleteZonaTope oZonaTopeNuevo = (ITarifarioFleteZonaTope)zonasTopes.GetTarifarioFleteZonaTope(i);
                ITarifarioFleteZonaTope oZonaTopeRef   = tariRef.ZonasTopesCol.ConsultarExisteByZonaTopeID(oZonaTopeNuevo.TarifarioFleteTope.Tope.TopeID, oZonaTopeNuevo.TarifarioFleteZona.Zona.ZonaID);

                if (oZonaTopeRef != null)
                {
                    //Hacer el calculo segun corresponda...Si se trata de un porcentaje o de un importe fijo
                    if (tariFleteNuevo.FactorAjuste != "")
                    {
                        if (esPorcentaje)
                        {
                            if (tariFleteNuevo.FactorAjuste == "+")
                            {
                                oZonaTopeNuevo.Importe = oZonaTopeRef.Importe + (oZonaTopeRef.Importe * (tariFleteNuevo.PorcentajeAjuste / 100));
                                if (tariFleteNuevo.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    oZonaTopeNuevo.ImporteBultoExc = oZonaTopeRef.ImporteBultoExc + (oZonaTopeRef.ImporteBultoExc * (tariFleteNuevo.PorcentajeAjuste / 100));
                                }
                            }
                            else
                            {
                                oZonaTopeNuevo.Importe = oZonaTopeRef.Importe - (oZonaTopeRef.Importe * (tariFleteNuevo.PorcentajeAjuste / 100));
                                if (tariFleteNuevo.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    oZonaTopeNuevo.ImporteBultoExc = oZonaTopeRef.ImporteBultoExc - (oZonaTopeRef.ImporteBultoExc * (tariFleteNuevo.PorcentajeAjuste / 100));
                                    if (oZonaTopeNuevo.ImporteBultoExc < 0)
                                    {
                                        oZonaTopeNuevo.ImporteBultoExc = 0;
                                    }
                                }
                                if (oZonaTopeNuevo.Importe < 0)
                                {
                                    oZonaTopeNuevo.Importe = 0;
                                }
                            }
                        }
                        else
                        {
                            if (tariFleteNuevo.FactorAjuste == "+")
                            {
                                oZonaTopeNuevo.Importe = oZonaTopeRef.Importe + tariFleteNuevo.ImporteAjuste;
                                if (tariFleteNuevo.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    oZonaTopeNuevo.ImporteBultoExc = oZonaTopeRef.ImporteBultoExc + tariFleteNuevo.ImporteAjuste;
                                }
                            }
                            else
                            {
                                oZonaTopeNuevo.Importe = oZonaTopeRef.Importe - tariFleteNuevo.ImporteAjuste;
                                if (tariFleteNuevo.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                                {
                                    oZonaTopeNuevo.ImporteBultoExc = oZonaTopeRef.ImporteBultoExc - tariFleteNuevo.ImporteAjuste;
                                    if (oZonaTopeNuevo.ImporteBultoExc < 0)
                                    {
                                        oZonaTopeNuevo.ImporteBultoExc = 0;
                                    }
                                }
                                if (oZonaTopeNuevo.Importe < 0)
                                {
                                    oZonaTopeNuevo.Importe = 0;
                                }
                            }
                        }
                    }
                    else
                    {
                        oZonaTopeNuevo.Importe = oZonaTopeRef.Importe;
                        if (tariFleteNuevo.ValorizacionTarifario == SisPack.ValorizacionTarifario.Bulto_Kilogramo)
                        {
                            oZonaTopeNuevo.ImporteBultoExc = oZonaTopeRef.ImporteBultoExc;
                        }
                    }
                }
            }


            try
            {
                if (tariFleteNuevo.ZonasCol.Guardar(usuarioID))
                {
                    if (tariFleteNuevo.ZonasTopesCol.Guardar(usuarioID))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }