我的英語不好,因爲我是西班牙語,所以我使用翻譯如果你不明白的東西問我。datagrid中的總價格,當我通過它的價格
我的問題是,我正在做一個程序,在主窗口中有兩個窗口我在第二個窗口中有一個數據網格,我用文本框傳遞信息,問題是通過傳遞總價格乘以我得到的數量甜品價格的甜點,數據網格中的總價格,當我通過它圍繞該價格,如果價格發生1.20該程序將更改爲1.
給我沒有錯誤,所以我將不得不花費整個程序代碼很抱歉。
這是第二個窗口
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (Application.Current.Properties["seleccionado"] == null)
{
textBox1.IsEnabled = false;
Postresinfo = new TabladePostre();
}
else
{
Postresinfo = (TabladePostre) (Application.Current.Properties["seleccionado"]);
textBox1.IsEnabled=false;
textBox1.Text = Convert.ToString(Postresinfo.refPostre);
textBox2.Text = Postresinfo.NombrePostre;
textBox3.Text = Convert.ToString(Postresinfo.cantidad);
textBox4.Text = Convert.ToString(Postresinfo.precio);
textBox5.Text = Convert.ToString(Postresinfo.preciototal);
}
LinqdePostresDataContext BasedeDatos;
string filename = "";
private void button1_Click(object sender, RoutedEventArgs e)
{
BasedeDatos(LinqdePostresDataContext)Application.Current.Properties["basedeDatos"];
Postresinfo.NombrePostre = textBox2.Text;
Postresinfo.cantidad = Convert.ToInt32(textBox3.Text);
Postresinfo.precio = Convert.ToDecimal(textBox4.Text);
Postresinfo.preciototal = Convert.ToDecimal(textBox5.Text);
Postresinfo.imagen = filename;
if (Application.Current.Properties["seleccionado"] != null)
{
Postresinfo.refPostre=Convert.ToInt32(textBox1.Text);
}
else
{
BasedeDatos.TabladePostres.InsertOnSubmit(Postresinfo);
}
BasedeDatos.SubmitChanges();
this.Close();
}
decimal precio = 0;
private void button2_Click(object sender, RoutedEventArgs e)
{
precio = Convert.ToDecimal(textBox4.Text);
textBox5.Text = Convert.ToString(precio * Convert.ToDecimal(textBox3.Text));
}
private void button9_Click(object sender, RoutedEventArgs e)
{
// Configure open file dialog box
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
dlg.FileName = "Document"; // Default file name
dlg.DefaultExt = ".jpg"; // Default file extension
dlg.Filter = "Text documents (.jpg)|*.jpg"; // Filter files by extension
// Show open file dialog box
Nullable<bool> result = dlg.ShowDialog();
// Process open file dialog box results
if (result == true)
{
// Open document
filename = dlg.FileName;
ImageSourceConverter conversor = new ImageSourceConverter();
image1.Source = (ImageSource)conversor.ConvertFromString(filename);
}
}
這是主要的窗口:
LinqdePostresDataContext BasedeDatos = new LinqdePostresDataContext();
private void activar(object sender, RoutedEventArgs e)
{
Cargartabla();
}
private void Cargartabla()
{
var postre = (from n in BasedeDatos.TabladePostres
select n);
dataGrid1.ItemsSource = postre;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
Application.Current.Properties["seleccionado"] = null;
Ventana2 Ventana2 = new Ventana2();
Ventana2.Show();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
BasedeDatos.TabladePostres.DeleteOnSubmit((TabladePostre)dataGrid1.SelectedItem);
BasedeDatos.SubmitChanges();
Cargartabla();
}
private void Activar2(object sender, EventArgs e)
{
Cargartabla();
}
private void button3_Click(object sender, RoutedEventArgs e)
{
Application.Current.Properties["seleccionado((TabladePostre)dataGrid1.SelectedItem);
Application.Current.Properties["basedeDatos"] = BasedeDatos;
Ventana2 ventana2 = new Ventana2();
ventana2.Show();
}
如果你也需要知道我有INT價格,INT數量的總價在數據庫小數。
感謝的答覆,我想這兩個選項給了我,但不能正常工作,這些都是錯誤:
Postresinfo.refPostre = float.Parse(textBox1.Text)給了我沒有錯誤,程序運行正常並沒有什麼變化
float.TryParse(textBox1.Text,出Postresinfo.refPostre)具有這些故障:
錯誤1的屬性,索引或動態成員訪問可能不如out或ref參數傳遞。
錯誤2的最好重載方法匹配「float.TryParse(字符串,出浮動)」具有一些無效參數
錯誤3參數2:不能從「OUT INT」轉換爲「浮出來」
我試過其他的代碼並沒有什麼變化,該程序正常運行
巴蒂爾現在,我想這樣的代碼:
Convert.ToDecimal(textBox1.Text);
但它沒有改變,正常運行。
我也試過其他的代碼,但沒有任何變化和程序正常運行
故障未TextBox1中,我認爲這是因爲它是在TextBox5文本框,我在小數輸入價格,並將它傳遞到DataGrid是圓形
我還會附上列失敗我:
<DataGridTextColumn Binding="{Binding Path=preciototal}" Header="Precio Total"/>
謝謝。
仍然會引起異常。請提及 –
謝謝@NoIdeaForName,我已經更新了我的答案。 –