📄 designreportselectdlg.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
using System.Globalization;
namespace TreeReportApp
{
/// <summary>
/// TreeReportSelectDlg 的摘要说明。
/// </summary>
public class TreeReportSelectDlg : System.Windows.Forms.Form
{
private System.Windows.Forms.TreeView treeView_catalog;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Button button_new;
private System.Windows.Forms.Button button_open;
private System.Windows.Forms.Button button2;
private System.Data.OleDb.OleDbConnection conn;
private System.Windows.Forms.ImageList imageList_treelist;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button button_cacel;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.ListView listView_report;
private TreeReportDesignFrm m_Parent = null;
public TreeReportDesignFrm ParentFormHolder
{
get
{
return this.m_Parent;
}
set
{
this.m_Parent = value;
}
}
public TreeReportSelectDlg()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
if (!System.IO.Directory.Exists("reportlayout\\"))
System.IO.Directory.CreateDirectory("reportlayout\\");
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TreeReportSelectDlg));
this.treeView_catalog = new System.Windows.Forms.TreeView();
this.imageList_treelist = new System.Windows.Forms.ImageList(this.components);
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel1 = new System.Windows.Forms.Panel();
this.button_new = new System.Windows.Forms.Button();
this.button_open = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button_cacel = new System.Windows.Forms.Button();
this.conn = new System.Data.OleDb.OleDbConnection();
this.panel2 = new System.Windows.Forms.Panel();
this.listView_report = new System.Windows.Forms.ListView();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// treeView_catalog
//
this.treeView_catalog.Dock = System.Windows.Forms.DockStyle.Left;
this.treeView_catalog.ImageList = this.imageList_treelist;
this.treeView_catalog.Location = new System.Drawing.Point(0, 0);
this.treeView_catalog.Name = "treeView_catalog";
this.treeView_catalog.Size = new System.Drawing.Size(144, 389);
this.treeView_catalog.TabIndex = 0;
this.treeView_catalog.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView_catalog_AfterSelect);
//
// imageList_treelist
//
this.imageList_treelist.ImageSize = new System.Drawing.Size(16, 16);
this.imageList_treelist.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList_treelist.ImageStream")));
this.imageList_treelist.TransparentColor = System.Drawing.Color.Transparent;
//
// splitter1
//
this.splitter1.Location = new System.Drawing.Point(144, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(3, 389);
this.splitter1.TabIndex = 1;
this.splitter1.TabStop = false;
//
// panel1
//
this.panel1.AllowDrop = true;
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
this.panel1.Controls.Add(this.button_new);
this.panel1.Controls.Add(this.button_open);
this.panel1.Controls.Add(this.button2);
this.panel1.Controls.Add(this.button_cacel);
this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
this.panel1.Location = new System.Drawing.Point(504, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(96, 389);
this.panel1.TabIndex = 3;
//
// button_new
//
this.button_new.Location = new System.Drawing.Point(15, 41);
this.button_new.Name = "button_new";
this.button_new.Size = new System.Drawing.Size(72, 31);
this.button_new.TabIndex = 0;
this.button_new.Text = "新 建";
this.button_new.Click += new System.EventHandler(this.button_new_Click);
//
// button_open
//
this.button_open.Location = new System.Drawing.Point(16, 104);
this.button_open.Name = "button_open";
this.button_open.Size = new System.Drawing.Size(72, 31);
this.button_open.TabIndex = 0;
this.button_open.Text = "文 件";
this.button_open.Click += new System.EventHandler(this.button_open_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(16, 344);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 31);
this.button2.TabIndex = 0;
this.button2.Text = "帮 助";
//
// button_cacel
//
this.button_cacel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button_cacel.Location = new System.Drawing.Point(16, 184);
this.button_cacel.Name = "button_cacel";
this.button_cacel.Size = new System.Drawing.Size(72, 31);
this.button_cacel.TabIndex = 0;
this.button_cacel.Text = "取 消";
this.button_cacel.Click += new System.EventHandler(this.button_cacel_Click);
//
// panel2
//
this.panel2.Controls.Add(this.listView_report);
this.panel2.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel2.Location = new System.Drawing.Point(147, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(357, 389);
this.panel2.TabIndex = 4;
//
// listView_report
//
this.listView_report.Alignment = System.Windows.Forms.ListViewAlignment.Default;
this.listView_report.AllowColumnReorder = true;
this.listView_report.AllowDrop = true;
this.listView_report.Dock = System.Windows.Forms.DockStyle.Fill;
this.listView_report.HideSelection = false;
this.listView_report.Location = new System.Drawing.Point(0, 0);
this.listView_report.MultiSelect = false;
this.listView_report.Name = "listView_report";
this.listView_report.Size = new System.Drawing.Size(357, 389);
this.listView_report.SmallImageList = this.imageList_treelist;
this.listView_report.TabIndex = 3;
this.listView_report.View = System.Windows.Forms.View.Details;
this.listView_report.DoubleClick += new System.EventHandler(this.listView_report_DoubleClick);
//
// TreeReportSelectDlg
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(600, 389);
this.ControlBox = false;
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.treeView_catalog);
this.MaximumSize = new System.Drawing.Size(608, 416);
this.MinimumSize = new System.Drawing.Size(608, 416);
this.Name = "TreeReportSelectDlg";
this.Text = "TreeReportSelectDlg";
this.Load += new System.EventHandler(this.TreeReportSelectDlg_Load);
this.DoubleClick += new System.EventHandler(this.listView_report_DoubleClick);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void TreeReportSelectDlg_Load(object sender, System.EventArgs e)
{
//连接据库,这段程序用一个公共连接类代替
conn.ConnectionString = TreeConnection.connstr;
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
TreeNode rootnode = new TreeNode( "最近打开的报表",0,0);
treeView_catalog.Nodes.Add( rootnode );
System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select distinct ManageCategory from ReportsManage ",conn);
System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();
while(rd.Read())
{
TreeNode newnode = new TreeNode(rd.GetString(0),1,1);
newnode.Tag = rd.GetString(0);
treeView_catalog.Nodes.Add(newnode);
}
rd.Close();
conn.Close();
treeView_catalog.ExpandAll();
listView_report.Columns.Add("报表名称",120,HorizontalAlignment.Left);
listView_report.Columns.Add("描述",300,HorizontalAlignment.Left);
listView_report.View = View.Details;
treeView_catalog.SelectedNode = treeView_catalog.Nodes[0];
LoadRecentReports();
}
private void treeView_catalog_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
listView_report.Items.Clear();
if (treeView_catalog.SelectedNode == treeView_catalog.Nodes[0])//最近打开文档
{
LoadRecentReports();
}
else
{
if (conn.State == System.Data.ConnectionState.Closed)
conn.Open();
//选出当前类的所有报表
System.Data.OleDb.OleDbCommand cmd = new OleDbCommand("select * from ReportsManage where ManageCategory ='" + treeView_catalog.SelectedNode.Tag + "'" ,conn);
System.Data.OleDb.OleDbDataReader rd = cmd.ExecuteReader();
while(rd.Read())
{
//ListViewItem item = new ListViewItem(rd.GetString(rd.GetOrdinal("CReportName") + "[" + rd.GetString(rd.GetOrdinal("ReportID") + "]"));
ListViewItem item = new ListViewItem( rd.GetString(rd.GetOrdinal("ReportID")),3);//显示
//item.Tag = rd.GetString(rd.GetOrdinal("ReportID"));//保存值
item.Tag = "reportid";//标志
int n = rd.GetOrdinal("CReportName");//中或英文名称说明
string reportdescript = rd.IsDBNull(n)?"":rd.GetString(n);
item.SubItems.Add(reportdescript);
listView_report.Items.Add(item);
}
rd.Close();
conn.Close();
}
}
private void button_new_Click(object sender, System.EventArgs e)
{
this.ParentFormHolder.manageinfo.initReportManageInfo();//初始化
this.ParentFormHolder.newReport();
this.Close();
}
/// <summary>
/// LoadRecentReports - 显示最近打使用的RPX文档记录集(XML文档)中的内容
/// </summary>
private void LoadRecentReports()
{
listView_report.Items.Clear();
try
{
//建立XML文棣对应的数据集
DataSet _reportsDS = new DataSet("RecentData");
_reportsDS.Locale = CultureInfo.InvariantCulture;
DataTable _reportsTable;
if(System.IO.File.Exists(Application.StartupPath + @"\Settings\recent.xml"))
{
_reportsDS.ReadXml(Application.StartupPath + @"\Settings\recent.xml");
_reportsTable = _reportsDS.Tables["Reports"];
_reportsTable.Locale = CultureInfo.InvariantCulture;
//建立视图,按时间排序
DataView _view = new DataView(_reportsDS.Tables["Reports"]);
_view.Sort = "TimeStamp";
int i;
System.Collections.ArrayList _filesExist = new ArrayList();
for(i = 0; i < _view.Count;i++)
{
System.Data.DataRowView _row = _view[i];
if(System.IO.File.Exists(_row["ReportPath"].ToString()))
{
int k;
bool _bNotFound = true;
//检查是否有重复的
for(k = 0;k < _filesExist.Count && _bNotFound;k++)
{
if(string.Compare(_filesExist[k].ToString(), _row["ReportPath"].ToString()) == 0)
{
_bNotFound = false;
}
}
//加入到列表中
if(_bNotFound)
{
_filesExist.Add(_row["ReportPath"].ToString());
if (_row["ReportID"].ToString().Length>0)
{
this.listView_report.Items.Add(_row["ReportID"].ToString(),3);
this.listView_report.Items[this.listView_report.Items.Count - 1].Tag = "reportid";
this.listView_report.Items[this.listView_report.Items.Count - 1].SubItems.Add(_row["EReportName"].ToString());
}
else
{
int _indexOfLast = _row["ReportPath"].ToString().LastIndexOf(@"\", _row["ReportPath"].ToString().Length);
if(_indexOfLast != -1)
{
this.listView_report.Items.Add("[F]"+_row["ReportPath"].ToString().Substring(_indexOfLast + 1),2);
}
else
{
this.listView_report.Items.Add(_row["ReportPath"].ToString(),2);
}
this.listView_report.Items[this.listView_report.Items.Count - 1].Tag = "reportfile";
this.listView_report.Items[this.listView_report.Items.Count - 1].SubItems.Add(_row["ReportPath"].ToString());
}
}
}
}
}
else
{
//建立一个最近数据集(XML文档)
_reportsTable = _reportsDS.Tables.Add("Reports");
_reportsTable.Columns.Add("ReportPath", typeof(string));
_reportsTable.Columns.Add("TimeStamp", typeof(System.DateTime));
//定义各语言版本的报表名称
_reportsTable.Columns.Add("ReportID", typeof(string));
_reportsTable.Columns.Add("EReportName", typeof(string));
_reportsTable.Columns.Add("CReportName", typeof(string));
_reportsTable.Columns.Add("HReportName", typeof(string));
_reportsDS.WriteXml(Application.StartupPath + @"\Settings\recent.xml", XmlWriteMode.WriteSchema);
}
}
catch(System.IO.IOException exp)
{
MessageBox.Show(exp.ToString());
}
}
/// <summary>
/// lvRecent_DoubleCLick - 双击报表,打开它
/// </summary>
private void listView_report_DoubleClick(object sender, System.EventArgs e)
{
try
{
this.ParentFormHolder.manageinfo.initReportManageInfo();//初始化
//如果是数据表中已管理的报表
if("reportfile".Equals(this.listView_report.SelectedItems[0].Tag.ToString()))
this.ParentFormHolder.LoadReportFromFile(this.listView_report.SelectedItems[0].SubItems[1].Text);
else//数据表中没有管理的报表,从文件打开
this.ParentFormHolder.LoadReportFromDB(this.listView_report.SelectedItems[0].Text);
this.Close();
}
catch(System.IO.IOException ex)
{
MessageBox.Show("发生错误于: " + ex.InnerException.ToString());
}
}
private void button_open_Click(object sender, System.EventArgs e)
{
if(this.ParentFormHolder.CallDialog(true))
{
//this.ParentFormHolder.manageinfo.initReportManageInfo();//初始化
this.Close();
}
}
private void button_cacel_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.Abort;
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -