private void cargaVariables() { try { /* * usuario = Request.QueryString["usuario"]; * idAlmacen = Convert.ToInt32(Request.QueryString["isla"]); * idCaja = Convert.ToInt32(Request.QueryString["caja"]); * lblUsuario.Text = usuario; * lblCaja.Text = idCaja.ToString(); * lblIsla.Text = idAlmacen.ToString(); * GridGastos.DataBind();*/ usuario = Request.QueryString["u"];// Session["usuario"].ToString(); idAlmacen = Convert.ToInt32(Request.QueryString["p"]); idCaja = Convert.ToInt32(Request.QueryString["c"]); lblUsuario.Text = usuario; lblCaja.Text = idCaja.ToString(); lblIsla.Text = idAlmacen.ToString(); GridGastos.DataBind(); } catch (Exception ex) { lblUsuario.Text = "0"; lblCaja.Text = "0"; lblIsla.Text = "0"; GridGastos.DataSource = null; GridGastos.DataBind(); } }
protected void btnNuevoGasto_Click(object sender, EventArgs e) { try { usuario = lblUsuario.Text; idAlmacen = Convert.ToInt32(lblIsla.Text); idCaja = Convert.ToInt32(lblCaja.Text); decimal importe = Convert.ToDecimal(txtMonto.Text); string justificacion = txtMotivo.Text; string referencia = txtReferencia.Text; bool nuevoGasto = datos.agregaGasto(idAlmacen, idCaja, usuario, importe, justificacion, referencia); if (nuevoGasto) { lblErrores.Text = ""; txtMonto.Text = ""; txtMotivo.Text = ""; txtReferencia.Text = ""; GridGastos.DataBind(); } else { lblErrores.Text = "No se logro agregar el gasto, verifique su conexión e intentelo nuevamente mas tarde."; } } catch (Exception) { } }
private void cargaGrid() { try { lblMontoTotal.Text = 0.ToString("C"); string diaIni = txtFechaIni.Text; string diaFin = txtFechaFin.Text; DateTime fechaIni = Convert.ToDateTime(diaIni); DateTime fechaFin = Convert.ToDateTime(diaFin); if (fechaIni <= fechaFin) { if (fechaIni < fechas.obtieneFechaLocal()) { if (fechaFin < fechas.obtieneFechaLocal()) { string isla = ddlIslas.SelectedValue; string usuario = ddlUsuario.SelectedValue; string islas = obtieneIslas(); string whereSlq = ""; string condicion = ""; if (islas != "") { condicion = " and g.idAlmacen in(" + islas + ") "; } if (ddlIslas.SelectedValue == "T" && ddlUsuario.SelectedValue == "T") { whereSlq = ""; } else if (ddlIslas.SelectedValue != "T" && ddlUsuario.SelectedValue == "T") { whereSlq = "g.idAlmacen = " + ddlIslas.SelectedValue + " and "; } else if (ddlIslas.SelectedValue != "T" && ddlUsuario.SelectedValue != "T") { whereSlq = "g.idAlmacen = " + ddlIslas.SelectedValue + " and g.usuario = '" + ddlUsuario.SelectedValue + "' and "; } else if (ddlIslas.SelectedValue == "T" && ddlUsuario.SelectedValue != "T") { whereSlq = "g.usuario = '" + ddlUsuario.SelectedValue + "' and "; } string sql = "select g.id_gasto,g.fecha,g.hora,g.idAlmacen,c.nombre,g.usuario,g.referencia,g.justificacion,g.importe,(u.nombre+' '+u.apellido_pat+' '+isnull(u.apellido_mat,'')) as nombreU" + " from gastos g" + " inner join catalmacenes c on c.idAlmacen = g.idAlmacen" + " inner join usuarios_PV u on u.usuario = g.usuario" + " where " + whereSlq + " g.fecha between '" + diaIni + "' and '" + diaFin + "' " + condicion + " order by g.id_gasto asc"; BaseDatos ejecuta = new BaseDatos(); DataSet data = new DataSet(); object[] ejecutado = ejecuta.scalarData(sql); if ((bool)ejecutado[0]) { data = (DataSet)ejecutado[1]; } GridGastos.DataSource = data; GridGastos.DataBind(); } else { txtFechaFin.Text = fechas.obtieneFechaLocal().ToString("yyyy-MM-dd"); lblError.Text = "La fecha final no puede ser mayor al dia actual."; } } else { txtFechaIni.Text = fechas.obtieneFechaLocal().ToString("yyyy-MM-dd"); lblError.Text = "La fecha inicial no puede ser mayor al dia actual."; } } else { txtFechaIni.Text = fechas.obtieneFechaLocal().ToString("yyyy-MM-dd"); txtFechaFin.Text = fechas.obtieneFechaLocal().ToString("yyyy-MM-dd"); lblError.Text = "La fecha inicial no puede ser mayor a la fecha final."; } } catch (Exception) { GridGastos.DataSource = null; GridGastos.DataBind(); } }