📄 newprojectdb.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.Diagnostics;
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 NewProjectDB : Form
{
private string AppFrame = "S3";
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 buttonXP1;
private CodeBuilders cb;
private DALTypeAddIn cm_blltype;
private DALTypeAddIn cm_daltype;
private ComboBox cmbDB;
private Container components;
private string dbname = "";
private IDbObject dbobj;
private DbSettings dbset;
private GroupBox groupBox1;
private GroupBox groupBox2;
private GroupBox groupBox4;
private GroupBox groupBox5;
private GroupBox groupBox7;
private Label label1;
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 NewProject np;
private PictureBox pictureBox1;
private ProgressBar progressBar1;
private string ProOutPath = "";
private ModuleSettings setting;
private TextBox txtDbHelper;
private TextBox txtFolder;
private TextBox txtNamespace;
private TextBox txtTabNamepre;
private VSProject vsp = new VSProject();
public NewProjectDB(string longservername, NewProject fromForm, string proOutPath, string appFrame)
{
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;
this.np = fromForm;
this.ProOutPath = proOutPath;
this.AppFrame = appFrame;
fromForm.Hide();
}
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.ProOutPath == "")
{
MessageBox.Show("目标文件夹为空!");
}
else
{
this.dbname = this.cmbDB.Text;
this.pictureBox1.Visible = true;
this.mythread = new Thread(new ThreadStart(this.ThreadWork));
this.mythread.Start();
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Hand);
}
}
private void buttonXP1_Click(object sender, EventArgs e)
{
base.Hide();
this.np.Show();
}
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 CreatCS()
{
string appFrame = this.AppFrame;
if (appFrame != null)
{
if (!(appFrame == "One"))
{
if (!(appFrame == "S3"))
{
if (appFrame == "F3")
{
this.CreatCsF3();
}
return;
}
}
else
{
this.CreatCsOne();
return;
}
this.CreatCsS3();
}
}
private void CreatCsF3()
{
string proOutPath = this.ProOutPath;
this.FolderCheck(proOutPath);
string folder = proOutPath + @"\Model";
if (this.cb.Folder != "")
{
folder = folder + @"\" + this.cb.Folder;
}
this.FolderCheck(folder);
string filename = folder + @"\" + this.cb.ModelName + ".cs";
string strCode = this.cb.GetCodeFrameS3Model();
this.WriteFile(filename, strCode);
this.AddClassFile(folder + @"\Model.csproj", this.cb.ModelName + ".cs", "");
string dbType = this.dbobj.DbType;
if ((this.dbobj.DbType == "SQL2000") || (this.dbobj.DbType == "SQL2005"))
{
dbType = "SQLServer";
}
string str6 = proOutPath + @"\" + dbType + "DAL";
if (this.cb.Folder != "")
{
str6 = str6 + @"\" + this.cb.Folder;
}
this.FolderCheck(str6);
string str7 = str6 + @"\" + this.cb.DALName + ".cs";
string str8 = this.cb.GetCodeFrameF3DAL(this.GetDALType(), true, true, true, true, true, true, true);
this.WriteFile(str7, str8);
this.AddClassFile(str6 + @"\" + dbType + "DAL.csproj", this.cb.DALName + ".cs", "");
string str9 = proOutPath + @"\DALFactory";
this.FolderCheck(str9);
string path = str9 + @"\DataAccess.cs";
string strContent = this.cb.GetCodeFrameF3DALFactory();
if (File.Exists(path))
{
if (File.ReadAllText(path, Encoding.Default).IndexOf("class DataAccess") > 0)
{
strContent = this.cb.GetCodeFrameF3DALFactoryMethod();
this.vsp.AddMethodToClass(path, strContent);
}
else
{
strContent = this.cb.GetCodeFrameF3DALFactory();
StreamWriter writer = new StreamWriter(path, true, Encoding.Default);
writer.Write(strContent);
writer.Flush();
writer.Close();
}
}
else
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -