示例#1
0
        public RentRoomInfoWindow(int Type, RentRoom RR = null, int roomID = -1)
        {
            this.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            InitializeComponent();
            this.type   = Type;
            this.roomID = roomID;
            if (RR != null)
            {
                this.rentRoom = RR;
            }
            else
            {
                this.rentRoom = new RentRoom();
            }

            this.DataContext = this.bindingRentRoom;
            if (type == EDITACTION)
            {
                switchToEditAction();
            }
            else if (type == ADDACTION)
            {
                switchToAddAction();
            }
            else
            {
                switchToInfoAction();
            }
            //this.DialogResult = false;
        }
示例#2
0
        private void btnDeleteRentRoom_Click(object sender, RoutedEventArgs e)

        {
            try
            {
                using (var db = new RoomManagerEntities2())
                {
                    this.IsEnabled = false;
                    var screen = new ConfirmWindow($"Ban Co Chac Muon Xoa Rent Room {rentRoom.id}");
                    screen.ShowDialog();
                    if (screen.DialogResult == true)
                    {
                        var deleteItem = new RentRoom()
                        {
                            id = rentRoom.id
                        };
                        db.RentRooms.Attach(deleteItem);
                        db.RentRooms.Remove(deleteItem);
                        db.SaveChanges();
                        var oldRoom = db.Rooms.SingleOrDefault(b => b.Id == this.rentRoom.roomID);
                        oldRoom.Status = 1;

                        db.SaveChanges();
                        this.Close();
                    }
                    this.IsEnabled = true;
                }
            }
            catch (Exception ex)
            {
                this.IsEnabled = true;
                MessageBox.Show("delete failure");
                switchToInfoAction();
            }
        }
示例#3
0
        public void setDataToForm(RentRoom rentRoom)
        {
            tbxID.Text         = rentRoom.id.ToString();
            tbxRoomID.Text     = rentRoom.roomID.ToString();
            tbxRenterName.Text = rentRoom.renterName;
            tbxTel.Text        = rentRoom.tel;
            tbxPrice.Text      = rentRoom.price.ToString();
            var dateString = rentRoom.date.ToString();

            dpDate.SelectedDate = rentRoom.date;
        }
示例#4
0
        public RentRoom getDataFromForm()
        {
            RentRoom result = new RentRoom();

            //result.id = 0;// int.Parse( tbxID.Text);
            result.roomID     = int.Parse(tbxRoomID.Text);
            result.renterName = tbxRenterName.Text;
            result.tel        = tbxTel.Text;
            result.price      = float.Parse(tbxPrice.Text);
            result.date       = dpDate.SelectedDate.Value;
            return(result);
        }
示例#5
0
        private void dgRentRoom_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            RentRoom rr = dgRentRoom.SelectedItem as RentRoom;

            if (rr != null)
            {
                var screen = new RentRoomInfoWindow(RentRoomInfoWindow.INFOACTION, rr);
                this.IsEnabled = false;
                screen.ShowDialog();

                this.IsEnabled = true;
            }
            LoadDuLieu();
        }
示例#6
0
        public void LoadData()
        {
            rentRoom                 = getRentRoomFromData(rentRoom.id);
            tbID.Text                = rentRoom.id.ToString();
            tbRoomID.Text            = rentRoom.roomID.ToString();
            tbRenterName.Text        = rentRoom.renterName;
            tbTel.Text               = rentRoom.tel;
            tbPrice.Text             = rentRoom.price.ToString();
            tbDate.Text              = rentRoom.date.ToString();
            UsDetailList             = getUSDDetailFromData();
            dgUSDDetails.ItemsSource = UsDetailList;
            var priceUsDetail = UsDetailList.Select(i => i.price).DefaultIfEmpty(0).Sum();

            tbTotalPrice.Text = (priceUsDetail + rentRoom.price).ToString() + " USD";
        }
示例#7
0
        private void btnImportRentRoom_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == true)
            {
                var wookbook = new Workbook(openFileDialog.FileName);
                var tabs     = wookbook.Worksheets;
                using (var db = new RoomManagerEntities2())
                {
                    foreach (var tab in tabs)
                    {
                        try
                        {
                            if (tab.Name == "RentRoom")
                            {
                                var col  = 'B';
                                var row  = 2;
                                var cell = tab.Cells[$"{ col}{ row}"];
                                while (cell.Value != null)
                                {
                                    var newRent = new RentRoom()
                                    {
                                        roomID     = tab.Cells[$"B{row}"].IntValue,
                                        renterName = tab.Cells[$"C{row}"].StringValue,
                                        tel        = tab.Cells[$"D{row}"].StringValue,
                                        price      = tab.Cells[$"E{row}"].DoubleValue,
                                        date       = tab.Cells[$"F{row}"].DateTimeValue,
                                    };
                                    db.RentRooms.Add(newRent);

                                    db.SaveChanges();

                                    row++;
                                    cell = tab.Cells[$"{ col}{ row}"];
                                }
                                LoadRentRoomData();
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
            }
        }
示例#8
0
        public void switchToInfoAction()
        {
            type                      = INFOACTION;
            lbTitle.Content           = "Info Rent Room";
            spRentRoomInfo.Visibility = Visibility.Visible;
            spRentRoomAE.Visibility   = Visibility.Collapsed;

            //data
            if (type == INFOACTION)
            {
                rentRoom          = getRentRoomFromData(rentRoom.id);
                tbID.Text         = rentRoom.id.ToString();
                tbRoomID.Text     = rentRoom.roomID.ToString();
                tbRenterName.Text = rentRoom.renterName;
                tbTel.Text        = rentRoom.tel;
                tbPrice.Text      = rentRoom.price.ToString();
                tbDate.Text       = rentRoom.date.ToString();
            }
        }
示例#9
0
 public CheckOutWindow(RentRoom rr)
 {
     InitializeComponent();
     rentRoom = rr;
 }