protected void btnAgregar_Click(object sender, EventArgs e) { clsGastos Pedido = new clsGastos(); if (Session["objDGastos"] != null) { Pedido = (clsGastos)Session["objDGastos"]; } string Descripcion = Convert.ToString(txtDescripcion.Text); Decimal Monto = Decimal.Parse(txtMonto.Text); Pedido.AgregarDetalle(Descripcion, Monto); System.Nullable<Decimal> tot = 0; tot = (from i in Pedido.Items select i.Monto).Sum(); Pedido.Total = Convert.ToDecimal(tot); Session["objDGastos"] = Pedido; Agregar(); }
public List<clsGastos> BuscarFechaGastos(DateTime FechaIni, DateTime FechaFin) { SqlCommand cmd = new SqlCommand("LISTAR_XFECHA_GASTOS2", cnx); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("FechaInicio", FechaIni); cmd.Parameters.AddWithValue("FechaFin", FechaFin); cnx.Open(); SqlDataReader dr = cmd.ExecuteReader(); List<clsGastos> col = new List<clsGastos>(); while (dr.Read()) { clsGastos obj = new clsGastos(); obj.Fecha = Convert.ToDateTime(dr["Fecha"]); obj.Total = Convert.ToDecimal(dr["Total"]); obj.IdGastos = Convert.ToInt32(dr["IdGastos"]); col.Add(obj); } cnx.Close(); return col; }
public Boolean RegistrarGastos(clsGastos Gastos) { //cnx.Open(); //SqlTransaction transaction = cnx.BeginTransaction(); /* Boolean bolExito = false; try {*/ SqlCommand cmd = new SqlCommand("PA_REGISTRAR_GASTOS",cnx); cmd.CommandType = CommandType.StoredProcedure; // cmd.Connection = cnx; // cmd.Transaction = transaction; SqlParameter paramId = new SqlParameter("@IdGastos", SqlDbType.Int, 8); paramId.Direction = ParameterDirection.Output; cmd.Parameters.Add(paramId); cmd.Parameters.AddWithValue("IdTrabajador", Gastos.Trabajador.Codigo); cmd.Parameters.AddWithValue("IdProveedor", Gastos.Proveedor.Codigo); cmd.Parameters.AddWithValue("UbicacionFisica", Gastos.UbicacionFisica); cmd.Parameters.AddWithValue("Fecha", Gastos.Fecha); cmd.Parameters.AddWithValue("@Total", Gastos.Total); //Gastos.IdGastos = Convert.ToInt32(cmd.ExecuteScalar()); Gastos.IdGastos = Convert.ToInt32(paramId.Value); cnx.Open(); foreach (clsDetalleGastos item in Gastos.Items) { SqlCommand cmdItem = new SqlCommand("PA_REGISTRAR_DetalleGASTOS",cnx); cmdItem.CommandType = CommandType.StoredProcedure; //cmdItem.Connection = cnx; // cmdItem.Transaction = transaction; SqlParameter paramId2 = new SqlParameter("@IdDetalleGastos", SqlDbType.Int, 8); paramId2.Direction = ParameterDirection.Output; //cmdItem.Transaction = transaction; cmdItem.Parameters.Add(paramId2); cmdItem.Parameters.AddWithValue("@Descripcion", item.Descripcion); cmdItem.Parameters.AddWithValue("@Monto", item.Monto); cmdItem.Parameters.AddWithValue("@IdGasto", 2);//item.Gastos.IdGastos); //cnx.Open(); Int32 a = cmdItem.ExecuteNonQuery(); } // transaction.Commit(); /* bolExito = true; } catch (Exception ex) { // transaction.Rollback(); } cnx.Close(); return bolExito;*/ Int32 i = cmd.ExecuteNonQuery(); cnx.Close(); if (i == 1 ) return true; //Gastos.IdGastos = Convert.ToInt32(paramId.Value); //Proveedor.Codigo = Convert.ToInt32(paramId.Value); return false; }
public Boolean GuardarGasto(clsGastos Gastos ) { clsGastosDAO dal = new clsGastosDAO(); return dal.RegistrarGastos(Gastos); }
protected void btnGuardar_Click(object sender, EventArgs e) { Gastos = (clsGastos)Session["objDGastos"]; Gastos.Proveedor = new clsProveedor(); Gastos.Proveedor.Codigo = Convert.ToInt32(txtProveedor.Text); Gastos.Trabajador = new clsTrabajador(); Gastos.Trabajador.Codigo = Convert.ToInt32(txtTrabajador.Text); Gastos.UbicacionFisica = Convert.ToString(txtUF.Text); // Gastos = (clsGastos)Session["objDGastos"]; if (calFecha.SelectedDate == DateTime.MinValue) { Label1.Text = "*Seleccione una fecha de inicio"; } else { Gastos.Fecha = calFecha.SelectedDate; if (GastosCOM.GuardarGasto(Gastos) == true) { string message = "Gastos Registrado Correctamente"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); } else { string message = "Gastos NO REGISTRADO"; System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type = 'text/javascript'>"); sb.Append("window.onload=function(){"); sb.Append("alert('"); sb.Append(message); sb.Append("')};"); sb.Append("</script>"); ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", sb.ToString()); } } }