示例#1
0
        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;
            }
        }
示例#2
0
        private void dataGridViewMonsterLevels_DoubleClick(object sender, EventArgs e)
        {
            int id = (int)dataGridViewMonsterLevels.SelectedRows[0].Cells[0].Value;

            using (Model.KeynerContext db = new Model.KeynerContext())
            {
                MemoryStream ms = new MemoryStream(db.MonsterLevelSet.FirstOrDefault(l => l.Id == id).HappyImage);
                pictureBoxHappy.Image = Image.FromStream(ms);
            }
            using (Model.KeynerContext db = new Model.KeynerContext())
            {
                MemoryStream ms = new MemoryStream(db.MonsterLevelSet.FirstOrDefault(l => l.Id == id).SadImage);
                pictureBoxSad.Image = Image.FromStream(ms);
            }
            using (Model.KeynerContext db = new Model.KeynerContext())
            {
                MemoryStream ms = new MemoryStream(db.MonsterLevelSet.FirstOrDefault(l => l.Id == id).NeutralImage);
                pictureBoxNeutral.Image = Image.FromStream(ms);
            }
            using (Model.KeynerContext db = new Model.KeynerContext())
            {
                MemoryStream ms = new MemoryStream(db.MonsterLevelSet.FirstOrDefault(l => l.Id == id).ReadyImage);
                pictureBoxReady.Image = Image.FromStream(ms);
            }
        }
示例#3
0
        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);
                    }
                }
            }
        }
示例#4
0
 private void FillDataGridShop()
 {
     using (Model.KeynerContext db = new Model.KeynerContext())
     {
         foreach (Model.Monster item in db.MonsterSet.ToList())
         {
             dataGridViewMonsters.Rows.Add(item.Id, item.Name);
         }
     }
 }
示例#5
0
 private void FillDataGridLevels()
 {
     using (Model.KeynerContext db = new Model.KeynerContext())
     {
         dataGridViewMonsterLevels.Rows.Clear();
         foreach (Model.MonsterLevel item in db.MonsterLevelSet.Where(l => l.Id_Monster == _monster.Id).ToList())
         {
             dataGridViewMonsterLevels.Rows.Add(item.Id, item.Id_Monster);
         }
     }
 }
示例#6
0
 private void FillDataGridGroups()
 {
     using (Model.KeynerContext db = new Model.KeynerContext())
     {
         dataGridViewGroups.Rows.Clear();
         foreach (Model.Group item in db.GroupSet.ToList())
         {
             dataGridViewGroups.Rows.Add(item.Id, item.Name);
         }
     }
 }
示例#7
0
 private void FillDataGridTests()
 {
     using (Model.KeynerContext db = new Model.KeynerContext())
     {
         dataGridViewTests.Rows.Clear();
         foreach (Model.Test item in db.TestSet.ToList())
         {
             dataGridViewTests.Rows.Add(item.Id, item.CountMistakes, item.BestTime);
         }
     }
 }
示例#8
0
        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();
            }
        }
示例#9
0
        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();
            }
        }
示例#10
0
        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();
            }
        }
示例#11
0
        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;
            }
        }
示例#12
0
        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();
            }
        }