📄 designreportconfiginfo.cs
字号:
using System;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Windows.Forms;
namespace TreeReportApp
{
/// <summary>
/// TreeReportConfigInfo 的摘要说明。
/// </summary>
public class TreeReportConfigInfo
{
public string connstr;
private System.Data.OleDb.OleDbDataAdapter configadapter;
private System.Data.DataSet configinfoset;
public System.Data.DataTable configdata;
//通过判断reportid有没有设置,而知道实例是否已初始化
private string reportid;
public TreeReportConfigInfo()
{
reportid = "";
configadapter = new System.Data.OleDb.OleDbDataAdapter();
configinfoset = new DataSet();
configdata = null;
//连接据库,这段程序用一个公共连接类代替
connstr = TreeConnection.connstr;//"Provider=SQLOLEDB.1;Password=20020830; Persist Security Info=True;User ID=liao;Initial Catalog=TreeDb;Data Source=LIAOHOME\\LIAOSQLSVR";
}
/// <summary>
/// setReportId --初始化,从数据表中载入配置数据
/// </summary>
public bool setReportId( string rptid)
{
reportid = rptid;
if (reportid.Length==0)
return false;
if (!loadReportConfigInfo())
{
reportid = "";
return false;
}
return true;
}
/// <summary>
/// getReportId --获取报表ID
/// </summary>
public string getReportId()
{
return reportid;
}
/// <summary>
/// loadReportConfigInfo---初始化,从数据表中载入配置数据
/// </summary>
public bool loadReportConfigInfo()
{
System.Data.OleDb.OleDbCommand cmd;
System.Data.OleDb.OleDbParameter param;
bool resultval = true;
//连接数据库
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connstr);
conn.Open();
try
{
cmd = new OleDbCommand("select * from Reportsconfigurable where ReportID='" + reportid + "'",conn);
configadapter.SelectCommand = cmd;
//SqlClient的语句
//cmd = new OleDbCommand("INSERT INTO Reportsconfigurable(ReportID, ControlID,DisplaySelectable,DisplayDefaultVal,DataFieldSelectable,FormatSelectable,StyleSelectable,ColorSelctable,IsMultilanguish,ELabelCaption,CLabelCaption,HLabelCaption,CaptionConfigurable) " +
// "VALUES('" + reportid + "', @ControlID,@DisplaySelectable,@DisplayDefaultVal,@DataFieldSelectable,@FormatSelectable,@StyleSelectable,@ColorSelctable,@IsMultilanguish,@ELabelCaption,@CLabelCaption,@HLabelCaption,@CaptionConfigurable)", conn);
//OleDb的语句
cmd = new OleDbCommand("INSERT INTO Reportsconfigurable(ReportID, ControlID,DisplaySelectable,DisplayDefaultVal,DataFieldSelectable,FormatSelectable,StyleSelectable,ColorSelctable,IsMultilanguish,ELabelCaption,CLabelCaption,HLabelCaption,CaptionConfigurable,EName,CName,Hname) " +
"VALUES('" + reportid + "', ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", conn);
cmd.Parameters.Add("@ControlID",OleDbType.VarChar,100,"ControlID");
cmd.Parameters.Add("@DisplaySelectable",OleDbType.Char,1,"DisplaySelectable");
cmd.Parameters.Add("@DisplayDefaultVal",OleDbType.Char,1,"DisplayDefaultVal");
cmd.Parameters.Add("@DataFieldSelectable",OleDbType.Char,1,"DataFieldSelectable");
cmd.Parameters.Add("@FormatSelectable",OleDbType.Char,1,"FormatSelectable");
cmd.Parameters.Add("@StyleSelectable",OleDbType.Char,1,"StyleSelectable");
cmd.Parameters.Add("@ColorSelctable",OleDbType.Char,1,"ColorSelctable");
cmd.Parameters.Add("@IsMultilanguish",OleDbType.Char,1,"IsMultilanguish");
cmd.Parameters.Add("@ELabelCaption",OleDbType.VarChar,512,"ELabelCaption");
cmd.Parameters.Add("@CLabelCaption",OleDbType.VarChar,512,"CLabelCaption");
cmd.Parameters.Add("@HLabelCaption",OleDbType.VarChar,512,"HLabelCaption");
cmd.Parameters.Add("@CaptionConfigurable",OleDbType.Char,1,"CaptionConfigurable");
cmd.Parameters.Add("@EName",OleDbType.VarChar,50,"EName");
cmd.Parameters.Add("@CName",OleDbType.VarChar,50,"CName");
cmd.Parameters.Add("@HName",OleDbType.VarChar,50,"HName");
configadapter.InsertCommand = cmd;
//SqlClient的语句
//cmd = new OleDbCommand("UPDATE Reportsconfigurable " +
// "SET ControlID=@ControlID1,DisplaySelectable=@DisplaySelectable,DisplayDefaultVal=@DisplayDefaultVal,DataFieldSelectable=@DataFieldSelectable,FormatSelectable=@FormatSelectable,StyleSelectable=@StyleSelectable,ColorSelctable=@ColorSelctable,IsMultilanguish=@IsMultilanguish,ELabelCaption=@ELabelCaption,CLabelCaption=@CLabelCaption,HLabelCaption=@HLabelCaption,CaptionConfigurable=@CaptionConfigurable " +
// "WHERE ReportID='" + reportid +"' and ControlID=@oldControlID",conn);
//OleDb的语句
cmd = new OleDbCommand("UPDATE Reportsconfigurable " +
"SET ControlID=?,DisplaySelectable=?,DisplayDefaultVal=?,DataFieldSelectable=?,FormatSelectable=?,StyleSelectable=?,ColorSelctable=?,IsMultilanguish=?,ELabelCaption=?,CLabelCaption=?,HLabelCaption=?,CaptionConfigurable=?,EName=?,CName=?,HName=? " +
"WHERE ReportID='" + reportid +"' and ControlID=?",conn);
param = cmd.Parameters.Add("@ControlID",OleDbType.VarChar,100,"ControlID");
param.SourceVersion = DataRowVersion.Current;
cmd.Parameters.Add("@DisplaySelectable",OleDbType.Char,1,"DisplaySelectable");
cmd.Parameters.Add("@DisplayDefaultVal",OleDbType.Char,1,"DisplayDefaultVal");
cmd.Parameters.Add("@DataFieldSelectable",OleDbType.Char,1,"DataFieldSelectable");
cmd.Parameters.Add("@FormatSelectable",OleDbType.Char,1,"FormatSelectable");
cmd.Parameters.Add("@StyleSelectable",OleDbType.Char,1,"StyleSelectable");
cmd.Parameters.Add("@ColorSelctable",OleDbType.Char,1,"ColorSelctable");
cmd.Parameters.Add("@IsMultilanguish",OleDbType.Char,1,"IsMultilanguish");
cmd.Parameters.Add("@ELabelCaption",OleDbType.VarChar,512,"ELabelCaption");
cmd.Parameters.Add("@CLabelCaption",OleDbType.VarChar,512,"CLabelCaption");
cmd.Parameters.Add("@HLabelCaption",OleDbType.VarChar,512,"HLabelCaption");
cmd.Parameters.Add("@CaptionConfigurable",OleDbType.Char,1,"CaptionConfigurable");
cmd.Parameters.Add("@EName",OleDbType.VarChar,50,"EName");
cmd.Parameters.Add("@CName",OleDbType.VarChar,50,"CName");
cmd.Parameters.Add("@HName",OleDbType.VarChar,50,"HName");
param = cmd.Parameters.Add("@oldControlID",OleDbType.VarChar,100,"ControlID");
param.SourceVersion = DataRowVersion.Original;
configadapter.UpdateCommand = cmd;
//SqlClient的语句
//cmd = new OleDbCommand("DELETE FROM Reportsconfigurable WHERE ReportID='" + reportid +"' and ControlID=@oldControlID",conn);
//OleDb的语句
cmd = new OleDbCommand("DELETE FROM Reportsconfigurable WHERE ReportID='" + reportid +"' and ControlID=?",conn);
param = cmd.Parameters.Add("@oldControlID",OleDbType.VarChar,100,"ControlID");
param.SourceVersion = DataRowVersion.Original;
configadapter.DeleteCommand = cmd;
configinfoset.Tables.Clear();
configadapter.Fill(configinfoset);
configdata = configinfoset.Tables[0];
}
catch
{ resultval = false;}
conn.Close();
return resultval;
}
/// <summary>
/// writeReportConfigInfo---把配置数据写入数据表中
/// </summary>
public bool writeReportConfigInfo()
{
Debug.Assert(configdata!=null, "还没在初始化!");
if(reportid.Length == 0)
return false;
bool resultval = true;
//连接数据库
//System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(connstr);
//conn.Open();
//configadapter.DeleteCommand.Connection = conn;
//configadapter.InsertCommand.Connection = conn;
//configadapter.UpdateCommand.Connection = conn;
//configadapter.SelectCommand.Connection = conn;
try
{
configadapter.Update(configdata);
}
catch //(Exception e)
{
resultval = false;
//MessageBox.Show("出错:" + e.Message.ToString()+e.ToString());
}
//conn.Close();
return resultval;
}
/// <summary>
/// loadReportConfigInfoFromRcx ---从rcx文件中载入可配置数据
/// </summary>
public bool loadReportConfigInfoFromRcx(string ConfigInfofile)
{
string pathstr = ConfigInfofile;
if (!pathstr.ToUpper().EndsWith(".RCX"))
{
int n = pathstr.LastIndexOf(".");
if (n>=0)
pathstr = pathstr.Substring(0,n) + ".rcx";
else
pathstr = pathstr + ".rcx";
}
try
{
//从文件载入
System.Data.DataSet ds = new DataSet();
ds.ReadXml(pathstr);
//清除原数据,把载入的记录加入 可配置数据集中
configdata.Rows.Clear();
configdata.BeginLoadData();
DataRow[] rows = ds.Tables[0].Select("ReportID='" + reportid + "'");
configdata.LoadDataRow(rows,false);
configdata.EndLoadData();
ds.Dispose();
return true;
}
catch
{
//MessageBox.Show("出错:" + e.Message.ToString());
}
return false;
}
/// <summary>
/// writeReportConfigInfoToRcx---把可配置数据写到rcx文件
/// </summary>
public bool writeReportConfigInfoToRcx(string ConfigInfofile)
{
if (reportid.Length==0)
return false;
string pathstr = ConfigInfofile;
if (!pathstr.ToUpper().EndsWith(".RCX"))
{
int n = pathstr.LastIndexOf(".");
if (n>=0)
pathstr = pathstr.Substring(0,n) + ".rcx";
else
pathstr = pathstr + ".rcx";
}
try
{
configinfoset.WriteXml(pathstr);
return true;
}
catch
{
//MessageBox.Show("出错:" + e.Message.ToString());
}
return false;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -