You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
221 lines
10 KiB
C#
221 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
using ICSharpCode.Core;
|
|
using Mesnac.Basic;
|
|
using Mesnac.Gui.Edit.Common;
|
|
using Mesnac.PlugIn.View;
|
|
using Mesnac.Gui.Edit.Dialog;
|
|
using Mesnac.Gui.Edit.Pad;
|
|
|
|
namespace Mesnac.Gui.Edit.ViewContent
|
|
{
|
|
public partial class FrmDataSource : DefaultViewContent
|
|
{
|
|
private int datasourceSelectedIndex = -1; //保存选中的数据源索引
|
|
public FrmDataSource()
|
|
{
|
|
InitializeComponent();
|
|
this.InitUIMethod();
|
|
this.RefreshLvDataSource(); //刷新数据源
|
|
}
|
|
|
|
#region 重写DefaultViewCotnent的RedrawContent方法
|
|
|
|
/// <summary>
|
|
/// 重绘组件事件触发时执行
|
|
/// </summary>
|
|
public override void RedrawContent()
|
|
{
|
|
base.RedrawContent();
|
|
this.InitUIMethod();
|
|
this.RefreshLvDataSource(); //刷新数据源
|
|
}
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// 初始化界面元素
|
|
/// </summary>
|
|
protected void InitUIMethod()
|
|
{
|
|
this.Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_Text")); //数据源管理器
|
|
this.TitleName = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_Text")); //数据源管理器
|
|
this.groupBox1.Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_groupBox1_Text")); //数据源信息
|
|
this.groupBox2.Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_groupBox2_Text")); //数据对象信息
|
|
this.groupBox3.Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_groupBox3_Text")); //数据对象详情
|
|
|
|
this.lvDataSource.Columns[0].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colName_Text")); //名称
|
|
this.lvDataSource.Columns[1].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colDataDriverName_Text")); //数据驱动
|
|
this.lvDataSource.Columns[2].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colServer_Text")); //服务器
|
|
this.lvDataSource.Columns[3].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colUserName_Text")); //用户名
|
|
this.lvDataSource.Columns[4].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colPassword_Text")); //密码
|
|
this.lvDataSource.Columns[5].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colDatabase_Text")); //数据库
|
|
this.lvDataSource.Columns[6].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataSource_colConnectionTimeout_Text")); //连接超时
|
|
|
|
this.lvDataObject.Columns[0].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataObject_colDataObjectName_Text")); //数据对象名称
|
|
this.lvDataObject.Columns[1].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataObject_colDataObjectType_Text")); //数据对象类型
|
|
|
|
this.lvDataObjectDetails.Columns[0].Text = StringParser.Parse(ResourceService.GetString("Mesnac_ViewContent_FrmDataSource_lvDataObjectDetails_colDetailsName_Text")); //名称
|
|
|
|
this.mnuNewDataSource.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Form_mnuNew_Text")); //新建
|
|
this.mnuEditDataSource.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Form_mnuEdit_Text")); //编辑
|
|
this.mnuDelDataSource.Text = StringParser.Parse(ResourceService.GetString("Mesnac_Form_mnuDelete_Text")); //删除
|
|
}
|
|
|
|
/// <summary>
|
|
/// 刷新列表视图中的数据源数据
|
|
/// </summary>
|
|
public void RefreshLvDataSource()
|
|
{
|
|
this.lvDataSource.Items.Clear();
|
|
//重置工程数据源工厂
|
|
DisplayUtil<ProjectWindow>.ResetProjectDataSourceFactory();//重置工程
|
|
Dictionary<string, Mesnac.Basic.DataSourceItem> datasources = DataSourceFactory.Instance.DataSources;
|
|
if (datasources != null)
|
|
{
|
|
ListViewItem lvItem = null;
|
|
foreach (Mesnac.Basic.DataSourceItem dataSourceItem in datasources.Values)
|
|
{
|
|
lvItem = new ListViewItem();
|
|
lvItem.Text = dataSourceItem.Name;
|
|
lvItem.SubItems.Add(dataSourceItem.Driver);
|
|
lvItem.SubItems.Add(dataSourceItem.Server);
|
|
lvItem.SubItems.Add(dataSourceItem.UserName);
|
|
lvItem.SubItems.Add(dataSourceItem.Password);
|
|
lvItem.SubItems.Add(dataSourceItem.Database);
|
|
lvItem.SubItems.Add(dataSourceItem.ConnectionTimeout.ToString());
|
|
//lvItem.SubItems.Add(dataSourceItem.DriverClass);
|
|
//lvItem.SubItems.Add(dataSourceItem.DataSourceClass);
|
|
this.lvDataSource.Items.Add(lvItem);
|
|
}
|
|
if (this.datasourceSelectedIndex != -1)
|
|
{
|
|
if (this.datasourceSelectedIndex >= this.lvDataSource.Items.Count)
|
|
{
|
|
this.datasourceSelectedIndex = this.lvDataSource.Items.Count - 1;
|
|
}
|
|
if (this.datasourceSelectedIndex < 0)
|
|
{
|
|
this.datasourceSelectedIndex = 0;
|
|
}
|
|
this.lvDataSource.Items[this.datasourceSelectedIndex].Selected = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
//新建数据源
|
|
private void mnuNewDataSource_Click(object sender, EventArgs e)
|
|
{
|
|
FrmNewDataSource frmNewDataSource = new FrmNewDataSource();
|
|
DialogResult result = frmNewDataSource.ShowDialog(this);
|
|
if (result == DialogResult.OK)
|
|
{
|
|
this.RefreshLvDataSource();
|
|
}
|
|
}
|
|
//编辑数据源
|
|
private void mnuEditDataSource_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.lvDataSource.SelectedItems.Count > 0)
|
|
{
|
|
ListViewItem viewItem = this.lvDataSource.SelectedItems[0];
|
|
FrmNewDataSource frmNewDataSource = new FrmNewDataSource(viewItem.Text);
|
|
DialogResult result = frmNewDataSource.ShowDialog(this);
|
|
if (result == DialogResult.OK)
|
|
{
|
|
this.RefreshLvDataSource();
|
|
}
|
|
}
|
|
}
|
|
//删除数据源
|
|
private void mnuDelDataSource_Click(object sender, EventArgs e)
|
|
{
|
|
if (this.lvDataSource.SelectedItems.Count > 0)
|
|
{
|
|
ListViewItem viewItem = this.lvDataSource.SelectedItems[0];
|
|
string msg1 = StringParser.Parse(ResourceService.GetString("Dialog_MessageBox_DeleteAsk")); //确定要删除吗?
|
|
DialogResult result = MessageBox.Show(msg1, Mesnac.Basic.LanguageHelper.Caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
DataSourceFactory.Instance.Remove(viewItem.Text);
|
|
DisplayUtil<ProjectWindow>.SaveProjectDataSource(); //更新至文件
|
|
this.RefreshLvDataSource(); //刷新视图列表
|
|
}
|
|
}
|
|
}
|
|
//选中数据源列出数据源下的数据对象
|
|
private void lvDataSource_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.lvDataSource.SelectedItems.Count==1)
|
|
{
|
|
this.datasourceSelectedIndex = this.lvDataSource.SelectedIndices[0];
|
|
|
|
this.lvDataObject.Items.Clear();
|
|
this.lvDataObjectDetails.Items.Clear();
|
|
|
|
ListViewItem item = this.lvDataSource.SelectedItems[0];
|
|
TreeNode root = DataSourceFactory.Instance.Root;
|
|
TreeNode dataSourceNode = null;
|
|
foreach (TreeNode node in root.Nodes)
|
|
{
|
|
if (node.Text == item.Text)
|
|
{
|
|
dataSourceNode = node;
|
|
break;
|
|
}
|
|
}
|
|
if (dataSourceNode != null)
|
|
{
|
|
ListViewItem lvItem = null;
|
|
//数据对象
|
|
foreach (TreeNode dataObjectsNode in dataSourceNode.Nodes)
|
|
{
|
|
foreach (TreeNode dataObjectNode in dataObjectsNode.Nodes)
|
|
{
|
|
lvItem = new ListViewItem();
|
|
lvItem.Text = dataObjectNode.Text;
|
|
lvItem.Tag = dataObjectNode;
|
|
lvItem.SubItems.Add(dataObjectsNode.Text);
|
|
this.lvDataObject.Items.Add(lvItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 选中数据对象,列出数据对象下的列信息
|
|
/// </summary>
|
|
private void lvDataObject_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (this.lvDataObject.SelectedItems.Count == 1)
|
|
{
|
|
this.lvDataObjectDetails.Items.Clear();
|
|
|
|
ListViewItem item = this.lvDataObject.SelectedItems[0];
|
|
TreeNode dataObjectNode = item.Tag as TreeNode;
|
|
if (dataObjectNode != null)
|
|
{
|
|
foreach(TreeNode detailsNode in dataObjectNode.Nodes)
|
|
{
|
|
ListViewItem lvItem = new ListViewItem();
|
|
lvItem.Text = detailsNode.Text;
|
|
|
|
this.lvDataObjectDetails.Items.Add(lvItem);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void lvDataSource_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
mnuEditDataSource.PerformClick();
|
|
}
|
|
}
|
|
}
|