📄 frmcategory.cs
字号:
node.Nodes.Add(newNode);
}
else //if this node does have a parent category, find its parent and then add this node to that parent node
{
//TreeNode tnode = this.tvwCatCode.TopNode;
foreach(TreeNode nd in node.Nodes)
{
if (nd.Text.Equals(parent))
{
newNode = new TreeNode (current);
nd.Nodes.Add (current);
}
}
}
this.treePopulated = true;
}//end while
}
if (this.treePopulated)
{
this.tvwCatCode.ExpandAll();
this.tvwCatCode.Sorted = true;
}
reader.Close();
}
catch(Exception excep)
{
MessageBox.Show("发生错误 "+excep.Message.ToString ());
}
}
private void btnUpdate_Click(object sender, System.EventArgs e)
{
foreach (Control ctrl in this.Controls)
{
if ((ctrl.GetType().ToString() != "System.Windows.Forms.NumericUpDown") && (ctrl.GetType().ToString() != "System.Windows.Forms.TreeView")&&(ctrl.GetType().ToString() != "System.Windows.Forms.Label"))
{
if (ctrl.Text == "")
allValidated = false;
}
else
{
if (this.updRate.Value <=0)
allValidated = false;
}
}
try
{
if (allValidated)
{
flag = true;
strPrdCat stPrdCat = new strPrdCat(); //create a new structure
//populate the structure
//get the current category code
stPrdCat.CatCode = tvwCatCode.SelectedNode.Text;
stPrdCat.CatTitle = txtCatTitle.Text ;
stPrdCat.CatDesc = txtCatDesc.Text ;
stPrdCat.Rate =this.updRate.Value;
if (this.txtFlvlCatCode.Text == stPrdCat.CatCode)
MessageBox.Show ("请输入第一层类别代码");
else
{
stPrdCat.FlvlCatCode = this.txtFlvlCatCode.Text; //get the parent category code
string info = ("更新以下信息:第一层类别代码: "+stPrdCat.FlvlCatCode+",费率:"+stPrdCat.Rate+" 名称: "+stPrdCat.CatTitle+" 说明:"+stPrdCat.CatDesc);
MessageBox.Show(info);
string askquestion="信息正确吗?要继续更新操作吗?";
DialogResult result = MessageBox.Show(this,askquestion,"非常高兴",MessageBoxButtons.YesNo);
if (result == DialogResult.Yes )
{
stPrdCat.Rate = rate;
StockManagement stkMgmt = new StockManagement();
stkMgmt.ModifyProdCat(stPrdCat);
MessageBox.Show ("已更新记录");
}
else
{
MessageBox.Show ("已取消记录更新");
}
this.ClearDetails ();
flag = true;
this.populateTree ();
}
}
else
MessageBox.Show ("未完成详细信息,不能更新。");
}
catch(Exception excep)
{
MessageBox.Show("发生错误 "+excep.Message.ToString ());
}
}
private void updRate_ValueChanged(object sender, System.EventArgs e)
{
rate = updRate.Value;
}
private void tvwCatCode_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs evt)
{
try
{
this.catCode = tvwCatCode.SelectedNode.Text;
if (!this.catCode.Equals ("Product Categories"))
{
DataConnection.commnd.CommandText = "Select catdesc,flvlcatcode,cattitle,rate from productcategories where catcode='"+this.catCode+"'";
OleDbDataReader reader = DataConnection.commnd.ExecuteReader();
reader.Read();
this.txtCatCode.Text = this.catCode;
this.txtCatDesc.Text = reader.GetString(0);
this.txtFlvlCatCode.Text = reader.GetString(1);
this.txtCatTitle.Text = reader.GetString(2);
this.updRate.Value = reader.GetDecimal(3);
this.btnInsert.Enabled =true;
this.btnUpdate.Enabled =true;
reader.Close();
}
}
catch(Exception excep)
{
MessageBox.Show("发生错误 "+excep.Message.ToString ());
}
}
private void btnInsert_Click(object sender, System.EventArgs e)
{
frmAddCategory frmCat = new frmAddCategory();
frmCat.MdiParent = this.ParentForm;
frmCat.Show();
this.ClearDetails();
}
private void btnExit_Click(object sender, System.EventArgs e)
{
frmMainMenu.varPrdCategory = 0;
this.Close ();
}
private void tvwCatCode_Click(object sender, System.EventArgs e)
{
if (this.flag)
this.populateTree();
}
private void txtCatDesc_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
//first check if the cat code and parent cat code have been entered
if ((this.txtCatCode.Text !="") && (this.txtFlvlCatCode.Text != ""))
{
if (this.txtCatDesc.Text == "")
{
errorMsg = ("类别说明不能为空,请输入有效值。");
this.errCategory.SetError(this.txtCatDesc, errorMsg);
allValidated = false;
e.Cancel =true;
}
}
}
private void txtCatDesc_Validated(object sender, System.EventArgs e)
{
errCategory.SetError(this.txtCatDesc,"");
allValidated = true;
}
private void updRate_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
//first check if the cat code and parent cat code have been entered
if ((this.txtCatCode.Text !="") && (this.txtFlvlCatCode.Text != ""))
{
if (this.updRate.Value <= 0 )
{
errorMsg = ("费率不能为 0 或着负数,请输入有效值。");
this.errCategory.SetError(this.updRate, errorMsg);
allValidated = false;
e.Cancel =true;
}
}
}
private void updRate_Validated(object sender, System.EventArgs e)
{
errCategory.SetError(this.updRate,"");
allValidated = true;
}
private void txtCatTitle_Validated(object sender, System.EventArgs e)
{
errCategory.SetError(this.txtCatTitle,"");
allValidated = true;
}
private void txtCatTitle_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
//first check if the cat code and parent cat code have been entered
if ((this.txtFlvlCatCode.Text != ""))
{
if (this.txtCatTitle.Text == "")
{
errorMsg = ("类别名称不能为空,请输入有效值。");
this.errCategory.SetError(this.txtCatTitle, errorMsg);
allValidated = false;
e.Cancel =true;
}
}
}
private void txtFlvlCatCode_Validated(object sender, System.EventArgs e)
{
errCategory.SetError(this.txtFlvlCatCode,"");
allValidated = true;
}
private void txtFlvlCatCode_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
if (this.txtCatCode.Text != "") //check for current category
{
if (this.txtFlvlCatCode.Text == "") //check for parent category
{
errorMsg = ("第一层类别代码不能为空,请输入“00”或其他有效值。");
this.errCategory.SetError(this.txtFlvlCatCode, errorMsg);
allValidated = false;
e.Cancel =true;
}
}
}
public void ClearDetails()
{
this.txtCatDesc.Text ="";
this.txtCatCode.Text ="";
this.txtFlvlCatCode.Text ="";
this.txtCatTitle.Text = "";
this.updRate.Value =0;
}
private void frmCategory_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
frmMainMenu.varPrdCategory = 0;
}
private void tvwCatCode_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.tvwCatCode,"选择一个类别代码");
}
private void txtCatDesc_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.txtCatDesc,"类别说明");
}
private void txtCatCode_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.txtCatCode,"类别代码");
}
private void txtFlvlCatCode_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.txtFlvlCatCode,"父类别代码");
}
private void txtCatTitle_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.txtCatTitle,"类别名称");
}
private void btnInsert_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.btnInsert,"添加新的记录信息");
}
private void btnUpdate_MouseHover(object sender, System.EventArgs e)
{
this.tipCategory.SetToolTip(this.btnUpdate,"更新记录信息");
}
private void frmCategory_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
this.populateTree();
this.tvwCatCode.Sorted = true;
if (this.treePopulated)
{
if (addflag == true)
{
this.btnInsert.Enabled =false;
this.btnUpdate.Enabled =false;
}
}
else
{
this.btnInsert.Enabled =true;
this.btnUpdate.Enabled =false;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -