我正在尝试处理价值变化,所以我可以进行计算
private void supplierDiscountPercetangeSpinEdit_EditValueChanging(object sender, DevExpress.XtraEditors.Controls.ChangingEventArgs e)
{
decimal price, percentage, calculatedPrice;
price = (decimal)supplierPriceSpinEdit.EditValue;
percentage = Convert.ToDecimal(e.NewValue); // breakpoint 1
calculatedPrice = Popust.Izracunaj(price, percentage); // breakpoint 2
supplierPriceWithDiscountSpinEdit.EditValue = calculatedPrice;
}
Run Code Online (Sandbox Code Playgroud)
在Breakpoint 1 e.NewValue是object {string} "1.00"
在Breakpoint 2 percentage是object {decimal} 100
它必须是 1.00M
我怎样才能转换e.NewValue为十进制?
这是处理和使用的正确方法吗?
public partial class Form1 : Form
{
winappContext _context;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
using (_context = new winappContext())
{
_context = new winappContext();
var query = from c in _context.Customers
orderby c.CustomerName
select c;
this.customerBindingSource.DataSource = query.ToList();
}
....
Run Code Online (Sandbox Code Playgroud)
或者我需要调用_context.Dispose()onFormClosing
谢谢