private void buttonSaveShop_Click(object sender, EventArgs e) { if (textBoxCost.Text == "") { MessageBox.Show("Text box for cost is empty"); return; } using (Model.KeynerContext db = new Model.KeynerContext()) { if (_shop == null) { _shop = new Model.Shop { Id_Monster = _id, Cost = Convert.ToInt32(textBoxCost.Text) }; db.ShopSet.Add(_shop); } else { _shop.Cost = Convert.ToInt32(textBoxCost.Text); db.Entry(_shop).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); buttonSaveShop.Enabled = false; textBoxCost.Enabled = false; } }
private void dataGridViewMonsterLevels_CellContentClick(object sender, DataGridViewCellEventArgs e) { DataGridView dataGrid = (DataGridView)sender; DataGridViewButtonColumn button = dataGrid.Columns[e.ColumnIndex] as DataGridViewButtonColumn; int id = ((int)dataGrid.Rows[e.RowIndex].Cells[0].Value); if (e.ColumnIndex == dataGrid.Columns["ColumnEditMonserLevelButton"].Index && e.RowIndex >= 0) { using (Model.KeynerContext db = new Model.KeynerContext()) { Model.MonsterLevel monsterLevel = db.MonsterLevelSet.FirstOrDefault(m => m.Id == id); FormNewMonsterLevel form = new FormNewMonsterLevel(ref monsterLevel, _monster.Id); form.ShowDialog(); if (form.DialogResult == DialogResult.Yes) { this.FillDataGridLevels(); } } } if (e.ColumnIndex == dataGrid.Columns["ColumnDeleteMonsterLevelButton"].Index && e.RowIndex >= 0) { if (MessageBox.Show("Do you want delete this monster level?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (Model.KeynerContext db = new Model.KeynerContext()) { db.Entry(db.MonsterLevelSet.FirstOrDefault(m => m.Id == id)).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); dataGrid.Rows.RemoveAt(e.RowIndex); } } } }
private void button1_Click(object sender, EventArgs e) { if (_test == null) { _test = new Model.Test(); } _test.Text = ""; if (numericUpDownCountRepeat.Value > 0) { for (int i = 0; i < (int)numericUpDownCountRepeat.Value; i++) { _test.Text += richTextBoxText.Text + "\n"; } } else { _test.Text = richTextBoxText.Text; } _test.CountMistakes = (int)numericUpDownCountMistakes.Value; _test.MaxTime = (int)numericUpDownMaxTime.Value; List <ValidationResult> validationResults = new List <ValidationResult>(); ValidationContext validationContext = new ValidationContext(_test); if (!Validator.TryValidateObject(_test, validationContext, validationResults, true)) { string errorMesseges = ""; foreach (ValidationResult item in validationResults) { errorMesseges += item.ErrorMessage + "\n"; } MessageBox.Show(errorMesseges, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (Model.KeynerContext db = new Model.KeynerContext()) { if (_modified) { db.Entry(_test).State = System.Data.Entity.EntityState.Modified; } else { db.TestSet.Add(_test); } db.SaveChanges(); this.DialogResult = DialogResult.Yes; this.Close(); } }
private void buttonSaveMonsterLevel_Click(object sender, EventArgs e) { if (_monsterLevel == null) { _monsterLevel = new Model.MonsterLevel(); } using (MemoryStream ms = new MemoryStream()) { pictureBoxHappy.Image.Save(ms, ImageFormat.Gif); _monsterLevel.HappyImage = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { pictureBoxSad.Image.Save(ms, ImageFormat.Gif); _monsterLevel.SadImage = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { pictureBoxNeutral.Image.Save(ms, ImageFormat.Gif); _monsterLevel.NeutralImage = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { pictureBoxReady.Image.Save(ms, ImageFormat.Gif); _monsterLevel.ReadyImage = ms.ToArray(); } using (Model.KeynerContext db = new Model.KeynerContext()) { if (_modified) { db.Entry(_monsterLevel).State = System.Data.Entity.EntityState.Modified; } else { _monsterLevel.Id_Monster = _monsterId; db.MonsterLevelSet.Add(_monsterLevel); } db.SaveChanges(); this.DialogResult = DialogResult.Yes; this.Close(); } }
private void buttonSaveMonster_Click(object sender, EventArgs e) { if (_monster == null) { _monster = new Model.Monster(); } _monster.Name = textBoxMonsterName.Text; List <ValidationResult> validationResults = new List <ValidationResult>(); ValidationContext validationContext = new ValidationContext(_monster); if (!Validator.TryValidateObject(_monster, validationContext, validationResults, true)) { string errorMesseges = ""; foreach (ValidationResult item in validationResults) { errorMesseges += item.ErrorMessage + "\n"; } MessageBox.Show(errorMesseges, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (Model.KeynerContext db = new Model.KeynerContext()) { if (_modified) { db.Entry(_monster).State = System.Data.Entity.EntityState.Modified; } else { db.MonsterSet.Add(_monster); } db.SaveChanges(); } if (_modified == false) { buttonNewLevel.Visible = true; _modified = true; } else { this.Close(); } }
private void buttonSaveGroup_Click(object sender, EventArgs e) { if (_group == null) { _group = new Model.Group(); } _group.Name = textBoxGroupName.Text; List <ValidationResult> validationResults = new List <ValidationResult>(); ValidationContext validationContext = new ValidationContext(_group); if (!Validator.TryValidateObject(_group, validationContext, validationResults, true)) { string errorMesseges = ""; foreach (ValidationResult item in validationResults) { errorMesseges += item.ErrorMessage + "\n"; } MessageBox.Show(errorMesseges, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } using (Model.KeynerContext db = new Model.KeynerContext()) { if (_modified) { db.Entry(_group).State = System.Data.Entity.EntityState.Modified; } else { db.GroupSet.Add(_group); } db.SaveChanges(); this.DialogResult = DialogResult.Yes; this.Close(); } }