Exemplo n.º 1
0
 private void btn_Eliminar_Click(object sender, EventArgs e)
 {
     if (txt_Nombre.Text == "")
     {
         MessageBox.Show("No hay un cliente seleccionado para eliminar");
         this.Cliente_Load();
     }
     else
     {
         try
         {
             Database.DataClassesDataContext cc = new Database.DataClassesDataContext();
             int ClienteId = Convert.ToInt32(dgv_Clientes.CurrentRow.Cells[0].Value);
             Database.Cliente clientedelete = cc.Clientes.Single(w => w.Id == ClienteId);
             cc.Clientes.DeleteOnSubmit(clientedelete);
             cc.SubmitChanges();
             MessageBox.Show("El Cliente ha sido eliminado!");
             this.Cliente_Load();
         }
         catch (Exception ex)
         {
             System.Console.WriteLine(ex.Message);
             MessageBox.Show("No se ha podido eliminar al cliente!");
             this.Cliente_Load();
         }
     }
 }
Exemplo n.º 2
0
 private void btn_Eliminar_Click(object sender, EventArgs e)
 {
     if (txt_Codigo.Text == "")
     {
         MessageBox.Show("Debe seleccionar un producto para eliminar!");
         this.Productos_Load();
     }
     else
     {
         try
         {
             Database.DataClassesDataContext cp = new Database.DataClassesDataContext();
             int ProductoId = Convert.ToInt32(dgv_Productos.CurrentRow.Cells[0].Value);
             Database.Producto productodelete = cp.Productos.Single(w => w.Prod_Cod == ProductoId);
             cp.Productos.DeleteOnSubmit(productodelete);
             cp.SubmitChanges();
             MessageBox.Show("El Producto ha sido eliminado!");
             this.Productos_Load();
         }
         catch (Exception ex)
         {
             System.Console.WriteLine(ex.Message);
             MessageBox.Show("No se ha podido eliminar el producto seleccionado!");
             this.Productos_Load();
         }
     }
 }
Exemplo n.º 3
0
        private void btn_Confirmar_Click(object sender, EventArgs e)
        {
            Validaciones.Clear();
            Database.DataClassesDataContext cc = new Database.DataClassesDataContext();

            if (ValidarCampos())
            {
                switch (operacion)
                {
                case "agregar":
                    try
                    {
                        Database.Cliente newcliente = new Database.Cliente();
                        newcliente.Nombre    = txt_Nombre.Text.Trim();
                        newcliente.Apellido  = txt_Apellido.Text.Trim();
                        newcliente.Direccion = txt_Domicilio.Text.Trim();
                        newcliente.Telefono  = txt_Telefono.Text.Trim();
                        cc.Clientes.InsertOnSubmit(newcliente);
                        cc.SubmitChanges();
                        MessageBox.Show("Nuevo cliente cargado!");
                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                        MessageBox.Show("No se pudo guardar el cliente ingresado!");
                        break;
                    }


                case "modificar":
                    try
                    {
                        int ClienteId = Convert.ToInt32(dgv_Clientes.CurrentRow.Cells[0].Value);
                        var query     = cc.Clientes.Where(w => w.Id == ClienteId).FirstOrDefault();
                        query.Nombre    = txt_Nombre.Text.Trim();
                        query.Apellido  = txt_Apellido.Text.Trim();
                        query.Direccion = txt_Domicilio.Text.Trim();
                        query.Telefono  = txt_Telefono.Text.Trim();
                        cc.SubmitChanges();
                        MessageBox.Show("Cliente Actualizado!");
                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                        MessageBox.Show("No se pudo actualizar correctamente el cliente!");
                        break;
                    }
                }
                this.Cliente_Load();
            }
        }
Exemplo n.º 4
0
 void ListarClientes()
 {
     Database.DataClassesDataContext cc = new Database.DataClassesDataContext();
     dgv_Clientes.DataSource = cc.Clientes;
 }
Exemplo n.º 5
0
 void ListarProductos()
 {
     Database.DataClassesDataContext cp = new Database.DataClassesDataContext();
     dgv_Productos.DataSource = cp.Productos;
 }
Exemplo n.º 6
0
        private void btn_Confirmar_Click(object sender, EventArgs e)
        {
            Validaciones.Clear();
            Database.DataClassesDataContext cp = new Database.DataClassesDataContext();

            if (ValidarCampos())
            {
                switch (operacion)
                {
                case "agregar":
                    try
                    {
                        Database.Producto newproducto = new Database.Producto();
                        newproducto.Prod_Cod    = Int32.Parse(txt_Codigo.Text);
                        newproducto.Prod_Desc   = txt_Producto.Text;
                        newproducto.Prod_Precio = Decimal.Parse(txt_Precio.Text);
                        if (cb_Web.Checked)
                        {
                            newproducto.Prod_Web = true;
                        }
                        else
                        {
                            newproducto.Prod_Web = false;
                        }
                        cp.Productos.InsertOnSubmit(newproducto);
                        cp.SubmitChanges();
                        MessageBox.Show("Nuevo producto cargado!");
                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                        MessageBox.Show("No se pudo guardar el producto ingresado!");
                        break;
                    }


                case "modificar":
                    try
                    {
                        int ProductoId = Convert.ToInt32(dgv_Productos.CurrentRow.Cells[0].Value);
                        var query      = cp.Productos.Where(w => w.Prod_Cod == ProductoId).FirstOrDefault();
                        query.Prod_Cod    = Int32.Parse(txt_Codigo.Text);;
                        query.Prod_Desc   = txt_Producto.Text;
                        query.Prod_Precio = Decimal.Parse(txt_Precio.Text);
                        if (cb_Web.Checked)
                        {
                            query.Prod_Web = true;
                        }
                        else
                        {
                            query.Prod_Web = false;
                        }
                        cp.SubmitChanges();
                        MessageBox.Show("Producto Actualizado!");
                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Console.WriteLine(ex.Message);
                        MessageBox.Show("No se pudo actualizar correctamente el producto!");
                        break;
                    }
                }
                this.Productos_Load();
            }
        }