Ejemplo n.º 1
0
        private void BtnConfirm_Click(object sender, EventArgs e)
        {
            switch (this.Tag)
            {
            case "AddForm":
            {
                if (string.IsNullOrEmpty(this.tbRoomTypePrice.Text) || string.IsNullOrEmpty(this.tbRoomType.Text))
                {
                    MessageBox.Show("Các thông tin không được để trống",
                                    "THÊM LOẠI PHÒNG THẤT BẠI",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
                else
                {
                    var roomType = new RoomTypeDTO();
                    roomType.RoomTypeID    = this.tbRoomType.Text;
                    roomType.RoomTypePrice = Convert.ToInt64(this.tbRoomTypePrice.Text.Replace(",", ""));

                    if (RoomTypeBUS.InsertRoomType(roomType))
                    {
                        MessageBox.Show(
                            "Thêm loại phòng " + roomType.RoomTypeID + " thành công!",
                            "THÊM LOẠI PHÒNG THÀNH CÔNG!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        var mainForm = (MainForm)Owner;
                        mainForm.ReLoadRoomTypeList();
                        mainForm.ReLoadFindRoom();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(
                            "Loại phòng " + roomType.RoomTypeID + " đã tồn tại!",
                            "THÊM LOẠI PHÒNG THẤT BẠI!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }
                }
                break;
            }

            case "EditForm":
            {
                if (string.IsNullOrEmpty(this.tbRoomType.Text))
                {
                    MessageBox.Show("Các thông tin không được để trống",
                                    "THÊM LOẠI PHÒNG THẤT BẠI",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                }
                else
                {
                    var roomType = new RoomTypeDTO();
                    roomType.RoomTypeID    = this.tbRoomType.Text;
                    roomType.RoomTypePrice = Convert.ToInt64(this.tbRoomTypePrice.Text.Replace(",", ""));

                    if (RoomTypeBUS.UpdateRoomType(roomType))
                    {
                        MessageBox.Show(
                            "Sửa loại phòng " + roomType.RoomTypeID + " thành công!",
                            "SỬA LOẠI PHÒNG THÀNH CÔNG!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Information);

                        var mainForm = (MainForm)Owner;
                        mainForm.ReLoadRoomTypeList();
                        mainForm.ReLoadRoomData();
                        mainForm.ReLoadAvailableRoom();
                        mainForm.ReLoadFindRoom();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(
                            "Sửa loại phòng " + roomType.RoomTypeID + " thất bại!",
                            "THÊM LOẠI PHÒNG THẤT BẠI!",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Warning);
                    }
                }
                break;
            }
            }
        }