Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                DataAcces dataAcces = new DataAcces();
                string tempID;
                string description = productoTxt.Text;
                int price = int.Parse(precioTxt.Text);

                Product product = new Product(description, price);

                foreach (DataGridViewRow row in dataGridView1.SelectedRows)
                {
                    tempID = row.Cells[0].Value.ToString();
                    product.Id = int.Parse(tempID);
                }
                dataAcces.UpdateProduct(product);
                dataAcces.displayProducts(dataGridView1);
                productoTxt.Clear();
                precioTxt.Clear();

            }
            catch(Exception ex)
            {
                MessageBox.Show("Error "+ ex);
            }
        }
Esempio n. 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DataAcces dataAcces = new DataAcces();

            try
            {
                string description = productoTxt.Text;
                int price = int.Parse(precioTxt.Text);
                string comment = comentarioTxt.Text;
                Product product = new Product(description, price);
                dataAcces.insertProduct(product);
                productoTxt.Clear();
                precioTxt.Clear();
                comentarioTxt.Clear();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Datos incorrectos! Favor revisar");
            }
        }
Esempio n. 3
0
        private void SaveOrderBTN_Click(object sender, EventArgs e)
        {
            DataAcces access = new DataAcces();
            int idClient =Convert.ToInt16( CDGTXT.Text);
            DateTime orderDate = DateTime.Now;
            DateTime requireDate = ReleaseDate_Picker.Value;
            int total = Convert.ToInt32( Total_TXT.Text);
            if (requireDate.Equals(orderDate) || requireDate < orderDate)
            {
                MessageBox.Show("La fecha de entrega debe ser mayor a la fecha actual");
                return;
            }
            Order order = new Order(idClient,orderDate,requireDate,total);
            access.saveOrder(order);

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                int id = (int)row.Cells[0].Value;
                int quantity = Convert.ToInt32( row.Cells[2].Value);
                int price = (int)row.Cells[3].Value;
                Product product = new Product(id, price, quantity);
                access.saveOrderProducts(product);
            }
            formulario.RefreshDatagrid();
            dataGridView1.Rows.Clear();
            CDGTXT.Clear();
            Total_TXT.Clear();
            NOMTXT.Clear();
            APTXT.Clear();
        }
Esempio n. 4
0
        public void UpdateProduct(Product product)
        {
            command = new SqlCommand("UPDATE Productos SET Producto=@product, Cantidad=@quantity,Precio_Unidad=@price ,Comentario=@comment WHERE ID_Producto=@id", conecction);

            parameter = new SqlParameter();
            parameter.ParameterName = "@id";
            parameter.Value = product.Id;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@product";
            parameter.Value = product.Description;
            parameter.SqlDbType = SqlDbType.VarChar;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@quantity";
            parameter.Value = product.Quantity;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@price";
            parameter.Value = product.Price;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@comment";
            parameter.Value = product.Comment;
            parameter.SqlDbType = SqlDbType.VarChar;
            command.Parameters.Add(parameter);

            try
            {
                conecction.Open();
                command.ExecuteNonQuery();
                MessageBox.Show("Producto Editado");
                conecction.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex);
            }
            finally
            {
                conecction.Close();
            }
        }
Esempio n. 5
0
        public void saveOrderProducts(Product product)
        {
            command = new SqlCommand("Insert into Pedidos (ID_Orden,ID_Producto,Cantidad,Precio) Values (@idOrder,@idProduct,@quantity,@price)", conecction);
            int id =lastOrderId();

            parameter = new SqlParameter();
            parameter.ParameterName = "@idOrder";
            parameter.Value = id;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@idProduct";
            parameter.Value = product.Id;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@quantity";
            parameter.Value =product.Quantity;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@price";
            parameter.Value = product.Price;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            try
            {
                conecction.Open();
                command.ExecuteNonQuery();
                MessageBox.Show("pedido agregado");
                conecction.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error! " + ex);
            }
            finally
            {
                conecction.Close();
            }
        }
Esempio n. 6
0
        public void insertProduct(Product product)
        {
            command = new SqlCommand("Insert into Productos (Producto,Precio_Unidad,Comentario) Values (@producto,@precio,@comentario)", conecction);

            parameter = new SqlParameter();
            parameter.ParameterName = "@producto";
            parameter.Value = product.Description;
            parameter.SqlDbType = SqlDbType.VarChar;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@precio";
            parameter.Value = product.Price;
            parameter.SqlDbType = SqlDbType.Int;
            command.Parameters.Add(parameter);

            parameter = new SqlParameter();
            parameter.ParameterName = "@comentario";
            parameter.Value = product.Comment;
            parameter.SqlDbType = SqlDbType.VarChar;
            command.Parameters.Add(parameter);

            try
            {
                conecction.Open();
                command.ExecuteNonQuery();
                conecction.Close();
                MessageBox.Show("Producto nuevo agregada");
            }
            catch (SqlException ex)
            {
                MessageBox.Show("Error ! " + ex);
            }
            finally
            {
                conecction.Close();
            }
        }