Ejemplo n.º 1
0
        private void IssueLiabBtn_Click(object sender, RoutedEventArgs e)
        {
            //Check input first
            if (false != CheckLiabData())
            {
                Customer tempCust = new Customer();
                Vehicle  tempVeh  = new Vehicle();
                //Check for existing owner in DB
                if (false == ManageDB.CheckForOwnerInDB(EgnTxt.Text, ref tempCust))
                {
                    tempCust = new Customer(OwnerNameTxt.Text, EgnTxt.Text);
                    ManageDB.AddCustInDB(tempCust);
                }
                //Check for existing car in DB
                if (false == ManageDB.CheckForVehInDB(VinTxt.Text, ref tempVeh))
                {
                    tempVeh = new Vehicle(MakeTxt.Text, ModelTxt.Text, int.Parse(YearTxt.Text), int.Parse(MonthTxt.Text), " ",
                                          (VehicleType)VehTypeCmb.SelectedIndex, (CoupeType)7, int.Parse(PowerTxt.Text), " ", VinTxt.Text, tempCust.CustomerId);
                    ManageDB.AddVehInDB(tempVeh);
                }

                //Calculate Liability Insurance price
                double price = Calculations.CalcLiabPrice((VehicleType)VehTypeCmb.SelectedIndex, int.Parse(ExpTxt.Text), int.Parse(PowerTxt.Text),
                                                          int.Parse(EngCapTxt.Text), FuelTypeCmb.SelectedIndex, int.Parse(YearTxt.Text));
                DateTime issueDate = DateTime.Now;
                DateTime dueDate   = DateTime.Now.AddYears(1);
                //Get the id of the new policy
                int insuranceNumb = ManageDB.GetInsuranceCount() + 1;

                Insurance tempIns = new Insurance(insuranceNumb, tempCust.CustomerId, tempVeh.VehicleId, price, issueDate, dueDate, (InsuranceType)1, 0);
                //Save insurance in DB
                ManageDB.AddInsuranceInDB(tempIns);
                //Preview insurance
                IssueLiabPreview previewWin = new IssueLiabPreview(tempIns, tempVeh, tempCust);
                previewWin.Show();
                ClearAllControls();
            }
            else
            {
                //Invalid input -> show error msg
                MessageBox.Show("Въведени са некоректни данни!");
            }
        }
Ejemplo n.º 2
0
        public void FillData(int count, string Egn)
        {
            //count and Egn are not checked for validity, since they are checked in RefPage.xaml.cs
            Customer         temp             = new Customer();
            List <Insurance> listOfInsurances = new List <Insurance>();

            //Check for the owner in the Database
            if (ManageDB.CheckForOwnerInDB(Egn, ref temp))
            {
                ClientNameLbl.Content = temp.Name;

                //Get list of the insurances for the current client by EGN from Database
                ManageDB.GetClientInsurances(Egn, ref listOfInsurances);
                DataGrid.ItemsSource = listOfInsurances;

                //Display only needed columns from Database
                var col = new DataGridTextColumn();
                col.Header  = "Застраховка №";
                col.Binding = new Binding("Id");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "МПС №";
                col.Binding = new Binding("VehicleID");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "Премия(лв.)";
                col.Binding = new Binding("PolicyPrice");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "Валидна от";
                col.Binding = new Binding("IssueDate");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "Валидна до";
                col.Binding = new Binding("DueDate");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "Тип застраховка";
                col.Binding = new Binding("TypeOfInsurance");
                DataGrid.Columns.Add(col);

                col         = new DataGridTextColumn();
                col.Header  = "Застрахователна сума в лв. (Каско)";
                col.Binding = new Binding("InsuranceMoney");
                DataGrid.Columns.Add(col);

                //Set the data grid to read only to prevent change of the data from Database
                DataGrid.IsReadOnly = true;
            }
            else
            {
                ClientNameLbl.Content = "";
                DataGrid.Visibility   = Visibility.Hidden;
                PrintBtn.IsEnabled    = false;
                MessageBox.Show("Няма намерени застраховки за този клиент!");
            }
        }