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 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 dataGridView1_MouseClick(object sender, MouseEventArgs e) { _id = (int)dataGridViewMonsters.SelectedRows[0].Cells[0].Value; pictureBoxHappy.Image = null; pictureBoxSad.Image = null; pictureBoxNeutral.Image = null; pictureBoxReady.Image = null; using (Model.KeynerContext db = new Model.KeynerContext()) { _shop = db.ShopSet.FirstOrDefault(s => s.Id_Monster == _id); try { Model.MonsterLevel monster = db.MonsterLevelSet.FirstOrDefault(m => m.Id_Monster == _id); pictureBoxHappy.Image = Image.FromStream(new MemoryStream(monster.HappyImage)); pictureBoxSad.Image = Image.FromStream(new MemoryStream(monster.SadImage)); pictureBoxNeutral.Image = Image.FromStream(new MemoryStream(monster.NeutralImage)); pictureBoxReady.Image = Image.FromStream(new MemoryStream(monster.ReadyImage)); } catch (NullReferenceException) { MessageBox.Show("Not all pictures uploaded"); } } if (_shop != null) { textBoxCost.Text = _shop.Cost.ToString(); } else { textBoxCost.Text = ""; } if (buttonSaveShop.Enabled == false) { buttonSaveShop.Enabled = true; textBoxCost.Enabled = true; } }
public FormNewMonsterLevel(ref Model.MonsterLevel monsterLevel, int monsterId) : this(monsterId) { this._monsterLevel = monsterLevel; using (MemoryStream ms = new MemoryStream(_monsterLevel.HappyImage)) { pictureBoxHappy.Image = Image.FromStream(ms); } using (MemoryStream ms = new MemoryStream(_monsterLevel.SadImage)) { pictureBoxSad.Image = Image.FromStream(ms); } using (MemoryStream ms = new MemoryStream(_monsterLevel.NeutralImage)) { pictureBoxNeutral.Image = Image.FromStream(ms); } using (MemoryStream ms = new MemoryStream(_monsterLevel.ReadyImage)) { pictureBoxReady.Image = Image.FromStream(ms); } _modified = true; }