📄 ucstatinst.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using dist.hb.EnvQueryStat.Pub;
using System.Collections;
namespace dist.hb.EnvQueryStat.StatSet
{
public partial class ucStatInst : UserControl
{
private ArrayList MainGrouList;
private ArrayList SecondGroupList;
private clsProcAttFilter proAttFilter;
private clsProcStatItem StatItem;
public ucStatInst()
{
InitializeComponent();
MainGrouList = new ArrayList();
SecondGroupList = new ArrayList();
proAttFilter = new clsProcAttFilter();
StatItem = new clsProcStatItem();
}
private OleDbConnection m_OleDbConn;
public OleDbConnection OleDbConn
{
get { return m_OleDbConn; }
set
{
if (value == null) return;
if (value == m_OleDbConn) return;
m_OleDbConn = value;
}
}
private void splitterControl1_SplitterMoved(object sender, SplitterEventArgs e)
{
}
//以下函数填充树(处理统计分类)
//处理统计分类
System.Data.DataTable m_SCTable;
//绑定到统计分类表
private void BindSCTable()
{
DataSet ds = new DataSet();
string strSQL;
strSQL = "SELECT StatClassID,PStatClassID,StatClassName FROM FS_StatInstClass";
System.Data.OleDb.OleDbDataAdapter Adapter = new System.Data.OleDb.OleDbDataAdapter(strSQL, m_OleDbConn);
Adapter.Fill(ds, "FS_StatInstClass");
m_SCTable = ds.Tables["FS_StatInstClass"];
}
private void FillTree()
{
if (m_SCTable == null) return;
DataRow[] drs = m_SCTable.Select("PStatClassID is null");
if (drs == null) return;
FillTree(drs, null);
}
private void FillTree(DataRow[] drs, TreeNode pNode)
{
if (drs == null) return;
if (drs.Length <= 0) return;
foreach (DataRow row in drs)
{
TreeNode nd = AddNode(pNode, row["StatClassName"].ToString(), row["StatClassID"].ToString());
DataRow[] NEWdrs = m_SCTable.Select("PStatClassID =" + row["StatClassID"]);
FillTree(NEWdrs, nd);
//增加统计实例节点(being)
CreateStatInstNode(nd);
//增加统计实例节点(end)
}
}
//以下函数处理统计实例
System.Data.OleDb.OleDbDataAdapter m_StatInstDbDataAdapter;
System.Data.DataSet m_StatInstDataSet;
System.Data.DataTable m_StatInstTable;
OleDbCommandBuilder m_StatInstCB;
string m_strStatInstTbl = "FS_StatInst";
int m_nStatInstImageIndex = 6;
//统计实例绑定
private void BindStatInstTable()
{
DataSet ds = new DataSet();
string strSQL;
strSQL = "SELECT * FROM " + m_strStatInstTbl;
m_StatInstDbDataAdapter = new System.Data.OleDb.OleDbDataAdapter(strSQL, m_OleDbConn);
m_StatInstCB = new OleDbCommandBuilder(m_StatInstDbDataAdapter);
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = m_OleDbConn;
//cmd.Transaction = m_tran;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSQL;
m_StatInstDbDataAdapter.SelectCommand = cmd;
m_StatInstDbDataAdapter.Fill(ds, m_strStatInstTbl);
m_StatInstTable = ds.Tables[m_strStatInstTbl];
m_StatInstDataSet = ds;
}
private void CreateStatInstNode(TreeNode tr)
{
if (tr == null) return;
DataRow[] drs = m_StatInstTable.Select("StatClassID =" + tr.Name);
if (drs == null) return;
if (drs.Length <= 0) return;
foreach (DataRow row in drs)
{
TreeNode nd = AddNode(tr, row["StatInstName"].ToString(), row["StatInstID"].ToString());
nd.ImageIndex = m_nStatInstImageIndex;
nd.SelectedImageIndex = m_nStatInstImageIndex;
}
}
private TreeNode NewStatInst(TreeNode tn)
{
if (tn == null || tn.ImageIndex == m_nStatInstImageIndex) return null;
if (lookUpEdit1.GetColumnValue("AbstractStatID") == null)
{
MessageBox.Show("请选择统计模板", "消息");
return null;
}
DataRow row;
row = m_StatInstTable.NewRow();
int iReturn = GetMaxID();//统计实例ID;
row["StatInstID"] = iReturn;
row["AbstractStatID"] = (int)lookUpEdit1.GetColumnValue("AbstractStatID");//统计实例
row["StatClassID"] = Convert.ToInt32(tn.Name);
row["StatInstName"] = textBox_QueryInstName.Text;
row["MainGroupType"] = comboBox_GroupType.SelectedIndex;////分组类型,0为地图,1为属性
row["MainGroupItem"] = comboBox_GroupObj1.SelectedItem;//主分组对象,如果为地图,则是图层,如果为属性,则为字段
row["SecondGroupField"] = comboBox_groupObj2.SelectedItem;//次分组对象,为字段
row["AttWinVisible"] = checkBox_attVisible.Checked;
row["GroupItemVisible"] = checkBox_GroupVisible.Checked;
row["StatItemVsisible"] = checkBox_StatItemVisible.Checked;
row["IsWebStat"] = checkBoxWebStat.Checked;
m_StatInstTable.Rows.Add(row);
TreeNode newTN = AddNode(tn, textBox_QueryInstName.Text, iReturn.ToString());
newTN.ImageIndex = m_nStatInstImageIndex;
return newTN;
}
private TreeNode ModifyStatInst(TreeNode tn)
{
if (tn == null || tn.ImageIndex != m_nStatInstImageIndex) return null;
DataRow row;
//选择的就是统计模板,找不到记录集的情况不应该出现
DataRow[] drs = m_StatInstTable.Select("StatInstID=" + tn.Name);
if (drs == null || drs.Length == 0)
{
MessageBox.Show("没有找到要更新的数据!", "消息");
return null;
}
row = drs[0];
if (lookUpEdit1.GetColumnValue("AbstractStatID") == null)
{
MessageBox.Show("请选择统计模板", "消息");
return null;
}
row["StatInstID"] = Convert.ToInt32(tn.Name);//统计实例
row["AbstractStatID"] = (int)lookUpEdit1.GetColumnValue("AbstractStatID");//统计模板
row["StatClassID"] = Convert.ToInt32(tn.Parent.Name);//统计分类
row["StatInstName"] = textBox_QueryInstName.Text;
row["MainGroupType"] = comboBox_GroupType.SelectedIndex;////分组类型,0为地图,1为属性
row["MainGroupItem"] = comboBox_GroupObj1.SelectedItem;//主分组对象,如果为地图,则是图层,如果为属性,则为字段
row["SecondGroupField"] = comboBox_groupObj2.SelectedItem;//次分组对象,为字段
row["AttWinVisible"] = checkBox_attVisible.Checked;
row["GroupItemVisible"] = checkBox_GroupVisible.Checked;
row["StatItemVsisible"] = checkBox_StatItemVisible.Checked;
row["IsWebStat"] = checkBoxWebStat.Checked;
tn.Text = textBox_QueryInstName.Text;
tn.ImageIndex = m_nStatInstImageIndex;
return tn;
}
//取最大值
private int GetMaxID()
{
if (m_StatInstTable == null) return 0;
string strTemp = m_StatInstTable.Compute("MAX(StatInstID)", "").ToString();
if (strTemp == "") return 1;
else return 1 + Convert.ToInt32(strTemp);
}
//树节点操作
private TreeNode AddNode(TreeNode pNode, string strTxt, string strKey)
{
if (pNode == null)
{
TreeNode pNode1 = treeView1.Nodes.Add(strKey, strTxt);//增加根节点
return pNode1;
}
else
{
return pNode.Nodes.Add(strKey, strTxt);
}
}
//窗体初始化
private void ucStatInst_Load(object sender, EventArgs e)
{
comboBox_GroupType.SelectedIndex = 0;//分组类型
BindStatInstTable();//绑定统计实例表
BindSCTable();//绑定统计分类表
FillTree();
InitLookupData();
//实例化属性过滤对象
proAttFilter.OleDbConn = m_OleDbConn;
treeView1.ExpandAll();
StatItem.OleDbConn = m_OleDbConn;
StatItem.gridView2 = gridView2;
StatItem.procAttFilter = proAttFilter;
StatItem.repositoryItemComboBox_statField = repositoryItemComboBox_statField;
//StatItem.LoadStatItemTable();
}
private void btnNew_Click(object sender, EventArgs e)
{
textBox_QueryInstName.Text = "";
}
private void btnSave_Click(object sender, EventArgs e)
{
if (textBox_QueryInstName.Text == "")
{
MessageBox.Show("统计实例名称不能为空!");
return;
}
TreeNode tn = treeView1.SelectedNode;
if (tn == null)
{
MessageBox.Show("请选择统计类别!");
return;
}
gridControl1.EmbeddedNavigator.Buttons.EndEdit.DoClick();
gridControl2.EmbeddedNavigator.Buttons.EndEdit.DoClick();
//如果选择的是分类节点,则增加;如果选择的统计节点,则修改。
if (tn.ImageIndex != m_nStatInstImageIndex) tn = NewStatInst(tn);
else tn = ModifyStatInst(tn);
if (tn == null) return;
tn.SelectedImageIndex = m_nStatInstImageIndex;
tn.ImageIndex = m_nStatInstImageIndex;
try
{
m_StatInstDbDataAdapter.Update(m_StatInstDataSet, m_strStatInstTbl);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
return;
}
//要考虑删除的顺序
proAttFilter.StatInstID = Convert.ToInt32(tn.Name);//保存统计实例的ID
StatItem.DeleteStatItemTable();//删除统计项目
clsProcGroupItem proGroupItem = new clsProcGroupItem();
proGroupItem.OleDbConn = m_OleDbConn;
proGroupItem.m_nStatInstID = Convert.ToInt32(tn.Name);//统计实例ID
proGroupItem.MainGroupContent = listBox_GroupItem1;
proGroupItem.SecondGroupContent = listBox_GroupItem2;
proGroupItem.DeleteGroupContent();//删除分组内容
proAttFilter.SaveAttFilterTable(Convert.ToInt32(tn.Name));//保存属性过滤表
proGroupItem.SaveGroupContent();//保存分组目录
StatItem.SaveStatItemTable(); //保存统计项目
}
private void btnDelete_Click(object sender, EventArgs e)
{
TreeNode tn = treeView1.SelectedNode;
if (tn == null || tn.ImageIndex != m_nStatInstImageIndex)
{
return;
}
//选择的就是统计模板,找不到记录集的情况不应该出现
DataRow[] drs = m_StatInstTable.Select("StatInstID=" + tn.Name);
if (drs == null || drs.Length == 0)
{
MessageBox.Show("没有找到要删除的数据!", "消息");
return;
}
proAttFilter.StatInstID = Convert.ToInt32(tn.Name);//保存统计实例的ID
//删除树节点
tn.Remove();
drs[0].Delete();
try
{
gridControl1.DataSource = null;
textBox_QueryInstName.Text = "";
listBox_GroupItem1.Items.Clear();
listBox_GroupItem2.Items.Clear();
proAttFilter.DeleteAttFilterTable(Convert.ToInt32(tn.Name));//先删除子表,属性过滤表
if (StatItem != null)
{
StatItem.DeleteStatItemTable();//先删除子表,统计项目
StatItem.LoadStatItemTable();
}
m_StatInstDbDataAdapter.Update(m_StatInstDataSet, m_strStatInstTbl);
proAttFilter.LoadAttFilterTable();
lookUpEdit1_EditValueChanged(null, null);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
}
}
private void lookUpEdit1_Properties_EditValueChanged(object sender, EventArgs e)
{
}
//初始化统计模板
private void InitLookupData()
{
DataSet ds = new DataSet();
System.Data.OleDb.OleDbDataAdapter dbAdapter = new System.Data.OleDb.OleDbDataAdapter(
"SELECT StatName,AbstractStatID FROM FS_AbstractStat", m_OleDbConn);
dbAdapter.Fill(ds, "FS_AbstractStat");
DataViewManager dvm = new DataViewManager(ds);
DataView dvLookup;
dvLookup = dvm.CreateDataView(ds.Tables["FS_AbstractStat"]);
// <lookUpEdit1>
//lookUpEdit1.DataBindings.Add("EditValue", dvLookup, "VTID");
lookUpEdit1.Properties.DataSource = dvLookup;
lookUpEdit1.Properties.DisplayMember = "StatName";
lookUpEdit1.Properties.ValueMember = "AbstractStatID";
// </lookUpEdit1>
}
//加载一个统计时的事件
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode tn = e.Node;
if (tn == null || tn.ImageIndex != m_nStatInstImageIndex) return;
DataRow row;
DataRow[] drs = m_StatInstTable.Select("StatInstID=" + tn.Name);
if (drs == null || drs.Length == 0) return;
row = drs[0];
lookUpEdit1.EditValue = Convert.ToInt32(row["AbstractStatID"]);
textBox_QueryInstName.Text = row["StatInstName"].ToString();
object obj;
obj = row["AttWinVisible"];
if (obj.ToString() == "") checkBox_attVisible.Checked = false;
else checkBox_attVisible.Checked = Convert.ToBoolean(obj);
obj = row["GroupItemVisible"];
if (obj.ToString() == "") checkBox_GroupVisible.Checked = false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -