在C#里实现DATAGRID的打印预览和打印
点击次数:17 次 发布日期:2008-11-26 11:14:09 作者:源代码网
|
源代码网推荐 源代码网推荐 using System; 源代码网推荐 using System.Drawing; 源代码网推荐 using System.Collections; 源代码网推荐 using System.ComponentModel; 源代码网推荐 using System.Windows.Forms; 源代码网推荐 using System.Data; 源代码网推荐 using System.Data.OleDb; 源代码网推荐 源代码网推荐 namespace DataGridPrint 源代码网推荐 { 源代码网推荐 /// <summary> 源代码网推荐 /// Summary description for Form1. 源代码网推荐 /// </summary> 源代码网推荐 public class Form1 : System.Windows.Forms.Form 源代码网推荐 { 源代码网推荐 private System.Windows.Forms.Panel panel1; 源代码网推荐 private System.Windows.Forms.DataGrid dgTest; 源代码网推荐 private System.Windows.Forms.Button btnFillDataGrid; 源代码网推荐 private System.Windows.Forms.MainMenu mnuFile; 源代码网推荐 private System.Windows.Forms.MenuItem menuItem1; 源代码网推荐 private System.Windows.Forms.MenuItem miPrintPreview; 源代码网推荐 private System.Windows.Forms.MenuItem miPrint; 源代码网推荐 private System.Windows.Forms.MenuItem menuItem4; 源代码网推荐 private System.Windows.Forms.MenuItem miExit; 源代码网推荐 private System.Windows.Forms.DataGridTableStyle dgtsCustomers; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn1; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn2; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn3; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn4; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn6; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn7; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn8; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn9; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn10; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn11; 源代码网推荐 private System.Windows.Forms.DataGridTextBoxColumn dataGridTextBoxColumn5; 源代码网推荐 private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1; 源代码网推荐 private System.Data.SqlClient.SqlCommand sqlSelectCommand1; 源代码网推荐 private System.Data.SqlClient.SqlCommand sqlInsertCommand1; 源代码网推荐 private System.Data.SqlClient.SqlCommand sqlUpdateCommand1; 源代码网推荐 private System.Data.SqlClient.SqlCommand sqlDeleteCommand1; 源代码网推荐 private System.Data.SqlClient.SqlConnection sqlConnection1; 源代码网推荐 /// <summary> 源代码网推荐 /// Required designer variable. 源代码网推荐 /// </summary> 源代码网推荐 private System.ComponentModel.Container components = null; 源代码网推荐 源代码网推荐 public Form1() 源代码网推荐 { 源代码网推荐 // 源代码网推荐 // Required for Windows Form Designer support 源代码网推荐 // 源代码网推荐 InitializeComponent(); 源代码网推荐 源代码网推荐 // 源代码网推荐 // TODO: Add any constructor code after InitializeComponent call 源代码网推荐 // 源代码网推荐 } 源代码网推荐 源代码网推荐 /// <summary> 源代码网推荐 /// Clean up any resources being used. 源代码网推荐 /// </summary> 源代码网推荐 protected override void Dispose( bool disposing ) 源代码网推荐 { 源代码网推荐 if( disposing ) 源代码网推荐 { 源代码网推荐 if (components != null) 源代码网推荐 { 源代码网推荐 components.Dispose(); 源代码网推荐 } 源代码网推荐 } 源代码网推荐 base.Dispose( disposing ); 源代码网推荐 } 源代码网推荐 源代码网推荐 #region Windows Form Designer generated code 源代码网推荐 /// <summary> 源代码网推荐 /// Required method for Designer support - do not modify 源代码网推荐 /// the contents of this method with the code editor. 源代码网推荐 /// </summary> 源代码网推荐 private void InitializeComponent() 源代码网推荐 { 源代码网推荐 this.panel1 = new System.Windows.Forms.Panel(); 源代码网推荐 this.dgTest = new System.Windows.Forms.DataGrid(); 源代码网推荐 this.dgtsCustomers = new System.Windows.Forms.DataGridTableStyle(); 源代码网推荐 this.dataGridTextBoxColumn1 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn2 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn3 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn4 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn5 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn6 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn7 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn8 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn9 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn10 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.dataGridTextBoxColumn11 = new System.Windows.Forms.DataGridTextBoxColumn(); 源代码网推荐 this.btnFillDataGrid = new System.Windows.Forms.Button(); 源代码网推荐 this.mnuFile = new System.Windows.Forms.MainMenu(); 源代码网推荐 this.menuItem1 = new System.Windows.Forms.MenuItem(); 源代码网推荐 this.miPrintPreview = new System.Windows.Forms.MenuItem(); 源代码网推荐 this.miPrint = new System.Windows.Forms.MenuItem(); 源代码网推荐 this.menuItem4 = new System.Windows.Forms.MenuItem(); 源代码网推荐 this.miExit = new System.Windows.Forms.MenuItem(); 源代码网推荐 this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter(); 源代码网推荐 this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand(); 源代码网推荐 this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand(); 源代码网推荐 this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand(); 源代码网推荐 this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand(); 源代码网推荐 this.sqlConnection1 = new System.Data.SqlClient.SqlConnection(); 源代码网推荐 this.panel1.SuspendLayout(); 源代码网推荐 ((System.ComponentModel.ISupportInitialize)(this.dgTest)).BeginInit(); 源代码网推荐 this.SuspendLayout(); 源代码网推荐 // 源代码网推荐 // panel1 源代码网推荐 // 源代码网推荐 this.panel1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 源代码网推荐 | System.Windows.Forms.AnchorStyles.Left) 源代码网推荐 | System.Windows.Forms.AnchorStyles.Right); 源代码网推荐 this.panel1.Controls.AddRange(new System.Windows.Forms.Control[] { 源代码网推荐 this.dgTest}); 源代码网推荐 this.panel1.Location = new System.Drawing.Point(0, 9); 源代码网推荐 this.panel1.Name = "panel1"; 源代码网推荐 this.panel1.Size = new System.Drawing.Size(788, 398); 源代码网推荐 this.panel1.TabIndex = 1; 源代码网推荐 // 源代码网推荐 // dgTest 源代码网推荐 // 源代码网推荐 this.dgTest.DataMember = ""; 源代码网推荐 this.dgTest.Dock = System.Windows.Forms.DockStyle.Fill; 源代码网推荐 this.dgTest.HeaderForeColor = System.Drawing.SystemColors.ControlText; 源代码网推荐 this.dgTest.Name = "dgTest"; 源代码网推荐 this.dgTest.Size = new System.Drawing.Size(788, 398); 源代码网推荐 this.dgTest.TabIndex = 0; 源代码网推荐 this.dgTest.TableStyles.AddRange(new System.Windows.Forms.DataGridTableStyle[] { 源代码网推荐 this.dgtsCustomers}); 源代码网推荐 // 源代码网推荐 // dgtsCustomers 源代码网推荐 // 源代码网推荐 this.dgtsCustomers.DataGrid = this.dgTest; 源代码网推荐 this.dgtsCustomers.GridColumnStyles.AddRange(new System.Windows.Forms.DataGridColumnStyle[] { 源代码网推荐 this.dataGridTextBoxColumn1, 源代码网推荐 this.dataGridTextBoxColumn2, 源代码网推荐 this.dataGridTextBoxColumn3, 源代码网推荐 this.dataGridTextBoxColumn4, 源代码网推荐 this.dataGridTextBoxColumn5, 源代码网推荐 this.dataGridTextBoxColumn6, 源代码网推荐 this.dataGridTextBoxColumn7, 源代码网推荐 this.dataGridTextBoxColumn8, 源代码网推荐 this.dataGridTextBoxColumn9, 源代码网推荐 this.dataGridTextBoxColumn10, 源代码网推荐 this.dataGridTextBoxColumn11}); 源代码网推荐 this.dgtsCustomers.HeaderForeColor = System.Drawing.SystemColors.ControlText; 源代码网推荐 this.dgtsCustomers.MappingName = "Customers"; 源代码网推荐 this.dgtsCustomers.ReadOnly = true; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn1 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn1.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn1.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn1.HeaderText = "Customer Id"; 源代码网推荐 this.dataGridTextBoxColumn1.MappingName = "CustomerId"; 源代码网推荐 this.dataGridTextBoxColumn1.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn1.Width = 75; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn2 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn2.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn2.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn2.HeaderText = "Company Name"; 源代码网推荐 this.dataGridTextBoxColumn2.MappingName = "CompanyName"; 源代码网推荐 this.dataGridTextBoxColumn2.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn2.Width = 200; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn3 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn3.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn3.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn3.HeaderText = "Contact Name"; 源代码网推荐 this.dataGridTextBoxColumn3.MappingName = "ContactName"; 源代码网推荐 this.dataGridTextBoxColumn3.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn3.Width = 125; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn4 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn4.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn4.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn4.HeaderText = "Contact Title"; 源代码网推荐 this.dataGridTextBoxColumn4.MappingName = "ContactTitle"; 源代码网推荐 this.dataGridTextBoxColumn4.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn4.Width = 170; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn5 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn5.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn5.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn5.HeaderText = "Address"; 源代码网推荐 this.dataGridTextBoxColumn5.MappingName = "Address"; 源代码网推荐 this.dataGridTextBoxColumn5.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn5.Width = 250; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn6 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn6.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn6.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn6.HeaderText = "City"; 源代码网推荐 this.dataGridTextBoxColumn6.MappingName = "City"; 源代码网推荐 this.dataGridTextBoxColumn6.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn6.Width = 150; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn7 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn7.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn7.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn7.HeaderText = "Region"; 源代码网推荐 this.dataGridTextBoxColumn7.MappingName = "Region"; 源代码网推荐 this.dataGridTextBoxColumn7.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn7.Width = 150; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn8 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn8.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn8.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn8.HeaderText = "Postal Code"; 源代码网推荐 this.dataGridTextBoxColumn8.MappingName = "PostalCode"; 源代码网推荐 this.dataGridTextBoxColumn8.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn8.Width = 150; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn9 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn9.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn9.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn9.HeaderText = "Country"; 源代码网推荐 this.dataGridTextBoxColumn9.MappingName = "Country"; 源代码网推荐 this.dataGridTextBoxColumn9.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn9.Width = 125; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn10 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn10.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn10.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn10.HeaderText = "Phone"; 源代码网推荐 this.dataGridTextBoxColumn10.MappingName = "Phone"; 源代码网推荐 this.dataGridTextBoxColumn10.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn10.Width = 125; 源代码网推荐 // 源代码网推荐 // dataGridTextBoxColumn11 源代码网推荐 // 源代码网推荐 this.dataGridTextBoxColumn11.Format = ""; 源代码网推荐 this.dataGridTextBoxColumn11.FormatInfo = null; 源代码网推荐 this.dataGridTextBoxColumn11.HeaderText = "Fax"; 源代码网推荐 this.dataGridTextBoxColumn11.MappingName = "Fax"; 源代码网推荐 this.dataGridTextBoxColumn11.NullText = ""; 源代码网推荐 this.dataGridTextBoxColumn11.Width = 125; 源代码网推荐 // 源代码网推荐 // btnFillDataGrid 源代码网推荐 // 源代码网推荐 this.btnFillDataGrid.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right); 源代码网推荐 this.btnFillDataGrid.Location = new System.Drawing.Point(645, 426); 源代码网推荐 this.btnFillDataGrid.Name = "btnFillDataGrid"; 源代码网推荐 this.btnFillDataGrid.Size = new System.Drawing.Size(133, 28); 源代码网推荐 this.btnFillDataGrid.TabIndex = 2; 源代码网推荐 this.btnFillDataGrid.Text = "&Fill DataGrid"; 源代码网推荐 this.btnFillDataGrid.Click += new System.EventHandler(this.btnFillDataGrid_Click); 源代码网推荐 // 源代码网推荐 // mnuFile 源代码网推荐 // 源代码网推荐 this.mnuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { 源代码网推荐 this.menuItem1}); 源代码网推荐 // 源代码网推荐 // menuItem1 源代码网推荐 // 源代码网推荐 this.menuItem1.Index = 0; 源代码网推荐 this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { 源代码网推荐 this.miPrintPreview, 源代码网推荐 this.miPrint, 源代码网推荐 this.menuItem4, 源代码网推荐 this.miExit}); 源代码网推荐 this.menuItem1.Text = "&File"; 源代码网推荐 // 源代码网推荐 // miPrintPreview 源代码网推荐 // 源代码网推荐 this.miPrintPreview.Index = 0; 源代码网推荐 this.miPrintPreview.Text = "Print Pre&view"; 源代码网推荐 this.miPrintPreview.Click += new System.EventHandler(this.miPrintPreview_Click); 源代码网推荐 // 源代码网推荐 // miPrint 源代码网推荐 // 源代码网推荐 this.miPrint.Index = 1; 源代码网推荐 this.miPrint.Text = "&Print"; 源代码网推荐 this.miPrint.Click += new System.EventHandler(this.miPrint_Click); 源代码网推荐 // 源代码网推荐 // menuItem4 源代码网推荐 // 源代码网推荐 this.menuItem4.Index = 2; 源代码网推荐 this.menuItem4.Text = "-"; 源代码网推荐 // 源代码网推荐 // miExit 源代码网推荐 // 源代码网推荐 this.miExit.Index = 3; 源代码网推荐 this.miExit.Text = "E&xit"; 源代码网推荐 this.miExit.Click += new System.EventHandler(this.miExit_Click); 源代码网推荐 // 源代码网推荐 // sqlDataAdapter1 源代码网推荐 // 源代码网推荐 this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1; 源代码网推荐 this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1; 源代码网推荐 this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1; 源代码网推荐 this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] { 源代码网推荐 new System.Data.Common.DataTableMapping("Table", "Customers", new System.Data.Common.DataColumnMapping[] { 源代码网推荐 new System.Data.Common.DataColumnMapping("CustomerID", "CustomerID"), 源代码网推荐 new System.Data.Common.DataColumnMapping("CompanyName", "CompanyName"), 源代码网推荐 new System.Data.Common.DataColumnMapping("ContactName", "ContactName"), 源代码网推荐 new System.Data.Common.DataColumnMapping("ContactTitle", "ContactTitle"), 源代码网推荐 new System.Data.Common.DataColumnMapping("Address", "Address"), 源代码网推荐 new System.Data.Common.DataColumnMapping("City", "City"), 源代码网推荐 new System.Data.Common.DataColumnMapping("Region", "Region"), 源代码网推荐 new System.Data.Common.DataColumnMapping("PostalCode", "PostalCode"), 源代码网推荐 new System.Data.Common.DataColumnMapping("Country", "Country"), 源代码网推荐 new System.Data.Common.DataColumnMapping("Phone", "Phone"), 源代码网推荐 new System.Data.Common.DataColumnMapping("Fax", "Fax")})}); 源代码网推荐 this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1; 源代码网推荐 // 源代码网推荐 // sqlSelectCommand1 源代码网推荐 // 源代码网推荐 this.sqlSelectCommand1.CommandText = "SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region," + 源代码网推荐 " PostalCode, Country, Phone, Fax FROM Customers"; 源代码网推荐 this.sqlSelectCommand1.Connection = this.sqlConnection1; 源代码网推荐 // 源代码网推荐 // sqlInsertCommand1 源代码网推荐 // 源代码网推荐 this.sqlInsertCommand1.CommandText = @"INSERT INTO Customers(CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)"; 源代码网推荐 this.sqlInsertCommand1.Connection = this.sqlConnection1; 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone")); 源代码网推荐 this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax")); 源代码网推荐 // 源代码网推荐 // sqlUpdateCommand1 源代码网推荐 // 源代码网推荐 this.sqlUpdateCommand1.CommandText = @"UPDATE Customers SET CustomerID = @CustomerID, CompanyName = @CompanyName, ContactName = @ContactName, ContactTitle = @ContactTitle, Address = @Address, City = @City, Region = @Region, PostalCode = @PostalCode, Country = @Country, Phone = @Phone, Fax = @Fax WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL); SELECT CustomerID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax FROM Customers WHERE (CustomerID = @CustomerID)"; 源代码网推荐 this.sqlUpdateCommand1.Connection = this.sqlConnection1; 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CustomerID", System.Data.SqlDbType.NVarChar, 5, "CustomerID")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CompanyName", System.Data.SqlDbType.NVarChar, 40, "CompanyName")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactName", System.Data.SqlDbType.NVarChar, 30, "ContactName")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@ContactTitle", System.Data.SqlDbType.NVarChar, 30, "ContactTitle")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Address", System.Data.SqlDbType.NVarChar, 60, "Address")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@City", System.Data.SqlDbType.NVarChar, 15, "City")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Region", System.Data.SqlDbType.NVarChar, 15, "Region")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@PostalCode", System.Data.SqlDbType.NVarChar, 10, "PostalCode")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Country", System.Data.SqlDbType.NVarChar, 15, "Country")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Phone", System.Data.SqlDbType.NVarChar, 24, "Phone")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Fax", System.Data.SqlDbType.NVarChar, 24, "Fax")); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null)); 源代码网推荐 // 源代码网推荐 // sqlDeleteCommand1 源代码网推荐 // 源代码网推荐 this.sqlDeleteCommand1.CommandText = @"DELETE FROM Customers WHERE (CustomerID = @Original_CustomerID) AND (Address = @Original_Address OR @Original_Address IS NULL AND Address IS NULL) AND (City = @Original_City OR @Original_City IS NULL AND City IS NULL) AND (CompanyName = @Original_CompanyName) AND (ContactName = @Original_ContactName OR @Original_ContactName IS NULL AND ContactName IS NULL) AND (ContactTitle = @Original_ContactTitle OR @Original_ContactTitle IS NULL AND ContactTitle IS NULL) AND (Country = @Original_Country OR @Original_Country IS NULL AND Country IS NULL) AND (Fax = @Original_Fax OR @Original_Fax IS NULL AND Fax IS NULL) AND (Phone = @Original_Phone OR @Original_Phone IS NULL AND Phone IS NULL) AND (PostalCode = @Original_PostalCode OR @Original_PostalCode IS NULL AND PostalCode IS NULL) AND (Region = @Original_Region OR @Original_Region IS NULL AND Region IS NULL)"; 源代码网推荐 this.sqlDeleteCommand1.Connection = this.sqlConnection1; 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CustomerID", System.Data.SqlDbType.NVarChar, 5, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CustomerID", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Address", System.Data.SqlDbType.NVarChar, 60, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Address", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_City", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "City", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_CompanyName", System.Data.SqlDbType.NVarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CompanyName", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactName", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactName", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_ContactTitle", System.Data.SqlDbType.NVarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "ContactTitle", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Country", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Country", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Fax", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Fax", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Phone", System.Data.SqlDbType.NVarChar, 24, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Phone", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_PostalCode", System.Data.SqlDbType.NVarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "PostalCode", System.Data.DataRowVersion.Original, null)); 源代码网推荐 this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Region", System.Data.SqlDbType.NVarChar, 15, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Region", System.Data.DataRowVersion.Original, null)); 源代码网推荐 // 源代码网推荐 // sqlConnection1 源代码网推荐 // 源代码网推荐 this.sqlConnection1.ConnectionString = "data source=QIEYJ;initial catalog=Northwind;persist security info=False;user id=s" + 源代码网推荐 "a;workstation id=QIEYJ;packet size=4096"; 源代码网推荐 // 源代码网推荐 // Form1 源代码网推荐 // 源代码网推荐 this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); 源代码网推荐 this.ClientSize = new System.Drawing.Size(788, 463); 源代码网推荐 this.Controls.AddRange(new System.Windows.Forms.Control[] { 源代码网推荐 this.btnFillDataGrid, 源代码网推荐 this.panel1}); 源代码网推荐 this.Menu = this.mnuFile; 源代码网推荐 this.Name = "Form1"; 源代码网推荐 this.Text = "DataGrid Print Sample"; 源代码网推荐 this.panel1.ResumeLayout(false); 源代码网推荐 ((System.ComponentModel.ISupportInitialize)(this.dgTest)).EndInit(); 源代码网推荐 this.ResumeLayout(false); 源代码网推荐 源代码网推荐 } 源代码网推荐 #endregion 源代码网推荐 源代码网推荐 /// <summary> 源代码网推荐 /// The main entry point for the application. 源代码网推荐 /// </summary> 源代码网推荐 [STAThread] 源代码网推荐 static void Main() 源代码网推荐 { 源代码网推荐 Application.Run(new Form1()); 源代码网推荐 } 源代码网推荐 源代码网推荐 private void btnFillDataGrid_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 DataTable dt = new DataTable("Customers"); 源代码网推荐 try 源代码网推荐 { 源代码网推荐 sqlDataAdapter1.Fill(dt); 源代码网推荐 dgTest.DataSource = dt; 源代码网推荐 } 源代码网推荐 catch (System.Exception ex) 源代码网推荐 { 源代码网推荐 MessageBox.Show(this,ex.Message); 源代码网推荐 } 源代码网推荐 } 源代码网推荐 源代码网推荐 private void miPrintPreview_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 DataGridPrintDocument dpd = new DataGridPrintDocument(dgTest); 源代码网推荐 dpd.ColumnHeaderFont=new Font("Arial",8,FontStyle.Bold); 源代码网推荐 dpd.DefaultPageSettings.Landscape = true; 源代码网推荐 源代码网推荐 PrintPreviewDialog PrintPrevDlg=new PrintPreviewDialog(); 源代码网推荐 PrintPrevDlg.Document = dpd; 源代码网推荐 PrintPrevDlg.ShowDialog(this); 源代码网推荐 } 源代码网推荐 源代码网推荐 private void miPrint_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 源代码网推荐 DataGridPrintDocument dpd = new DataGridPrintDocument(dgTest); 源代码网推荐 dpd.DefaultPageSettings.Landscape = true; 源代码网推荐 源代码网推荐 PrintDialog PrintDlg=new PrintDialog(); 源代码网推荐 PrintDlg.Document = dpd; 源代码网推荐 源代码网推荐 DialogResult dlgresult=PrintDlg.ShowDialog(this); 源代码网推荐 if (dlgresult==DialogResult.OK) 源代码网推荐 dpd.Print(); 源代码网推荐 源代码网推荐 } 源代码网推荐 源代码网推荐 private void miExit_Click(object sender, System.EventArgs e) 源代码网推荐 { 源代码网推荐 Application.Exit(); 源代码网推荐 } 源代码网推荐 } 源代码网推荐 } 做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。 源代码网推荐 源代码网供稿. |
