private void button1_Click(object sender, EventArgs e) { if (thelist.SelectedIndex != -1) { data.Rows.Clear(); List <OperationObj> ops = OperationObj.getAllBySellId(sells[thelist.SelectedIndex].id); float total = 0; foreach (OperationObj op in ops) { ProductObj p = ProductObj.getById(op.product_id); float price = 0; if (operation_type == 1) { price = p.price_in; } else if (operation_type == 2) { price = p.price_out; } data.Rows.Add(p.id, p.unit, p.name, op.q, price, op.q * price); total += op.q * price; } data.Rows.Add("", "", "Total", "", "", total); } }
public void load_products() { dataGridView1.Rows.Clear(); List <ProductObj> list = ProductObj.getAll(); for (int i = 0; i < list.Count; i++) { int input = OperationObj.getSumByProduct(list[i].id, 1); int output = OperationObj.getSumByProduct(list[i].id, 2); //MessageBox.Show(input + " - " + output); dataGridView1.Rows.Add(list[i].id, list[i].name, (input - output)); } }
public History() { InitializeComponent(); label1.Text = pname; dataGridView1.Columns.Add("q", "Cant"); dataGridView1.Columns.Add("tipo", "Tipo"); dataGridView1.Columns.Add("fecha", "Fecha"); dataGridView1.Columns[0].Width = 50; dataGridView1.Columns[1].Width = 100; dataGridView1.Columns[2].Width = 200; List <OperationObj> operations = OperationObj.getAllByProduct(int.Parse(pid)); for (int i = 0; i < operations.Count; i++) { dataGridView1.Rows.Add(operations[i].q, operations[i].operation_type_id, operations[i].created_at); } }
public static List<OperationObj> getAllBySellId(int sell_id) { List<OperationObj> list = new List<OperationObj>(); Connection c = new Connection(); MySqlCommand cmd = c.con.CreateCommand(); cmd.CommandText = "select * from operation where sell_id=" + sell_id + " order by created_at desc"; c.con.Open(); MySqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { OperationObj product = new OperationObj(); product.product_id = r.GetInt32("product_id"); //product.sell_id= r.GetInt32("sell_id"); product.q = r.GetInt32("q"); product.operation_type_id = r.GetInt32("operation_type_id"); product.created_at = r.GetDateTime("created_at"); list.Add(product); } return list; }
public static List <OperationObj> getAllByProduct(int product_id) { List <OperationObj> list = new List <OperationObj>(); Connection c = new Connection(); MySqlCommand cmd = c.con.CreateCommand(); cmd.CommandText = "select * from operation where product_id=" + product_id + " order by created_at desc"; c.con.Open(); MySqlDataReader r = cmd.ExecuteReader(); while (r.Read()) { OperationObj product = new OperationObj(); product.product_id = r.GetInt32("id"); //product.sell_id= r.GetInt32("sell_id"); product.q = r.GetInt32("q"); product.operation_type_id = r.GetInt32("operation_type_id"); product.created_at = r.GetDateTime("created_at"); list.Add(product); } return(list); }