private void button1_Click(object sender, EventArgs e)
        {
            productItems.Clear();
            materialItems.Clear();

            Compositions compositions = new Compositions(SQL);
            Products products = new Products(SQL);
            List<Product> allProducts = products.getList();

            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                if ((row.Cells[0].Value == null) || (row.Cells[1].Value == null))
                    continue;

                Product p = allProducts.Where(a => row.Cells[0].Value.ToString() == a.ToString()).First<Product>();

                int amount = 0;
                if (!int.TryParse(row.Cells[1].Value.ToString(), out amount))
                {
                    row.Cells[1].ErrorText = "Zadaná hodnota není číslo!";
                    return;
                }
                row.Cells[1].ErrorText = "";
                List<Composition> c = compositions.getList(p.ID);
                c.ForEach(a=>{
                    MaterialUnitPair pair = new MaterialUnitPair(a.MaterialType, a.Unit);
                    if(materialItems.ContainsKey(pair)){
                        materialItems[pair] += a.Amount * amount;
                    }
                    else{
                        materialItems.Add(pair, a.Amount * amount);
                    }
                });

                if (productItems.ContainsKey(p))
                {
                    productItems[p] += amount;
                }
                else
                {
                    productItems.Add(p, amount);
                }
            }

            dataGridView2.Rows.Clear();
            dataGridView2.Refresh();

            foreach (MaterialUnitPair m in materialItems.Keys) {
                dataGridView2.Rows.Add(m.MaterialType, materialItems[m], m.Unit);
            }
        }
Example #2
0
        public override void init(bool firstRun = true)
        {
            Status = "Připojování k databázi...";
            connector = Authorization.login(AppSettings.Nick, AppSettings.Password);
            connector.onError = new Action(()=>connectorErrorHandler(connector));
            SQL = new MySQLDriver(connector);
            Units = new Units(SQL);
            Auth = new Authorization(SQL);
            MaterialTypes = new MaterialTypes(SQL);
            Compositions = new Compositions(SQL);
            Status = "Inicializace...";

            if (firstRun){}

            initState = true;
            if (!connector.IsConnected())
            {
                handleError();
                return;
            }
            reload();
            refresh();
        }