Skip to content

Commit

Permalink
11111111
Browse files Browse the repository at this point in the history
  • Loading branch information
陈珙 committed Jan 8, 2020
1 parent f994221 commit a83d854
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 218 deletions.
17 changes: 12 additions & 5 deletions AutoBuildEntity/AutoBuildEntityPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,15 @@ private void AutoBuildEntityEvent(object sender, EventArgs e)
try
{
//读取表集合
autoBuildEntityContent.TablesName = GetTables(entityXmlModel.ConnString);
autoBuildEntityContent.TablesName = GetTables(entityXmlModel.ConnString, entityXmlModel.Type);
}
catch (Exception ex)
{
uiShell.ShowMessageBox(string.Format("数据库访问异常:{0}", ex.Message));
uiShell.ShowMessageBox($"数据库访问异常:{ex.Message}");
return;
}

new MainForm(autoBuildEntityContent).ShowDialog();
new MainForm(autoBuildEntityContent, entityXmlModel.Type).ShowDialog();
}

/// <summary>
Expand All @@ -88,11 +88,18 @@ private SelectedProject GetSelectedProject()
/// </summary>
/// <param name="sqlstr"></param>
/// <returns></returns>
private List<string> GetTables(string sqlstr)
private List<string> GetTables(string sqlstr, string sqlType)
{
var dbTable = new DbTable(sqlstr);

return dbTable.QueryMysqlTablesName();
switch (sqlType)
{
case "mysql":
return dbTable.QueryMysqlTablesName();
case "mssql":
return dbTable.QueryMssqlTablesName();
default: throw new Exception("未知类型");
}
}
}
}
10 changes: 9 additions & 1 deletion AutoBuildEntity/Common/Extension/ProjectExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
Expand Down Expand Up @@ -47,6 +48,9 @@ public static void AddFilesToProject(this Project projectDte, List<string> files
{
projectDte.ProjectItems.AddFromFile(file);
}

//if (files.Any())
// projectDte.Save();
}

/// <summary>
Expand All @@ -60,6 +64,9 @@ public static void RemoveFilesFromProject(this Project projectDte, List<string>
{
projectDte.ProjectItems.Item(Path.GetFileName(file)).Remove();
}

//if (files.Any())
// projectDte.Save();
}

/// <summary>
Expand All @@ -70,6 +77,7 @@ public static void RemoveFilesFromProject(this Project projectDte, List<string>
public static void ShowMessageBox(this IVsUIShell uiShell, string msg)
{
var clsid = Guid.Empty;
int result;
ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(
0,
ref clsid,
Expand All @@ -81,7 +89,7 @@ public static void ShowMessageBox(this IVsUIShell uiShell, string msg)
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
OLEMSGICON.OLEMSGICON_INFO,
0,
out _));
out result));
}
}
}
71 changes: 2 additions & 69 deletions AutoBuildEntity/Common/Helper/SqlHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ namespace 陈珙.AutoBuildEntity.Common.Helper
{
public static class SqlHelper
{
/// <summary>
/// mssql查询
/// </summary>
/// <param name="connStr"></param>
/// <param name="sql"></param>
/// <param name="sqlParameter"></param>
/// <returns></returns>
public static DataTable Query(string connStr, string sql, SqlParameter[] sqlParameter = null)
public static DataTable MssqlQuery(string connStr, string sql, SqlParameter[] sqlParameter = null)
{
var dt = new DataTable();
using (var conn = new SqlConnection(connStr))
Expand All @@ -36,12 +29,6 @@ public static DataTable Query(string connStr, string sql, SqlParameter[] sqlPara
return dt;
}

/// <summary>
/// mysql查询
/// </summary>
/// <param name="connStr"></param>
/// <param name="sql"></param>
/// <returns></returns>
public static DataTable MysqlQuery(string connStr, string sql)
{
var dt = new DataTable();
Expand All @@ -61,13 +48,7 @@ public static DataTable MysqlQuery(string connStr, string sql)
return dt;
}

/// <summary>
/// mysql类型映射
/// </summary>
/// <param name="dbtype"></param>
/// <param name="isNullable"></param>
/// <returns></returns>
public static string MapCsharpType(string dbtype, bool isNullable)
public static string MapMysqlToCsharpType(string dbtype, bool isNullable)
{
if (string.IsNullOrEmpty(dbtype)) return dbtype;
dbtype = dbtype.ToLower();
Expand Down Expand Up @@ -109,53 +90,5 @@ public static string MapCsharpType(string dbtype, bool isNullable)
}
return csharpType;
}

/// <summary>
/// mssql类型映射
/// </summary>
/// <param name="dbtype"></param>
/// <returns></returns>
public static Type MapCommonType(string dbtype)
{
if (string.IsNullOrEmpty(dbtype)) return Type.Missing.GetType();
dbtype = dbtype.ToLower();
Type commonType;
switch (dbtype)
{
case "bigint": commonType = typeof(long); break;
case "binary": commonType = typeof(byte[]); break;
case "bit": commonType = typeof(bool); break;
case "char": commonType = typeof(string); break;
case "date": commonType = typeof(DateTime); break;
case "datetime": commonType = typeof(DateTime); break;
case "datetime2": commonType = typeof(DateTime); break;
case "datetimeoffset": commonType = typeof(DateTimeOffset); break;
case "decimal": commonType = typeof(decimal); break;
case "float": commonType = typeof(double); break;
case "image": commonType = typeof(byte[]); break;
case "int": commonType = typeof(int); break;
case "money": commonType = typeof(decimal); break;
case "nchar": commonType = typeof(string); break;
case "ntext": commonType = typeof(string); break;
case "numeric": commonType = typeof(decimal); break;
case "nvarchar": commonType = typeof(string); break;
case "real": commonType = typeof(Single); break;
case "smalldatetime": commonType = typeof(DateTime); break;
case "smallint": commonType = typeof(short); break;
case "smallmoney": commonType = typeof(decimal); break;
case "sql_variant": commonType = typeof(object); break;
case "sysname": commonType = typeof(object); break;
case "text": commonType = typeof(string); break;
case "time": commonType = typeof(TimeSpan); break;
case "timestamp": commonType = typeof(byte[]); break;
case "tinyint": commonType = typeof(byte); break;
case "uniqueidentifier": commonType = typeof(Guid); break;
case "varbinary": commonType = typeof(byte[]); break;
case "varchar": commonType = typeof(string); break;
case "xml": commonType = typeof(string); break;
default: commonType = typeof(object); break;
}
return commonType;
}
}
}
18 changes: 8 additions & 10 deletions AutoBuildEntity/Form/MainForm.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
<TabControl Grid.ColumnSpan="5" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="500" Width="772">
<TabItem Header="数据源" Width="80" Height="28" FontSize="13">
<Grid Background="#FFE5E5E5">
<TextBox x:Name="addedSearchBox" HorizontalAlignment="Left" Height="25" Margin="26,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" KeyUp="addedSearchBox_KeyUp"/>
<GroupBox Header="已添加的物理表(更新)" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="407" Width="240">
<ListView x:Name="HadAddListView" HorizontalAlignment="Left" Height="333" VerticalAlignment="Top" Width="220" Margin="10,39,-2,0" HorizontalContentAlignment="Right" >
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" Click="TemplateHadAddCheckBox_ClickEvent" Tag="{Binding Path= Name}" IsChecked="{Binding IsChecked}" />
<CheckBox HorizontalAlignment="Center" Click="TemplateHadAddCheckBox_ClickEvent" Tag="{Binding Path= Name}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
<CheckBox x:Name="HadCheckSelectAll" HorizontalAlignment="Center" VerticalAlignment="Center" Click="HadAddSelectAll_ClickEvent" />
Expand All @@ -31,15 +30,14 @@
</ListView.View>
</ListView>
</GroupBox>
<TextBox x:Name="unAddSearchBox" HorizontalAlignment="Left" Height="25" Margin="273,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" KeyUp="unAddSearchBox_KeyUp"/>
<GroupBox Header="未添加的物理表(添加)" HorizontalAlignment="Left" Margin="255,10,0,0" VerticalAlignment="Top" Height="407" Width="240">
<ListView x:Name="NoAddListView" HorizontalAlignment="Left" Height="333" VerticalAlignment="Top" Width="220" Margin="10,39,-2,0" HorizontalContentAlignment="Right" >
<ListView.View>
<GridView>
<GridViewColumn>
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" Click="TemplateNoAddCheckBox_ClickEvent" Tag="{Binding Path= Name}" IsChecked="{Binding IsChecked}" />
<CheckBox HorizontalAlignment="Center" Click="TemplateNoAddCheckBox_ClickEvent" Tag="{Binding Path= Name}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Click="NoAddSelectAll_ClickEvent" />
Expand All @@ -49,7 +47,6 @@
</ListView.View>
</ListView>
</GroupBox>
<TextBox x:Name="unExistSearchBox" HorizontalAlignment="Left" Height="25" Margin="516,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" KeyUp="unExistSearchBox_KeyUp"/>
<GroupBox Header="不存在的实体(删除)" HorizontalAlignment="Left" Margin="500,10,0,0" VerticalAlignment="Top" Height="407" Width="240">
<ListView x:Name="NoExistListView" HorizontalAlignment="Left" Height="333" VerticalAlignment="Top" Width="220" Margin="10,39,-2,0" HorizontalContentAlignment="Right">
<ListView.View>
Expand All @@ -58,7 +55,7 @@
<CheckBox HorizontalAlignment="Center" VerticalAlignment="Center" Click="NoExistSelectAll_ClickEvent" />
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox HorizontalAlignment="Center" Click="TemplateNoExistCheckBox_ClickEvent" Tag="{Binding Path= Name}" IsChecked="{Binding IsChecked}" ></CheckBox>
<CheckBox HorizontalAlignment="Center" Click="TemplateNoExistCheckBox_ClickEvent" Tag="{Binding Path= Name}" ></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Expand All @@ -78,14 +75,15 @@
<GroupBox Header="版权" HorizontalAlignment="Left" Margin="10,143,0,0" VerticalAlignment="Top" Height="128" Width="742">
<Label Content="此源码版权归作者所有,欢迎使用提出建议,但未经作者同意必须保留此段声明" HorizontalAlignment="Left" Margin="0,10,-2,0" VerticalAlignment="Top" Height="93" Width="732"/>
</GroupBox>
<GroupBox Header="使用" HorizontalAlignment="Left" Margin="10,276,0,0" VerticalAlignment="Top" Height="96" Width="742">
<GroupBox Header="使用" HorizontalAlignment="Left" Margin="10,276,0,0" VerticalAlignment="Top" Height="128" Width="742">
<Label Content="__entity.xml为插件使用配置,请修改数据库连接,并把文件放到需要使用的项目下。点击项目右键-自动生成实体工具。&#xA;&#xA;相关博客文章:http://www.cnblogs.com/skychen1218/p/6848128.html" HorizontalAlignment="Left" Margin="0,0,-2,0" VerticalAlignment="Top" Height="102" Width="732"/>
</GroupBox>
<GroupBox Header="版本" HorizontalAlignment="Left" Margin="10,377,0,0" VerticalAlignment="Top" Height="82" Width="742">
<Label Content="V1.4&#xA;" HorizontalAlignment="Left" Margin="0,0,-2,0" VerticalAlignment="Top" Height="56" Width="732"/>
</GroupBox>
</Grid>
</TabItem>
</TabControl>
<TextBox x:Name="addedSearchBox" HorizontalAlignment="Left" Height="25" Margin="40,79,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" Grid.ColumnSpan="3" KeyUp="addedSearchBox_KeyUp"/>
<TextBox x:Name="unAddSearchBox" HorizontalAlignment="Left" Height="25" Margin="54,79,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" Grid.ColumnSpan="3" Grid.Column="2" KeyUp="unAddSearchBox_KeyUp"/>
<TextBox x:Name="unExistSearchBox" HorizontalAlignment="Left" Height="25" Margin="23,79,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="218" Grid.Column="4" KeyUp="unExistSearchBox_KeyUp"/>

</Grid>
</Window>
Loading

0 comments on commit a83d854

Please sign in to comment.