C#winform 控件开发 TreeView实例 using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.SqlClient;
using ControlLib;
namespace TestControls
{
/// <summary>
/// Summary description for Form2.
/// </summary>
public class TestForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panelTop;
private ControlLib.dbTreeViewCtrl bookTree;
private System.Windows.Forms.TextBox txtBookID;
private System.Windows.Forms.Button btnFind;
private System.Data.DataSet dsBooks;
private System.Data.DataView bookDataView;
private System.Data.SqlClient.SqlConnection accessConn;
private System.Data.SqlClient.SqlCommand cmdGetAuthors;
private System.Windows.Forms.Splitter splitter2;
private System.Windows.Forms.Panel panelContainer;
private System.Windows.Forms.Panel panelPublisher;
private System.Windows.Forms.TextBox txtPubContry;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtPubState;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txtPubCity;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox txtPubName;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Panel panelAuthor;
private System.Windows.Forms.TextBox txtAuthAddress;
private System.Windows.Forms.Label label12;
private System.Windows.Forms.TextBox txtAuthLastName;
private System.Windows.Forms.Label label11;
private System.Windows.Forms.TextBox txtAuthZip;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txtAuthState;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txtAuthCity;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox txtAuthFirstName;
private System.Windows.Forms.Label label9;
private System.Windows.Forms.Label label10;
private System.Windows.Forms.Panel panelTitle;
private System.Windows.Forms.Label lblTitleID;
private System.Windows.Forms.TextBox txtBookAdvPaid;
private System.Windows.Forms.TextBox txtBookRoylaty;
private System.Windows.Forms.TextBox txtBookPrice;
private System.Windows.Forms.TextBox txtBookYTDSales;
private System.Windows.Forms.Label label21;
private System.Windows.Forms.Label label20;
private System.Windows.Forms.Label label19;
private System.Windows.Forms.Label label18;
private System.Windows.Forms.TextBox txtBookTitleNodes;
private System.Windows.Forms.Label label17;
private System.Windows.Forms.TextBox txtBookPubDate;
private System.Windows.Forms.Label label16;
private System.Windows.Forms.TextBox txtBookType;
private System.Windows.Forms.Label label15;
private System.Windows.Forms.TextBox txtBookTitle;
private System.Windows.Forms.Label label14;
private System.Windows.Forms.Label label13;
private ControlLib.dbImageBox imgBookCover;
private System.Windows.Forms.ImageList imgList;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuPublisher;
private System.Windows.Forms.MenuItem menuAuthor;
private System.Windows.Forms.MenuItem menuTitle;
private System.Windows.Forms.Label lblLocate;
private System.Windows.Forms.Label lblAuthorID;
private System.Windows.Forms.Label lblPublisherID;
private System.ComponentModel.IContainer components;
public TestForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
this.SetUpDataBinding ();
}
/// <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.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(TestForm));
this.panelTop = new System.Windows.Forms.Panel();
this.btnFind = new System.Windows.Forms.Button();
this.txtBookID = new System.Windows.Forms.TextBox();
this.lblLocate = new System.Windows.Forms.Label();
this.imgList = new System.Windows.Forms.ImageList(this.components);
this.accessConn = new System.Data.SqlClient.SqlConnection();
this.dsBooks = new System.Data.DataSet();
this.bookDataView = new System.Data.DataView();
this.cmdGetAuthors = new System.Data.SqlClient.SqlCommand();
this.splitter2 = new System.Windows.Forms.Splitter();
this.panelContainer = new System.Windows.Forms.Panel();
this.panelAuthor = new System.Windows.Forms.Panel();
this.lblAuthorID = new System.Windows.Forms.Label();
this.txtAuthAddress = new System.Windows.Forms.TextBox();
this.label12 = new System.Windows.Forms.Label();
this.txtAuthLastName = new System.Windows.Forms.TextBox();
this.label11 = new System.Windows.Forms.Label();
this.txtAuthZip = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.txtAuthState = new System.Windows.Forms.TextBox();
this.label7 = new System.Windows.Forms.Label();
this.txtAuthCity = new System.Windows.Forms.TextBox();
this.label8 = new System.Windows.Forms.Label();
this.txtAuthFirstName = new System.Windows.Forms.TextBox();
this.label9 = new System.Windows.Forms.Label();
this.label10 = new System.Windows.Forms.Label();
this.panelPublisher = new System.Windows.Forms.Panel();
this.lblPublisherID = new System.Windows.Forms.Label();
this.txtPubContry = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.txtPubState = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtPubCity = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtPubName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.panelTitle = new System.Windows.Forms.Panel();
this.lblTitleID = new System.Windows.Forms.Label();
this.txtBookTitleNodes = new System.Windows.Forms.TextBox();
this.imgBookCover = new ControlLib.dbImageBox(this.components);
this.txtBookAdvPaid = new System.Windows.Forms.TextBox();
this.txtBookRoylaty = new System.Windows.Forms.TextBox();
this.txtBookPrice = new System.Windows.Forms.TextBox();
this.txtBookYTDSales = new System.Windows.Forms.TextBox();
this.label21 = new System.Windows.Forms.Label();
this.label20 = new System.Windows.Forms.Label();
this.label19 = new System.Windows.Forms.Label();
this.label18 = new System.Windows.Forms.Label();
this.label17 = new System.Windows.Forms.Label();
this.txtBookPubDate = new System.Windows.Forms.TextBox();
this.label16 = new System.Windows.Forms.Label();
this.txtBookType = new System.Windows.Forms.TextBox();
this.label15 = new System.Windows.Forms.Label();
this.txtBookTitle = new System.Windows.Forms.TextBox();
this.label14 = new System.Windows.Forms.Label();
this.label13 = new System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuPublisher = new System.Windows.Forms.MenuItem();
this.menuAuthor = new System.Windows.Forms.MenuItem();
this.menuTitle = new System.Windows.Forms.MenuItem();
this.bookTree = new ControlLib.dbTreeViewCtrl(this.components);
this.panelTop.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dsBooks)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.bookDataView)).BeginInit();
this.panelContainer.SuspendLayout();
this.panelAuthor.SuspendLayout();
this.panelPublisher.SuspendLayout();
this.panelTitle.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.imgBookCover)).BeginInit();
this.SuspendLayout();
//
// panelTop
//
this.panelTop.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(215)))), ((int)(((byte)(215)))), ((int)(((byte)(255)))));
this.panelTop.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panelTop.Controls.Add(this.btnFind);
this.panelTop.Controls.Add(this.txtBookID);
this.panelTop.Controls.Add(this.lblLocate);
this.panelTop.Dock = System.Windows.Forms.DockStyle.Top;
this.panelTop.Location = new System.Drawing.Point(0, 0);
this.panelTop.Name = "panelTop";
this.panelTop.Size = new System.Drawing.Size(715, 60);
this.panelTop.TabIndex = 0;
this.panelTop.Paint = new System.Windows.Forms.PaintEventHandler(this.panelTop_Paint);
//
// btnFind
//
this.btnFind.Location = new System.Drawing.Point(461, 17);
this.btnFind.Name = "btnFind";
this.btnFind.Size = new System.Drawing.Size(90, 25);
this.btnFind.TabIndex = 2;
this.btnFind.Text = "Find";
this.btnFind.Click = new System.EventHandler(this.btnFind_Click);
//
// txtBookID
//
this.txtBookID.Location = new System.Drawing.Point(326, 17);
this.txtBookID.Name = "txtBookID";
this.txtBookID.Size = new System.Drawing.Size(120, 21);
this.txtBookID.TabIndex = 1;
//
// lblLocate
//
this.lblLocate.AutoSize = true;
this.lblLocate.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(177)));
this.lblLocate.Location = new System.Drawing.Point(58, 17);
this.lblLocate.Name = "lblLocate";
this.lblLocate.Size = new System.Drawing.Size(242, 16);
this.lblLocate.TabIndex = 0;
this.lblLocate.Text = "Locate Publisher By Publisher ID :";
this.lblLocate.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// imgList
//
this.imgList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imgList.ImageStream")));
this.imgList.TransparentColor = System.Drawing.Color.Transparent;
this.imgList.Images.SetKeyName(0, "");
this.imgList.Images.SetKeyName(1, "");
this.imgList.Images.SetKeyName(2, "");
this.imgList.Images.SetKeyName(3, "");
//
// accessConn
//
this.accessConn.ConnectionString = "Data Source=MS-20151014LHIW;Initial Catalog=TheSampleSQL;Integrated Security=True"
"";
this.accessConn.FireInfoMessageEventOnUserErrors = false;
//
// dsBooks
//
this.dsBooks.DataSetName = "Books";
this.dsBooks.Locale = new System.Globalization.CultureInfo("en-US");
//
// cmdGetAuthors
//
this.cmdGetAuthors.CommandText = "SELECT GetAuthors.* FROM GetAuthors";
this.cmdGetAuthors.Connection = this.accessConn;
//
// splitter2
//
this.splitter2.Location = new System.Drawing.Point(259, 60);
this.splitter2.Name = "splitter2";
this.splitter2.Size = new System.Drawing.Size(3, 346);
this.splitter2.TabIndex = 4;
this.splitter2.TabStop = false;
//
// panelContainer
//
this.panelContainer.Controls.Add(this.panelAuthor);
this.panelContainer.Controls.Add(this.panelPublisher);
this.panelContainer.Controls.Add(this.panelTitle);
this.panelContainer.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelContainer.Location = new System.Drawing.Point(262, 60);
this.panelContainer.Name = "panelContainer";
this.panelContainer.Size = new System.Drawing.Size(453, 346);
this.panelContainer.TabIndex = 5;
//
// panelAuthor
//
this.panelAuthor.BackColor = System.Drawing.SystemColors.Control;
this.panelAuthor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panelAuthor.Controls.Add(this.lblAuthorID);
this.panelAuthor.Controls.Add(this.txtAuthAddress);
this.panelAuthor.Controls.Add(this.label12);
this.panelAuthor.Controls.Add(this.txtAuthLastName);
this.panelAuthor.Controls.Add(this.label11);
this.panelAuthor.Controls.Add(this.txtAuthZip);
this.panelAuthor.Controls.Add(this.label6);
this.panelAuthor.Controls.Add(this.txtAuthState);
this.panelAuthor.Controls.Add(this.label7);
this.panelAuthor.Controls.Add(this.txtAuthCity);
this.panelAuthor.Controls.Add(this.label8);
this.panelAuthor.Controls.Add(this.txtAuthFirstName);
this.panelAuthor.Controls.Add(this.label9);
this.panelAuthor.Controls.Add(this.label10);
this.panelAuthor.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelAuthor.Location = new System.Drawing.Point(0, 0);
this.panelAuthor.Name = "panelAuthor";
this.panelAuthor.Size = new System.Drawing.Size(453, 346);
this.panelAuthor.TabIndex = 11;
//
// lblAuthorID
//
this.lblAuthorID.Cursor = System.Windows.Forms.Cursors.IBeam;
this.lblAuthorID.Location = new System.Drawing.Point(288, 370);
this.lblAuthorID.Name = "lblAuthorID";
this.lblAuthorID.Size = new System.Drawing.Size(134, 18);
this.lblAuthorID.TabIndex = 22;
this.lblAuthorID.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// txtAuthAddress
//
this.txtAuthAddress.Location = new System.Drawing.Point(134, 164);
this.txtAuthAddress.Name = "txtAuthAddress";
this.txtAuthAddress.Size = new System.Drawing.Size(269, 21);
this.txtAuthAddress.TabIndex = 21;
//
// label12
//
this.label12.Location = new System.Drawing.Point(38, 164);
this.label12.Name = "label12";
this.label12.Size = new System.Drawing.Size(87, 24);
this.label12.TabIndex = 20;
this.label12.Text = "Address:";
//
// txtAuthLastName
//
this.txtAuthLastName.Location = new System.Drawing.Point(134, 103);
this.txtAuthLastName.Name = "txtAuthLastName";
this.txtAuthLastName.Size = new System.Drawing.Size(269, 21);
this.txtAuthLastName.TabIndex = 19;
//
// label11
//
this.label11.Location = new System.Drawing.Point(38, 103);
this.label11.Name = "label11";
this.label11.Size = new System.Drawing.Size(87, 25);
this.label11.TabIndex = 18;
this.label11.Text = "Last Name:";
//
// txtAuthZip
//
this.txtAuthZip.Location = new System.Drawing.Point(134, 267);
this.txtAuthZip.Name = "txtAuthZip";
this.txtAuthZip.Size = new System.Drawing.Size(87, 21);
this.txtAuthZip.TabIndex = 17;
//
// label6
//
this.label6.Location = new System.Drawing.Point(48, 267);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(58, 25);
this.label6.TabIndex = 16;
this.label6.Text = "Zip:";
//
// txtAuthState
//
this.txtAuthState.Location = new System.Drawing.Point(134, 233);
this.txtAuthState.Name = "txtAuthState";
this.txtAuthState.Size = new System.Drawing.Size(87, 21);
this.txtAuthState.TabIndex = 15;
//
// label7
//
this.label7.Location = new System.Drawing.Point(48, 233);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(58, 24);
this.label7.TabIndex = 14;
this.label7.Text = "State:";
//
// txtAuthCity
//
this.txtAuthCity.Location = new System.Drawing.Point(134, 198);
this.txtAuthCity.Name = "txtAuthCity";
this.txtAuthCity.Size = new System.Drawing.Size(269, 21);
this.txtAuthCity.TabIndex = 13;
//
// label8
//
this.label8.Location = new System.Drawing.Point(48, 198);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(58, 25);
this.label8.TabIndex = 12;
this.label8.Text = "City:";
//
// txtAuthFirstName
//
this.txtAuthFirstName.Location = new System.Drawing.Point(134, 69);
this.txtAuthFirstName.Name = "txtAuthFirstName";
this.txtAuthFirstName.Size = new System.Drawing.Size(269, 21);
this.txtAuthFirstName.TabIndex = 11;
//
// label9
//
this.label9.Location = new System.Drawing.Point(38, 69);
this.label9.Name = "label9";
this.label9.Size = new System.Drawing.Size(87, 25);
this.label9.TabIndex = 10;
this.label9.Text = "First Name:";
//
// label10
//
this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label10.Location = new System.Drawing.Point(38, 17);
this.label10.Name = "label10";
this.label10.Size = new System.Drawing.Size(202, 25);
this.label10.TabIndex = 9;
this.label10.Text = "Author Info";
this.label10.Click = new System.EventHandler(this.label10_Click);
//
// panelPublisher
//
this.panelPublisher.BackColor = System.Drawing.SystemColors.Control;
this.panelPublisher.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panelPublisher.Controls.Add(this.lblPublisherID);
this.panelPublisher.Controls.Add(this.txtPubContry);
this.panelPublisher.Controls.Add(this.label5);
this.panelPublisher.Controls.Add(this.txtPubState);
this.panelPublisher.Controls.Add(this.label4);
this.panelPublisher.Controls.Add(this.txtPubCity);
this.panelPublisher.Controls.Add(this.label3);
this.panelPublisher.Controls.Add(this.txtPubName);
this.panelPublisher.Controls.Add(this.label2);
this.panelPublisher.Controls.Add(this.label1);
this.panelPublisher.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelPublisher.Location = new System.Drawing.Point(0, 0);
this.panelPublisher.Name = "panelPublisher";
this.panelPublisher.Size = new System.Drawing.Size(453, 346);
this.panelPublisher.TabIndex = 10;
//
// lblPublisherID
//
this.lblPublisherID.Location = new System.Drawing.Point(269, 362);
this.lblPublisherID.Name = "lblPublisherID";
this.lblPublisherID.Size = new System.Drawing.Size(144, 26);
this.lblPublisherID.TabIndex = 9;
this.lblPublisherID.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtPubContry
//
this.txtPubContry.Location = new System.Drawing.Point(134, 241);
this.txtPubContry.Name = "txtPubContry";
this.txtPubContry.Size = new System.Drawing.Size(260, 21);
this.txtPubContry.TabIndex = 8;
//
// label5
//
this.label5.Location = new System.Drawing.Point(48, 241);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(58, 25);
this.label5.TabIndex = 7;
this.label5.Text = "Country:";
//
// txtPubState
//
this.txtPubState.Location = new System.Drawing.Point(134, 207);
this.txtPubState.Name = "txtPubState";
this.txtPubState.Size = new System.Drawing.Size(260, 21);
this.txtPubState.TabIndex = 6;
//
// label4
//
this.label4.Location = new System.Drawing.Point(48, 207);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(58, 25);
this.label4.TabIndex = 5;
this.label4.Text = "State:";
//
// txtPubCity
//
this.txtPubCity.Location = new System.Drawing.Point(134, 172);
this.txtPubCity.Name = "txtPubCity";
this.txtPubCity.Size = new System.Drawing.Size(260, 21);
this.txtPubCity.TabIndex = 4;
//
// label3
//
this.label3.Location = new System.Drawing.Point(48, 172);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(58, 25);
this.label3.TabIndex = 3;
this.label3.Text = "City:";
//
// txtPubName
//
this.txtPubName.Location = new System.Drawing.Point(38, 112);
this.txtPubName.Name = "txtPubName";
this.txtPubName.Size = new System.Drawing.Size(356, 21);
this.txtPubName.TabIndex = 2;
//
// label2
//
this.label2.Location = new System.Drawing.Point(38, 86);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 25);
this.label2.TabIndex = 1;
this.label2.Text = "Publisher Name:";
//
// label1
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(38, 26);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(202, 25);
this.label1.TabIndex = 0;
this.label1.Text = "Publisher Info";
//
// panelTitle
//
this.panelTitle.BackColor = System.Drawing.SystemColors.Control;
this.panelTitle.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panelTitle.Controls.Add(this.lblTitleID);
this.panelTitle.Controls.Add(this.txtBookTitleNodes);
this.panelTitle.Controls.Add(this.imgBookCover);
this.panelTitle.Controls.Add(this.txtBookAdvPaid);
this.panelTitle.Controls.Add(this.txtBookRoylaty);
this.panelTitle.Controls.Add(this.txtBookPrice);
this.panelTitle.Controls.Add(this.txtBookYTDSales);
this.panelTitle.Controls.Add(this.label21);
this.panelTitle.Controls.Add(this.label20);
this.panelTitle.Controls.Add(this.label19);
this.panelTitle.Controls.Add(this.label18);
this.panelTitle.Controls.Add(this.label17);
this.panelTitle.Controls.Add(this.txtBookPubDate);
this.panelTitle.Controls.Add(this.label16);
this.panelTitle.Controls.Add(this.txtBookType);
this.panelTitle.Controls.Add(this.label15);
this.panelTitle.Controls.Add(this.txtBookTitle);
this.panelTitle.Controls.Add(this.label14);
this.panelTitle.Controls.Add(this.label13);
this.panelTitle.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelTitle.Location = new System.Drawing.Point(0, 0);
this.panelTitle.Name = "panelTitle";
this.panelTitle.Size = new System.Drawing.Size(453, 346);
this.panelTitle.TabIndex = 12;
//
// lblTitleID
//
this.lblTitleID.Location = new System.Drawing.Point(355, 379);
this.lblTitleID.Name = "lblTitleID";
this.lblTitleID.Size = new System.Drawing.Size(58, 17);
this.lblTitleID.TabIndex = 28;
this.lblTitleID.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// txtBookTitleNodes
//
this.txtBookTitleNodes.Location = new System.Drawing.Point(29, 181);
this.txtBookTitleNodes.Multiline = true;
this.txtBookTitleNodes.Name = "txtBookTitleNodes";
this.txtBookTitleNodes.Size = new System.Drawing.Size(374, 60);
this.txtBookTitleNodes.TabIndex = 18;
//
// imgBookCover
//
this.imgBookCover.ImagePath = null;
this.imgBookCover.Location = new System.Drawing.Point(48, 267);
this.imgBookCover.Name = "imgBookCover";
this.imgBookCover.Size = new System.Drawing.Size(77, 86);
this.imgBookCover.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
this.imgBookCover.TabIndex = 30;
this.imgBookCover.TabStop = false;
//
// txtBookAdvPaid
//
this.txtBookAdvPaid.BackColor = System.Drawing.Color.White;
this.txtBookAdvPaid.Location = new System.Drawing.Point(288, 336);
this.txtBookAdvPaid.Name = "txtBookAdvPaid";
this.txtBookAdvPaid.ReadOnly = true;
this.txtBookAdvPaid.Size = new System.Drawing.Size(120, 21);
this.txtBookAdvPaid.TabIndex = 26;
this.txtBookAdvPaid.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// txtBookRoylaty
//
this.txtBookRoylaty.Location = new System.Drawing.Point(288, 310);
this.txtBookRoylaty.Name = "txtBookRoylaty";
this.txtBookRoylaty.Size = new System.Drawing.Size(120, 21);
this.txtBookRoylaty.TabIndex = 25;
this.txtBookRoylaty.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// txtBookPrice
//
this.txtBookPrice.Location = new System.Drawing.Point(288, 284);
this.txtBookPrice.Name = "txtBookPrice";
this.txtBookPrice.Size = new System.Drawing.Size(120, 21);
this.txtBookPrice.TabIndex = 24;
this.txtBookPrice.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// txtBookYTDSales
//
this.txtBookYTDSales.Location = new System.Drawing.Point(288, 258);
this.txtBookYTDSales.Name = "txtBookYTDSales";
this.txtBookYTDSales.Size = new System.Drawing.Size(120, 21);
this.txtBookYTDSales.TabIndex = 23;
this.txtBookYTDSales.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// label21
//
this.label21.Location = new System.Drawing.Point(163, 336);
this.label21.Name = "label21";
this.label21.Size = new System.Drawing.Size(120, 25);
this.label21.TabIndex = 22;
this.label21.Text = "Advance Paid:";
//
// label20
//
this.label20.Location = new System.Drawing.Point(163, 310);
this.label20.Name = "label20";
this.label20.Size = new System.Drawing.Size(120, 25);
this.label20.TabIndex = 21;
this.label20.Text = "Royalty %:";
//
// label19
//
this.label19.Location = new System.Drawing.Point(163, 284);
this.label19.Name = "label19";
this.label19.Size = new System.Drawing.Size(120, 25);
this.label19.TabIndex = 20;
this.label19.Text = "Price:";
//
// label18
//
this.label18.Location = new System.Drawing.Point(163, 258);
this.label18.Name = "label18";
this.label18.Size = new System.Drawing.Size(120, 25);
this.label18.TabIndex = 19;
this.label18.Text = "YTD Sales";
//
// label17
//
this.label17.Location = new System.Drawing.Point(29, 164);
this.label17.Name = "label17";
this.label17.Size = new System.Drawing.Size(120, 24);
this.label17.TabIndex = 17;
this.label17.Text = "Title Nodes:";
//
// txtBookPubDate
//
this.txtBookPubDate.Location = new System.Drawing.Point(144, 129);
this.txtBookPubDate.Name = "txtBookPubDate";
this.txtBookPubDate.Size = new System.Drawing.Size(182, 21);
this.txtBookPubDate.TabIndex = 16;
//
// label16
//
this.label16.Location = new System.Drawing.Point(29, 129);
this.label16.Name = "label16";
this.label16.Size = new System.Drawing.Size(105, 25);
this.label16.TabIndex = 15;
this.label16.Text = "Publisher Date:";
//
// txtBookType
//
this.txtBookType.Location = new System.Drawing.Point(106, 95);
this.txtBookType.Name = "txtBookType";
this.txtBookType.Size = new System.Drawing.Size(220, 21);
this.txtBookType.TabIndex = 14;
//
// label15
//
this.label15.Location = new System.Drawing.Point(29, 95);
this.label15.Name = "label15";
this.label15.Size = new System.Drawing.Size(57, 25);
this.label15.TabIndex = 13;
this.label15.Text = "Type:";
//
// txtBookTitle
//
this.txtBookTitle.Location = new System.Drawing.Point(106, 60);
this.txtBookTitle.Multiline = true;
this.txtBookTitle.Name = "txtBookTitle";
this.txtBookTitle.Size = new System.Drawing.Size(297, 22);
this.txtBookTitle.TabIndex = 12;
//
// label14
//
this.label14.Location = new System.Drawing.Point(29, 60);
this.label14.Name = "label14";
this.label14.Size = new System.Drawing.Size(67, 25);
this.label14.TabIndex = 11;
this.label14.Text = "Title:";
//
// label13
//
this.label13.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, ((System.Drawing.FontStyle)((System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic))), System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label13.Location = new System.Drawing.Point(19, 17);
this.label13.Name = "label13";
this.label13.Size = new System.Drawing.Size(202, 25);
this.label13.TabIndex = 10;
this.label13.Text = "Book Detail";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuPublisher,
this.menuAuthor,
this.menuTitle});
this.menuItem1.Text = "Add/Remove Group";
//
// menuPublisher
//
this.menuPublisher.Checked = true;
this.menuPublisher.Index = 0;
this.menuPublisher.Text = "Publisher";
this.menuPublisher.Click = new System.EventHandler(this.menuPublisher_Click);
//
// menuAuthor
//
this.menuAuthor.Checked = true;
this.menuAuthor.Index = 1;
this.menuAuthor.Text = "Author";
this.menuAuthor.Click = new System.EventHandler(this.menuAuthor_Click);
//
// menuTitle
//
this.menuTitle.Enabled = false;
this.menuTitle.Index = 2;
this.menuTitle.Text = "Title";
this.menuTitle.Click = new System.EventHandler(this.menuTitle_Click);
//
// bookTree
//
this.bookTree.AutoBuildTree = true;
this.bookTree.DataSource = null;
this.bookTree.DisplayMember = "title";
this.bookTree.Dock = System.Windows.Forms.DockStyle.Left;
this.bookTree.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.bookTree.ImageIndex = 2;
this.bookTree.ImageList = this.imgList;
this.bookTree.Location = new System.Drawing.Point(0, 60);
this.bookTree.Name = "bookTree";
this.bookTree.SelectedImageIndex = 2;
this.bookTree.Size = new System.Drawing.Size(259, 346);
this.bookTree.TabIndex = 1;
this.bookTree.ValueMember = "title_id";
this.bookTree.AfterSelect = new System.Windows.Forms.TreeViewEventHandler(this.bookTree_AfterSelect);
//
// TestForm
//
this.AcceptButton = this.btnFind;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(715, 406);
this.Controls.Add(this.panelContainer);
this.Controls.Add(this.splitter2);
this.Controls.Add(this.bookTree);
this.Controls.Add(this.panelTop);
this.Menu = this.mainMenu1;
this.Name = "TestForm";
this.Tag = "Author";
this.Text = "Book Browser";
this.Load = new System.EventHandler(this.TestForm_Load);
this.panelTop.ResumeLayout(false);
this.panelTop.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dsBooks)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.bookDataView)).EndInit();
this.panelContainer.ResumeLayout(false);
this.panelAuthor.ResumeLayout(false);
this.panelAuthor.PerformLayout();
this.panelPublisher.ResumeLayout(false);
this.panelPublisher.PerformLayout();
this.panelTitle.ResumeLayout(false);
this.panelTitle.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.imgBookCover)).EndInit();
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new TestForm());
}
public void SetUpDataBinding()
{
int nRows = 0;
try
{
this.accessConn.Open();
SqlDataAdapter daAuthors = new SqlDataAdapter (this.cmdGetAuthors);
nRows = daAuthors.Fill (this.dsBooks, "Authors");
}
catch (System.Data .SqlClient.SqlException e)
{
MessageBox.Show (String.Format ("Database Error: {0}", e.Message), "TestControl Application");
}
catch ( System.Exception e)
{
MessageBox.Show (String.Format ("Error: {0}", e.Message), "TestControl Application");
}
this.accessConn.Close();
this.bookDataView = dsBooks.Tables ["Authors"].DefaultView;
this.bookTree.AutoBuildTree = false;
this.bookTree.SetLeafData ("Title", "title", "title_id", 2, 2);
this.bookTree.DataSource = this.bookDataView;
this.bookTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0);
this.bookTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);
this.bookTree.BuildTree();
if ( this.bookTree.Nodes.Count <= 0 )
return;
System.Windows.Forms.Binding myBinding;
this.txtPubName.DataBindings.Add ("Text", bookDataView, "pub_name");
this.txtPubCity.DataBindings.Add ("Text", bookDataView, "pub_City");
this.txtPubState.DataBindings.Add ("Text", bookDataView, "pub_State");
this.txtPubContry.DataBindings.Add ("Text", bookDataView, "pub_Country");
this.lblPublisherID.DataBindings.Add ("Text", bookDataView, "pub_id");
this.txtAuthFirstName.DataBindings.Add ("Text", bookDataView, "au_fname");
this.txtAuthLastName.DataBindings.Add ("Text", bookDataView, "au_lname");
this.txtAuthAddress.DataBindings.Add ("Text", bookDataView, "au_address");
this.txtAuthCity.DataBindings.Add ("Text", bookDataView, "au_city");
this.txtAuthZip.DataBindings.Add ("Text", bookDataView, "au_zip");
this.txtAuthState.DataBindings.Add ("Text", bookDataView, "au_state");
this.lblAuthorID.DataBindings.Add ("Text", bookDataView, "au_id");
this.txtBookTitle.DataBindings.Add ("Text", bookDataView, "title");
this.txtBookTitleNodes.DataBindings.Add ("Text", bookDataView, "title_notes");
this.txtBookType.DataBindings.Add ("Text", bookDataView, "title_type");
this.txtBookYTDSales.DataBindings.Add ("Text", bookDataView, "title_ytd_sales");
this.lblTitleID.DataBindings.Add ("Text", bookDataView, "title_id");
this.imgBookCover.DataBindings.Add ("ImagePath", bookDataView, "title_imagePath");
myBinding = this.txtBookPrice.DataBindings.Add ("Text", bookDataView, "title_price");
myBinding.Format = new ConvertEventHandler(CurrencyFormat);
myBinding = this.txtBookPubDate.DataBindings.Add ("Text", bookDataView, "title_pubdate");
myBinding.Format = new ConvertEventHandler(DateFormat);
myBinding = this.txtBookRoylaty.DataBindings.Add ("Text", bookDataView, "title_royalty");
myBinding.Format = new ConvertEventHandler(PercentFormat);
myBinding = this.txtBookAdvPaid.DataBindings.Add ("Text", bookDataView, "title_advance");
myBinding.Format = new ConvertEventHandler(CurrencyFormat);
String sName = this.bookTree.Tag == null ? "Item" : this.bookTree.Tag.ToString();
this.lblLocate.Text = "Locate " sName " By " sName " ID: ";
}
public void CurrencyFormat(object sender, ConvertEventArgs e)
{
if ( e.Value is System.DBNull )
return;
e.Value = (Convert.ToDouble(e.Value)).ToString ("C");
}
public void PercentFormat(object sender, ConvertEventArgs e)
{
if ( e.Value is System.DBNull )
return;
double percentValue = Convert.ToDouble (e.Value);
percentValue = percentValue / 100;
e.Value = percentValue.ToString("P0");
}
public void DateFormat(object sender, ConvertEventArgs e)
{
if ( e.Value is System.DBNull )
return;
e.Value = Convert.ToDateTime (e.Value).ToShortDateString();
}
private void btnFind_Click(object sender, System.EventArgs e)
{
if ( this.txtBookTitle.Text.Trim() != String.Empty )
{
TreeNode currentNode = this.bookTree.FindNodeByValue (this.txtBookID.Text.ToUpper());
if ( currentNode != null )
bookTree.SelectedNode = currentNode;
else
{
this.txtBookID.Focus();
this.txtBookID.SelectAll();
}
}
}
private void RebuildTree ()
{
String sSort = "";
int nCheckedCount = 0;
this.bookTree.RemoveAllGroups();
// set groups and sorting string
for (int i=0; i<this.menuItem1.MenuItems.Count; i )
{
MenuItem menu = this.menuItem1.MenuItems[i];
menu.Enabled = true;
if ( menu.Checked)
{
nCheckedCount ;
switch (menu.Text)
{
case "Publisher" :
sSort = "pub_id, ";
this.bookTree.AddGroup ("Publisher", "pub_id", "pub_name", "pub_id", 0, 0);
break;
case "Author" :
sSort = "au_name, ";
this.bookTree.AddGroup ("Author", "au_id", "au_name", "au_id", 1, 3);
break;
case "Title" :
sSort = "title_id, ";
this.bookTree.AddGroup ("Title", "title_id", "title", "title_id", 2, 2);
break;
}
}
}
// disable the only unchecked menu item to disallow check it.(It, in fact, is a leaf group)
if ( nCheckedCount == this.menuItem1.MenuItems.Count - 1 )
{
for (int i=0; i<this.menuItem1.MenuItems.Count; i )
if ( !menuItem1.MenuItems[i].Checked )
this.menuItem1.MenuItems[i].Enabled = false;
}
// determine which group is the leaf group and set the leaf data
if ( sSort.IndexOf ("title_id") < 0 )
this.bookTree.SetLeafData ("Title", "title", "title_id", 2, 2);
else if (sSort.IndexOf ("au_name") < 0 )
this.bookTree.SetLeafData ("Author", "au_name", "au_id", 1, 3);
else
this.bookTree.SetLeafData ("Publisher", "pub_name", "pub_id", 0, 0);
// sort and re-build the tree
this.bookDataView.Sort = sSort "title_id";
this.bookTree.BuildTree();
String sName = this.bookTree.Tag == null ? "Item" : this.bookTree.Tag.ToString();
this.lblLocate.Text = "Locate " sName " By " sName " ID: ";
}
private void menuPublisher_Click(object sender, System.EventArgs e)
{
this.menuPublisher.Checked = !this.menuPublisher.Checked;
this.RebuildTree();
}
private void menuAuthor_Click(object sender, System.EventArgs e)
{
this.menuAuthor.Checked = !this.menuAuthor.Checked;
this.RebuildTree();
}
private void menuTitle_Click(object sender, System.EventArgs e)
{
this.menuTitle.Checked = !this.menuTitle.Checked;
this.RebuildTree();
}
private void bookTree_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
ControlLib.dbTreeNode node = (ControlLib.dbTreeNode) e.Node;
// determine which page to display
if ( node != null )
{
switch (node.GroupName)
{
case "Publisher" :
this.panelAuthor.Visible = false;
this.panelTitle.Visible = false;
this.panelPublisher.Visible = true;
break;
case "Author" :
this.panelPublisher.Visible = false;
this.panelTitle.Visible = false;
this.panelAuthor.Visible = true;
break;
case "Title" :
this.panelPublisher.Visible = false;
this.panelAuthor.Visible = false;
this.panelTitle.Visible = true;
break;
}
}
}
private void panelTop_Paint(object sender, PaintEventArgs e)
{
}
private void TestForm_Load(object sender, EventArgs e)
{
}
private void label10_Click(object sender, EventArgs e)
{
}
}
}
评论