📄 codeexport.cs
字号:
namespace Codematic
{
using Codematic.Properties;
using Codematic.UserControls;
using LTP.CmConfig;
using LTP.CodeBuild;
using LTP.CodeHelper;
using LTP.DBFactory;
using LTP.IDBO;
using LTP.Utility;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WiB.Pinkie.Controls;
public class CodeExport : Form
{
private Button btn_Add;
private Button btn_Addlist;
private ButtonXP btn_Cancle;
private Button btn_Del;
private Button btn_Dellist;
private ButtonXP btn_Export;
private ButtonXP btn_TargetFold;
private CodeBuilders cb;
private INIFile cfgfile;
private DALTypeAddIn cm_blltype;
private DALTypeAddIn cm_daltype;
private ComboBox cmbDB;
private string cmcfgfile = (Application.StartupPath + @"\cmcfg.ini");
private Container components;
private string dbname = "";
private IDbObject dbobj;
private DbSettings dbset;
private GroupBox groupBox1;
private GroupBox groupBox2;
private GroupBox groupBox3;
private GroupBox groupBox4;
private GroupBox groupBox5;
private GroupBox groupBox6;
private Label label1;
private Label label2;
private Label label3;
private Label label4;
private Label label5;
private Label label6;
private Label label7;
private Label label8;
private Label labelNum;
private Label lblServer;
private ListBox listTable1;
private ListBox listTable2;
private Thread mythread;
private NameRule namerule = new NameRule();
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private RadioButton radBtn_F3;
private RadioButton radBtn_One;
private RadioButton radBtn_S3;
private ModuleSettings setting;
private TextBox txtDbHelper;
private TextBox txtFolder;
private TextBox txtNamespace;
private TextBox txtTabNamepre;
private TextBox txtTargetFolder;
private VSProject vsp = new VSProject();
public CodeExport(string longservername)
{
this.InitializeComponent();
this.dbset = DbConfig.GetSetting(longservername);
this.dbobj = DBOMaker.CreateDbObj(this.dbset.DbType);
this.dbobj.DbConnectStr = this.dbset.ConnectStr;
this.cb = new CodeBuilders(this.dbobj);
this.lblServer.Text = this.dbset.Server;
}
private void AddClassFile(string ProjectFile, string classFileName, string ProType)
{
if (File.Exists(ProjectFile))
{
switch (ProType)
{
case "2003":
this.vsp.AddClass2003(ProjectFile, classFileName);
return;
case "2005":
this.vsp.AddClass2005(ProjectFile, classFileName);
return;
}
this.vsp.AddClass(ProjectFile, classFileName);
}
}
private void btn_Add_Click(object sender, EventArgs e)
{
int count = this.listTable1.SelectedItems.Count;
ListBox.SelectedObjectCollection selectedItems = this.listTable1.SelectedItems;
for (int i = 0; i < count; i++)
{
this.listTable2.Items.Add(this.listTable1.SelectedItems[i]);
}
for (int j = 0; j < count; j++)
{
if (this.listTable1.SelectedItems.Count > 0)
{
this.listTable1.Items.Remove(this.listTable1.SelectedItems[0]);
}
}
this.IsHasItem();
}
private void btn_Addlist_Click(object sender, EventArgs e)
{
int count = this.listTable1.Items.Count;
for (int i = 0; i < count; i++)
{
this.listTable2.Items.Add(this.listTable1.Items[i]);
}
this.listTable1.Items.Clear();
this.IsHasItem();
}
private void btn_Cancle_Click(object sender, EventArgs e)
{
base.Close();
}
private void btn_Del_Click(object sender, EventArgs e)
{
int count = this.listTable2.SelectedItems.Count;
ListBox.SelectedObjectCollection selectedItems = this.listTable2.SelectedItems;
for (int i = 0; i < count; i++)
{
this.listTable1.Items.Add(this.listTable2.SelectedItems[i]);
}
for (int j = 0; j < count; j++)
{
if (this.listTable2.SelectedItems.Count > 0)
{
this.listTable2.Items.Remove(this.listTable2.SelectedItems[0]);
}
}
this.IsHasItem();
}
private void btn_Dellist_Click(object sender, EventArgs e)
{
int count = this.listTable2.Items.Count;
for (int i = 0; i < count; i++)
{
this.listTable1.Items.Add(this.listTable2.Items[i]);
}
this.listTable2.Items.Clear();
this.IsHasItem();
}
private void btn_Export_Click(object sender, EventArgs e)
{
try
{
if (this.txtTargetFolder.Text.Trim() == "")
{
MessageBox.Show("目标文件夹为空!");
}
else
{
this.cfgfile.IniWriteValue("Project", "lastpath", this.txtTargetFolder.Text.Trim());
this.dbname = this.cmbDB.Text;
this.pictureBox1.Visible = true;
this.mythread = new Thread(new ThreadStart(this.ThreadWork));
this.mythread.Start();
}
}
catch (Exception exception)
{
LogInfo.WriteLog(exception);
MessageBox.Show(exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
private void btn_TargetFold_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
if (dialog.ShowDialog(this) == DialogResult.OK)
{
this.txtTargetFolder.Text = dialog.SelectedPath;
}
}
public void CheckDirectory(string SourceDirectory)
{
DirectoryInfo info = new DirectoryInfo(SourceDirectory);
if (info.Exists)
{
FileInfo[] files = info.GetFiles();
int length = files.Length;
for (int i = 0; i < length; i++)
{
switch (files[i].Extension)
{
case ".csproj":
this.ReplaceNamespaceProj(files[i].FullName, this.txtNamespace.Text.Trim());
break;
case ".cs":
case ".ascx":
case ".aspx":
case ".asax":
case ".master":
this.ReplaceNamespace(files[i].FullName, this.txtNamespace.Text.Trim());
break;
}
}
DirectoryInfo[] directories = info.GetDirectories();
for (int j = 0; j < directories.Length; j++)
{
this.CheckDirectory(directories[j].FullName);
}
}
}
private void cmbDB_SelectedIndexChanged(object sender, EventArgs e)
{
string text = this.cmbDB.Text;
List<string> tables = this.dbobj.GetTables(text);
this.listTable1.Items.Clear();
this.listTable2.Items.Clear();
if (tables.Count > 0)
{
foreach (string str2 in tables)
{
this.listTable1.Items.Add(str2);
}
}
this.IsHasItem();
}
private void CodeExport_Load(object sender, EventArgs e)
{
string str7;
string dbName = "master";
string dbType = this.dbobj.DbType;
if (dbType != null)
{
if (!(dbType == "SQL2000") && !(dbType == "SQL2005"))
{
if ((dbType == "Oracle") || (dbType == "OleDb"))
{
dbName = this.dbset.DbName;
}
else if (dbType == "MySQL")
{
dbName = "mysql";
}
}
else
{
dbName = "master";
}
}
if ((this.dbset.DbName == "") || (this.dbset.DbName == dbName))
{
List<string> dBList = this.dbobj.GetDBList();
if ((dBList != null) && (dBList.Count > 0))
{
foreach (string str2 in dBList)
{
this.cmbDB.Items.Add(str2);
}
}
}
else
{
this.cmbDB.Items.Add(this.dbset.DbName);
}
if (this.cmbDB.Items.Count > 0)
{
this.cmbDB.SelectedIndex = 0;
}
else
{
List<string> tables = this.dbobj.GetTables("");
this.listTable1.Items.Clear();
this.listTable2.Items.Clear();
if (tables.Count > 0)
{
foreach (string str3 in tables)
{
this.listTable1.Items.Add(str3);
}
}
}
this.btn_Export.Enabled = false;
this.setting = ModuleConfig.GetSettings();
string appFrame = this.setting.AppFrame;
if (appFrame != null)
{
if (!(appFrame == "One"))
{
if (appFrame == "S3")
{
this.radBtn_S3.Checked = true;
}
else if (appFrame == "F3")
{
this.radBtn_F3.Checked = true;
}
}
else
{
this.radBtn_One.Checked = true;
}
}
this.cm_blltype = new DALTypeAddIn("LTP.IBuilder.IBuilderBLL");
this.cm_blltype.Title = "BLL";
this.groupBox5.Controls.Add(this.cm_blltype);
this.cm_blltype.Location = new Point(30, 0x10);
this.cm_blltype.SetSelectedDALType(this.setting.BLLType.Trim());
this.cm_daltype = new DALTypeAddIn("LTP.IBuilder.IBuilderDAL");
this.cm_daltype.Title = "DAL";
this.groupBox5.Controls.Add(this.cm_daltype);
this.cm_daltype.Location = new Point(30, 40);
this.cm_daltype.SetSelectedDALType(this.setting.DALType);
this.txtDbHelper.Text = this.setting.DbHelperName;
if ((this.setting.DbHelperName == "DbHelperSQL") && ((str7 = this.dbobj.DbType) != null))
{
if (!(str7 == "SQL2000") && !(str7 == "SQL2005"))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -