📄 frmproductdetails.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 frmProductDetails.
/// </summary>
public class frmProductDetails : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtPrdName;
private System.Windows.Forms.Label lblProdId;
private System.Windows.Forms.Label lblCatCode;
private System.Windows.Forms.Label lblPrdName;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.GroupBox grpSearch;
private System.Windows.Forms.Button btnAdd;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button btnUpdate;
private System.Windows.Forms.Button btnNew;
private System.Windows.Forms.ComboBox cboCatCode;
private System.Windows.Forms.ComboBox cboProdId;
private System.Windows.Forms.DataGrid dbgDispProd;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TreeView tvwCatCode;
//other variables
private string[] searchValue;
private string prodName;
private bool addFlag = false;
private bool updatedFlag = false;
private string catCode, str;
private System.Windows.Forms.HelpProvider hlpProductDetails;
private bool treePopulated = false;
private System.Windows.Forms.ToolTip tipProductDetails;
private OleDbDataReader reader;
public static bool flag = false;
private Settings settings;
public frmProductDetails()
{
//initialize the arrays
searchValue = new string[3];
//
// Required for Windows Form Designer support
//
InitializeComponent();
settings=new Settings();
this.hlpProductDetails.HelpNamespace=settings.uiDirectory+ @"\HELP\SupermarketHelp.chm";
//
// 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.components = new System.ComponentModel.Container();
this.txtPrdName = new System.Windows.Forms.TextBox();
this.lblProdId = new System.Windows.Forms.Label();
this.lblCatCode = new System.Windows.Forms.Label();
this.cboCatCode = new System.Windows.Forms.ComboBox();
this.lblPrdName = new System.Windows.Forms.Label();
this.cboProdId = new System.Windows.Forms.ComboBox();
this.btnSearch = new System.Windows.Forms.Button();
this.grpSearch = new System.Windows.Forms.GroupBox();
this.tvwCatCode = new System.Windows.Forms.TreeView();
this.btnAdd = new System.Windows.Forms.Button();
this.btnNew = new System.Windows.Forms.Button();
this.btnUpdate = new System.Windows.Forms.Button();
this.dbgDispProd = new System.Windows.Forms.DataGrid();
this.btnExit = new System.Windows.Forms.Button();
this.hlpProductDetails = new System.Windows.Forms.HelpProvider();
this.tipProductDetails = new System.Windows.Forms.ToolTip(this.components);
((System.ComponentModel.ISupportInitialize)(this.dbgDispProd)).BeginInit();
this.SuspendLayout();
//
// txtPrdName
//
this.txtPrdName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.hlpProductDetails.SetHelpKeyword(this.txtPrdName, "");
this.txtPrdName.Location = new System.Drawing.Point(96, 40);
this.txtPrdName.Name = "txtPrdName";
this.hlpProductDetails.SetShowHelp(this.txtPrdName, true);
this.txtPrdName.TabIndex = 2;
this.txtPrdName.Text = "";
this.txtPrdName.MouseHover += new System.EventHandler(this.txtPrdName_MouseHover);
this.txtPrdName.Leave += new System.EventHandler(this.txtPrdName_Leave);
//
// lblProdId
//
this.lblProdId.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblProdId.Location = new System.Drawing.Point(376, 40);
this.lblProdId.Name = "lblProdId";
this.lblProdId.Size = new System.Drawing.Size(72, 16);
this.lblProdId.TabIndex = 5;
this.lblProdId.Text = "产品标识";
this.lblProdId.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblCatCode
//
this.lblCatCode.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblCatCode.Location = new System.Drawing.Point(208, 32);
this.lblCatCode.Name = "lblCatCode";
this.lblCatCode.Size = new System.Drawing.Size(80, 32);
this.lblCatCode.TabIndex = 3;
this.lblCatCode.Text = "类别代码";
this.lblCatCode.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboCatCode
//
this.cboCatCode.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cboCatCode.Location = new System.Drawing.Point(288, 40);
this.cboCatCode.Name = "cboCatCode";
this.cboCatCode.Size = new System.Drawing.Size(80, 21);
this.cboCatCode.TabIndex = 4;
this.cboCatCode.MouseHover += new System.EventHandler(this.cboCatCode_MouseHover);
//
// lblPrdName
//
this.lblPrdName.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblPrdName.Location = new System.Drawing.Point(8, 40);
this.lblPrdName.Name = "lblPrdName";
this.lblPrdName.Size = new System.Drawing.Size(88, 16);
this.lblPrdName.TabIndex = 1;
this.lblPrdName.Text = "产品名称";
this.lblPrdName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cboProdId
//
this.cboProdId.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.cboProdId.Location = new System.Drawing.Point(448, 40);
this.cboProdId.Name = "cboProdId";
this.cboProdId.Size = new System.Drawing.Size(72, 21);
this.cboProdId.TabIndex = 6;
this.cboProdId.DropDown += new System.EventHandler(this.cboProdId_DropDown);
this.cboProdId.MouseHover += new System.EventHandler(this.cboProdId_MouseHover);
//
// btnSearch
//
this.btnSearch.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnSearch.Location = new System.Drawing.Point(536, 40);
this.btnSearch.Name = "btnSearch";
this.btnSearch.TabIndex = 7;
this.btnSearch.Text = "搜索(&S)";
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// grpSearch
//
this.grpSearch.Location = new System.Drawing.Point(0, 16);
this.grpSearch.Name = "grpSearch";
this.grpSearch.Size = new System.Drawing.Size(624, 48);
this.grpSearch.TabIndex = 0;
this.grpSearch.TabStop = false;
//
// tvwCatCode
//
this.tvwCatCode.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.tvwCatCode.ImageIndex = -1;
this.tvwCatCode.Location = new System.Drawing.Point(8, 80);
this.tvwCatCode.Name = "tvwCatCode";
this.tvwCatCode.SelectedImageIndex = -1;
this.tvwCatCode.Size = new System.Drawing.Size(216, 256);
this.tvwCatCode.TabIndex = 8;
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);
//
// btnAdd
//
this.btnAdd.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnAdd.Location = new System.Drawing.Point(8, 352);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(144, 23);
this.btnAdd.TabIndex = 10;
this.btnAdd.Text = "添加类别(&A)";
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
this.btnAdd.MouseHover += new System.EventHandler(this.btnAdd_MouseHover);
//
// btnNew
//
this.btnNew.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnNew.Location = new System.Drawing.Point(440, 352);
this.btnNew.Name = "btnNew";
this.btnNew.TabIndex = 11;
this.btnNew.Text = "新建(&N)";
this.btnNew.Click += new System.EventHandler(this.btnNew_Click);
//
// btnUpdate
//
this.btnUpdate.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnUpdate.Location = new System.Drawing.Point(528, 352);
this.btnUpdate.Name = "btnUpdate";
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);
//
// dbgDispProd
//
this.dbgDispProd.DataMember = "";
this.dbgDispProd.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.dbgDispProd.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dbgDispProd.Location = new System.Drawing.Point(240, 80);
this.dbgDispProd.Name = "dbgDispProd";
this.dbgDispProd.Size = new System.Drawing.Size(432, 256);
this.dbgDispProd.TabIndex = 9;
this.dbgDispProd.MouseHover += new System.EventHandler(this.dbgDispProd_MouseHover);
this.dbgDispProd.CurrentCellChanged += new System.EventHandler(this.dbgDispProd_CurrentCellChanged);
//
// btnExit
//
this.btnExit.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.btnExit.Location = new System.Drawing.Point(632, 352);
this.btnExit.Name = "btnExit";
this.btnExit.TabIndex = 13;
this.btnExit.Text = "退出(&E)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// hlpProductDetails
//
this.hlpProductDetails.HelpNamespace = "";
//
// tipProductDetails
//
this.tipProductDetails.AutomaticDelay = 150;
//
// frmProductDetails
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(720, 381);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.dbgDispProd);
this.Controls.Add(this.btnUpdate);
this.Controls.Add(this.btnNew);
this.Controls.Add(this.btnAdd);
this.Controls.Add(this.tvwCatCode);
this.Controls.Add(this.btnSearch);
this.Controls.Add(this.cboProdId);
this.Controls.Add(this.lblPrdName);
this.Controls.Add(this.cboCatCode);
this.Controls.Add(this.lblCatCode);
this.Controls.Add(this.lblProdId);
this.Controls.Add(this.txtPrdName);
this.Controls.Add(this.grpSearch);
this.Font = new System.Drawing.Font("Arial", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.HelpButton = true;
this.hlpProductDetails.SetHelpKeyword(this, "adding new products");
this.hlpProductDetails.SetHelpString(this, "adding new products");
this.Name = "frmProductDetails";
this.hlpProductDetails.SetShowHelp(this, true);
this.Text = "产品详细信息";
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmProductDetails_Closing);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.frmProductDetails_Paint);
((System.ComponentModel.ISupportInitialize)(this.dbgDispProd)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void btnSearch_Click(object sender, System.EventArgs e)
{
try
{
if(this.txtPrdName.Text != "") //if product name is not null
{
searchValue[0] = this.txtPrdName.Text;
}
else
{
searchValue[0] = "";
}
if(this.cboCatCode.Text != "") //if catcode is not null
{
searchValue[1] = this.cboCatCode.Text;
}
else if(this.cboCatCode.Text == "") //if catcode is null
{
searchValue[1] = "";
}
if(this.cboProdId.Text != "") //if prodid is not null
{
searchValue[2] = this.cboProdId.Text;
}
else
{
searchValue[2] = "" ;
}
StockManagement stkMgmt = new StockManagement();
//fetch the product details
if (stkMgmt.FetchProdDetails(searchValue).Rows.Count >0)
{
this.dbgDispProd.DataSource = stkMgmt.FetchProdDetails(searchValue);
this.dbgDispProd.Refresh();
}
else //search yielded no records
{
MessageBox.Show ("未捕获到任何记录");
}
this.ClearDetails();
}
catch(Exception excep)
{
MessageBox.Show ("发生错误 "+excep.Message.ToString ());
}
}
public void ClearDetails()
{
this.txtPrdName.Text = "";
this.cboCatCode.Text = "";
this.cboProdId.Text = "";
}
private void btnAdd_Click(object sender, System.EventArgs e)
{
addFlag = true;
frmAddCategory frmCat = new frmAddCategory();
frmCat.MdiParent=this.ParentForm;
frmCat.Show();
}
private void txtPrdName_Leave(object sender, System.EventArgs e)
{
prodName = txtPrdName.Text;
}
private void btnNew_Click(object sender, System.EventArgs e)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -