📄 setorginfo.cs
字号:
if (myNode.Index>=10 || myNode.Parent == null) //第二个条件是使根节点的编码为0
this.textBox2.Text = myNode.Index.ToString();
else
this.textBox2.Text = "0" + myNode.Index.ToString();
strTextBox3_Text = "";
CalParentNodesCount(myNode);//计算机构合成编码信息
this.textBox3.Text = strTextBox3_Text;
}
//---------------------退出窗体--------------------------------
private void btnQuit_Click(object sender, System.EventArgs e)
{
this.Close();
}
//----------------------修改机构名称--------------------------------
private void btnModify_Click(object sender, System.EventArgs e)
{
string strNewEnterpriseName = this.textBox1.Text.Trim();
this.treeView1.SelectedNode.Text = strNewEnterpriseName;
string strFilter = "单位编号 = '" + this.textBox3.Text.Trim() + "'";
//通过单位编号在数据集中查找到数据项,并修改其名称和类别
try
{
DataRow[] myRow = this.tblSetOrgInfo.Select(strFilter);
if (myRow.Length ==1)
{
myRow[0]["类别"] = strNewEnterpriseName;
myRow[0]["单位名称"] = strNewEnterpriseName;
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
SaveModify();//向数据库中提交修改,并保存
}
//-----------------将某个项目增加为第一级项目--------------------------
private void btnNewFirstClass_Click(object sender, System.EventArgs e)
{
string strNewEnterpriseName = this.textBox1.Text.Trim();
TreeNode newNode = new TreeNode(strNewEnterpriseName);
this.treeView1.Nodes.Add(newNode);//增加为第一级别
this.treeView1.SelectedNode = newNode;
InputTextBox2AndTextBox3(newNode); //填写TextBox2和TextBox3
//为新插入的项计算各个数据,如ItemIndex,AbsIndex等
int lastRowIndex = this.tblSetOrgInfo.Rows.Count-1;
string strAbsIndex = this.tblSetOrgInfo.Rows[lastRowIndex]["AbsIndex"].ToString().Trim();
int intAbsIndex = Int32.Parse(strAbsIndex) + 1;
string strItemIndex = this.textBox2.Text.Trim();
int intItemIndex = Int32.Parse(strItemIndex);
string strEnterpriseID = this.textBox3.Text.Trim();
int intItemLevel = 0;
int intParentIndex = -1;
try
{
DataRow newRow = this.tblSetOrgInfo.NewRow();
newRow[1] = strNewEnterpriseName;
newRow[2] = intAbsIndex;
newRow[3] = intItemIndex;
newRow[4] = intItemLevel;
newRow[5] = intParentIndex;
newRow[6] = strItemIndex;
newRow[7] = strEnterpriseID;
newRow[8] = strNewEnterpriseName;
this.tblSetOrgInfo.Rows.Add(newRow);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
tblSetOrgInfo.RejectChanges();
}
SaveModify();//向数据库保存修改
}
//-----------添加同级项-------------------
private void btnNewThisClass_Click(object sender, System.EventArgs e)
{
AddRecord(true);
}
//-----------添加子项-------------------
private void btnNewChildClass_Click(object sender, System.EventArgs e)
{
AddRecord(false);
}
//-----------根据输入参数确定向树形图中添加同级项还是子项-------------------
private void AddRecord(bool blAddInThisClass)
{
string strItemLevel = "";
string strParentIndex = "";
string strFilter = "单位编号 = '" + this.textBox3.Text.Trim() + "'";
try
{
DataRow[] myRow = this.tblSetOrgInfo.Select(strFilter);//通过单位编号在数据集中查找到数据项
if (myRow.Length == 1)
{
strItemLevel = myRow[0]["ItemLevel"].ToString().Trim();
//向数据集中添加新项
if (blAddInThisClass == true)
strParentIndex = myRow[0]["ParentIndex"].ToString().Trim();
else
strParentIndex = myRow[0]["AbsIndex"].ToString().Trim();
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
//向树形图中添加新项
string strNewEnterpriseName = this.textBox1.Text.Trim();
TreeNode newNode = new TreeNode(strNewEnterpriseName);
if (blAddInThisClass == true)
{
if (this.treeView1.SelectedNode.Parent == null) //当为第一级添加子节点时
this.treeView1.Nodes.Add(newNode);
else
this.treeView1.SelectedNode.Parent.Nodes.Add(newNode);
}
else
this.treeView1.SelectedNode.Nodes.Add(newNode);
this.treeView1.SelectedNode = newNode;
InputTextBox2AndTextBox3(newNode); //填写TextBox2和TextBox3
//为新插入的项计算各个数据,如ItemIndex,AbsIndex等
int lastRowIndex = this.tblSetOrgInfo.Rows.Count-1;
string strAbsIndex = this.tblSetOrgInfo.Rows[lastRowIndex]["AbsIndex"].ToString().Trim();
int intAbsIndex = Int32.Parse(strAbsIndex) + 1;
string strItemIndex = this.textBox2.Text.Trim();
int intItemIndex = Int32.Parse(strItemIndex);
string strEnterpriseID = this.textBox3.Text.Trim();
int intItemLevel = 0;
if (blAddInThisClass == true)
intItemLevel = Int32.Parse(strItemLevel);
else
intItemLevel = Int32.Parse(strItemLevel) + 1;
int intParentIndex = Int32.Parse(strParentIndex);
try
{
DataRow newRow = this.tblSetOrgInfo.NewRow();
newRow[1] = strNewEnterpriseName;
newRow[2] = intAbsIndex;
newRow[3] = intItemIndex;
newRow[4] = intItemLevel;
newRow[5] = intParentIndex;
newRow[6] = strItemIndex;
newRow[7] = strEnterpriseID;
newRow[8] = strNewEnterpriseName;
this.tblSetOrgInfo.Rows.Add(newRow);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
tblSetOrgInfo.RejectChanges();
}
//将更改保存入数据库
SaveModify();
}
//-----------删除在树形图中选中的项目-------------------
private void btnDelete_Click(object sender, System.EventArgs e)
{
string strEnterpriseID = this.textBox3.Text.Trim();
string strFilter = "单位编号 = '" + strEnterpriseID + "'";
try
{
DataRow[] myRow = this.tblSetOrgInfo.Select(strFilter);
if (myRow.Length ==1)//找到该条记录,并从数据集中删除
{
string strFilter_ParentIndex = "ParentIndex = '" + myRow[0]["AbsIndex"].ToString().Trim() + "'";
DataRow[] myChildRows = this.tblSetOrgInfo.Select(strFilter_ParentIndex);
myRow[0].Delete();
foreach (DataRow aRow in myChildRows)//如果该项目有子项,则将子项也一并全部删除
{
aRow.Delete();
}
}
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
this.treeView1.SelectedNode.Remove();
SaveModify();//将更改保存入数据库
}
//-----------将数据集中的输入保存到数据库中-------------------
private void SaveModify()
{
try
{
this.sqlDataAdapter1.Update(this.tblSetOrgInfo);
}
catch(Exception express)
{
MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
tblSetOrgInfo.RejectChanges();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -