📄 operatedtset.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
using System.Collections;
namespace bizdb
{
/// <summary>
/// OperateDtset 的摘要说明。
/// </summary>
public class OperateDtset
{
private Dataset_xyxk dtSet = new Dataset_xyxk(); ///实例化私有的DataSet对象
private dbAccess operSql = new dbAccess(); ///实例化私有的dbAccess类对象
public OperateDtset()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public void addDateToDtSet( string sqlWords, string tabName, string firCol, string senCol )
{ ///+1次重载的方法,接收四个参数, 调用dataRead的方法,将数据按引用填入DataSet
operSql.dtRead( ref dtSet, sqlWords, tabName, firCol, senCol );
}
public void sheTable( ComboBox cbo, string tabName, string tabCol ) ///+1次重载的方法,接收三个参数,
{ ///将ComboBox与DataSet关连起来,并将数据填入ComboBox
foreach( DataRow dr in dtSet.Tables[tabName].Rows )
cbo.Items.Add(dr[tabCol].ToString() );
}
public void addDateToDtSet( string sqlWords, string tabName, string firCol, string senCol, string thrCol )
{ ///+2次重载的方法,接收五个参数,调用dataRead的方法,将数据按引用填入DataSet
operSql.dtRead( ref dtSet, sqlWords, tabName, firCol, senCol, thrCol );
}
public void sheTable( ComboBox cbo, string tabName, string tabCol, string selCol, int tabSubNo )
{ ///+2重载的方法。以与当前cbo中显示的字段相对应的No字段为条件,查找另一张表中所需的字段,并将其值赋给另一个cbo
for ( int i = 0; i < dtSet.Tables[tabName].Rows.Count; i++)
{
if ( Int32.Parse(dtSet.Tables[tabName].Rows[i][selCol].ToString()) == tabSubNo )
cbo.Items.Add( dtSet.Tables[tabName].Rows[i][tabCol].ToString());
}
}
public int selCol( ComboBox cbo, string tabName, string tabCol )
{ ///+1次重载,用cbo的index为条件,查找与当前ComboBox所显示的字段相对应的No字段,以便作为进一步查询的条件
int selNo = Int32.Parse( dtSet.Tables[tabName].Rows[cbo.SelectedIndex][tabCol].ToString() );
return selNo;
}
public int selCol( ComboBox cbo, string tabName, string tabCol, string selCol )
{ ///+2次重载,用cbo的当前显示列为条件,查找与当前ComboBox所显示的字段相对应的No字段,以便作为进一步查询的条件
string cboItemCol = cbo.SelectedItem.ToString();
int selNo = 0;
for ( int tabRows = 0; tabRows < dtSet.Tables[tabName].Rows.Count; tabRows++)
{
if ( dtSet.Tables[tabName].Rows[tabRows][selCol].ToString() == cboItemCol )
{
selNo = Int32.Parse( dtSet.Tables[tabName].Rows[tabRows][tabCol].ToString() );
break;
}
}
return selNo;
}
public ArrayList addAry( string tabName, string tabCol, string selCol, int selNo )
{ ///以上面的方法中得到的tabNo作为条件,将满足该条件的值存入数组中
ArrayList ary = new ArrayList();
for ( int rows = 0; rows < dtSet.Tables[tabName].Rows.Count; rows++)
{
if ( Int32.Parse( dtSet.Tables[tabName].Rows[rows][tabCol].ToString() ) == selNo )
ary.Add( Int32.Parse( dtSet.Tables[tabName].Rows[rows][selCol].ToString()) );
}
return ary;
}
public void addList( ListBox lst, ListBox yxkLst, string tabName, string tabCol, string selCol )
{ ///将没有与"添加课程"列表框中重复的课程显示在课程名称列表框中。需满足表的No字段和数组匹配、
foreach ( int array in Form_xyxk.aryList ) ///且该行的Name字段未出现在"添加课程"列表框中。
{
for ( int tabCount = 0; tabCount < dtSet.Tables[tabName].Rows.Count; tabCount++ )
{
if ( Int32.Parse( dtSet.Tables[tabName].Rows[tabCount][tabCol].ToString() ) == array
&& yxkLst.FindStringExact( dtSet.Tables[tabName].Rows[tabCount][selCol].ToString() ).ToString() == "-1" )
{
lst.Items.Add( dtSet.Tables[tabName].Rows[tabCount][selCol].ToString() );
break;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -