📄 ucaddinmanage.cs
字号:
namespace Codematic.UserControls
{
using Codematic;
using Maticsoft.AddInManager;
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
public class UcAddInManage : UserControl
{
private AddIn addin = new AddIn();
private Button btn_Add;
private Button btnBrow;
private UcCodeView codeview;
private IContainer components;
private ContextMenu contextMenu1;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label label5;
private Label label6;
private ListView listView1;
private MenuItem menu_ShowMain;
private TabControl tabControlAddIn;
private TabPage tabPage_Add;
private TabPage tabPage_Code;
private TabPage tabPage_List;
private TextBox txtAssembly;
private TextBox txtClassname;
private TextBox txtDecr;
private TextBox txtFile;
private TextBox txtName;
private TextBox txtVersion;
public UcAddInManage()
{
this.InitializeComponent();
this.codeview = new UcCodeView();
this.tabPage_Code.Controls.Add(this.codeview);
this.CreatView();
this.BindlistView();
this.LoadAddinFile();
}
private void BindlistView()
{
DataSet addInList = this.addin.GetAddInList();
if ((addInList != null) && (addInList.Tables.Count > 0))
{
DataTable table = addInList.Tables[0];
if (table != null)
{
this.listView1.Items.Clear();
foreach (DataRow row in table.Rows)
{
string text = row["Name"].ToString();
string str2 = row["Decription"].ToString();
string str3 = row["Assembly"].ToString();
row["Classname"].ToString();
string str4 = row["Version"].ToString();
ListViewItem item = new ListViewItem(row["Guid"].ToString(), 0);
item.SubItems.Add(text);
item.SubItems.Add(str3);
item.SubItems.Add(str4);
item.SubItems.Add(str2);
this.listView1.Items.AddRange(new ListViewItem[] { item });
}
}
}
}
private void btn_Add_Click(object sender, EventArgs e)
{
try
{
if (((this.txtClassname.Text.Trim() == "") || (this.txtAssembly.Text.Trim() == "")) || (this.txtName.Text.Trim() == ""))
{
MessageBox.Show(this, "组件信息不完整,请认真填写!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
else
{
string text = this.txtFile.Text;
if (File.Exists(text))
{
int num = text.LastIndexOf(@"\");
if (num > 1)
{
string str2 = text.Substring(num + 1);
if (File.Exists(Application.StartupPath + @"\" + str2))
{
if (MessageBox.Show("该组件已经存在,是否覆盖原组件?", "同名提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
File.Copy(text, Application.StartupPath + @"\" + str2, true);
}
}
else
{
File.Copy(text, Application.StartupPath + @"\" + str2, true);
}
}
this.addin.Guid = Guid.NewGuid().ToString().ToUpper();
this.addin.Classname = this.txtClassname.Text;
this.addin.Assembly = this.txtAssembly.Text;
this.addin.Decription = this.txtDecr.Text;
this.addin.Name = this.txtName.Text;
this.addin.Version = this.txtVersion.Text;
this.addin.AddAddIn();
this.BindlistView();
this.LoadAddinFile();
MessageBox.Show(this, "组件添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
this.tabControlAddIn.SelectedIndex = 1;
}
else
{
MessageBox.Show(this, "所选择的文件不存在!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
}
catch (Exception exception)
{
MessageBox.Show(this, "组件添加失败!\r\n或者请手工复制该文件至安装目录,并修改配置文件即可。\r\n" + exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
LogInfo.WriteLog(exception);
}
}
private void btnBrow_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog dialog = new OpenFileDialog();
dialog.Title = "打开sql脚本文件";
dialog.Filter = "DLL Files (*.dll)|*.dll|All files (*.*)|*.*";
if (dialog.ShowDialog(this) == DialogResult.OK)
{
string fileName = dialog.FileName;
this.txtFile.Text = fileName;
Assembly assembly = Assembly.LoadFile(fileName);
AssemblyName name = assembly.GetName();
Version version = name.Version;
this.txtAssembly.Text = name.Name;
this.txtVersion.Text = version.Major + "." + version.MajorRevision;
bool flag = false;
foreach (System.Type type in assembly.GetTypes())
{
if (this.IsValidPlugin(type))
{
flag = true;
this.txtClassname.Text = type.FullName;
}
}
if (!flag)
{
MessageBox.Show(this, "非标准代码生成插件,请重新选择或改写文件!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
}
}
catch (Exception exception)
{
MessageBox.Show(this, "加载组件失败!\r\n请检查该组件是否符合接口标准或文件是否正确。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
LogInfo.WriteLog(exception);
}
}
private void CreatView()
{
this.listView1.Columns.Clear();
this.listView1.Items.Clear();
this.listView1.View = View.Details;
this.listView1.GridLines = true;
this.listView1.FullRowSelect = true;
this.listView1.Columns.Add("编号", 60, HorizontalAlignment.Left);
this.listView1.Columns.Add("名称", 150, HorizontalAlignment.Left);
this.listView1.Columns.Add("程序集", 100, HorizontalAlignment.Left);
this.listView1.Columns.Add("版本", 60, HorizontalAlignment.Left);
this.listView1.Columns.Add("说明", 150, HorizontalAlignment.Left);
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.tabControlAddIn = new TabControl();
this.tabPage_Add = new TabPage();
this.btnBrow = new Button();
this.btn_Add = new Button();
this.txtFile = new TextBox();
this.txtVersion = new TextBox();
this.txtClassname = new TextBox();
this.txtAssembly = new TextBox();
this.txtDecr = new TextBox();
this.txtName = new TextBox();
this.label6 = new Label();
this.label5 = new Label();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -