2016-07-28 26 views
1

私は保険会社の申請をしています。これはcomboBoxdatePickerで構成されています。 comboBixは、ChauffeurとAccountantのリストで構成されています。方針は£500から始まります。ユーザが運転手である場合、ユーザが会計士である場合、ポリシーは10%上昇し、ユーザポリシーは10%減少する。ユーザーが21〜25の場合、ユーザーが26〜75の場合、ポリシーは20%増加し、ポリシーは10%減少します。私はこれらの計算を行っていますが、なんらかの理由により、私の年齢計算によって総ポリシーが上書きされています。たとえば、ユーザーが運転手で21歳から25歳の場合、ポリシーは10%上がってからさらに20%上がるはずですが、私のポリシーは20%増加するだけです。私はカウンターが必要だと思うが、もし私がそれを必要とするかどうかは分からない。あなたは、ポリシーの値を変更することはありませんしている2つの別々の計算をカウントしてください

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); 
     } 
    } 

答えて

1

を休閑として感謝

は私のコードです。例えば

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(); 
     } 

これは、更新された値にポリシーを変更しません。

このコードを使用してみてください:また

private void btnAddDriver_Click(object sender, RoutedEventArgs e) 
    { 




     if (cmbOccupation.SelectedItem.ToString() == Occumpation.Chauffeur.ToString()) 
     { 
      policy = (policy + policy*Chauffeur); 
      txtPolicy.Text = policy.ToString(); 
     } 
     else if(cmbOccupation.SelectedItem.ToString()== Occumpation.Accountant.ToString()) 
     { 
      policy = (policy - policy*Accountant); 
      txtPolicy.Text = policy.ToString(); 
     } 




     DateTime birthDate = Convert.ToDateTime(dpkDOB.SelectedDate); 

     if (birthDate.Age().Years() > 21 && birthDate.Age().Years() < 26) 
     { 
      policy = (policy + policy*age2125); 
      txtPolicy.Text = policy.ToString(); 
     } 
     else if (birthDate.Age().Years() > 26 && birthDate.Age().Years() < 76) 
     { 
      policy = (policy - policy*age2675); 
      txtPolicy.Text = policy.ToString(); 
     } 



    } 

、あなたは政策変数を変更したくない場合は、この使用:あなたがポリシー値を更新していない

private void btnAddDriver_Click(object sender, RoutedEventArgs e) 
{ 
    double tempPolicy = policy; 



    if (cmbOccupation.SelectedItem.ToString() == Occumpation.Chauffeur.ToString()) 
    { 
     tempPolicy = (tempPolicy + tempPolicy*Chauffeur); 
     txtPolicy.Text = tempPolicy.ToString(); 
    } 
    else if(cmbOccupation.SelectedItem.ToString()== Occumpation.Accountant.ToString()) 
    { 
     tempPolicy = (tempPolicy - tempPolicy*Accountant); 
     txtPolicy.Text = tempPolicy.ToString(); 
    } 




    DateTime birthDate = Convert.ToDateTime(dpkDOB.SelectedDate); 

    if (birthDate.Age().Years() > 21 && birthDate.Age().Years() < 26) 
    { 
     tempPolicy = (tempPolicy + tempPolicy*age2125); 
     txtPolicy.Text = tempPolicy.ToString(); 
    } 
    else if (birthDate.Age().Years() > 26 && birthDate.Age().Years() < 76) 
    { 
     tempPolicy = (tempPolicy - tempPolicy*age2675); 
     txtPolicy.Text = tempPolicy.ToString(); 
    } 



} 
+1

これは魅力的でした。あなたの時間と助けてくれてありがとう –

1

をテキストだけです。次に、コンボから1つを選択するときに、すべてのポリシーを要約してもよろしいですか?そうでない場合は、ポリシーの範囲を変更してください。

private void btnAddDriver_Click(object sender, RoutedEventArgs e) 
{ 

    decimal policy = 500M; 
    decimal Chauffeur = 0.10M; 
    decimal Accountant = 0.10M; 
    decimal age2125 = 0.20M; 
    decimal age2675 = 0.10M; 

    if (cmbOccupation.SelectedItem.ToString() == Occumpation.Chauffeur.ToString()) 
    { 
     policy += policy * Chauffeur; 
    } 
    else if (cmbOccupation.SelectedItem.ToString() == Occumpation.Accountant.ToString()) 
    { 
     policy -= policy * Accountant; 
    } 

    DateTime? birthDate = dpkDOB.SelectedDate; 
    if (birthDate != null) 
    { 
     if (birthDate.Age().Years() > 21 && birthDate.Age().Years() < 26) 
     { 
      policy += policy * age2125; 
     } 
     else if (birthDate.Age().Years() > 26 && birthDate.Age().Years() < 76) 
     { 
      policy -= policy * age2675; 
     } 
    } 

    txtPolicy.Text = policy.ToString(); 
} 
関連する問題