//TownsUnit,乡镇级辖属单位信息
//获取数据表记录信息
public DataTable TownsUnit_Select_By_Condition(string SearchTxt)
{
SqlDataAdapter myAdapter = new SqlDataAdapter("SELECT BaseInfo_TownsUnit.Id, BaseInfo_TownsUnit.TownCode, BaseInfo_TownsUnit.UnitCode, BaseInfo_TownsUnit.UnitName, BaseInfo_TownsUnit.ParentUnitCode, BaseInfo_TownsUnit_1.UnitName AS parunitname, BaseInfo_Towns.TownsName FROM BaseInfo_TownsUnit INNER JOIN BaseInfo_Towns ON BaseInfo_TownsUnit.TownCode = BaseInfo_Towns.TownsCode LEFT OUTER JOIN BaseInfo_TownsUnit AS BaseInfo_TownsUnit_1 ON BaseInfo_TownsUnit.ParentUnitCode = BaseInfo_TownsUnit_1.UnitCode WHERE " + SearchTxt + " ORDER BY [BaseInfo_TownsUnit].[TownCode],[BaseInfo_TownsUnit].[UnitName]", mycon);
DataSet mySet = new DataSet();
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try
{ myAdapter.Fill(mySet, "SchoolTab"); }
catch
{ mycon.Close(); }
return mySet.Tables["SchoolTab"];//返回表数据
}
//获取单条信息记录
public DataTable TownsUnit_Select_One_ById(int id)
{
//定义数据适配器
SqlDataAdapter myAdapter = new SqlDataAdapter("SELECT * FROM [BaseInfo_TownsUnit] WHERE [id]=" + id.ToString(), mycon);
DataSet mySet = new DataSet();
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try { myAdapter.Fill(mySet, "SchoolTab"); }
catch { mycon.Close(); }
return mySet.Tables["SchoolTab"];//返回表数据
}
//获取单条信息记录
public DataTable TownsUnit_Select_One_ByUnitCode(String UnitCode)
{
//定义数据适配器
SqlDataAdapter myAdapter = new SqlDataAdapter("SELECT * FROM [BaseInfo_TownsUnit] WHERE [UnitCode]='" + UnitCode + "'", mycon);
DataSet mySet = new DataSet();
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try { myAdapter.Fill(mySet, "SchoolTab"); }
catch { mycon.Close(); }
return mySet.Tables["SchoolTab"];//返回表数据
}
//获取指定单位下的子单位
public DataTable TownsUnit_Get_Childs(String UnitCode, Boolean IncludeSelf = true)
{
String sql = "select * from Build_TownsUnit where ParentUnitCode='" + UnitCode + "'" + (IncludeSelf ? " or UnitCode='" + UnitCode + "'" : "");
DataTable myTable = new DataTable();
try
{
SqlDataAdapter myAdapter = new SqlDataAdapter(sql, mycon);
myAdapter.Fill(myTable);
return myTable;//返回表数据
}
catch (Exception ex)
{
mycon.Close();
return null;
}
}
public DataTable TownsUnit_Get_Parent(String UnitCode)
{
String sql = "select * from Build_TownsUnit where UnitCode=(select ParentUnitCode from Build_TownsUnit where UnitCode='"+UnitCode+"')";
DataTable myTable = new DataTable();
try
{
SqlDataAdapter myAdapter = new SqlDataAdapter(sql, mycon);
myAdapter.Fill(myTable);
return myTable;//返回表数据
}
catch (Exception ex)
{
mycon.Close();
return null;
}
}
///条件统计记录
public int TownsUnit_Count_By_Condition(string conditionTxt)
{
//定义数据适配器
SqlCommand myCmd = new SqlCommand("SELECT COUNT([id]) FROM [BaseInfo_TownsUnit] WHERE " + conditionTxt, mycon);
int RecCount = 0;
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try
{ RecCount = (int)myCmd.ExecuteScalar(); }
catch
{ mycon.Close(); }
return RecCount;//返回统计值
}
//条件删除记录
public bool TownsUnit_Delete_By_Condition(string conditionTxt)
{
//定义数据适配器
SqlCommand myCmd = new SqlCommand("DELETE FROM [BaseInfo_TownsUnit] WHERE " + conditionTxt, mycon);
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try
{ myCmd.ExecuteNonQuery(); }
catch
{ mycon.Close(); return false; }
return true;//返回值
}
//添加记录
public bool TownsUnit_Insert_By_params(string TownCode, string UnitCode, string UnitName, String ParentUnitCode)
{
//定义数据适配器
SqlCommand myCmd = new SqlCommand("INSERT INTO [BaseInfo_TownsUnit] ([TownCode],[UnitCode],[UnitName],[ParentUnitCode]) VALUES ('" + TownCode + "','" + UnitCode + "','" +
UnitName + "','" + ParentUnitCode + "')", mycon);
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try
{ myCmd.ExecuteNonQuery(); }
catch
{ mycon.Close(); return false; }
return true;//返回值
}
//更新记录
public bool TownsUnit_Update_By_params(string TownCode, string UnitCode, string UnitName, String ParentUnitCode ,int id)
{
//定义数据适配器
SqlCommand myCmd = new SqlCommand("UPDATE [BaseInfo_TownsUnit] SET [TownCode]='" + TownCode + "',[UnitCode]='" + UnitCode + "',[UnitName]='" + UnitName + "',[ParentUnitCode]='"
+ ParentUnitCode + "' WHERE [id]=" + id.ToString(), mycon);
//打开数据连接
if (mycon.State == ConnectionState.Closed) { mycon.Open(); }
try
{ myCmd.ExecuteNonQuery(); }
catch
{ mycon.Close(); return false; }
return true;//返回值
}
//*=================================================================================================================================================================