예제 #1
0
        private void BUC_Dealers_Click(object sender, EventArgs e)
        {
            _hPanel.Controls.Clear();
            DealerControl dc = new DealerControl(_vPanel, _hPanel);

            _hPanel.Controls.Add(dc);
            dc.Dock = DockStyle.Fill;
            dc.Show();
        }
        private void BindInterfaceDataToObject()
        {
            _dealer.DealerName = TB_PMC_DealerName.Text;
            _dealer.Code       = TB_PMC_DealerCode.Text;
            _dealer.Address    = TB_PMC_DealerAddress.Text;
            _dealer.Contact    = TB_PMC_DealerContact.Text;

            if (_dealer.DealerName.Equals("") ||
                _dealer.Code.Equals("") ||
                _dealer.Address.Equals("") ||
                _dealer.Contact.Equals(""))
            {
                MessageBox.Show("Fill up all boxes!!");
            }
            else
            {
                ConfirmChange();
            }

            void ConfirmChange()
            {
                DialogResult dialogResult = MessageBox.Show(BPMC_AddOrUpdate.Text + " Dealer? ", "Confirm Change?", MessageBoxButtons.YesNo);

                if (dialogResult == DialogResult.Yes)
                {
                    if (_dealer != null)
                    {
                        if (BPMC_AddOrUpdate.Text.Equals("Update"))
                        {
                            if (DealerManager.UpdateDealer(_dealer))
                            {
                                MessageBox.Show("Dealer Updated successfully!");

                                ReloadDealerControl();
                            }
                            else
                            {
                                MessageBox.Show("Error! Dealer Code already Exist! Dealer Code must be unique!");
                            }
                        }
                        else if (BPMC_AddOrUpdate.Text.Equals("Add"))
                        {
                            if (DealerManager.AddDealer(_dealer))
                            {
                                MessageBox.Show("Dealer Added successfully!");

                                ReloadDealerControl();
                            }
                            else
                            {
                                MessageBox.Show("Error! Dealer Code already Exist! Dealer Code must be unique!");
                            }
                        }
                    }
                    else
                    {
                    }
                }
                else if (dialogResult == DialogResult.No)
                {
                    //do something else
                }

                void ReloadDealerControl()
                {
                    _hPanel.Controls.Clear();
                    _dealerControl = new DealerControl(_vPanel, _hPanel);
                    _hPanel.Controls.Add(_dealerControl);
                    _dealerControl.Dock = DockStyle.Fill;
                    _dealerControl.Show();
                    _popUpForm.Close();
                }
            }
        }