コード例 #1
0
        private void CreateRoom()
        {
            var room = new Room()
            {
                CategoryID     = Convert.ToInt32(comboCategory.SelectedValue),
                Image          = WindowsImageConverter.ConvertImage(pictureBox1.Image),
                IsDeleted      = false,
                Price          = txtPrice.Value,
                Number         = Convert.ToInt32(txtRoomNumber.Value),
                IsEmpty        = checkIsAvaiable.Checked,
                IsAvailable    = checkIsEmpty.Checked,
                NumberOfBeds   = Convert.ToInt32(txtNumberOfBeds.Value),
                NumberOfPeople = Convert.ToInt32(txtPeopleCapacity.Value),
            };
            var result = WindowsFormValidationContext.Validated <Room>(room);

            if (result.Item1)
            {
                roomReposity.Add(room);
                if (roomReposity.SaveChanges() > 0)
                {
                    MessageBox.Show("The Room has been saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                foreach (var item in result.Item2)
                {
                    MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
コード例 #2
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (room != null)
     {
         room.Number         = Convert.ToInt32(txtRoomNumber.Value);
         room.Image          = WindowsImageConverter.ConvertImage(pictureBox1.Image);
         room.NumberOfBeds   = Convert.ToInt32(txtNumberOfBeds.Value);
         room.Price          = Convert.ToInt32(txtPrice.Value);
         room.CategoryID     = Convert.ToInt32(comboCategory.SelectedValue.ToString());
         room.NumberOfPeople = Convert.ToInt32(txtPeopleCapacity.Value);
         room.IsAvailable    = checkIsAvaiable.Checked;
         room.IsEmpty        = checkIsEmpty.Checked;
         roomReposity.Edit(room);
         if (roomReposity.SaveChanges() > 0)
         {
             MessageBox.Show("Successful Editing", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("You Didn't Select Any Room", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }