我有以下代码。我的总计显示在wpf上,但是当我试图计算小计时,它不起作用。即使我的屏幕显示总计字段的值,它也只返回0。我已经厌倦了直接在屏幕上引用Total1字段,但是这也不起作用。需要得到一个小计,然后计算税收和总计。有什么想法吗?我只是看不到我遗漏了什么。
c#
private string total1;
private string total2;
private string total3;
private string total4;
public string Total1
{
get
{
//string ProdId = ((ComboBoxItem)Product1.SelectedItem).Tag;
double qty1;
bool good = double.TryParse(quantity1, out qty1);
if (!(good)) qty1 = 0.0;
double len1;
bool good2 = double.TryParse(length1, out len1);
if (!(good2)) len1 = 0.0;
double pri1;
bool good3 = double.TryParse(price1, out pri1);
if (!(good3)) pri1 = 0.0;
double res = qty1 * len1 * pri1;
total1 = res.ToString();
return total1;
}
set
{
double qty1;
bool good = double.TryParse(quantity1, out qty1);
if (!(good)) qty1 = 0.0;
double len1;
bool good2 = double.TryParse(length1, out len1);
if (!(good2)) len1 = 0.0;
double pri1;
bool good3 = double.TryParse(price1, out pri1);
if (!(good3)) pri1 = 0.0;
double res = qty1 * len1 * pri1;
total1 = res.ToString();
OnPropertyChanged("Total1");
OnPropertyChanged("SubTotal");
}
}
public string SubTotal
{
get
{
double t1;
bool good = double.TryParse(total1, out t1);
if (!(good)) t1 = 0.0;
double t2;
bool good2 = double.TryParse(total2, out t2);
if (!(good2)) t2 = 0.0;
double t3;
bool good3 = double.TryParse(total3, out t3);
if (!(good3)) t3 = 0.0;
double t4;
bool good4 = double.TryParse(total4, out t4);
if (!(good4)) t4 = 0.0;
double res = t1 + t2 + t3 + t4;
return res.ToString();
}
set
{
double t1;
bool good = double.TryParse(total1, out t1);
if (!(good)) t1 = 0.0;
double t2;
bool good2 = double.TryParse(total2, out t2);
if (!(good2)) t2 = 0.0;
double t3;
bool good3 = double.TryParse(total3, out t3);
if (!(good3)) t3 = 0.0;
double t4;
bool good4 = double.TryParse(total4, out t4);
if (!(good4)) t4 = 0.0;
double res = t1 + t2 + t3 + t4;
subTotal = res.ToString();
OnPropertyChanged("SubTotal");
OnPropertyChanged("TaxTotal");
OnPropertyChanged("GrandTotal");
}
}
克马尔
<TextBox Grid.Column="11" Grid.Row="2" Width="80" Name="Total1" Height="24"
TextAlignment="Right" FontFamily="Arial" HorizontalAlignment="Center" IsReadOnly="True"
Text="{Binding Path=Total1, Mode=TwoWay}" />
<TextBox Grid.Column="7" Grid.Row="16" Width="80" Name="SubTotal" FontFamily="Arial"
TextAlignment="Right" Height="24" HorizontalAlignment="Center" IsReadOnly="True"
Text="{Binding Path=SubTotal, Mode=TwoWay}" />
1条答案
按热度按时间oug3syen1#
有些事
这应该行得通
克马尔