protected void Page_Load(object sender, EventArgs e) { ConectionDB conection = new ConectionDB(); var RProvedores = "SELECT p.idProvedor,p.razonSocial,c.descripcion,p.direccion,p.tel,p.correo,p.cuentaBancaria " + "FROM dbo.Provedor as p " + "Inner join dbo.Categoria as c on p.categoria = c.idCategoria;"; Tab_prove.DataSource = conection.GetData(RProvedores); Tab_prove.DataBind(); //Drop_list de Propietarios string sqlQuery = "SELECT idCategoria, descripcion FROM [dbo].[Categoria]"; DataTable dt = conection.GetData(sqlQuery); if (dt.Rows.Count > 0) { foreach (DataRow item in dt.Rows) { ListItem newItem = new ListItem(item[1].ToString(), item[0].ToString()); DD_categoria.Items.Add(newItem); } } var fill = "SELECT [idCategoria], CONCAT ([descripcion]) As Nombre FROM [dbo].[Categoria]"; try { //Recuperamos los datos de BD DD_categoria.DataSource = conection.GetData(fill); //POblamos la GridView con la Data recuperada DD_categoria.DataBind(); //Cerramos conexion a BD } catch (Exception ex) { Response.Write(ex.Message); } conection.CloseDB(); }
protected void solicitar_materialBtn_Click(object sender, EventArgs e) { var fecha = fecha_txt.SelectedDate.ToString("yyyy-MM-dd"); var idObra = DD_Obra.SelectedValue; var categoria = DD_categoria.SelectedValue; var material = material_txt.Value; var id = Request.QueryString["ID"]; ConectionDB conection = new ConectionDB(); if (String.IsNullOrEmpty(id)) { String SqlCommand = String.Format("INSERT INTO [dbo].[Requisicion] ([fechaCreacion],[encargado],[obra],[tipoDeMaterial],[descripcion],[estado],[fechaPedido],[fechaEntrega])VALUES ('{0}',{1},{2},{3},'{4}',1,null,null);", fecha, Session["id"], idObra, categoria, material); try { var result = conection.insertCommand(SqlCommand); if (result != 0) { //notificacion DD_Obra.Dispose(); DD_categoria.Dispose(); Response.Write("<script>alert('Registro Guardado.');</script>"); Response.Redirect("~/NuevaRequisicion"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } conection.CloseDB(); fecha_txt.SelectedDate = DateTime.Now; DD_Obra.SelectedValue = ""; DD_categoria.SelectedValue = ""; material_txt.Value = ""; }