用户信息和数据库的增删改查修改
This commit is contained in:
1 parent
10611241d1
commit
5d9ab90ed3
16 files changed
+511
-23
No files matched your search
+2
-1
@@ -24,7 +24,7 @@ namespace SunlightAggregationManager
|
||||
}
|
||||
private void Window_Loaded(object sender, RoutedEventArgs e)
|
||||
{
|
||||
GlobalLogManager.RegisterTarget(LOG);
|
||||
GlobalLogManager.RegisterTarget(LOG,LogGing.LogGingDATA);
|
||||
|
||||
DataContext = new MainWindowViewModel();
|
||||
}
|
||||
@@ -86,6 +86,7 @@ namespace SunlightAggregationManager
|
||||
{
|
||||
state.Visibility = Visibility.Collapsed;
|
||||
Picture.Visibility = Visibility.Visible;
|
||||
Picture.Content = new View.ExtendPage();
|
||||
}
|
||||
private void ListViewItem_MouseLeftButtonUp_user(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
|
||||
@@ -101,6 +101,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Http:" + ex.ToString());
|
||||
//client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
tcpClient.Connected = (client, e) =>
|
||||
{
|
||||
//设定显示状态
|
||||
System.Data.DataRow targetRow =ViewModel.MainWindowViewModel._service.Select("ID = 1").FirstOrDefault()!;
|
||||
System.Data.DataRow targetRow =ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
|
||||
if (targetRow != null)
|
||||
{
|
||||
targetRow.BeginEdit();
|
||||
@@ -60,7 +60,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
};//成功连接到服务器
|
||||
tcpClient.Closing = (client, e) => { return EasyTask.CompletedTask; };//即将从服务器断开连接。此处仅主动断开才有效。
|
||||
tcpClient.Closed = (client, e) => {
|
||||
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("ID = 1").FirstOrDefault()!;
|
||||
System.Data.DataRow targetRow = ViewModel.MainWindowViewModel._service.Select("Service = 'Sunlight_Server_Link'").FirstOrDefault()!;
|
||||
if (targetRow != null)
|
||||
{
|
||||
targetRow.BeginEdit();
|
||||
@@ -138,6 +138,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{//错误
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("Tcp:" + ex.ToString());
|
||||
client.SendAsync("Target instruction parsing error manager will close connection");
|
||||
foreach (var item in AsyncTcpServer.service.Clients)
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
private string DB_IP = null!;
|
||||
private string DB_PASSWORD = null!;
|
||||
|
||||
public void Config(string ip, string name, string type, string id, string password)
|
||||
public async void Config(string ip, string name, string type, string id, string password)
|
||||
{
|
||||
DB_IP = ip;
|
||||
DB_ID = id;
|
||||
@@ -26,7 +26,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
DB_TYPE = type;
|
||||
DB_PASSWORD = password;
|
||||
|
||||
_= ConfigAsync();
|
||||
await ConfigAsync();
|
||||
|
||||
}
|
||||
public async Task ConfigAsync()
|
||||
@@ -63,6 +63,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Link timeout\n"+ex.ToString());
|
||||
// 失败处理
|
||||
return; // 直接返回,不执行后续代码
|
||||
@@ -76,7 +77,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
// 创建一个空的 DataTable 用于存放查询结果
|
||||
DataTable dataTable = new DataTable();
|
||||
|
||||
// 沿用你原有的数据库连接字符串构建逻辑
|
||||
// 数据库连接字符串构建逻辑
|
||||
var builder = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = DB_IP,
|
||||
@@ -109,8 +110,9 @@ namespace SunlightAggregationManager.UserClass
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogGing.ERRDATA(ex);
|
||||
Console.WriteLine("DataBase Query failed\n" + ex.ToString());
|
||||
// 这里可以选择将异常抛出给调用方,或者返回一个空的 DataTable
|
||||
// 将异常抛出给调用方,或者返回一个空的 DataTable
|
||||
throw;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,118 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
|
||||
namespace SunlightAggregationManager.UserClass
|
||||
{
|
||||
public class LogGing
|
||||
{
|
||||
public static void LogGingDATA(string dat)
|
||||
{
|
||||
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
||||
string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件
|
||||
string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:";
|
||||
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(logPath))//检查日志文件并写入启动日志
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + dat);
|
||||
wr.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write);
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine(Log_time + dat);
|
||||
wr.Close();
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();//创建日志路径
|
||||
}
|
||||
}
|
||||
public static void ERRDATA(System.Exception dat)
|
||||
{
|
||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string logpath = System.Environment.CurrentDirectory + "\\ERR";//日志文件目录
|
||||
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||
string log_path = logpath + "\\ERR" + Log_time + ".txt";
|
||||
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(log_path))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.Source.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.StackTrace.ToString());
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error] ||" + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + dat.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + dat.Message.ToString() + Environment.NewLine.ToString());
|
||||
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + dat.ToString());
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();
|
||||
}
|
||||
}
|
||||
public static void ExchangeDATA(string dat)
|
||||
{
|
||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
string logpath = System.Environment.CurrentDirectory + "\\Exchange";//日志文件目录
|
||||
// string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||
// System.IO.DirectoryInfo log = new System.IO.DirectoryInfo();//生成日志文件目录
|
||||
string log_path = logpath + "\\Exchange" + Log_time + ".txt";
|
||||
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
if (Directory.Exists(logpath))//检查日志路径
|
||||
{
|
||||
if (!File.Exists(log_path))//检查文件并写入
|
||||
{
|
||||
// FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建文件
|
||||
// StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
// wr.Close();
|
||||
FileStream fil = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wfil = new StreamWriter(fil);//创建文件
|
||||
wfil.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||
wfil.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||
wr.WriteLine("[" + Log_timehms + "];[Exchange] ||" + dat);
|
||||
wr.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DirectoryInfo directoryInfo = new DirectoryInfo(logpath);
|
||||
directoryInfo.Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,6 +46,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
//将规则添加到防火墙策略中
|
||||
policy?.Rules.Add(rule);
|
||||
Console.WriteLine("Add firewall port:"+port);
|
||||
}
|
||||
|
||||
public static void DelPort(int port, string protocol)
|
||||
@@ -65,7 +66,7 @@ namespace SunlightAggregationManager.UserClass
|
||||
if (rule.Name == GetName(port, protocol))
|
||||
{
|
||||
rules.Remove(rule.Name);
|
||||
Console.WriteLine(@"Firewall rule deleted successfully.");
|
||||
//Console.WriteLine(@"Firewall rule deleted successfully.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-8
@@ -10,25 +10,32 @@ namespace SunlightAggregationManager.UserClass
|
||||
public class ControlWriter : TextWriter
|
||||
{
|
||||
private readonly TextBox _textbox;
|
||||
private readonly Action<string> _logGingDataAction;
|
||||
|
||||
public ControlWriter(TextBox textbox)
|
||||
public ControlWriter(TextBox textbox,Action<string> logGingDataAction)
|
||||
{
|
||||
_textbox = textbox;
|
||||
_logGingDataAction = logGingDataAction;
|
||||
}
|
||||
|
||||
public override void Write(char value) => AppendText(DateTime.Now + ": " + value.ToString());
|
||||
public override void Write(string? value) => AppendText(DateTime.Now + ": " + value);
|
||||
public override void WriteLine(string? value) => AppendText(DateTime.Now + ": "+value + Environment.NewLine);
|
||||
public override void Write(char value) => AppendText(DateTime.Now + ": " + value.ToString(), true);
|
||||
public override void Write(string? value) => AppendText(DateTime.Now + ": " + value, true);
|
||||
public override void WriteLine(string? value) => AppendText(DateTime.Now + ": "+value + Environment.NewLine, true);
|
||||
|
||||
private void AppendText(string text)
|
||||
private void AppendText(string text, bool invokeExternalLog)
|
||||
{
|
||||
if (!_textbox.Dispatcher.CheckAccess())
|
||||
{
|
||||
_textbox.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => AppendText(text)));
|
||||
_textbox.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => AppendText(text, true)));
|
||||
return;
|
||||
}
|
||||
_textbox.AppendText(text);
|
||||
_textbox.ScrollToEnd();
|
||||
|
||||
if (invokeExternalLog)
|
||||
{
|
||||
_logGingDataAction?.Invoke(text);
|
||||
}
|
||||
}
|
||||
|
||||
public override Encoding Encoding => Encoding.UTF8;
|
||||
@@ -41,10 +48,10 @@ namespace SunlightAggregationManager.UserClass
|
||||
|
||||
// 【核心功能】注册目标 TextBox
|
||||
// 子页面加载时调用这个方法
|
||||
public static void RegisterTarget(TextBox logBox)
|
||||
public static void RegisterTarget(TextBox logBox ,Action<string> logGingDataAction)
|
||||
{
|
||||
// 创建新的 Writer
|
||||
_currentWriter = new ControlWriter(logBox);
|
||||
_currentWriter = new ControlWriter(logBox, logGingDataAction);
|
||||
|
||||
// 【关键】将 Console 的输出重定向到这个 Writer
|
||||
// 这样 Console.WriteLine("...") 就会自动写入到 logBox 中
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
<Window x:Class="SunlightAggregationManager.UserWindow.User"
|
||||
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:SunlightAggregationManager.UserWindow"
|
||||
xmlns:viewmodel="clr-namespace:SunlightAggregationManager.ViewModel"
|
||||
xmlns:lang="clr-namespace:SunlightAggregationManager"
|
||||
mc:Ignorable="d"
|
||||
Loaded="user_Loaded"
|
||||
ResizeMode="NoResize"
|
||||
Title="MAC_SET"
|
||||
Height="900" Width="1440" MinHeight="900" MinWidth="1440"
|
||||
BorderBrush="White" Background="White">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="5"/>
|
||||
<RowDefinition/>
|
||||
<RowDefinition Height="100"/>
|
||||
</Grid.RowDefinitions>
|
||||
<GridSplitter Grid.Row="1" Height="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Row="0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition MinWidth="200" MaxWidth="500"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FFCECECE"/>
|
||||
<Grid Grid.Column="0">
|
||||
<!--用户-->
|
||||
<TextBox x:Name="_User" Height="30" Margin="105,10,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1" InputMethod.IsInputMethodEnabled="False" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,10,0,100" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.user}" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<!--名-->
|
||||
<TextBox x:Name="_Name" Height="30" Margin="105,55,10,100" VerticalAlignment="Top" FontSize="16" MaxLines="1" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,55,0,100" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Name}" VerticalAlignment="Top" Width="85" FontSize="20"/>
|
||||
<!--密码-->
|
||||
<TextBox x:Name="Pasword" Height="30" Margin="105,100,10,50" VerticalAlignment="Top" FontSize="16" MaxLines="1" InputMethod.IsInputMethodEnabled="False" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,100,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Password}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
<!--部门-->
|
||||
<TextBox x:Name="_Department" Height="30" Margin="105,145,10,50" VerticalAlignment="Top" FontSize="16" MaxLines="1" />
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,145,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Department}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
<!--组-->
|
||||
<ComboBox x:Name="GROUP" Height="30" Margin="105,190,10,100" VerticalAlignment="Top" FontSize="16" IsReadOnly="True">
|
||||
<ComboBoxItem Content="CHIEF"></ComboBoxItem>
|
||||
<ComboBoxItem Content="ENGINEER"></ComboBoxItem>
|
||||
<ComboBoxItem Content="POWERUSER"></ComboBoxItem>
|
||||
<ComboBoxItem Content="USER"></ComboBoxItem>
|
||||
</ComboBox>
|
||||
<TextBlock HorizontalAlignment="Left" Height="30" Margin="15,190,0,50" TextWrapping="Wrap"
|
||||
Text="{x:Static lang:ResourceLanguage.Groups}" VerticalAlignment="Top" Width="80" FontSize="20"/>
|
||||
</Grid>
|
||||
<Grid Grid.Column="2" Margin="0">
|
||||
<ScrollViewer Margin="0" VerticalScrollBarVisibility="Auto">
|
||||
<WrapPanel Orientation="Horizontal" x:Name="Capacity" >
|
||||
</WrapPanel>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<!--表-->
|
||||
<DataGrid Grid.Row="2" x:Name="DataGriduser" MouseDoubleClick="DataGridMac_MouseDoubleClick" SelectionMode="Single" AlternationCount="2" IsReadOnly="True"
|
||||
d:ItemsSource="{d:SampleData ItemCount=999}" AutoGenerateColumns="False" MinColumnWidth="30"
|
||||
HorizontalGridLinesBrush="#FFC9C9C9" VerticalGridLinesBrush="#FFC9C9C9" GridLinesVisibility="All" BorderBrush="{x:Null}"
|
||||
BorderThickness="1,1,1,1" ColumnHeaderHeight="40" HorizontalContentAlignment="Right" Grid.ColumnSpan="2"
|
||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
||||
CanUserResizeColumns="False" CanUserSortColumns="False" HeadersVisibility ="Column" Background="{x:Null}">
|
||||
<DataGrid.RowStyle >
|
||||
<Style TargetType="{x:Type DataGridRow}">
|
||||
<Style.Triggers>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||
<Setter Property="Background" Value="#FFFFFFFF" />
|
||||
</Trigger>
|
||||
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||
<Setter Property="Background" Value="#FFF0F0F0" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsMouseOver" Value="False">
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.RowStyle>
|
||||
<DataGrid.CellStyle>
|
||||
<Style TargetType="DataGridCell">
|
||||
<Setter Property="BorderThickness" Value="0"/>
|
||||
<Setter Property="MinWidth" Value="20"/>
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter Property="Background" Value="#FFC0C0C0"/>
|
||||
<Setter Property="BorderBrush" Value="#FFC0C0C0"/>
|
||||
<Setter Property="Foreground" Value="#000000"/>
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</DataGrid.CellStyle>
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.user}" Binding="{Binding User}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Name}" Binding="{Binding Name}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Password}" Binding="{Binding Password}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Department}" Binding="{Binding Department}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Groups}" Binding="{Binding Groups}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Binding="{Binding Capacity}" Width="0" MaxWidth="0" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.LastLoginIP}" Binding="{Binding LastLoginIP}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.LastLoginTime}" Binding="{Binding LastLoginTime}"
|
||||
Width="200" FontSize="15" MaxWidth="200" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!--存储按钮-->
|
||||
<Button Grid.Row="3" Content="存储" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Preservation" Margin="0,0,200,0">
|
||||
</Button>
|
||||
<!--删除按钮-->
|
||||
<Button Grid.Row="3" Content="删除" HorizontalAlignment="Right" Height="50" VerticalAlignment="Center" Width="100" FontSize="30"
|
||||
Click="Button_Delete" Margin="0,0,50,0">
|
||||
</Button>
|
||||
</Grid>
|
||||
</Window>
|
||||
@@ -0,0 +1,152 @@
|
||||
using SunlightAggregationManager.View;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SunlightAggregationManager.UserWindow
|
||||
{
|
||||
/// <summary>
|
||||
/// Machine.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class User : Window
|
||||
{
|
||||
CheckBox[] checkBoxes = new CheckBox[99];
|
||||
string[] strings = new string[8] {"修改系统设置", "修改用户设置",
|
||||
"设备监控","设备控制","远程设置","远程查询","输送信息","历史查询"};
|
||||
public User()
|
||||
{
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void user_Loaded(object sender, RoutedEventArgs e)//打开页面执行
|
||||
{
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
checkBoxes[i] = new CheckBox();
|
||||
checkBoxes[i].Content = strings[i].ToString();
|
||||
checkBoxes[i].FontSize = 20;
|
||||
checkBoxes[i].Width = 200;
|
||||
checkBoxes[i].Height = 50;
|
||||
Capacity.Children.Add(checkBoxes[i]);
|
||||
}
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
}
|
||||
|
||||
private void Tb_KeyFloating(object sender, TextCompositionEventArgs e)//输入事件
|
||||
{
|
||||
//Regex re = new Regex("[^0-9.-]+");
|
||||
Regex re = new Regex(@"^[.][0-9]+$|^[0-9]*[.]{0,1}[0-9]*$");// 非负浮点数
|
||||
e.Handled = !re.IsMatch(e.Text);
|
||||
}
|
||||
|
||||
private void DataGridMac_MouseDoubleClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
{
|
||||
string Capacity_;
|
||||
int rownum = DataGriduser.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
if (rownum != -1)//判断鼠标定位是否有效
|
||||
{
|
||||
/*定位选中行及指定列单元格文本信息*/
|
||||
_Name.Text = (DataGriduser.Columns[1].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
_User.Text = (DataGriduser.Columns[0].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();//定位第列
|
||||
GROUP.Text = (DataGriduser.Columns[4].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
Capacity_ = (DataGriduser.Columns[5].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
_Department.Text = (DataGriduser.Columns[3].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
Pasword.Text = (DataGriduser.Columns[2].GetCellContent(DataGriduser.Items[rownum]) as TextBlock)!.Text.Trim();
|
||||
|
||||
if (strings.Length > Capacity_.Length)
|
||||
{
|
||||
for (int i = 0; i < Capacity_.Length; i++)
|
||||
{
|
||||
if (Capacity_.Substring(i, 1) == "1")
|
||||
{
|
||||
checkBoxes[i].IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBoxes[i].IsChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
if (Capacity_.Substring(i, 1) == "1")
|
||||
{
|
||||
checkBoxes[i].IsChecked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
checkBoxes[i].IsChecked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_Preservation(object sender, RoutedEventArgs e)//保存按钮事件
|
||||
{
|
||||
Regex re_number = new Regex(@"^[0-9]+(.[0-9]{1,2})?$");//校验用正则表达式有1~2位小数的正实数
|
||||
Regex re_char = new Regex(@"^[A-Za-z0-9\s@()()/+!!_-]+$");//校验用正则表达式由数字,26个英文字母,空白字符和@()()/+!!_-组成的字符串
|
||||
|
||||
string user = _User.Text;
|
||||
string name = _Name.Text;
|
||||
string password = Pasword.Text;
|
||||
string Group = GROUP.Text;
|
||||
string Cap = "";
|
||||
string department = _Department.Text;
|
||||
for (int i = 0; i < strings.Length; i++)
|
||||
{
|
||||
if ((bool)checkBoxes[i].IsChecked!)
|
||||
{
|
||||
Cap = Cap + "1";
|
||||
}
|
||||
else { Cap = Cap + "0"; }
|
||||
}
|
||||
Dictionary<string, object> USER_new = new Dictionary<string, object>();//缓存函数
|
||||
USER_new.Add("User", user);
|
||||
USER_new.Add("Name", name);
|
||||
USER_new.Add("Password", password);
|
||||
USER_new.Add("Groups", Group);
|
||||
USER_new.Add("Capacity", Cap);
|
||||
USER_new.Add("Department", department);
|
||||
USER_new.Add("State", 0);
|
||||
USER_new.Add("Enterprise", MainWindowViewModel.Enterprise);
|
||||
|
||||
var rowdata = MainWindowViewModel.Selet_Memory(MainWindowViewModel._userData, "UserID", "User='" + user + "'");
|
||||
if (rowdata != null)
|
||||
{
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + user + "'", USER_new);
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindowViewModel.Insert_Memory(MainWindowViewModel._userData, USER_new);// 执行插入
|
||||
}
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
_Name.Text = null;
|
||||
|
||||
}
|
||||
|
||||
private void Button_Delete(object sender, RoutedEventArgs e)//删除按钮事件
|
||||
{
|
||||
try
|
||||
{
|
||||
MainWindowViewModel.Delete_Memory(MainWindowViewModel._userData, "User='" + _User.Text + "'");
|
||||
}
|
||||
catch (Exception) { }
|
||||
finally
|
||||
{
|
||||
DataGriduser.ItemsSource = MainWindowViewModel._userData.DefaultView;
|
||||
_Name.Text = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ namespace SunlightAggregationManager.UserWindow
|
||||
/// </summary>
|
||||
public partial class UserSet : Window
|
||||
{
|
||||
public UserSet()
|
||||
public UserSet(string id)
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<UserControl x:Class="SunlightAggregationManager.View.ExtendPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:SunlightAggregationManager.View"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 SunlightAggregationManager.View
|
||||
{
|
||||
/// <summary>
|
||||
/// ExtendPage.xaml 的交互逻辑
|
||||
/// </summary>
|
||||
public partial class ExtendPage : UserControl
|
||||
{
|
||||
public ExtendPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -105,7 +105,7 @@
|
||||
Binding="{Binding LastOfflineTime}" MinWidth="300" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.Groups}" Width="200" FontSize="26"
|
||||
Binding="{Binding Groups}" MinWidth="200" CanUserReorder="False"/>
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="*" FontSize="26"
|
||||
<DataGridTextColumn Header="{x:Static lang:ResourceLanguage.information}" Width="auto" FontSize="26"
|
||||
Binding="{Binding Note}" MinWidth="200" CanUserReorder="False"/>
|
||||
|
||||
</DataGrid.Columns>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using SunlightAggregationManager.UserClass;
|
||||
using SunlightAggregationManager.UserWindow;
|
||||
using SunlightAggregationManager.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -47,7 +48,8 @@ namespace SunlightAggregationManager.View
|
||||
|
||||
private void MenuItem_Information(object sender, RoutedEventArgs e)//信息
|
||||
{
|
||||
|
||||
User userSet =new User();
|
||||
userSet.Show();
|
||||
}
|
||||
|
||||
private async void MenuItem_Offine(object sender, RoutedEventArgs e)//下线
|
||||
@@ -79,9 +81,6 @@ namespace SunlightAggregationManager.View
|
||||
{
|
||||
MainWindowViewModel.Updata_Memory(MainWindowViewModel._userData, "User='" + user_id + "'", "99", "State");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -84,8 +84,10 @@ namespace SunlightAggregationManager.ViewModel
|
||||
row["State"] = 0;
|
||||
row["LinkID"] = 0;
|
||||
}
|
||||
|
||||
Machines.RowChanged += Machines_Updata;
|
||||
UserData.RowChanged += UserData_Updata;//注册userdata表更新事件
|
||||
UserData.RowDeleting += UserData_Updata;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -210,7 +212,45 @@ namespace SunlightAggregationManager.ViewModel
|
||||
SQLiteHelpers.InsertData("ActionLog", userlog);
|
||||
}
|
||||
}
|
||||
public static void Insert_Memory(DataTable DB, Dictionary<string, object> Value)//插入数据
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (DB)
|
||||
{
|
||||
DataRow drEmployee = DB.NewRow();
|
||||
drEmployee.BeginEdit();
|
||||
|
||||
foreach (KeyValuePair<string, object> kvp in Value)
|
||||
{
|
||||
drEmployee[kvp.Key] = kvp.Value;
|
||||
}
|
||||
drEmployee.EndEdit();
|
||||
DB.Rows.Add(drEmployee);
|
||||
drEmployee.AcceptChanges();
|
||||
// drEmployee.ClearErrors();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Insert_Row:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static void Delete_Memory(DataTable DB, string? key)//删除数据
|
||||
{
|
||||
try
|
||||
{
|
||||
lock (DB)
|
||||
{
|
||||
DataRow drEmployee = DB.Select(key).First();
|
||||
drEmployee.Delete();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Delete_Row:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
public static DataRow? Selet_Row(DataTable DB, string? key)//查询
|
||||
{
|
||||
try
|
||||
@@ -294,5 +334,6 @@ namespace SunlightAggregationManager.ViewModel
|
||||
Console.WriteLine("SDTD:" + ex.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user