📄 controlcustomers.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace Microsoft.Sql.SqlCe.Samples.Cs.NorthwindCe {
/// <summary>
/// Summary description for ControlCustomer.
/// </summary>
public class ControlCustomers : System.Windows.Forms.Control {
private System.Windows.Forms.Label labelCustomer;
private System.Windows.Forms.Label labelPostalCode;
private System.Windows.Forms.Label labelCountry;
private System.Windows.Forms.Label labelAddress;
private System.Windows.Forms.Label labelCity;
private System.Windows.Forms.Label labelContactName;
private System.Windows.Forms.Label labelContactTitle;
private System.Windows.Forms.Label labelPostalCodeValue;
private System.Windows.Forms.Label labelCountryValue;
private System.Windows.Forms.Label labelAddressValue;
private System.Windows.Forms.Label labelCityValue;
private System.Windows.Forms.Label labelContactNameValue;
private System.Windows.Forms.Label labelContactTitleValue;
private System.Windows.Forms.ComboBox comboBoxCustomers;
private SqlCeDataAdapter daCustomers = null;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public ControlCustomers() {
// This call is required by the Windows.Forms Form Designer.
//
InitializeComponent();
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing ) {
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose( disposing );
}
private void InitializeComponent() {
this.labelCustomer = new System.Windows.Forms.Label();
this.labelPostalCode = new System.Windows.Forms.Label();
this.labelCountry = new System.Windows.Forms.Label();
this.labelAddress = new System.Windows.Forms.Label();
this.labelCity = new System.Windows.Forms.Label();
this.labelContactName = new System.Windows.Forms.Label();
this.labelContactTitle = new System.Windows.Forms.Label();
this.comboBoxCustomers = new System.Windows.Forms.ComboBox();
this.labelAddressValue = new System.Windows.Forms.Label();
this.labelCityValue = new System.Windows.Forms.Label();
this.labelPostalCodeValue = new System.Windows.Forms.Label();
this.labelCountryValue = new System.Windows.Forms.Label();
this.labelContactNameValue = new System.Windows.Forms.Label();
this.labelContactTitleValue = new System.Windows.Forms.Label();
//
// labelCustomer
//
this.labelCustomer.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelCustomer.Location = new System.Drawing.Point(0, 16);
this.labelCustomer.Size = new System.Drawing.Size(64, 16);
this.labelCustomer.Text = "Name:";
this.labelCustomer.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelPostalCode
//
this.labelPostalCode.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelPostalCode.Location = new System.Drawing.Point(8, 136);
this.labelPostalCode.Size = new System.Drawing.Size(56, 16);
this.labelPostalCode.Text = "Zip:";
this.labelPostalCode.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelCountry
//
this.labelCountry.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelCountry.Location = new System.Drawing.Point(8, 168);
this.labelCountry.Size = new System.Drawing.Size(56, 16);
this.labelCountry.Text = "Country:";
this.labelCountry.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelAddress
//
this.labelAddress.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelAddress.Location = new System.Drawing.Point(8, 56);
this.labelAddress.Size = new System.Drawing.Size(56, 16);
this.labelAddress.Text = "Address:";
this.labelAddress.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelCity
//
this.labelCity.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelCity.Location = new System.Drawing.Point(8, 104);
this.labelCity.Size = new System.Drawing.Size(56, 16);
this.labelCity.Text = "City:";
this.labelCity.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelContactName
//
this.labelContactName.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelContactName.Location = new System.Drawing.Point(8, 200);
this.labelContactName.Size = new System.Drawing.Size(56, 16);
this.labelContactName.Text = "Name:";
this.labelContactName.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// labelContactTitle
//
this.labelContactTitle.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.8F, System.Drawing.FontStyle.Bold);
this.labelContactTitle.Location = new System.Drawing.Point(8, 232);
this.labelContactTitle.Size = new System.Drawing.Size(56, 16);
this.labelContactTitle.Text = "Title:";
this.labelContactTitle.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// comboBoxCustomers
//
this.comboBoxCustomers.Location = new System.Drawing.Point(72, 16);
this.comboBoxCustomers.Size = new System.Drawing.Size(160, 21);
//
// labelAddressValue
//
this.labelAddressValue.Location = new System.Drawing.Point(80, 56);
this.labelAddressValue.Size = new System.Drawing.Size(152, 32);
//
// labelCityValue
//
this.labelCityValue.Location = new System.Drawing.Point(80, 104);
this.labelCityValue.Size = new System.Drawing.Size(152, 16);
//
// labelPostalCodeValue
//
this.labelPostalCodeValue.Location = new System.Drawing.Point(80, 136);
this.labelPostalCodeValue.Size = new System.Drawing.Size(152, 16);
//
// labelCountryValue
//
this.labelCountryValue.Location = new System.Drawing.Point(80, 168);
this.labelCountryValue.Size = new System.Drawing.Size(152, 16);
//
// labelContactNameValue
//
this.labelContactNameValue.Location = new System.Drawing.Point(80, 200);
this.labelContactNameValue.Size = new System.Drawing.Size(152, 16);
//
// labelContactTitleValue
//
this.labelContactTitleValue.Location = new System.Drawing.Point(80, 232);
this.labelContactTitleValue.Size = new System.Drawing.Size(152, 16);
//
// ControlCustomer
//
this.Controls.Add(this.labelContactTitleValue);
this.Controls.Add(this.labelContactNameValue);
this.Controls.Add(this.labelCountryValue);
this.Controls.Add(this.labelPostalCodeValue);
this.Controls.Add(this.labelCityValue);
this.Controls.Add(this.labelAddressValue);
this.Controls.Add(this.labelCustomer);
this.Controls.Add(this.labelPostalCode);
this.Controls.Add(this.labelCountry);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelCity);
this.Controls.Add(this.labelContactName);
this.Controls.Add(this.labelContactTitle);
this.Controls.Add(this.comboBoxCustomers);
this.Size = new System.Drawing.Size(246, 302);
}
#endregion
// This function initializes or refreshes the Customer DataSet.
//
public void InitCustomers() {
// Starts the cursor icon since this function may take some time.
//
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
SqlCeConnection cnNorthwind = NorthwindData.GetInstance().NorthwindConnection;
DataSet dsNorthwind = NorthwindData.GetInstance().NorthwindDataSet;
DataTable dtCustomers = null;
try {
// This will execute only the first time the InitCustomers method is called.
//
if (null == daCustomers) {
daCustomers = new SqlCeDataAdapter(@"SELECT * FROM Customers ORDER BY CompanyName", cnNorthwind);
}
dtCustomers = dsNorthwind.Tables["Customers"];
// Initialize the Customer DataSet
//
if (null == dtCustomers) {
daCustomers.Fill(dsNorthwind, "Customers");
dtCustomers = dsNorthwind.Tables["Customers"];
// Binds the database values to the controls
//
comboBoxCustomers.DataSource = dtCustomers;
comboBoxCustomers.DisplayMember = "CompanyName";
comboBoxCustomers.ValueMember = "CustomerID";
labelAddressValue.DataBindings.Add("Text", dtCustomers, "Address");
labelCityValue.DataBindings.Add("Text", dtCustomers, "City");
labelPostalCodeValue.DataBindings.Add("Text", dtCustomers, "PostalCode");
labelCountryValue.DataBindings.Add("Text", dtCustomers, "Country");
labelContactNameValue.DataBindings.Add("Text", dtCustomers, "ContactName");
labelContactTitleValue.DataBindings.Add("Text", dtCustomers, "ContactTitle");
}
// Refresh the Customer DataSet
//
else {
dtCustomers.Clear();
daCustomers.Fill(dsNorthwind, "Customers");
}
}
catch(SqlCeException e) {
// Error handling mechanism
//
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
NorthwindData.ShowErrors(e);
return;
}
catch(Exception e) {
// Error handling mechanism
//
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
MessageBox.Show(e.Message, "Northwind");
return;
}
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -