Esempio n. 1
0
        private void cargarAlimentos(string product)
        {
            comboBox2.Items.Clear();
            listaProductos.Clear();
            conexion = Connection.GetConnection();
            MySqlCommand cm = new MySqlCommand("SELECT id_prod, name_prod, des_prod, price_prod, stock_prod FROM product WHERE name_prod = @product && stock_prod > 0", conexion);

            cm.Parameters.AddWithValue("@product", product);
            MySqlDataReader consultar = cm.ExecuteReader();

            while (consultar.Read())
            {
                ProductAccount producto = new ProductAccount();
                producto.id_prod    = consultar.GetInt32(0);
                producto.name_prod  = consultar.GetString(1);
                producto.des_prod   = consultar.GetString(2);
                producto.price_prod = consultar.GetDouble(3);
                producto.stock_prod = consultar.GetInt32(4);
                listaProductos.Add(producto);
                ComboBoxItem item = new ComboBoxItem();
                item.Text  = $"{producto.des_prod}";
                item.Value = producto.id_prod;

                comboBox2.Items.Add(item);
                comboBox2.SelectedIndex = 0;
            }

            if (comboBox2.Items.Count == 0)
            {
                comboBox2.Text = "";
            }
        }
Esempio n. 2
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            numericUpDown1.Value = 0;
            comboBox2.Items.Clear();
            listaProductos.Clear();
            //TODO: Mostrar productos del nuevo proveedor
            int             id       = listaProveedores[comboBox1.SelectedIndex].id_prov;
            MySqlConnection conexion = Connection.GetConnection();
            MySqlCommand    cm       = new MySqlCommand("SELECT id_prod, name_prod, purchasePrice_prod FROM product WHERE provider_id_prov = @id", conexion);

            cm.Parameters.AddWithValue("@id", id);
            MySqlDataReader consultar = cm.ExecuteReader();

            while (consultar.Read())
            {
                ProductAccount producto = new ProductAccount();
                producto.id_prod            = consultar.GetInt32(0);
                producto.name_prod          = consultar.GetString(1);
                producto.purchasePrice_prod = consultar.GetDouble(2);
                listaProductos.Add(producto);
                ComboBoxItem item = new ComboBoxItem();
                item.Text  = $"{producto.id_prod} - {producto.name_prod}";
                item.Value = producto.id_prod;

                comboBox2.Items.Add(item);
                comboBox2.SelectedIndex = 0;
            }

            if (comboBox2.Items.Count == 0)
            {
                comboBox2.Text = "";
            }
        }
        private void GenerateImage(string imageString)
        {
            var productAccount = new ProductAccount();
            var image          = GenerateImageFromString(imageString);
            var filePath       = Path.Combine(ImageGeneratorPath, "imageToFind.jpg");

            image.Save(filePath);
        }
Esempio n. 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox2.Text != "")
            {
                //agregamos al carrito
                ProductAccount productNew = listaProductos[comboBox2.SelectedIndex];
                productNew.items = 1;

                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = productNew.id_prod;
                dataGridView1.Rows[n].Cells[1].Value = productNew.name_prod;
                dataGridView1.Rows[n].Cells[2].Value = productNew.des_prod;
                dataGridView1.Rows[n].Cells[3].Value = productNew.price_prod;
                dataGridView1.Rows[n].Cells[4].Value = 1;
                dataGridView1.Rows[n].Cells[5].Value = productNew.price_prod;
                carrito.Add(productNew);
                sumarTotal(productNew.price_prod);
            }
        }
Esempio n. 5
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (comboBox2.Text != "" && numericUpDown1.Value != 0)
            {
                listaProductos[comboBox2.SelectedIndex].items = Convert.ToInt32(numericUpDown1.Value);
                //agregamos al carrito
                carrito.Add(listaProductos[comboBox2.SelectedIndex]);
                ProductAccount  producto  = listaProductos[comboBox2.SelectedIndex];
                providerAccount proveedor = listaProveedores[comboBox1.SelectedIndex];
                double          total     = producto.purchasePrice_prod * Convert.ToDouble(numericUpDown1.Value);
                Console.WriteLine(total);
                //mostrar en datagrid
                int n = dataGridView1.Rows.Add();
                dataGridView1.Rows[n].Cells[0].Value = producto.id_prod;
                dataGridView1.Rows[n].Cells[1].Value = producto.name_prod;
                dataGridView1.Rows[n].Cells[2].Value = proveedor.name_prov;
                dataGridView1.Rows[n].Cells[3].Value = producto.purchasePrice_prod;
                dataGridView1.Rows[n].Cells[4].Value = total;

                sumarTotal(total);
            }
        }
        private ProductAccount GenerateProductAccount(int accountId, string barcode)
        {
            var productAccount  = new ProductAccount();
            var query           = string.Format("SELECT p.*, ac.CategoryId FROM Products p JOIN ProductsCategories pc ON p.ProductId=pc.ProductId JOIN AccountsCategories ac ON pc.CategoryId=ac.CategoryId WHERE P.ProductId={0} AND ac.AccountId={1}", barcode, accountId);
            var dataBaseHandler = new DataBaseHandler();
            var dt = dataBaseHandler.RunQuery(query);

            if (dt.Rows.Count == 0)
            {
                return(null);
            }

            productAccount.ProductId   = Int32.Parse(barcode);
            productAccount.ProductName = dt.Rows[0].ItemArray[1].ToString();
            productAccount.SalePrice   = (decimal)dt.Rows[0].ItemArray[2];
            var categories = new List <int>();

            foreach (DataRow row in dt.Rows)
            {
                categories.Add((Int32)row.ItemArray[3]);
            }
            productAccount.Categories = categories;
            return(productAccount);
        }
Esempio n. 7
0
        private void button1_Click(object sender, EventArgs e)
        {
            ProductAccount newProductAccount = new ProductAccount();

            newProductAccount.name_prod = name_textbox.Text.Trim();
            newProductAccount.des_prod  = textBox2.Text.Trim();



            //if (Single.TryParse(textBox1.Text, out float result))
            //{
            //    MessageBox.Show("El campo solo acepta números flotantes", "Registro Producto", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //else
            //{

            //}
            newProductAccount.price_prod = Convert.ToSingle(textBox1.Text.Trim());

            //if (Single.TryParse(textBox3.Text, out float result2))
            //{
            //    MessageBox.Show("El campo solo acepta números flotantes", "Registro Producto", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //else
            //{

            //}
            newProductAccount.purchasePrice_prod = Convert.ToSingle(textBox3.Text.Trim());

            //float val = 0;
            //if (Single.TryParse(textBox1.Text, out val))
            //{

            //}
            //else
            //{
            //    textBox1.Text = val.ToString();
            //}

            newProductAccount.stock_prod = 0;

            int providerSelected = listaProveedores[comboBox1.SelectedIndex].id_prov;

            if (string.IsNullOrEmpty(name_textbox.Text) || string.IsNullOrEmpty(textBox2.Text) || string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox3.Text))
            {
                MessageBox.Show("Los campos no pueden quedar vacios", "Registro Cliente", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                try
                {
                    MySqlConnection conexion = Connection.GetConnection();
                    MySqlCommand    comm     = conexion.CreateCommand();
                    comm.CommandText = "INSERT INTO `product` (name_prod, des_prod, price_prod, purchasePrice_prod, stock_prod, provider_id_prov) VALUES(@name, @description, @price, @pricePurchase, @stock, @provider)";
                    comm.Parameters.AddWithValue("@name", name_textbox.Text);
                    comm.Parameters.AddWithValue("@description", textBox2.Text);
                    comm.Parameters.AddWithValue("@price", double.Parse(textBox1.Text));
                    comm.Parameters.AddWithValue("@pricePurchase", double.Parse(textBox3.Text));
                    comm.Parameters.AddWithValue("@stock", 0);
                    comm.Parameters.AddWithValue("@provider", providerSelected);
                    comm.ExecuteNonQuery();
                    conexion.Close();
                }
                catch (Exception err)
                {
                    Console.WriteLine(err);
                }
                name_textbox.Text       = "";
                textBox1.Text           = "";
                textBox2.Text           = "";
                textBox3.Text           = "";
                comboBox1.SelectedIndex = 0;
            }
        }