diff --git a/BPA.Model/BPA.Model.csproj b/BPA.Model/BPA.Model.csproj index 3e23012..f656a9e 100644 --- a/BPA.Model/BPA.Model.csproj +++ b/BPA.Model/BPA.Model.csproj @@ -8,10 +8,7 @@ - - - - + diff --git a/BPA.Model/RawMaterInfo.cs b/BPA.Model/RawMaterInfo.cs index 4f5b7ed..17eabc6 100644 --- a/BPA.Model/RawMaterInfo.cs +++ b/BPA.Model/RawMaterInfo.cs @@ -17,7 +17,7 @@ namespace BPA.Model /// 原料对应设备编号 /// 原料对应设备的料仓编号 /// 最后修改时间 - public RawMaterInfo(string id, string name, string dNum, string wNum, string lm) + public RawMaterInfo(string id, string name, int dNum, int wNum, string lm) { Id = id; Name = name; @@ -41,14 +41,14 @@ namespace BPA.Model /// /// 设备编号 /// - public string DeviceNum { get { return _mDeviceNum; } set { _mDeviceNum = value; OnPropertyChanged(); } } - private string _mDeviceNum; + public int DeviceNum { get { return _mDeviceNum; } set { _mDeviceNum = value; OnPropertyChanged(); } } + private int _mDeviceNum; /// /// 设备料仓编号 /// - public string WarehouseNum { get { return _mWarehouseNum; } set { _mWarehouseNum = value; OnPropertyChanged(); } } - private string _mWarehouseNum; + public int WarehouseNum { get { return _mWarehouseNum; } set { _mWarehouseNum = value; OnPropertyChanged(); } } + private int _mWarehouseNum; /// /// 最后修改时间 diff --git a/BPA.Model/RawMaterResult.cs b/BPA.Model/RawMaterResult.cs new file mode 100644 index 0000000..8801bff --- /dev/null +++ b/BPA.Model/RawMaterResult.cs @@ -0,0 +1,26 @@ +using BPA.Helper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.Model +{ + public class RawMaterResult : NotifyBase + { + + public string Id { get; set; } + + public int DeviceNum { get { return _mDeviceNum; } set { _mDeviceNum = value; OnPropertyChanged(); } } + private int _mDeviceNum; + + public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } } + private string _mName; + + + public int ChNum { get { return _mChNum; } set { _mChNum = value; OnPropertyChanged(); } } + private int _mChNum; + + } +} diff --git a/BPA.Model/SqlBase.cs b/BPA.Model/SqlBase.cs new file mode 100644 index 0000000..b1a4620 --- /dev/null +++ b/BPA.Model/SqlBase.cs @@ -0,0 +1,15 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.Model +{ + public class SqlBase + { + [SugarColumn(IsPrimaryKey = true)]//设置主键 + public string Id { get; set; } + } +} diff --git a/BPA.Model/Table/RawMaterTB.cs b/BPA.Model/Table/RawMaterTB.cs new file mode 100644 index 0000000..fee22f5 --- /dev/null +++ b/BPA.Model/Table/RawMaterTB.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.Model.Table +{ + /// + /// 物料表 + /// + public class RawMaterTB : SqlBase + { + + /// + /// 原料名称 + /// + public string Name { get; set; } + + /// + /// 设备编号 + /// + public int DeviceNum { get; set; } + + /// + /// 设备料仓编号 + /// + public int WarehouseNum { get; set; } + + /// + /// 最后修改时间 + /// + public string LastModified { get; set; } + + } +} diff --git a/BPA.Model/Table/RecipeTB.cs b/BPA.Model/Table/RecipeTB.cs new file mode 100644 index 0000000..437cb5e --- /dev/null +++ b/BPA.Model/Table/RecipeTB.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.Model.Table +{ + /// + /// 配方表 + /// + public class RecipeTB : SqlBase + { + + /// + /// 原料ID + /// + public string RawMaterId { get; set; } + + /// + /// 配方名称 + /// + public string Name { get; set; } + + /// + /// 创建时间 + /// + public DateTime CreateDate { get; set; } + } +} diff --git a/BPA.Model/ViewItem.cs b/BPA.Model/ViewItem.cs index 45efce4..410a061 100644 --- a/BPA.Model/ViewItem.cs +++ b/BPA.Model/ViewItem.cs @@ -1,5 +1,5 @@ using BPA.Helper; -using BPA.UIControl; +using Rubyer; using System; using System.Collections.Generic; using System.Linq; diff --git a/BPA.SingleDevice/App.xaml b/BPA.SingleDevice/App.xaml index a5a658e..4632726 100644 --- a/BPA.SingleDevice/App.xaml +++ b/BPA.SingleDevice/App.xaml @@ -6,8 +6,9 @@ - - + + + diff --git a/BPA.SingleDevice/App.xaml.cs b/BPA.SingleDevice/App.xaml.cs index 0ac7082..3c03c46 100644 --- a/BPA.SingleDevice/App.xaml.cs +++ b/BPA.SingleDevice/App.xaml.cs @@ -1,5 +1,5 @@ -using BPA.SingleDevice.View; -using BPA.UIControl; +using BPA.SingleDevice.Helper; +using BPA.SingleDevice.View; using System; using System.Collections.Generic; using System.Configuration; @@ -18,7 +18,7 @@ namespace BPA.SingleDevice protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); - + SqlHelper.GetInstance.Init(); MainView mv = new MainView(); mv.Show(); } diff --git a/BPA.SingleDevice/BPA.SingleDevice.csproj b/BPA.SingleDevice/BPA.SingleDevice.csproj index fc9bbb6..49a8708 100644 --- a/BPA.SingleDevice/BPA.SingleDevice.csproj +++ b/BPA.SingleDevice/BPA.SingleDevice.csproj @@ -7,8 +7,16 @@ true + + + + + + + + diff --git a/BPA.SingleDevice/Converter/GetIconConverter.cs b/BPA.SingleDevice/Converter/GetIconConverter.cs index f3a0118..8c3ad4f 100644 --- a/BPA.SingleDevice/Converter/GetIconConverter.cs +++ b/BPA.SingleDevice/Converter/GetIconConverter.cs @@ -1,5 +1,5 @@ -using BPA.UIControl.Commons; -using BPA.UIControl; +using Rubyer; +using Rubyer.Commons; using System; using System.Collections.Generic; using System.Globalization; diff --git a/BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs b/BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs index b700acc..48f093f 100644 --- a/BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs +++ b/BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs @@ -1,5 +1,4 @@ -using BPA.UIControl; -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -7,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Data; using System.Windows; +using Rubyer; namespace BPA.SingleDevice.Converter { diff --git a/BPA.SingleDevice/Helper/SqlHelper.cs b/BPA.SingleDevice/Helper/SqlHelper.cs new file mode 100644 index 0000000..a28aa6e --- /dev/null +++ b/BPA.SingleDevice/Helper/SqlHelper.cs @@ -0,0 +1,338 @@ +using BPA.Helper; +using BPA.Model; +using BPA.Model.Table; +using BPA.SingleDevice.Interface; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SingleDevice.Helper +{ + public class SqlHelper : ISqlHelper + { + private volatile static SqlHelper _Instance; + public static ISqlHelper GetInstance => _Instance ?? (_Instance = new SqlHelper()); + private SqlHelper() { } + + static string path + { + get + { + Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory); + return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AccessFile\\DB\\SingleDevice.db"); + } + } + + public DbType TempDbType { get; set; } = DbType.Sqlite; + public string ConnectionStr { get; set; } = $"Data Source={path}"; + public SqlSugarScope Db { get; set; } + + public OperateResult Init(DbType dt = DbType.Sqlite, string connectStr = "") + { + try + { + TempDbType = dt; + if (!string.IsNullOrEmpty(connectStr)) ConnectionStr = connectStr; + if (Db == null) + Db = new SqlSugarScope(new ConnectionConfig() + { + ConnectionString = ConnectionStr, + DbType = TempDbType, + IsAutoCloseConnection = true,//设置自动关闭连接 + }); + + string spnaName = "BPA.Model.Table";//实体类的命名空间 + Type[] ass = Assembly.LoadFrom(AppContext.BaseDirectory + "BPA.Model.dll").GetTypes().Where(p => p.Namespace == spnaName).ToArray(); + + if (TempDbType == DbType.Sqlite && File.Exists(path)) return new OperateResult(true); + + //创建数据库 + Db.DbMaintenance.CreateDatabase(); + + //创建数据表 + Db.CodeFirst.SetStringDefaultLength(200).InitTables(ass); + + return new OperateResult(true); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + return new OperateResult(ex.ToString()); + } + } + + public async Task AddAsync(T data) where T : class, new() + { + try + { + if (Db == null) return new OperateResult("DB 实例为空"); + var res = await Db.Insertable(data).ExecuteCommandAsync() > 0; + return new OperateResult(res); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + return new OperateResult(ex.ToString()); + } + } + + public async Task UpdateAsync(T data) where T : SqlBase, new() + { + try + { + if (Db == null) return new OperateResult("DB 实例为空"); + var res = await Db.Updateable(data).ExecuteCommandAsync() > 0; + return new OperateResult(res); + //var model = await Db.Queryable().FirstAsync(p => p.Id == data.Id); + //if (model != null) + //{ + // model.Name = data.Name; + // model.DeviceNum = data.DeviceNum; + // model.WarehouseNum = data.WarehouseNum; + // model.LastModified = data.LastModified; + // var res = await Db.Updateable(data).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + //} + //else + //{ + // return new OperateResult("未找到需要更新的信息"); + //} + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + return new OperateResult(ex.ToString()); + } + } + + //public async Task UpdateRecipeAsync(RecipeTB data) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var model = await Db.Queryable().FirstAsync(p => p.Id == data.Id); + // if (model != null) + // { + // model.Name = data.Name; + // var res = await Db.Updateable(model).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + // } + // else + // { + // return new OperateResult("未找到需要更新的信息"); + // } + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + public async Task DeleteAsync(string id) where T : SqlBase, new() + { + try + { + if (Db == null) return new OperateResult("DB 实例为空"); + var removeList = await Db.Queryable().FirstAsync(p => p.Id == id); + if (removeList != null) + { + var res = await Db.Deleteable(removeList).ExecuteCommandHasChangeAsync(); + return new OperateResult(res); + } + else + { + return new OperateResult("未找到需要移除的信息"); + } + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + return new OperateResult(ex.ToString()); + } + } + + public async Task>> GetListAsync() + { + OperateResult> result = new OperateResult>(); + try + { + if (Db == null) return new OperateResult>("DB 实例为空"); + result.Content = await Db.Queryable().ToListAsync(); + result.IsSuccess = true; + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + result.SetMsg(ex.ToString()); + } + return result; + } + + public async Task>> GetRecipeDetailInfoAsync(string recipeName) + { + OperateResult> result = new OperateResult>(); + try + { + if (Db == null) return new OperateResult>("DB 实例为空"); + result.Content = await Db.Queryable().Where(p => p.Name == recipeName).ToListAsync(); + result.IsSuccess = true; + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + result.SetMsg(ex.ToString()); + } + return result; + } + + + + //public async Task AddRawMater(RawMaterTB rm) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var res = await Db.Insertable(rm).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task UpdateRawMater(RawMaterTB rm) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var res = await Db.Updateable(rm).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task DeleteRawMater(string id) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var removeList = await Db.Queryable().FirstAsync(p => p.Id == id); + // if (removeList != null) + // { + // var res = await Db.Deleteable(removeList).ExecuteCommandHasChangeAsync(); + // return new OperateResult(res); + // } + // else + // { + // return new OperateResult("未找到需要移除的信息"); + // } + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task AddRecipe(RecipeTB rtb) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var res = await Db.Insertable(rtb).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task UpdateRecipe(RecipeTB rtb) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var res = await Db.Updateable(rtb).ExecuteCommandAsync() > 0; + // return new OperateResult(res); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task DeleteRecipe(string id) + //{ + // try + // { + // if (Db == null) return new OperateResult("DB 实例为空"); + // var removeList = await Db.Queryable().FirstAsync(p => p.Id == id); + // if (removeList != null) + // { + // var res = await Db.Deleteable(removeList).ExecuteCommandHasChangeAsync(); + // return new OperateResult(res); + // } + // else + // { + // return new OperateResult("未找到需要移除的信息"); + // } + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // return new OperateResult(ex.ToString()); + // } + //} + + //public async Task>> GetRawMaterList() + //{ + // OperateResult> result = new OperateResult>(); + // try + // { + // if (Db == null) return new OperateResult>("DB 实例为空"); + // result.Content = await Db.Queryable().ToListAsync(); + // result.IsSuccess = true; + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // result.SetMsg(ex.ToString()); + // } + // return result; + //} + + //public async Task>> GetRecipeList() + //{ + // OperateResult> result = new OperateResult>(); + // try + // { + // if (Db == null) return new OperateResult>("DB 实例为空"); + // result.Content = await Db.Queryable().ToListAsync(); + // result.IsSuccess = true; + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // result.SetMsg(ex.ToString()); + // } + // return result; + //} + + + } +} diff --git a/BPA.SingleDevice/Interface/ISqlHelper.cs b/BPA.SingleDevice/Interface/ISqlHelper.cs new file mode 100644 index 0000000..5bf8ff3 --- /dev/null +++ b/BPA.SingleDevice/Interface/ISqlHelper.cs @@ -0,0 +1,127 @@ +using BPA.Helper; +using BPA.Model; +using BPA.Model.Table; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPA.SingleDevice.Interface +{ + public interface ISqlHelper + { + public DbType TempDbType { get; set; } + + public string ConnectionStr { get; set; } + + public SqlSugarScope Db { get; set; } + + /// + /// 初始化 + /// + /// 数据库类型 + /// 数据库连接字符串 + /// + OperateResult Init(DbType dt = DbType.Sqlite, string connectStr = ""); + + /// + /// 添加数据 + /// + /// + /// + /// + Task AddAsync(T data) where T : class, new(); + + /// + /// 更新信息 + /// + /// + /// + Task UpdateAsync(T data) where T : SqlBase, new(); + + /// + /// 移除数据 + /// + /// + /// + Task DeleteAsync(string id) where T : SqlBase, new(); + + /// + /// 获取所有数据 + /// + /// + Task>> GetListAsync(); + + /// + /// 根据配方名称获取配方物料详细信息 + /// + /// + /// + Task>> GetRecipeDetailInfoAsync(string recipeName); + + + + + + ///// + ///// 添加原料 + ///// + ///// + ///// + //Task AddRawMater(RawMaterTB rm); + + ///// + ///// 更新原料信息 + ///// + ///// + ///// + //Task UpdateRawMater(RawMaterTB rm); + + ///// + ///// 删除原料信息 + ///// + ///// + ///// + //Task DeleteRawMater(string id); + + + + ///// + ///// 添加配方 + ///// + ///// + ///// + //Task AddRecipe(RecipeTB rtb); + + ///// + ///// 更新原料信息 + ///// + ///// + ///// + //Task UpdateRecipe(RecipeTB rtb); + + ///// + ///// 删除原料信息 + ///// + ///// + ///// + //Task DeleteRecipe(string id); + + + ///// + ///// 获取所有原料信息 + ///// + ///// + //Task>> GetRawMaterList(); + + ///// + ///// 获取所有配方信息 + ///// + ///// + //Task>> GetRecipeList(); + + + } +} diff --git a/BPA.SingleDevice/Themes/Generic.xaml b/BPA.SingleDevice/Themes/Generic.xaml index 5ef5c8e..4b7e50f 100644 --- a/BPA.SingleDevice/Themes/Generic.xaml +++ b/BPA.SingleDevice/Themes/Generic.xaml @@ -2,7 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:BPA.SingleDevice.Controls" - xmlns:ui="clr-namespace:BPA.UIControl;assembly=BPA.UIControl"> + xmlns:ui="http://rubyer.io/winfx/xaml/toolkit"> + + + + + + + + + + + + - + diff --git a/BPA.SingleDevice/View/MainView.xaml.cs b/BPA.SingleDevice/View/MainView.xaml.cs index 95e3738..75a4ea3 100644 --- a/BPA.SingleDevice/View/MainView.xaml.cs +++ b/BPA.SingleDevice/View/MainView.xaml.cs @@ -1,4 +1,5 @@ -using BPA.UIControl; +using Rubyer; +using Rubyer.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -18,7 +19,7 @@ namespace BPA.SingleDevice.View /// /// MainView.xaml 的交互逻辑 /// - public partial class MainView : Window + public partial class MainView : RubyerWindow { public MainView() { @@ -28,7 +29,7 @@ namespace BPA.SingleDevice.View private void MainView_Loaded(object sender, RoutedEventArgs e) { - ThemeManager.SwitchThemeMode(UIControl.Enums.ThemeMode.Dark); + ThemeManager.SwitchThemeMode(ThemeMode.Dark); } } } diff --git a/BPA.SingleDevice/View/RawMaterialManagementView.xaml b/BPA.SingleDevice/View/RawMaterialManagementView.xaml index 05c836d..de09d7f 100644 --- a/BPA.SingleDevice/View/RawMaterialManagementView.xaml +++ b/BPA.SingleDevice/View/RawMaterialManagementView.xaml @@ -6,7 +6,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:BPA.SingleDevice.View" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:ui="clr-namespace:BPA.UIControl;assembly=BPA.UIControl" + xmlns:ui="http://rubyer.io/winfx/xaml/toolkit" xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel" d:DesignHeight="450" d:DesignWidth="800" @@ -15,104 +15,106 @@ + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - + + diff --git a/BPA.SingleDevice/View/RecipeManagementView.xaml b/BPA.SingleDevice/View/RecipeManagementView.xaml index ce85497..c44925f 100644 --- a/BPA.SingleDevice/View/RecipeManagementView.xaml +++ b/BPA.SingleDevice/View/RecipeManagementView.xaml @@ -1,22 +1,34 @@ - + + + + + + - + diff --git a/BPA.SingleDevice/ViewModel/AddRawMaterialDialogViewModel.cs b/BPA.SingleDevice/ViewModel/AddRawMaterialDialogViewModel.cs new file mode 100644 index 0000000..0fd73e8 --- /dev/null +++ b/BPA.SingleDevice/ViewModel/AddRawMaterialDialogViewModel.cs @@ -0,0 +1,47 @@ +using BPA.Helper; +using Rubyer; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.ObjectModel; +using BPA.Model; +using Rubyer.Models; + +namespace BPA.SingleDevice.ViewModel +{ + public class AddRawMaterialDialogViewModel : NotifyBase, IDialogDataContext + { + public AddRawMaterialDialogViewModel() + { + for (int i = 1; i <= 4; i++) { DeviceNums.Add(i); } + for (int i = 1; i <= 14; i++) { ChNum.Add(i); } + SaveCommand = new BPARelayCommand(() => + { + //var par = new Parameters(); + //par.Add("RawMaterResultInfo", RawMaterResultInfo); + RequestClose?.Invoke(RawMaterResultInfo); + }); + } + + public string Title => "添加原料"; + + public event Action RequestClose; + + public void OnDialogOpened(object parameters) + { + if (parameters is RawMaterResult rm) RawMaterResultInfo = rm; + //var par = (IParameters)parameters; + //RawMaterResultInfo = par.GetValue("RawMaterResultInfo"); + } + + public ObservableCollection DeviceNums { get; set; } = new ObservableCollection(); + public ObservableCollection ChNum { get; set; } = new ObservableCollection(); + + public RawMaterResult RawMaterResultInfo { get { return _mRawMaterResultInfo; } set { _mRawMaterResultInfo = value; OnPropertyChanged(); } } + private RawMaterResult _mRawMaterResultInfo = new RawMaterResult(); + + public BPARelayCommand SaveCommand { get; set; } + } +} diff --git a/BPA.SingleDevice/ViewModel/MainViewModel.cs b/BPA.SingleDevice/ViewModel/MainViewModel.cs index 0403c74..f963170 100644 --- a/BPA.SingleDevice/ViewModel/MainViewModel.cs +++ b/BPA.SingleDevice/ViewModel/MainViewModel.cs @@ -1,7 +1,7 @@ using BPA.Helper; using BPA.Model; using BPA.SingleDevice.View; -using BPA.UIControl; +using Rubyer; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -17,12 +17,12 @@ namespace BPA.SingleDevice.ViewModel { public MainViewModel() { - //ViewItems = new ObservableCollection - //{ - // new ViewItem("原料管理", "总览", new RawMaterialManagementView(), IconType.Home2Line), - // new ViewItem("设备管理", "按钮", new DeviceManagementView(), IconType.CheckboxBlankFill), - // new ViewItem("配方管理", "文本框", new RecipeManagementView(), IconType.TBoxLine), - //}; + ViewItems = new ObservableCollection + { + new ViewItem("原料管理", "总览", new RawMaterialManagementView(), IconType.Home2Line), + new ViewItem("设备管理", "按钮", new DeviceManagementView(), IconType.CheckboxBlankFill), + new ViewItem("配方管理", "文本框", new RecipeManagementView(), IconType.TBoxLine), + }; SelecteCommand = new BPARelayCommand(DoNavChanged); } diff --git a/BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs b/BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs index c882050..38ae170 100644 --- a/BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs +++ b/BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs @@ -6,6 +6,14 @@ using System.Text; using System.Threading.Tasks; using System.Collections.ObjectModel; using BPA.Model; +using System.Diagnostics; +using BPA.SingleDevice.View; +using Rubyer.Models; +using Rubyer; +using NetTaste; +using BPA.SingleDevice.Helper; +using BPA.Model.Table; +using Microsoft.EntityFrameworkCore.Metadata.Conventions; namespace BPA.SingleDevice.ViewModel { @@ -13,10 +21,95 @@ namespace BPA.SingleDevice.ViewModel { public RawMaterialManagementViewModel() { - for (int i = 0; i < 10; i++) + SqlHelper.GetInstance.GetListAsync().Result.OnSuccess(s => { - RawMaterInfos.Add(new RawMaterInfo(i.ToString(), i.ToString(), i.ToString(), i.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); - } + s.ForEach(item => + { + RawMaterInfos.Add(new RawMaterInfo(item.Id, item.Name, item.DeviceNum, item.WarehouseNum, item.LastModified)); + }); + }); + + AddCommand = new BPARelayCommand(async () => + { + var content = new AddRawMaterialDialogView(); + var para = await Dialog.Show(content, new Parameters(), "添加原料", (d) => { }, (d, o) => + { + if (o is RawMaterResult rm) + { + string id = Guid.NewGuid().ToString(); + string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + SqlHelper.GetInstance.AddAsync(new RawMaterTB() + { + Id = id, + Name = rm.Name, + DeviceNum = rm.DeviceNum, + WarehouseNum = rm.ChNum, + LastModified = time + }).Result.OnSuccess(() => + { + RawMaterInfos.Add(new RawMaterInfo(id, rm.Name, rm.DeviceNum, rm.ChNum, time)); + }).OnFail(s => { Message.Error("RawMaterialManagementView", $"添加失败:{s}"); }); + } + }); + }); + + EditCommand = new BPARelayCommand(async (o) => + { + if (o != null && !string.IsNullOrEmpty(o.ToString())) + { + var index = RawMaterInfos.ToList().FindIndex(p => p.Id == o.ToString()); + if (index >= 0) + { + var para = await Dialog.Show(new AddRawMaterialDialogView(), new RawMaterResult() + { + Name = RawMaterInfos[index].Name, + DeviceNum = RawMaterInfos[index].DeviceNum, + ChNum = RawMaterInfos[index].WarehouseNum, + Id = RawMaterInfos[index].Id, + }, "原料编辑", (d) => { }, (d, o) => + { + if (o is RawMaterResult rm) + { + string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + SqlHelper.GetInstance.UpdateAsync(new RawMaterTB() + { + Id = RawMaterInfos[index].Id, + Name = rm.Name, + DeviceNum = rm.DeviceNum, + WarehouseNum = rm.ChNum, + LastModified = time + }).Result.OnSuccess(() => + { + RawMaterInfos[index].Name = rm.Name; + RawMaterInfos[index].DeviceNum = rm.DeviceNum; + RawMaterInfos[index].WarehouseNum = rm.ChNum; + RawMaterInfos[index].LastModified = time; + }).OnFail(s => { Message.Error("RawMaterialManagementView", $"修改失败:{s}"); }); + } + }); + } + } + }); + + RemoveCommand = new BPARelayCommand(async (o) => + { + if (o != null && !string.IsNullOrEmpty(o.ToString())) + { + var index = RawMaterInfos.ToList().FindIndex(p => p.Id == o.ToString()); + if (index >= 0) + { + var result = await MessageBoxR.Confirm("是否删除改数据?"); + if (result == System.Windows.MessageBoxResult.Yes) + { + SqlHelper.GetInstance.DeleteAsync(o.ToString()).OnSuccess(() => + { + RawMaterInfos.RemoveAt(index); + }).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); }); + } + } + } + }); + } public ObservableCollection RawMaterInfos { get; set; } = new ObservableCollection();