我正在爲一家保險公司提出申請。它由comboBox
和datePicker
組成。 comboBix
由司機和會計師名單組成。該政策開始在500英鎊。如果用戶是司機,那麼如果用戶是會計師,則用戶策略減少10%,則策略增加10%。如果用戶介於21和25之間,則如果用戶介於26和75之間,則策略增加20%,則策略降低10%。我有這些計算工作,但由於某種原因,總策略正在被我的年齡計算覆蓋。例如,如果用戶是司機並且在21到25之間,那麼保單應增加10%,然後再增加20%,但我的保單隻增加20%。我想我需要一個計數器,但我不確定是否需要一個計數器,如果是的話,我不確定我將如何去做一個計數器。由於計算兩次單獨計算
我的代碼休耕
XAML
<ComboBox x:Name="cmbOccupation" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Top" Width="120" Loaded="cmbOccupation_Loaded" />
<DatePicker HorizontalAlignment="Center" Name="dpkDOB" Grid.Column="1" VerticalAlignment="Top" Grid.Row="10" />
<TextBlock x:Name="txtPolicy" Grid.Row="2" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/>
xaml.cs
enum Occumpation
{
Chauffeur,
Accountant
}
int policy = 500;
double Chauffeur = 0.10;
double Accountant = 0.10;
double age2125 = 0.20;
double age2675 = 0.10;
private void cmbOccupation_Loaded(object sender, RoutedEventArgs e)
{
// ... A List.
List<string> occupation = new List<string>();
occupation.Add(Occumpation.Chauffeur.ToString());
occupation.Add(Occumpation.Accountant.ToString());
// ... Get the ComboBox reference.
var comboBox = sender as ComboBox;
// ... Assign the ItemsSource to the List.
comboBox.ItemsSource = occupation;
// ... Make the first item selected.
comboBox.SelectedIndex = 0;
}
private void btnAddDriver_Click(object sender, RoutedEventArgs e)
{
if (cmbOccupation.SelectedItem.ToString() == Occumpation.Chauffeur.ToString())
{
txtPolicy.Text = (policy + policy * Chauffeur).ToString();
}
else if(cmbOccupation.SelectedItem.ToString()== Occumpation.Accountant.ToString())
{
txtPolicy.Text = (policy - policy * Accountant).ToString();
}
DateTime birthDate = Convert.ToDateTime(dpkDOB.SelectedDate);
if (birthDate.Age().Years() > 21 && birthDate.Age().Years() < 26)
{
txtPolicy.Text = (policy + policy * age2125).ToString();
}
else if (birthDate.Age().Years() > 26 && birthDate.Age().Years() < 76)
{
txtPolicy.Text = (policy - policy * age2675).ToString();
}
}
Extensions.cs
public static class Extensions
{
public static TimeSpan Age(this DateTime dt)
{
return (DateTime.Now - dt);
}
public static int Years(this TimeSpan ts)
{
return (int)((double)ts.Days/365.2425);
}
}
這工作就像一個魅力。感謝您的時間和幫助 –