private void btnSelectCustomer_Click(object sender, RoutedEventArgs e) { UI.Customer.Customer selectCustomerWindow = new UI.Customer.Customer(true); if (selectCustomerWindow.ShowDialog() == true) { this._selectedCustomer = selectCustomerWindow.selectedCustomer; tbxContactName.Text = _selectedCustomer.ContactName; tbxCardId.Text = _selectedCustomer.CardId; tbxCompanyName.Text = _selectedCustomer.CompanyName; tbxAddress.Text = _selectedCustomer.Address; this._isNewCustomer = false; } }
private void btnUpdate_Click(object sender, RoutedEventArgs e) { try { if (IsFormInputsValid()) { if (tbxContactName.Text != _room.Customer.ContactName) { if (_selectedCustomer == null) { if (new CustomersLogic().SearchCustomers(tbxContactName.Text).Count > 0) { UI.Customer.Customer selectCustomerWindow = new UI.Customer.Customer(true, tbxContactName.Text); if (selectCustomerWindow.ShowDialog() == true) { this._selectedCustomer = selectCustomerWindow.selectedCustomer; tbxContactName.Text = _selectedCustomer.ContactName; tbxCardId.Text = _selectedCustomer.CardId; tbxCompanyName.Text = _selectedCustomer.CompanyName; tbxAddress.Text = _selectedCustomer.Address; this._isNewCustomer = false; } } else { this._isNewCustomer = true; } } } else { _selectedCustomer = _room.Customer; } if (_isNewCustomer) { Model.Customer customer = new Model.Customer() { ContactName = tbxContactName.Text, CustomerNo = " ", CompanyName = tbxCompanyName.Text, CardId = tbxCardId.Text, Address = tbxAddress.Text, Tel = Global.CurrentApartment.Tel }; new CustomersLogic().AddCustomer(customer); _selectedCustomer = new CustomersLogic().GetLatestCustomer(); } if (_selectedCustomer != null) { _room.RoomNo = tbxRoomNo.Text; _room.Customer = _selectedCustomer; _room.WUnitStart = long.Parse(tbxWUnitStart.Text); _room.EUnitStart = long.Parse(tbxEUnitStart.Text); _room.MonthCost = Decimal.Parse(tbxMonthCost.Text); _room.InsureCost = Decimal.Parse(tbxInsureCost.Text); _room.StartDate = dpStartDate.SelectedDate; _room.ApartmentId = Global.CurrentApartment.ApartmentId; _room.Floor = tbxFloor.Text; _room.Picture = " "; _room.ContractMonth = tbxContractMonth.Text != "" ? long.Parse(tbxContractMonth.Text) : 0; _room.LandTaxedPerson = rbIsLandTaxedPerson.IsChecked.Value; _room.Available = rbRoomAvailable.IsChecked.Value; new RoomsLogic().UpdateRoom(_room); MessageBox.Show("การแก้ไขข้อมูลสำเร็จเรียบร้อย", "สำเร็จ", MessageBoxButton.OK, MessageBoxImage.Information); this.DialogResult = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error); } }