添加项目文件。
This commit is contained in:
parent
bd8d82adf0
commit
7557154847
|
@ -0,0 +1,9 @@
|
|||
<Application x:Class="CeramicProjectTool.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:CeramicProjectTool"
|
||||
StartupUri="LoginWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,14 @@
|
|||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
|
||||
namespace CeramicProjectTool
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
using System.Windows;
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
|
@ -0,0 +1,15 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UseWPF>true</UseWPF>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="SqlSugarCore" Version="5.1.4.155" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34902.65
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CeramicProjectTool", "CeramicProjectTool.csproj", "{16041053-1738-4E81-A9D4-A2B0DB485243}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{16041053-1738-4E81-A9D4-A2B0DB485243}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{16041053-1738-4E81-A9D4-A2B0DB485243}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{16041053-1738-4E81-A9D4-A2B0DB485243}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{16041053-1738-4E81-A9D4-A2B0DB485243}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {E007FC4B-9338-4405-A99A-FE78B3D0E54A}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,60 @@
|
|||
<Window x:Class="CeramicProjectTool.LoginWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:CeramicProjectTool"
|
||||
mc:Ignorable="d"
|
||||
Title="登录" Height="450" Width="800">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TabControl Grid.Row="0">
|
||||
<TabItem IsSelected="True" Header="登录" Height="19" VerticalAlignment="Top">
|
||||
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center" >
|
||||
<TextBlock Margin="10" Text="CeramicProjectTool" FontSize="30"/>
|
||||
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="账号:" Width="50"/>
|
||||
<TextBox x:Name="usernameBox" Text="" Width="100"/>
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="密码:" Width="50" />
|
||||
<PasswordBox x:Name="passwdBox" Width="100" />
|
||||
|
||||
</StackPanel>
|
||||
<Button x:Name="loginButton" Content="登录" Width="100" Margin="10" Click="loginButton_Click"/>
|
||||
</StackPanel>
|
||||
|
||||
</TabItem>
|
||||
<TabItem Header="数据库配置">
|
||||
<StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="地址:" Width="60" />
|
||||
<TextBox x:Name="sourceBox" Width="100" />
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="数据库名:" Width="60" />
|
||||
<TextBox x:Name="dbNameBox" Width="100" />
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="账号:" Width="60" />
|
||||
<TextBox x:Name="dbUserNameBox" Width="100" />
|
||||
|
||||
</StackPanel>
|
||||
<StackPanel Margin="10" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<TextBlock Text="密码:" Width="60" />
|
||||
<PasswordBox x:Name="dbPwdBox" Width="100" />
|
||||
|
||||
</StackPanel>
|
||||
<Button x:Name="dbConfigButton" Content="保存" Width="100" Margin="10" Click="dbConfigButton_Click"/>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -0,0 +1,115 @@
|
|||
using CeramicProjectTool.Util;
|
||||
using System.Runtime.Intrinsics.Arm;
|
||||
using System.Security.Cryptography;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace CeramicProjectTool
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for MainWindow.xaml
|
||||
/// </summary>
|
||||
public partial class LoginWindow : Window
|
||||
{
|
||||
public LoginWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
Store.Init();
|
||||
|
||||
var dbConfig = Store.GetStoreData<Dictionary<string, string>>("dbConfig");
|
||||
if (dbConfig != null)
|
||||
{
|
||||
sourceBox.Text = dbConfig["dbSource"];
|
||||
dbNameBox.Text = dbConfig["dbName"];
|
||||
dbUserNameBox.Text = dbConfig["dbUserName"];
|
||||
dbPwdBox.Password = dbConfig["dbUserPwd"];
|
||||
DBHelper.SetConnStr(dbConfig);
|
||||
DBHelper.Init();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void loginButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!DBHelper.isInit)
|
||||
{
|
||||
MessageBox.Show("请先配置数据库连接信息!");
|
||||
return;
|
||||
}
|
||||
|
||||
var userName = usernameBox.Text;
|
||||
var passwd = passwdBox.Password;
|
||||
if (userName != "admin")
|
||||
{
|
||||
MessageBox.Show("只允许使用Admin账号登录!");
|
||||
return;
|
||||
}
|
||||
var pwd = getPasswdSha1(passwd);
|
||||
|
||||
|
||||
|
||||
var loginResult = DBHelper.Login(userName, pwd);
|
||||
if (loginResult)
|
||||
{
|
||||
MessageBox.Show("登录成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("登录失败!");
|
||||
}
|
||||
}
|
||||
|
||||
private string getPasswdSha1(string passwd)
|
||||
{
|
||||
var buffer = Encoding.UTF8.GetBytes(passwd);
|
||||
var sha1 = SHA1.Create().ComputeHash(buffer);
|
||||
var sb = new StringBuilder();
|
||||
foreach (var b in sha1)
|
||||
{
|
||||
sb.Append(b.ToString("x2").ToUpper());
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
private void dbConfigButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var dbConfig = Store.GetStoreData<Dictionary<string, string>>("dbConfig");
|
||||
if (dbConfig == null)
|
||||
{
|
||||
dbConfig = new Dictionary<string, string>();
|
||||
}
|
||||
var dbSource = sourceBox.Text;
|
||||
var dbUserName = dbUserNameBox.Text;
|
||||
var dbUserPwd = dbPwdBox.Password;
|
||||
var dbName = dbNameBox.Text;
|
||||
|
||||
dbConfig["dbSource"] = dbSource;
|
||||
dbConfig["dbName"] = dbName;
|
||||
dbConfig["dbUserName"] = dbUserName;
|
||||
dbConfig["dbUserPwd"] = dbUserPwd;
|
||||
|
||||
var saveResult = Store.SaveOrUpdateDataToFile("dbConfig", dbConfig);
|
||||
if (saveResult)
|
||||
{
|
||||
DBHelper.SetConnStr(dbConfig);
|
||||
DBHelper.Init();
|
||||
MessageBox.Show("保存成功!");
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("保存失败!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CeramicProjectTool.Util
|
||||
{
|
||||
public static class DBHelper
|
||||
{
|
||||
private static SqlSugar.SqlSugarClient _db;
|
||||
public static bool isInit = false;
|
||||
public static void Init()
|
||||
{
|
||||
if (_db == null)
|
||||
{
|
||||
_db = new SqlSugar.SqlSugarClient(new SqlSugar.ConnectionConfig()
|
||||
{
|
||||
ConnectionString = connStr,
|
||||
DbType = SqlSugar.DbType.SqlServer,
|
||||
IsAutoCloseConnection = true,
|
||||
InitKeyType = SqlSugar.InitKeyType.Attribute
|
||||
});
|
||||
isInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetConnStr(Dictionary<string, string> dbConfig)
|
||||
{
|
||||
DBHelper.connStr = $"Data Source={dbConfig["dbSource"]};Initial Catalog={dbConfig["dbName"]};User ID={dbConfig["dbUserName"]};Password={dbConfig["dbUserPwd"]}";
|
||||
}
|
||||
|
||||
public static string connStr = "";
|
||||
public static bool Login(string userName, string pwd)
|
||||
{
|
||||
var sql = $"select top 1 1 from nr_z_yhzh where zhanghao=@userName and mima=@pwd";
|
||||
var result = _db.Ado.GetInt(sql, new { userName, pwd });
|
||||
if (result >= 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace CeramicProjectTool.Util
|
||||
{
|
||||
public class PathUtil
|
||||
{
|
||||
public static string GetAppRootPath()
|
||||
{
|
||||
try
|
||||
{
|
||||
//string strPath = null;
|
||||
//System.Object objPath = Microsoft.Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\DigiWinCADI", "InstallPath", strPath);
|
||||
//strPath = objPath as string;
|
||||
return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
||||
}
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
string strMsg = ex.Message;
|
||||
MessageBox.Show(strMsg);
|
||||
return Environment.CurrentDirectory;
|
||||
}
|
||||
}
|
||||
private const string FILE_STORE_PATH = "Local/CeramicProject/data/FileStores";
|
||||
|
||||
|
||||
public static string AppRoot
|
||||
{
|
||||
get
|
||||
{
|
||||
string binPath = "";
|
||||
//binPath = System.Environment.GetEnvironmentVariable("CADI_HOME");
|
||||
binPath = GetAppRootPath();
|
||||
if (string.IsNullOrEmpty(binPath))
|
||||
{
|
||||
binPath = Environment.CurrentDirectory;
|
||||
}
|
||||
|
||||
//binPath = DynaTeam.Util.Path.GetFormularPath(binPath);
|
||||
_ = System.IO.Directory.CreateDirectory(binPath);
|
||||
binPath = System.IO.Path.GetDirectoryName(binPath) ?? Environment.CurrentDirectory;
|
||||
var appDataPath = System.IO.Path.Combine(binPath, FILE_STORE_PATH);
|
||||
if (!Directory.Exists(appDataPath))
|
||||
{
|
||||
Directory.CreateDirectory(appDataPath);
|
||||
}
|
||||
return appDataPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CeramicProjectTool.Util
|
||||
{
|
||||
public static class Store
|
||||
{
|
||||
private static string _storePath = PathUtil.AppRoot;
|
||||
private static Dictionary<string, object> datas = new Dictionary<string, object>();
|
||||
public static void StoreData(string key, string value)
|
||||
{
|
||||
// Store data to local file
|
||||
}
|
||||
|
||||
public static bool SaveOrUpdateDataToFile(string key, object value)
|
||||
{
|
||||
if (datas.ContainsKey(key))
|
||||
{
|
||||
datas[key] = value;
|
||||
}
|
||||
else
|
||||
{
|
||||
datas.Add(key, value);
|
||||
}
|
||||
return SaveToFile(key);
|
||||
}
|
||||
|
||||
public static T? GetStoreData<T>(string key)
|
||||
{
|
||||
if (datas.ContainsKey(key))
|
||||
{
|
||||
var data = datas[key];
|
||||
if (!(data is T))
|
||||
{
|
||||
try
|
||||
{
|
||||
var dataJson = Serialize(data);
|
||||
var dataObj = Deserialize<T>(dataJson);
|
||||
return dataObj;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
throw new InvalidCastException("数据类型不一致!");
|
||||
}
|
||||
}
|
||||
return (T)data;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (LoadFromFile(key))
|
||||
{
|
||||
return GetStoreData<T>(key);
|
||||
}
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
public static void Init()
|
||||
{
|
||||
if (_storePath == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Load data from local file
|
||||
loadAll();
|
||||
}
|
||||
|
||||
|
||||
public static bool SaveAll()
|
||||
{
|
||||
foreach (var key in datas.Keys)
|
||||
{
|
||||
if (!SaveToFile(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SaveToFile(string key)
|
||||
{
|
||||
var filePath = GetFilePath(key);
|
||||
var data = Serialize(datas[key]);
|
||||
try
|
||||
{
|
||||
System.IO.File.WriteAllText(filePath, data);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public static bool LoadFromFile(string key)
|
||||
{
|
||||
var filePath = GetFilePath(key);
|
||||
if (!System.IO.File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
var data = System.IO.File.ReadAllText(filePath);
|
||||
datas[key] = Deserialize<object>(data);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetFilePath(string key)
|
||||
{
|
||||
var fullPath = _storePath;
|
||||
if (!System.IO.Directory.Exists(fullPath))
|
||||
{
|
||||
System.IO.Directory.CreateDirectory(fullPath);
|
||||
}
|
||||
|
||||
return System.IO.Path.Combine(fullPath, key);
|
||||
}
|
||||
public static bool loadAll()
|
||||
{
|
||||
//var fullPath = System.IO.Path.Combine(AppRoot, FILE_STORE_PATH);
|
||||
if (!System.IO.Directory.Exists(_storePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var files = System.IO.Directory.GetFiles(_storePath);
|
||||
foreach (var file in files)
|
||||
{
|
||||
var key = System.IO.Path.GetFileName(file);
|
||||
key = key.Replace(".json", "");
|
||||
if (!LoadFromFile(key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#region 序列化
|
||||
private static string Serialize(object obj)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.SerializeObject(obj);
|
||||
}
|
||||
private static T? Deserialize<T>(string json)
|
||||
{
|
||||
return Newtonsoft.Json.JsonConvert.DeserializeObject<T>(json);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue