private void gw_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { add_ingr_in_food ingr_in_food = null; try { ingr_in_food = new add_ingr_in_food(Program.data_module, gw.Rows[gw.CurrentRow.Index].Cells[0].Value.ToString(), gw.Rows[gw.CurrentRow.Index].Cells[1].Value.ToString(), Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[4].Value.ToString()), Convert.ToInt32(gw.Rows[gw.CurrentRow.Index].Cells[5].Value.ToString())); ingr_in_food.ShowDialog(); } catch (Exception) { MessageBox.Show("Выберите ингридиент!"); } this.load_data_table(this._current_state); this.fill_food_data(); this.Update(); }
private void b_save_Click(object sender, EventArgs e) { try { if (lb_ingr.Text == "") { MessageBox.Show("Выберите ингредиент!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string brutto = tb_gross.Text; string netto = tb_net.Text; if (Convert.ToDouble(brutto) < Convert.ToDouble(netto)) { MessageBox.Show("Вес брутто не может быть меньше веса нетто!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { string result; //Результат попытки сохранения/добавления switch (this._state) { //Если добавляется новая запись... case "NEW": result = Program.add_read_module.add_ingr_in_food(food_name, this.tb_gross.Text, this.tb_net.Text, this.lb_ingr.Text); this.Close(); break; //Если модифицируется существующая... case "MOD": class_ingr_in_food ingr_in_food; ingr_in_food = Program.add_read_module.get_ingr_in_food(ingr_name, food_name); string ingr_old = ingr_in_food.ingr_name; string food_old = ingr_in_food.food_name; string food_ID = ingr_in_food.id_food; add_ingr_in_food ingr_in_foods = new add_ingr_in_food(Program.data_module, ingr_id); result = Program.add_read_module.upd_ingr_in_food(Convert.ToInt32(this.ingr_id), food_name, this.tb_gross.Text, this.tb_net.Text, this.lb_ingr.Text, ingr_old, food_ID); this.Close(); break; default: result = "NDF"; // не используется, однако mvs не позволяет // дальше работать переменной, которой в одной // из веток кода не присваивается значение break; } if (result == "OK") { if (this._state == "NEW") { this.set_state("OLD"); this.Dispose(); } else if (this._state == "MOD") { this.set_state("OLD"); } } else { MessageBox.Show(result); } this.Update(); } } } catch { } }
private void bAddIngr_Click(object sender, EventArgs e) { add_ingr_in_food ingr_in_food = new add_ingr_in_food(Program.data_module, _id); ingr_in_food.food_name = this.tb_name.Text; ingr_in_food.ShowDialog(); this.load_data_table(this._current_state); this.fill_food_data(); this.Update(); }
//Добавление ингридиента private void add_new_ingr_in_food() { add_ingr_in_food add_ingr = new add_ingr_in_food(Program.data_module, ingr_id); add_ingr.ShowDialog(); }