private void dtgGastosDiarios_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            this.dsGastosDA = (DsGastosDiariosAgencias)Session["dsGastos"];
            DsGastosDiariosAgencias.DatosRow dr = (DsGastosDiariosAgencias.DatosRow) this.dsGastosDA.Datos.Rows[e.Item.DataSetIndex];

            IGastoDiarioAgencia gda = GastoDiarioAgenciaFactory.GetGastoDiarioAgencia();

            gda.GastoDiarioAgenciaID = dr.GastoDiarioAgenciaID;
            try
            {
                gda.Eliminar();
                this.dtgGastosDiarios.EditItemIndex = -1;
                Session["dsGastos"] = null;
                this.BindGrilla();
            }
            catch (Exception ex)
            {
                string mensaje = ex.Message;
                try
                {
                    mensaje = this.TraducirTexto(ex.Message);
                    if (mensaje == "" || mensaje == null)
                    {
                        mensaje = ex.Message;
                    }
                }
                catch (Exception)
                {
                    mensaje = ex.Message;
                }
                ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(mensaje);
            }
        }
        private void BindGrilla()
        {
            SisPackController.AdministrarGrillas.Configurar(this.dtgGastosDiarios, "GastoDiarioAgenciaID", this.CantidadOpciones);
            dtgGastosDiarios.AllowPaging = false;

            if (Session["dsGastos"] == null)
            {
                IGastoDiarioAgencia gastoDA = GastoDiarioAgenciaFactory.GetGastoDiarioAgencia();
                gastoDA.AgenciaID = this.AgenciaConectadaID;
                this.dsGastosDA   = gastoDA.GetGastosDiariosAgenciasDataSet();
            }
            else
            {
                this.dsGastosDA = (DsGastosDiariosAgencias)Session["dsGastos"];
                if (this.dtgGastosDiarios.EditItemIndex != -1)
                {
                    DataGridItem item = this.dtgGastosDiarios.Items[this.dtgGastosDiarios.EditItemIndex];
                    DsGastosDiariosAgencias.DatosRow dr = (DsGastosDiariosAgencias.DatosRow) this.dsGastosDA.Datos.Rows[item.DataSetIndex];

                    try
                    {
                        dr.ConceptoGastoID = ((DropDownList)item.FindControl("ddlConceptoGasto")).SelectedValue == "" ? 0 : Convert.ToInt32(((DropDownList)item.FindControl("ddlConceptoGasto")).SelectedValue);
                        dr.GastoImporte    = ((TextBox)item.FindControl("txtGastoImporte")).Text == "" ? 0 : Convert.ToDouble(((TextBox)item.FindControl("txtGastoImporte")).Text);
                    }
                    catch (Exception) {}
                    dr.Observaciones = ((TextBox)item.FindControl("txtObservaciones")).Text;
                }
            }

            Session["dsGastos"] = this.dsGastosDA;
            this.dtgGastosDiarios.DataSource       = this.dsGastosDA;
            this.dtgGastosDiarios.CurrentPageIndex = 0;
            this.dtgGastosDiarios.DataBind();
        }
        private void dtgGastosDiarios_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            if (((TextBox)e.Item.FindControl("txtGastoImporte")).Text == "0")
            {
                ((TextBox)e.Item.FindControl("txtGastoImporte")).Text = "";
            }

            RequiredFieldValidator req = (RequiredFieldValidator)((PlaceHolder)e.Item.FindControl("phValidImporte")).FindControl("ReqGastoImporte");

            req.Enabled = true;
            req.Validate();
            if (!req.IsValid)
            {
                return;
            }

            Page.Validate();
            if (!Page.IsValid)
            {
                return;
            }

            this.dsGastosDA = (DsGastosDiariosAgencias)Session["dsGastos"];
            DsGastosDiariosAgencias.DatosRow dr = (DsGastosDiariosAgencias.DatosRow) this.dsGastosDA.Datos.Rows[e.Item.DataSetIndex];

            IGastoAgencia gastoAgencia = GastoAgenciaFactory.GetGastoAgencia();

            gastoAgencia.AgenciaID = this.AgenciaConectadaID;

            DsGastosAgencias.DatosRow[] dt = (DsGastosAgencias.DatosRow[])gastoAgencia.GetGastosAgenciasALLDataSet().Datos.Select("ConceptoGastoID=" + dr.ConceptoGastoID);
            double importe = dt[0].GastoImporte;

            if (dr.GastoImporte > importe)
            {
                ((ErrorWeb)this.phErrores.Controls[0]).setMensaje("El importe ingresado es mayor al permitido para este concepto.");
                return;
            }


            IGastoDiarioAgencia gda = GastoDiarioAgenciaFactory.GetGastoDiarioAgencia();

            gda.GastoDiarioAgenciaID = dr.GastoDiarioAgenciaID;
            gda.AgenciaID            = dr.AgenciaID;
            gda.ConceptoGastoID      = dr.ConceptoGastoID;
            gda.GastoImporte         = dr.GastoImporte;
            gda.Observaciones        = dr.IsObservacionesNull() ? null : dr.Observaciones;

            try
            {
                gda.Guardar();
                this.dtgGastosDiarios.EditItemIndex = -1;
                Session["dsGastos"] = null;
                this.BindGrilla();
            }
            catch (Exception ex)
            {
                string mensaje = ex.Message;
                try
                {
                    mensaje = this.TraducirTexto(ex.Message);
                    if (mensaje == "" || mensaje == null)
                    {
                        mensaje = ex.Message;
                    }
                }
                catch (Exception)
                {
                    mensaje = ex.Message;
                }
                ((ErrorWeb)this.phErrores.Controls[0]).setMensaje(mensaje);
            }
        }