📄 frmcategory.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace SupermarketProject
{
/// <summary>
/// Summary description for frmCategory.
/// </summary>
public class frmCategory : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView tvwCatCode;
private System.Windows.Forms.Label lblDesc;
private System.Windows.Forms.Label lblCatCode;
private System.Windows.Forms.Label lblRate;
private System.Windows.Forms.TextBox txtCatCode;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.NumericUpDown updRate;
private System.Windows.Forms.TextBox txtCatDesc;
private System.Windows.Forms.Button btnInsert;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtCatTitle;
private System.Windows.Forms.TextBox txtFlvlCatCode;
private System.Windows.Forms.Label lblFlvlCatCode;
private System.Windows.Forms.HelpProvider hlpCategory;
private System.Windows.Forms.ToolTip tipCategory;
//other variables
private decimal rate;
private string catCode;
private System.Windows.Forms.ErrorProvider errCategory;
private bool flag = false;
private bool allValidated = false;
public static bool addflag = false;
private bool treePopulated = false;
private string errorMsg;
private Settings settings;
public frmCategory()
{
InitializeComponent();
settings = new Settings();
this.hlpCategory.HelpNamespace = settings.uiDirectory+ @"\HELP\SupermarketHelp.chm";
}
/// <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();
this.tvwCatCode = new System.Windows.Forms.TreeView();
this.lblDesc = new System.Windows.Forms.Label();
this.lblCatCode = new System.Windows.Forms.Label();
this.lblRate = new System.Windows.Forms.Label();
this.txtCatDesc = new System.Windows.Forms.TextBox();
this.txtCatCode = new System.Windows.Forms.TextBox();
this.updRate = new System.Windows.Forms.NumericUpDown();
this.btnInsert = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.errCategory = new System.Windows.Forms.ErrorProvider();
this.label1 = new System.Windows.Forms.Label();
this.txtCatTitle = new System.Windows.Forms.TextBox();
this.txtFlvlCatCode = new System.Windows.Forms.TextBox();
this.lblFlvlCatCode = new System.Windows.Forms.Label();
this.hlpCategory = new System.Windows.Forms.HelpProvider();
this.tipCategory = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.updRate)).BeginInit();
this.SuspendLayout();
//
// tvwCatCode
//
this.tvwCatCode.ImageIndex = -1;
this.tvwCatCode.Location = new System.Drawing.Point(0, 0);
this.tvwCatCode.Name = "tvwCatCode";
this.tvwCatCode.SelectedImageIndex = -1;
this.hlpCategory.SetShowHelp(this.tvwCatCode, true);
this.tvwCatCode.Size = new System.Drawing.Size(797, 258);
this.tvwCatCode.TabIndex = 0;
this.tvwCatCode.Click += new System.EventHandler(this.tvwCatCode_Click);
this.tvwCatCode.MouseHover += new System.EventHandler(this.tvwCatCode_MouseHover);
this.tvwCatCode.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvwCatCode_AfterSelect);
//
// lblDesc
//
this.lblDesc.Location = new System.Drawing.Point(0, 284);
this.lblDesc.Name = "lblDesc";
this.lblDesc.Size = new System.Drawing.Size(120, 25);
this.lblDesc.TabIndex = 9;
this.lblDesc.Text = "说明";
this.lblDesc.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblCatCode
//
this.lblCatCode.Location = new System.Drawing.Point(355, 284);
this.lblCatCode.Name = "lblCatCode";
this.lblCatCode.Size = new System.Drawing.Size(96, 25);
this.lblCatCode.TabIndex = 1;
this.lblCatCode.Text = "产品代码";
this.lblCatCode.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblRate
//
this.lblRate.Location = new System.Drawing.Point(634, 276);
this.lblRate.Name = "lblRate";
this.lblRate.Size = new System.Drawing.Size(38, 24);
this.lblRate.TabIndex = 7;
this.lblRate.Text = "费率";
this.lblRate.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtCatDesc
//
this.txtCatDesc.Location = new System.Drawing.Point(86, 276);
this.txtCatDesc.Multiline = true;
this.txtCatDesc.Name = "txtCatDesc";
this.txtCatDesc.Size = new System.Drawing.Size(240, 103);
this.txtCatDesc.TabIndex = 10;
this.txtCatDesc.Text = "";
this.txtCatDesc.Validating += new System.ComponentModel.CancelEventHandler(this.txtCatDesc_Validating);
this.txtCatDesc.Validated += new System.EventHandler(this.txtCatDesc_Validated);
this.txtCatDesc.MouseHover += new System.EventHandler(this.txtCatDesc_MouseHover);
//
// txtCatCode
//
this.txtCatCode.Location = new System.Drawing.Point(499, 276);
this.txtCatCode.Name = "txtCatCode";
this.txtCatCode.ReadOnly = true;
this.txtCatCode.Size = new System.Drawing.Size(120, 21);
this.txtCatCode.TabIndex = 2;
this.txtCatCode.Text = "";
this.txtCatCode.MouseHover += new System.EventHandler(this.txtCatCode_MouseHover);
//
// updRate
//
this.updRate.Location = new System.Drawing.Point(701, 276);
this.updRate.Name = "updRate";
this.updRate.Size = new System.Drawing.Size(86, 21);
this.updRate.TabIndex = 8;
this.updRate.Validating += new System.ComponentModel.CancelEventHandler(this.updRate_Validating);
this.updRate.Validated += new System.EventHandler(this.updRate_Validated);
this.updRate.ValueChanged += new System.EventHandler(this.updRate_ValueChanged);
//
// btnInsert
//
this.btnInsert.Enabled = false;
this.btnInsert.Location = new System.Drawing.Point(29, 405);
this.btnInsert.Name = "btnInsert";
this.btnInsert.Size = new System.Drawing.Size(90, 43);
this.btnInsert.TabIndex = 11;
this.btnInsert.Text = "插入(&I)";
this.btnInsert.Click += new System.EventHandler(this.btnInsert_Click);
this.btnInsert.MouseHover += new System.EventHandler(this.btnInsert_MouseHover);
//
// btnUpdate
//
this.btnUpdate.Enabled = false;
this.btnUpdate.Location = new System.Drawing.Point(134, 405);
this.btnUpdate.Name = "btnUpdate";
this.btnUpdate.Size = new System.Drawing.Size(90, 43);
this.btnUpdate.TabIndex = 12;
this.btnUpdate.Text = "更新(&U)";
this.btnUpdate.Click += new System.EventHandler(this.btnUpdate_Click);
this.btnUpdate.MouseHover += new System.EventHandler(this.btnUpdate_MouseHover);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(240, 405);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(90, 43);
this.btnExit.TabIndex = 13;
this.btnExit.Text = "退出(&E)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// errCategory
//
this.errCategory.ContainerControl = this;
//
// label1
//
this.label1.Location = new System.Drawing.Point(355, 370);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 25);
this.label1.TabIndex = 5;
this.label1.Text = "类别名称";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// txtCatTitle
//
this.txtCatTitle.Location = new System.Drawing.Point(499, 370);
this.txtCatTitle.Name = "txtCatTitle";
this.txtCatTitle.Size = new System.Drawing.Size(202, 21);
this.txtCatTitle.TabIndex = 6;
this.txtCatTitle.Text = "";
this.txtCatTitle.Validating += new System.ComponentModel.CancelEventHandler(this.txtCatTitle_Validating);
this.txtCatTitle.Validated += new System.EventHandler(this.txtCatTitle_Validated);
this.txtCatTitle.MouseHover += new System.EventHandler(this.txtCatTitle_MouseHover);
//
// txtFlvlCatCode
//
this.txtFlvlCatCode.Location = new System.Drawing.Point(499, 319);
this.txtFlvlCatCode.Name = "txtFlvlCatCode";
this.txtFlvlCatCode.Size = new System.Drawing.Size(120, 21);
this.txtFlvlCatCode.TabIndex = 4;
this.txtFlvlCatCode.Text = "";
this.txtFlvlCatCode.Validating += new System.ComponentModel.CancelEventHandler(this.txtFlvlCatCode_Validating);
this.txtFlvlCatCode.Validated += new System.EventHandler(this.txtFlvlCatCode_Validated);
this.txtFlvlCatCode.MouseHover += new System.EventHandler(this.txtFlvlCatCode_MouseHover);
//
// lblFlvlCatCode
//
this.lblFlvlCatCode.Location = new System.Drawing.Point(355, 319);
this.lblFlvlCatCode.Name = "lblFlvlCatCode";
this.lblFlvlCatCode.Size = new System.Drawing.Size(106, 34);
this.lblFlvlCatCode.TabIndex = 3;
this.lblFlvlCatCode.Text = "第一层类别代码";
this.lblFlvlCatCode.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// tipCategory
//
this.tipCategory.AutomaticDelay = 150;
//
// frmCategory
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(825, 462);
this.Controls.Add(this.lblFlvlCatCode);
this.Controls.Add(this.txtFlvlCatCode);
this.Controls.Add(this.txtCatTitle);
this.Controls.Add(this.txtCatCode);
this.Controls.Add(this.txtCatDesc);
this.Controls.Add(this.label1);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.btnInsert);
this.Controls.Add(this.updRate);
this.Controls.Add(this.lblRate);
this.Controls.Add(this.lblCatCode);
this.Controls.Add(this.lblDesc);
this.Controls.Add(this.tvwCatCode);
this.Name = "frmCategory";
this.Text = "产品类别";
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmCategory_Closing);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmCategory_Paint);
((System.ComponentModel.ISupportInitialize)(this.updRate)).EndInit();
this.ResumeLayout(false);
}
#endregion
public void populateTree()
{
try
{
this.flag = false; // for the next add operation
//if tree exists, delete it and create fresh new tree with latest records
if (this.tvwCatCode.GetNodeCount(true) > 0)
{
this.tvwCatCode.SelectedNode = this.tvwCatCode.TopNode;
this.tvwCatCode.Nodes.Remove(this.tvwCatCode.SelectedNode);
}
//retrieve data for the treeview from the table
DataConnection.commnd.CommandText = "Select catcode,flvlcatcode from productcategories order by flvlcatcode";
OleDbDataReader reader = DataConnection.commnd.ExecuteReader();
if (reader.HasRows)
{
//create root node for the tree view
TreeNode node = this.tvwCatCode.Nodes.Add("产品类别");
TreeNode newNode = new TreeNode ();
string current,parent;
while(reader.Read ())
{
current = reader.GetString(0);
parent = reader.GetString(1);
//if this node has no parent category, add this node to the root node
if(parent.Equals ("00"))
{
newNode = new TreeNode (current);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -