Example #1
0
        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         = "";
        }
        protected void guardarObra_btn_Click(object sender, EventArgs e)
        {
            var         id        = Request.QueryString["ID"];
            ConectionDB conection = new ConectionDB();
            //Recogemos valores de la vista
            var encargado   = DD_Encargado.SelectedValue;
            var propietario = DD_Propietario.SelectedValue;
            var obra        = nombre_txt.Value;
            var direccion   = Txt_Direccion.Value;
            var fechaI      = fecha_DP.SelectedDate;
            var fecha       = fechaI.ToString("yyyy-MM-dd");

            //Si no hay valor en ID realizamos un Insert
            if (String.IsNullOrEmpty(id))
            {
                string SqlCommand = String.Format("INSERT INTO [dbo].[Obra] ([propietario],[encargado],[nombre],[direccion],[fechaInicio],[fechaTermino]) VALUES({0},{1},'{2}','{3}','{4}',null);", propietario, encargado, obra, direccion, fecha);
                try
                {
                    var result = conection.insertCommand(SqlCommand);

                    if (result != 0)
                    {
                        //notificacion
                        DD_Propietario.Dispose();
                        DD_Encargado.Dispose();
                        Response.Write("<script>alert('Registro Guardado.');</script>");
                        Response.Redirect("~/Obras");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            else
            {//En otro caso se trata de un Update
                string command = "UPDATE [dbo].[Obra] SET [propietario] =" + propietario +
                                 " ,[encargado] = " + encargado +
                                 ",[nombre] = '" + obra + "'" +
                                 ",[direccion] ='" + direccion + "'" +
                                 ",[fechaTermino] ='" + fecha + "'" +
                                 "WHERE idObra =" + id;
                try
                {
                    var result = conection.insertCommand(command);

                    if (result != 0)
                    {
                        //notificacion
                        DD_Propietario.Dispose();
                        DD_Encargado.Dispose();
                        Response.Write("<script>alert('Registro Actualizado.');</script>");
                        Response.Redirect("~/Obras");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
            DD_Encargado.SelectedValue   = "1";
            DD_Propietario.SelectedValue = "1";
            nombre_txt.Value             = "";
            Txt_Direccion.Value          = "";
            fecha_DP.SelectedDate        = DateTime.Now;
            conection.CloseDB();
        }