Exemplo n.º 1
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Model.Customer customer = new Model.Customer()
                {
                    //Only ContactName is currently used for adding new Customer
                    ContactName = tbxContactName.Text,
                    //Other information is set as default value
                    CustomerNo  = " ",
                    CompanyName = Global.CurrentApartment.CompanyName,
                    CardId      = "_-____-_____-__-_",
                    Address     = Global.CurrentApartment.Address,
                    Tel         = " "
                };
                new CustomersLogic().AddCustomer(customer);
                MessageBox.Show("การเพิ่มข้อมูลสำเร็จเรียบร้อย", "สำเร็จ", MessageBoxButton.OK, MessageBoxImage.Information);

                ClearForm();

                this.DialogResult = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
        private void UpdateCustomerData(Model.Customer customer)
        {
            UpdateCustomer updateWindow = new UpdateCustomer(customer);

            if (updateWindow.ShowDialog() == true)
            {
                dgCustomers.ItemsSource = new CustomersLogic().GetCustomers();
            }
        }
Exemplo n.º 3
0
 private void btnEdit_Click(object sender, RoutedEventArgs e)
 {
     selectedCustomer = dgCustomers.SelectedItem != null ? dgCustomers.SelectedItem as Model.Customer : null;
     if (selectedCustomer != null)
     {
         UpdateCustomerData(selectedCustomer);
     }
     else
     {
         MessageBox.Show("กรุณาเลือกข้อมูลที่จะแก้ไข", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 4
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (IsFormInputsValid())
                {
                    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)
                    {
                        Model.Room room = new Model.Room()
                        {
                            RoomNo          = tbxRoomNo.Text,
                            Customer        = _selectedCustomer,
                            WUnitStart      = long.Parse(tbxWUnitStart.Text),
                            EUnitStart      = long.Parse(tbxEUnitStart.Text),
                            MonthCost       = Decimal.Parse(tbxMonthCost.Text),
                            InsureCost      = Decimal.Parse(tbxInsureCost.Text),
                            StartDate       = dpStartDate.SelectedDate,
                            ApartmentId     = Global.CurrentApartment.ApartmentId,
                            Floor           = tbxFloor.Text,
                            Picture         = " ",
                            ContractMonth   = tbxContractMonth.Text != "" ? long.Parse(tbxContractMonth.Text) : 0,
                            LandTaxedPerson = rbIsLandTaxedPerson.IsChecked.Value,
                            Available       = rbRoomAvailable.IsChecked.Value
                        };
                        new RoomsLogic().AddRoom(room);
                        MessageBox.Show("การเพิ่มข้อมูลสำเร็จเรียบร้อย", "สำเร็จ", MessageBoxButton.OK, MessageBoxImage.Information);

                        ClearForm();

                        this.DialogResult = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemplo n.º 5
0
 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;
     }
 }
Exemplo n.º 6
0
 private void dgCustomers_MouseDoubleClick(object sender, MouseButtonEventArgs e)
 {
     if (sender != null)
     {
         DataGrid grid = sender as DataGrid;
         if (grid != null && grid.SelectedItems != null && grid.SelectedItems.Count == 1)
         {
             DataGridRow row = grid.ItemContainerGenerator.ContainerFromItem(grid.SelectedItem) as DataGridRow;
             selectedCustomer = row.Item as Model.Customer;
             if (!SelectMode)
             {
                 UpdateCustomerData(selectedCustomer);
             }
             else
             {
                 this.DialogResult = true;
             }
         }
     }
 }
Exemplo n.º 7
0
 private void btnDelete_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         selectedCustomer = dgCustomers.SelectedItem != null ? dgCustomers.SelectedItem as Model.Customer : null;
         if (selectedCustomer != null)
         {
             if (MessageBox.Show("ยืนยันที่จะลบข้อมูลผู้เช่า " + selectedCustomer.ContactName, "ยืนยันการลบข้อมูล", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
             {
                 CustomersLogic cl = new CustomersLogic();
                 cl.DaleteCustomer(selectedCustomer);
                 dgCustomers.ItemsSource = new CustomersLogic().GetCustomers();
             }
         }
         else
         {
             MessageBox.Show("กรุณาเลือกข้อมูลที่จะลบ", "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "เกิดข้อผิดพลาด", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
0
 private void PopulateCustomerData(Model.Customer customer)
 {
     tbxContactName.Text = customer.ContactName;
 }
Exemplo n.º 10
0
 public UpdateCustomer(Model.Customer customer)
 {
     InitializeComponent();
     _customer = customer;
     PopulateCustomerData(_customer);
 }