该类对上连接webservice的代理类,对下生成操作逻辑和数据库的连接和操作。界面设计时可直接用ObjectDataSource来连接操作就可以,增加可控性。便于程序的分层设计。
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web; //要在类中引入
using System.Configuration; //要在类中引入
using ServiceProxy;
namespace WorkOA
{
public class FJ
{
string _Url;
string _KEY_B;
DataTable _dt;
public string Message;
public FJ()
{
if (HttpContext.Current.Session["S_FJ_Table"] == null)
{
_dt = new DataTable();
_dt.Columns.Add(new DataColumn("FJ_ID", typeof(Int32)));
_dt.Columns["FJ_ID"].AutoIncrement = true;
_dt.Columns["FJ_ID"].AutoIncrementSeed = 1;
_dt.Columns["FJ_ID"].AutoIncrementStep = 1; //加入自增字段帮助检索
_dt.PrimaryKey = new DataColumn[] { _dt.Columns["FJ_ID"] };
_dt.Columns.Add(new DataColumn("FJ_MNo", typeof(string)));
_dt.Columns.Add(new DataColumn("FJ_MKinfoID", typeof(int)));
_dt.Columns.Add(new DataColumn("FJ_ML", typeof(string)));
_dt.Columns.Add(new DataColumn("FJ_FileName", typeof(string)));
_dt.Columns.Add(new DataColumn("FJ_FileType", typeof(string)));
_dt.Columns.Add(new DataColumn("FJ_OldName", typeof(string)));
HttpContext.Current.Session["S_FJ_Table"] = _dt;
}
else
_dt = (DataTable)HttpContext.Current.Session["S_FJ_Table"];
_Url = System.Configuration.ConfigurationManager.AppSettings["myhost.Service"];
_KEY_B = System.Configuration.ConfigurationManager.AppSettings["KEY_B"];
}
public DataTable DT
{
get
{
return _dt;
}
set
{
_dt = value;
}
}
public void Clean_FJ_Table()
{
if (HttpContext.Current.Session["S_FJ_Table"] != null)
{
HttpContext.Current.Session["S_FJ_Table"] = null;
}
}
public DataTable Get_FJ_Table()
{
//DT = (DataTable)HttpContext.Current.Session["S_FJ_Table"];
return _dt;
}
public void Add_FJ_Table(string FJ_MNo, int FJ_MKinfoID, string FJ_ML, string FJ_FileName, string FJ_FileType, string FJ_OldName)
{
DataRow dr = _dt.NewRow();
dr["FJ_MNo"] = FJ_MNo;
dr["FJ_MKinfoID"] = FJ_MKinfoID;
dr["FJ_ML"] = FJ_ML;
dr["FJ_FileName"] = FJ_FileName;
dr["FJ_FileType"] = FJ_FileType;
dr["FJ_OldName"] = FJ_OldName;
_dt.Rows.Add(dr);
HttpContext.Current.Session["S_FJ_Table"] = _dt; //为什么不返回也可以保存数据?为什么自动更新Session变量了呢?
}
public void Del_FJ_Table(int FJ_ID)
{
DataView dv = new DataView(_dt);
dv.Sort = "FJ_ID";
int i;
i = dv.Find(FJ_ID);
if (i >= 0)
{
dv.Delete(i);
}
dv.Sort = null;
HttpContext.Current.Session["S_FJ_Table"] = _dt;
}
public void UP_FJ_Table(int FJ_ID, string FJ_MNo, int FJ_MKinfoID, string FJ_ML, string FJ_FileName, string FJ_FileType, string FJ_OldName)
{
DataView dv = new DataView(_dt);
dv.Sort = "FJ_ID";
int i;
i = dv.Find(FJ_ID);
if (i >= 0)
{
dv[i][1] = FJ_MNo;
dv[i][2] = FJ_MKinfoID;
dv[i]["FJ_ML"] = FJ_ML;
dv[i]["FJ_FileName"] = FJ_FileName;
dv[i]["FJ_FileType"] = FJ_FileType;
dv[i]["FJ_OldName"] = FJ_OldName;
}
dv.Sort = null;
HttpContext.Current.Session["S_FJ_Table"] = _dt;
}
public DataTable Get_FJ(string FJ_MNo, int FJ_MKinfoID)
{
DataTable PTable=new DataTable();
PTable.Columns.Add(new DataColumn("FJ_MNo", typeof(string)));
PTable.Columns.Add(new DataColumn("FJ_MKinfoID", typeof(int)));
DataRow dr = PTable.NewRow();
dr["FJ_MNo"]=FJ_MNo;
dr["FJ_MKinfoID"]=FJ_MKinfoID;
PTable.Rows.Add(dr);
PTable.TableName = "P_SYS_FJ_Get";
DataSet ds=new DataSet();
ds.Tables.Add(PTable);
ServiceProxy.Service myser = new ServiceProxy.Service(_Url);
return myser.ExeOperate(ds, "SYS_FJ_Get", _KEY_B).Tables["O_SYS_FJ_Get"];
}
public bool Del_FJ(int FJ_ID)
{
DataTable PTable = new DataTable();
PTable.Columns.Add(new DataColumn("FJ_ID", typeof(int)));
DataRow dr = PTable.NewRow();
dr["FJ_ID"] = FJ_ID;
PTable.Rows.Add(dr);
PTable.TableName = "P_SYS_FJ_Del";
DataSet ds = new DataSet();
ds.Tables.Add(PTable);
ServiceProxy.Service myser = new ServiceProxy.Service(_Url);
ds = myser.ExeOperate(ds, "SYS_FJ_Del", _KEY_B);
return Convert.ToBoolean( ds.Tables[0].DefaultView[0][0]);
}
public bool Add_FJ()
{
DataSet ds = new DataSet();
_dt.TableName = "P_SYS_FJ_UP"; //要注意,不要忘了
ds.Tables.Add(_dt);
string m = _dt.DefaultView[0][1].ToString();
ServiceProxy.Service myser = new ServiceProxy.Service(_Url);
ds = myser.ExeOperate(ds, "SYS_FJ_UP", _KEY_B);
Message = ds.Tables[0].DefaultView[0][1].ToString();
return Convert.ToBoolean(ds.Tables[0].DefaultView[0][0]);
}
}
}