📄 producteditviewdialog.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MobileDevelopersHandbook
{
public partial class ProductEditViewDialog : Form
{
public ProductEditViewDialog()
{
InitializeComponent();
}
private void ProductEditViewDialog_Closing(object sender, CancelEventArgs e)
{
try
{
this.productBindingSource.EndEdit();
// If the changes are applied OK to the DataTable, apply them also to the database
ApplyUpdatesToDatabase();
}
// If your data source is a DataTable, you will get an exception from System.Data.
// If your underlying DataSource is a SqlCeResultSet, then EndEdit causes
// changes to applied to the database, hence you will get a SqlCeException
// if a constraint is violated, or some other error.
catch (System.Data.NoNullAllowedException)
{
MessageBox.Show("You have not entered one or more of the following required values: Name, ListPrice");
// Cancel the Form closing
e.Cancel = true;
}
}
private void ApplyUpdatesToDatabase()
{
// Write the changes back to the database
// Get the DataTable
DataTable sourceDataTable = ((DataRowView)this.productBindingSource.Current).DataView.Table;
ProductsDataSet.ProductDataTable productTable =
(ProductsDataSet.ProductDataTable)sourceDataTable;
ProductsDataSetTableAdapters.ProductTableAdapter ta =
new ProductsDataSetTableAdapters.ProductTableAdapter();
ta.Update(productTable);
}
private MyResultSetsResultSets.ProductCategoryResultSet productCategoryResultSet;
private void ProductEditViewDialog_Load(object sender, EventArgs e)
{
productCategoryResultSet =
new MobileDevelopersHandbook.MyResultSetsResultSets.ProductCategoryResultSet();
productCategoryResultSet.Bind(this.productCategoryBindingSource);
}
private void cancelMenuItem_Click(object sender, EventArgs e)
{
this.productBindingSource.CancelEdit();
this.DialogResult = DialogResult.Cancel;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -