Browse Source

添加用户权限管理

master
sc 9 months ago
parent
commit
04f0798c17
  1. 6
      App.xaml.cs
  2. 21
      MainWindow.xaml
  3. 20
      MainWindow.xaml.cs
  4. 1
      SunlightCentralizedControlManagement_SCCM_.csproj
  5. 4
      View/ProductionPlanningView.xaml
  6. 61
      View/ProductionPlanningView.xaml.cs
  7. 35
      ViewModel/MainWindowViewModel.cs
  8. 96
      ViewModel/ProductionPlanningModel.cs
  9. 8
      ViewModel/ViewModelLocator.cs
  10. 2
      WindowsView/User.xaml.cs

6
App.xaml.cs

@ -172,9 +172,9 @@ namespace SunlightCentralizedControlManagement_SCCM_
/// 启动初始页面
/// </summary>
private void Application_Startup(object sender, StartupEventArgs e)
{
// Application.Current.StartupUri = new Uri("Login.xaml", UriKind.Relative);
Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录
{
Current.StartupUri = new Uri("Login.xaml", UriKind.Relative);
//Current.StartupUri = new Uri("MainWindow.xaml", UriKind.Relative);//和MainWindwo同一目录
}
public static class SystemSleepTool

21
MainWindow.xaml

@ -10,6 +10,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
mc:Ignorable="d"
Loaded="Window_Loaded"
Title="SUNLIGHT SCCM b0.0.1 (2024/08/10)"
Height="1080" Width="1920" Background="#FF003640"
WindowState ="Maximized" WindowStyle="None">
@ -41,11 +42,19 @@
<Grid x:Name="GridTitle" Height="50" VerticalAlignment="Top" Background="#FF006361" MouseDown="GridTitle_MouseDown" Margin="60,0,0,0">
<TextBlock Text="Sunlight Centralized Control Management (SCCM)" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="22" Foreground="White"/>
<StackPanel VerticalAlignment="Center" Orientation="Horizontal" HorizontalAlignment="Right">
<ComboBox x:Name="username" VerticalAlignment="Center" FontSize="14" DropDownClosed="username_DropDownClosed" HorizontalAlignment="Right" Margin="0,0,5,0" Width="100" Foreground="White">
<ComboBox.ItemContainerStyle>
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="Foreground" Value="Black">
</Setter>
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
<TextBlock Text="{Binding Sys_Time}" VerticalAlignment="Center" FontSize="14" Foreground="White"/>
<materialDesign:PopupBox Foreground="White" Margin="10" PlacementMode="BottomAndAlignRightEdges" StaysOpen="False">
<StackPanel Width="150">
<Button Content="{x:Static lang:Resources.USER}" Click="ButtonUSER_Click"/>
<Button Content="{x:Static lang:Resources.SysSet}" Click="ButtonSYS_Click"/>
<Button Content="{x:Static lang:Resources.USER}" Click="ButtonUSER_Click" x:Name="User_" IsEnabled="{Binding USER_Capacity[1]}"/>
<Button Content="{x:Static lang:Resources.SysSet}" Click="ButtonSYS_Click" x:Name="SysSet_" IsEnabled="{Binding USER_Capacity[0]}"/>
<Separator/>
<Button Content="{x:Static lang:Resources.Permit}" Click="ButtonPermit_Click"/>
<Button Content="{x:Static lang:Resources.Help}" Click="Buttonhelp_Click"/>
@ -87,25 +96,25 @@
<TextBlock Text="{x:Static lang:Resources.ProductionPlanning}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Curve">
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Curve" IsEnabled="{Binding USER_Capacity[9]}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="ChartBellCurve" Width="25" Height="25" Margin="10" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.Curve}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Machine">
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Machine" IsEnabled="{Binding USER_Capacity[2]}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Settings" Width="25" Height="25" Margin="10" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.Machine}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Programgroup">
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_Programgroup" IsEnabled="{Binding USER_Capacity[9]}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Database" Width="25" Height="25" Margin="10" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.Programgroup}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>
</StackPanel>
</ListViewItem>
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_ConveyorCenters">
<ListViewItem Height="60" MouseLeftButtonUp="ListViewItem_ConveyorCenters" IsEnabled="{Binding USER_Capacity[12]}">
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Kind="Pipe" Width="25" Height="25" Margin="10" VerticalAlignment="Center"/>
<TextBlock Text="{x:Static lang:Resources.ConveyorCenters}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>

20
MainWindow.xaml.cs

@ -1,7 +1,9 @@
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.ViewModel;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
@ -17,6 +19,7 @@ using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Tab;
namespace SunlightCentralizedControlManagement_SCCM_
@ -29,9 +32,9 @@ namespace SunlightCentralizedControlManagement_SCCM_
public MainWindow()
{
DataContext = new MainWindowViewModel();
InitializeComponent();
InitializeComponent();
CountDown();
CDkey_();
CDkey_();
}
private void ButtonPopUpLogout_Click(object sender, RoutedEventArgs e)
@ -196,6 +199,19 @@ namespace SunlightCentralizedControlManagement_SCCM_
}
}
private void username_DropDownClosed(object sender, EventArgs e)
{
MainWindowViewModel.USERCapacity(username.Text);
}
private void Window_Loaded(object sender, RoutedEventArgs e)//打开页面
{
username.ItemsSource = MainWindowViewModel.USER_data.Select(
"Groups='" + MainWindowViewModel.USER_data.Select("Name='" + App.USER_Purview + "'").
First().Field<string>("Groups").ToString() + "'").
AsEnumerable().Select(rowdata => rowdata.Field<string>("Name")).ToList();
username.Text = App.USER_Purview;
}
}
}

1
SunlightCentralizedControlManagement_SCCM_.csproj

@ -123,7 +123,6 @@
<Compile Include="UserClass\StrToInt.cs" />
<Compile Include="UserClass\SubItem.cs" />
<Compile Include="UserClass\UserControlMenuItem.cs" />
<Compile Include="ViewModel\ProductionPlanningModel.cs" />
<Compile Include="ViewModel\CurveDiagramViewModel.cs" />
<Compile Include="ViewModel\MainWindowViewModel.cs" />
<Compile Include="ViewModel\ViewModelLocator.cs" />

4
View/ProductionPlanningView.xaml

@ -9,7 +9,7 @@
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:viewmodel="clr-namespace:SunlightCentralizedControlManagement_SCCM_.ViewModel"
xmlns:Ngantt="clr-namespace:nGantt;assembly=nGantt"
d:DataContext="{d:DesignInstance Type=viewmodel:ProductionPlanningModel}"
d:DataContext="{d:DesignInstance Type=viewmodel:MainWindowViewModel}"
mc:Ignorable="d" Loaded="UserControl_Loaded"
d:DesignHeight="900" d:DesignWidth="1800">
<UserControl.Resources>
@ -75,7 +75,7 @@
</StackPanel>
<StackPanel Grid.Row="1" Height="60" Background="#FF00204E" Orientation="Horizontal" HorizontalAlignment="Right">
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled" Foreground="#FF1368BD">
<ListViewItem Width="150" MouseLeftButtonUp="ListViewItem_New" x:Name="Quit">
<ListViewItem Width="150" MouseLeftButtonUp="ListViewItem_New" x:Name="Quit" IsEnabled="{Binding USER_Capacity[5]}">
<StackPanel Orientation="Horizontal" >
<materialDesign:PackIcon Kind="NewBox" Width="40" Height="30" Margin="10" VerticalAlignment="Center" Foreground="#FF1368BD"/>
<TextBlock Text="{x:Static lang:Resources.New}" VerticalAlignment="Center" Margin="20 10" Foreground="White"/>

61
View/ProductionPlanningView.xaml.cs

@ -54,7 +54,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
public ProductionPlanningView()
{
InitializeComponent();
DataContext = new ProductionPlanningModel();
Sdatepicker.Language = XmlLanguage.GetLanguage(Configini.IniReadvalue("SYS", "Language"));
CountDown();
}
@ -74,8 +73,8 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
ganttTaskContextMenuItems.Add(new ContextMenuItem(ViewClicked, Properties.Resources.View + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(AdvanceClicked, Properties.Resources.Advance + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(DelayedClicked, Properties.Resources.Delayed + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(EditClicked, Properties.Resources.edit + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(DeleteClicked, Properties.Resources.Delete + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(EditClicked, Properties.Resources.edit + "..."));
ganttTaskContextMenuItems.Add(new ContextMenuItem(DeleteClicked, Properties.Resources.Delete + "..."));
GanttChart.GanttTaskContextMenuItems = ganttTaskContextMenuItems;
GanttChartNEW();
@ -147,41 +146,47 @@ namespace SunlightCentralizedControlManagement_SCCM_.View
}
private void EditClicked(GanttTask ganttTask)
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
DataTable WorkOrder_dt = SQLiteHelpers.ExecuteDataSet(
"select * from WorkOrder where WorkOrder='" + ganttTask.ID + "'Order by StartTime", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
if (DateTime.Now > DateTime.Parse(WorkOrder_dt.Select().First().Field<object>("EndTime").ToString()))
if (MainWindowViewModel.USER_Capacity[6])
{
MessageBox.Show(Properties.Resources.EHCIP, "SCCM", MessageBoxButton.OK, MessageBoxImage.Warning);//禁止编辑历史工艺
}
else
{
if (WorkOrder_dt.Select().First().Field<object>("State").ToString() == "101")
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
DataTable WorkOrder_dt = SQLiteHelpers.ExecuteDataSet(
"select * from WorkOrder where WorkOrder='" + ganttTask.ID + "'Order by StartTime", null).Tables[0]; //读取表写入缓存
SQLiteHelpers.Close();
if (DateTime.Now > DateTime.Parse(WorkOrder_dt.Select().First().Field<object>("EndTime").ToString()))
{
Picture.Content = null;
Picture.Width = 600;
Picture.Content = new ProductionPlanningEdit(ganttTask.ID, true);
MessageBox.Show(Properties.Resources.EHCIP, "SCCM", MessageBoxButton.OK, MessageBoxImage.Warning);//禁止编辑历史工艺
}
else
else
{
MessageBox.Show(Properties.Resources.ENWOIP, "SCCM", MessageBoxButton.OK, MessageBoxImage.Warning);//禁止编辑非等待中的工单
if (WorkOrder_dt.Select().First().Field<object>("State").ToString() == "101")
{
Picture.Content = null;
Picture.Width = 600;
Picture.Content = new ProductionPlanningEdit(ganttTask.ID, true);
}
else
{
MessageBox.Show(Properties.Resources.ENWOIP, "SCCM", MessageBoxButton.OK, MessageBoxImage.Warning);//禁止编辑非等待中的工单
}
}
}
}//编辑
private void DeleteClicked(GanttTask ganttTask)//删除
{
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Delete + ganttTask.Name, "Delete ",
System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
if (MainWindowViewModel.USER_Capacity[7])
{
///执行删除
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("WorkOrder", "WorkOrder='" + ganttTask.ID + "'", null);
SQLiteHelpers.Close();
GanttChartNEW();
if (System.Windows.Forms.MessageBox.Show(Properties.Resources.Confirm + Properties.Resources.Delete + ganttTask.Name, "Delete ",
System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
{
///执行删除
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
SQLiteHelpers.Delete("WorkOrder", "WorkOrder='" + ganttTask.ID + "'", null);
SQLiteHelpers.Close();
GanttChartNEW();
}
}
}
private string FormatYear(Period period)

35
ViewModel/MainWindowViewModel.cs

@ -5,6 +5,7 @@ using Newtonsoft.Json.Linq;
using OpenTK.Graphics.ES11;
using SunlightCentralizedControlManagement_SCCM_.Properties;
using SunlightCentralizedControlManagement_SCCM_.UserClass;
using SunlightCentralizedControlManagement_SCCM_.WindowsView;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@ -65,20 +66,51 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
private SQLiteHelper SQLiteHelpers = null; //定义数据库
private readonly string DBAddress = Environment.CurrentDirectory + "\\DataBase\\SCCM.db"; //数据库路径
public static DataTable Machines = new DataTable(); //设备表缓存
public static DataTable USER_data = new DataTable();
public static UserControls.info[] inf = new UserControls.info[999]; //定义总览信息卡
public static int ERR_c = 0;//错误计数器
public static bool[] USER_Capacity { set; get; } = new bool[99];
public MainWindowViewModel()
{
SQLiteHelpers = new SQLiteHelper(DBAddress); //数据库连接路径
SQLiteHelpers.Open(); //打开数据库
Machines = SQLiteHelpers.ExecuteDataSet("select * from Machines Order by id", null).Tables[0]; //读取表写入缓存
USER_data = SQLiteHelpers.ExecuteDataSet("select * from USER order by Name desc", null).Tables[0];
SQLiteHelpers.Close();
USERCapacity(App.USER_Purview);//App.USER_Purview);
CountDown();
TcpClientNEW();
SQL_LINK();
}
public static void USERCapacity(string user) //权限
{
if (user != "ENGINEER")
{
string USER_Cap = USER_data.Select("Name='" + user + "'").First().Field<string>("Capacity").ToString();
for (int i = 0; i < USER_Cap.Length; i++)
{
if (USER_Cap.Substring(i, 1) == "1")
{
USER_Capacity[i] = true;
}
else
{
USER_Capacity[i] = false;
}
}
}
else
{
for (int i = 0; i < 99; i++)
{
USER_Capacity[i] = true;
}
}
}
public static async void SQL_LINK()//连接dbc数据库
{
if (conn_SC.State == ConnectionState.Open) conn_SC.Close();
@ -100,8 +132,7 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
LogGing.LogGingDATA("[Database='" + ex + "']=SQLSERVER");
ERR_c++;
}
}
}
public void CountDown()
{
DispatcherTimer timer1s = new DispatcherTimer//初始化循环,每1秒调用一次Tick

96
ViewModel/ProductionPlanningModel.cs

@ -1,96 +0,0 @@
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.SkiaSharpView.Painting;
using ScottPlot.Colormaps;
using System.Drawing;
using System.Windows.Media.TextFormatting;
using System.Xml.Linq;
using SkiaSharp;
using LiveChartsCore.Defaults;
using static System.Net.WebRequestMethods;
using System.Collections.ObjectModel;
using DyeingComputer.Properties;
using LiveChartsCore.Measure;
using LiveChartsCore.Motion;
using SunlightCentralizedControlManagement_SCCM_.Properties;
using static SunlightCentralizedControlManagement_SCCM_.UserClass.SqliteHelper;
using TouchSocket.Core;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using SunlightCentralizedControlManagement_SCCM_.View;
using LiveChartsCore.SkiaSharpView.Painting.Effects;
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using System.Windows.Documents;
using System.Reflection;
namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
{
public partial class ProductionPlanningModel : ObservableObject//ViewModelBase
{
//x轴时间格式
/* public Axis[] XAxes { get; set; } =
{
new DateTimeAxis(TimeSpan.FromSeconds(5) , date => date.ToString("yyyy-MM-dd HH:mm"))
{
CrosshairLabelsBackground = SKColors.DarkGray.AsLvcColor(),
CrosshairLabelsPaint = new SolidColorPaint(SKColors.DarkSlateBlue, 1),
CrosshairPaint = new SolidColorPaint(SKColors.DarkSlateGray, 1),
},
};
public Axis[] YAxes { get; set; } =
{
new Axis
{
MinLimit = 0,
// TextSize = 20,
LabelsDensity = 1,
Labels = MainWindowViewModel.Machines.AsEnumerable().Select(row=> row.Field<string>("name")).ToList(),//转换列名为机台
}
};
public ProductionPlanningModel()
{
var r = new Random();
var values1 = new ObservableCollection<ObservablePoint>();
for (var i = 0; i < 20; i++)
{
values1.Add(new ObservablePoint(r.Next(10, 20), r.Next(0, 20)));
}
Series = new ISeries[]
{
// use the second type parameter to specify the geometry to draw for every point
// there are already many predefined geometries in the
// LiveChartsCore.SkiaSharpView.Drawing.Geometries namespace
new ScatterSeries<ObservablePoint, RoundedRectangleGeometry>
{
Values = values1,
Stroke = null,
GeometrySize = 10,
},
// You can also use SVG paths to draw the geometry
// LiveCharts already provides some predefined paths in the SVGPoints class.
// you can declare your own gemetry and use the SkiaSharp api to draw it
};
}
public ISeries[] Series { get; set; } */
}
}

8
ViewModel/ViewModelLocator.cs

@ -29,12 +29,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.ViewModel
return ServiceLocator.Current.GetInstance<CurveDiagramViewModel>();
}
}
public ProductionPlanningModel Production
{
get
{
return ServiceLocator.Current.GetInstance<ProductionPlanningModel>();
}
}
}
}

2
WindowsView/User.xaml.cs

@ -90,8 +90,6 @@ namespace SunlightCentralizedControlManagement_SCCM_.WindowsView
string Group = GROUP.Text;
string Cap = null;
string note = Note.Text;
string t = null;
for (int i = 0; i < strings.Length; i++)
{
if ((bool)checkBoxes[i].IsChecked)

Loading…
Cancel
Save