Browse Source

物料管理添加

master
pry 1 year ago
parent
commit
d9b7884d47
24 changed files with 999 additions and 143 deletions
  1. +1
    -4
      BPA.Model/BPA.Model.csproj
  2. +5
    -5
      BPA.Model/RawMaterInfo.cs
  3. +26
    -0
      BPA.Model/RawMaterResult.cs
  4. +15
    -0
      BPA.Model/SqlBase.cs
  5. +36
    -0
      BPA.Model/Table/RawMaterTB.cs
  6. +30
    -0
      BPA.Model/Table/RecipeTB.cs
  7. +1
    -1
      BPA.Model/ViewItem.cs
  8. +3
    -2
      BPA.SingleDevice/App.xaml
  9. +3
    -3
      BPA.SingleDevice/App.xaml.cs
  10. +8
    -0
      BPA.SingleDevice/BPA.SingleDevice.csproj
  11. +2
    -2
      BPA.SingleDevice/Converter/GetIconConverter.cs
  12. +2
    -2
      BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs
  13. +338
    -0
      BPA.SingleDevice/Helper/SqlHelper.cs
  14. +127
    -0
      BPA.SingleDevice/Interface/ISqlHelper.cs
  15. +1
    -1
      BPA.SingleDevice/Themes/Generic.xaml
  16. +48
    -0
      BPA.SingleDevice/View/AddRawMaterialDialogView.xaml
  17. +28
    -0
      BPA.SingleDevice/View/AddRawMaterialDialogView.xaml.cs
  18. +57
    -10
      BPA.SingleDevice/View/MainView.xaml
  19. +4
    -3
      BPA.SingleDevice/View/MainView.xaml.cs
  20. +91
    -89
      BPA.SingleDevice/View/RawMaterialManagementView.xaml
  21. +23
    -11
      BPA.SingleDevice/View/RecipeManagementView.xaml
  22. +47
    -0
      BPA.SingleDevice/ViewModel/AddRawMaterialDialogViewModel.cs
  23. +7
    -7
      BPA.SingleDevice/ViewModel/MainViewModel.cs
  24. +96
    -3
      BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs

+ 1
- 4
BPA.Model/BPA.Model.csproj View File

@@ -8,10 +8,7 @@

<ItemGroup>
<PackageReference Include="BPA.Communication" Version="1.0.142" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPA.UIControl\BPA.UIControl.csproj" />
<PackageReference Include="Rubyer" Version="2.11.9" />
</ItemGroup>

</Project>

+ 5
- 5
BPA.Model/RawMaterInfo.cs View File

@@ -17,7 +17,7 @@ namespace BPA.Model
/// <param name="dNum">原料对应设备编号</param>
/// <param name="wNum">原料对应设备的料仓编号</param>
/// <param name="lm">最后修改时间</param>
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
/// <summary>
/// 设备编号
/// </summary>
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;

/// <summary>
/// 设备料仓编号
/// </summary>
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;

/// <summary>
/// 最后修改时间


+ 26
- 0
BPA.Model/RawMaterResult.cs View File

@@ -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;

}
}

+ 15
- 0
BPA.Model/SqlBase.cs View File

@@ -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; }
}
}

+ 36
- 0
BPA.Model/Table/RawMaterTB.cs View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.Model.Table
{
/// <summary>
/// 物料表
/// </summary>
public class RawMaterTB : SqlBase
{

/// <summary>
/// 原料名称
/// </summary>
public string Name { get; set; }

/// <summary>
/// 设备编号
/// </summary>
public int DeviceNum { get; set; }

/// <summary>
/// 设备料仓编号
/// </summary>
public int WarehouseNum { get; set; }

/// <summary>
/// 最后修改时间
/// </summary>
public string LastModified { get; set; }

}
}

+ 30
- 0
BPA.Model/Table/RecipeTB.cs View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.Model.Table
{
/// <summary>
/// 配方表
/// </summary>
public class RecipeTB : SqlBase
{

/// <summary>
/// 原料ID
/// </summary>
public string RawMaterId { get; set; }

/// <summary>
/// 配方名称
/// </summary>
public string Name { get; set; }

/// <summary>
/// 创建时间
/// </summary>
public DateTime CreateDate { get; set; }
}
}

+ 1
- 1
BPA.Model/ViewItem.cs View File

@@ -1,5 +1,5 @@
using BPA.Helper;
using BPA.UIControl;
using Rubyer;
using System;
using System.Collections.Generic;
using System.Linq;


+ 3
- 2
BPA.SingleDevice/App.xaml View File

@@ -6,8 +6,9 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/BPA.UIControl;component/Themes/Resources/I18N/zh-CN.xaml" />
<ResourceDictionary Source="/BPA.UIControl;component/Themes/Generic.xaml" />
<!--<ResourceDictionary Source="/BPA.UIControl;component/Themes/Resources/I18N/zh-CN.xaml" />-->
<!--<ResourceDictionary Source="/BPA.UIControl;component/Themes/Generic.xaml" />-->
<ResourceDictionary Source="pack://application:,,,/Rubyer;component/Themes/Generic.xaml" />
<ResourceDictionary Source="/BPA.SingleDevice;component/Themes/ThemesColor.xaml" />
<ResourceDictionary Source="/BPA.SingleDevice;component/Themes/Generic.xaml" />
</ResourceDictionary.MergedDictionaries>


+ 3
- 3
BPA.SingleDevice/App.xaml.cs View File

@@ -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();
}


+ 8
- 0
BPA.SingleDevice/BPA.SingleDevice.csproj View File

@@ -7,8 +7,16 @@
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Rubyer" Version="2.11.9" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BPA.Model\BPA.Model.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Business\" />
</ItemGroup>

</Project>

+ 2
- 2
BPA.SingleDevice/Converter/GetIconConverter.cs View File

@@ -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;


+ 2
- 2
BPA.SingleDevice/Converter/IsSelectedToIconConverter.cs View File

@@ -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
{


+ 338
- 0
BPA.SingleDevice/Helper/SqlHelper.cs View File

@@ -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<OperateResult> AddAsync<T>(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<OperateResult> UpdateAsync<T>(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<RawMaterTB>().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<OperateResult> UpdateRecipeAsync(RecipeTB data)
//{
// try
// {
// if (Db == null) return new OperateResult("DB 实例为空");
// var model = await Db.Queryable<RecipeTB>().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<OperateResult> DeleteAsync<T>(string id) where T : SqlBase, new()
{
try
{
if (Db == null) return new OperateResult("DB 实例为空");
var removeList = await Db.Queryable<T>().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<OperateResult<List<T>>> GetListAsync<T>()
{
OperateResult<List<T>> result = new OperateResult<List<T>>();
try
{
if (Db == null) return new OperateResult<List<T>>("DB 实例为空");
result.Content = await Db.Queryable<T>().ToListAsync();
result.IsSuccess = true;
}
catch (Exception ex)
{
MessageLog.GetInstance.Show(ex.ToString());
result.SetMsg(ex.ToString());
}
return result;
}

public async Task<OperateResult<List<RawMaterTB>>> GetRecipeDetailInfoAsync(string recipeName)
{
OperateResult<List<RawMaterTB>> result = new OperateResult<List<RawMaterTB>>();
try
{
if (Db == null) return new OperateResult<List<RawMaterTB>>("DB 实例为空");
result.Content = await Db.Queryable<RawMaterTB>().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<OperateResult> 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<OperateResult> 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<OperateResult> DeleteRawMater(string id)
//{
// try
// {
// if (Db == null) return new OperateResult("DB 实例为空");
// var removeList = await Db.Queryable<RawMaterTB>().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<OperateResult> 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<OperateResult> 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<OperateResult> DeleteRecipe(string id)
//{
// try
// {
// if (Db == null) return new OperateResult("DB 实例为空");
// var removeList = await Db.Queryable<RecipeTB>().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<OperateResult<List<RawMaterTB>>> GetRawMaterList()
//{
// OperateResult<List<RawMaterTB>> result = new OperateResult<List<RawMaterTB>>();
// try
// {
// if (Db == null) return new OperateResult<List<RawMaterTB>>("DB 实例为空");
// result.Content = await Db.Queryable<RawMaterTB>().ToListAsync();
// result.IsSuccess = true;
// }
// catch (Exception ex)
// {
// MessageLog.GetInstance.Show(ex.ToString());
// result.SetMsg(ex.ToString());
// }
// return result;
//}

//public async Task<OperateResult<List<RecipeTB>>> GetRecipeList()
//{
// OperateResult<List<RecipeTB>> result = new OperateResult<List<RecipeTB>>();
// try
// {
// if (Db == null) return new OperateResult<List<RecipeTB>>("DB 实例为空");
// result.Content = await Db.Queryable<RecipeTB>().ToListAsync();
// result.IsSuccess = true;
// }
// catch (Exception ex)
// {
// MessageLog.GetInstance.Show(ex.ToString());
// result.SetMsg(ex.ToString());
// }
// return result;
//}


}
}

+ 127
- 0
BPA.SingleDevice/Interface/ISqlHelper.cs View File

@@ -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; }

/// <summary>
/// 初始化
/// </summary>
/// <param name="dt">数据库类型</param>
/// <param name="connectStr">数据库连接字符串</param>
/// <returns></returns>
OperateResult Init(DbType dt = DbType.Sqlite, string connectStr = "");

/// <summary>
/// 添加数据
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="data"></param>
/// <returns></returns>
Task<OperateResult> AddAsync<T>(T data) where T : class, new();

/// <summary>
/// 更新信息
/// </summary>
/// <param name="data"></param>
/// <returns></returns>
Task<OperateResult> UpdateAsync<T>(T data) where T : SqlBase, new();

/// <summary>
/// 移除数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
Task<OperateResult> DeleteAsync<T>(string id) where T : SqlBase, new();

/// <summary>
/// 获取所有数据
/// </summary>
/// <returns></returns>
Task<OperateResult<List<T>>> GetListAsync<T>();

/// <summary>
/// 根据配方名称获取配方物料详细信息
/// </summary>
/// <param name="recipeName"></param>
/// <returns></returns>
Task<OperateResult<List<RawMaterTB>>> GetRecipeDetailInfoAsync(string recipeName);





///// <summary>
///// 添加原料
///// </summary>
///// <param name="rm"></param>
///// <returns></returns>
//Task<OperateResult> AddRawMater(RawMaterTB rm);

///// <summary>
///// 更新原料信息
///// </summary>
///// <param name="rm"></param>
///// <returns></returns>
//Task<OperateResult> UpdateRawMater(RawMaterTB rm);

///// <summary>
///// 删除原料信息
///// </summary>
///// <param name="id"></param>
///// <returns></returns>
//Task<OperateResult> DeleteRawMater(string id);



///// <summary>
///// 添加配方
///// </summary>
///// <param name="rtb"></param>
///// <returns></returns>
//Task<OperateResult> AddRecipe(RecipeTB rtb);

///// <summary>
///// 更新原料信息
///// </summary>
///// <param name="rtb"></param>
///// <returns></returns>
//Task<OperateResult> UpdateRecipe(RecipeTB rtb);

///// <summary>
///// 删除原料信息
///// </summary>
///// <param name="id"></param>
///// <returns></returns>
//Task<OperateResult> DeleteRecipe(string id);


///// <summary>
///// 获取所有原料信息
///// </summary>
///// <returns></returns>
//Task<OperateResult<List<RawMaterTB>>> GetRawMaterList();

///// <summary>
///// 获取所有配方信息
///// </summary>
///// <returns></returns>
//Task<OperateResult<List<RecipeTB>>> GetRecipeList();


}
}

+ 1
- 1
BPA.SingleDevice/Themes/Generic.xaml View File

@@ -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">
<Style TargetType="{x:Type controls:ControlDisplay}">
<Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
<Setter Property="HorizontalContentAlignment" Value="Center" />


+ 48
- 0
BPA.SingleDevice/View/AddRawMaterialDialogView.xaml View File

@@ -0,0 +1,48 @@
<UserControl x:Class="BPA.SingleDevice.View.AddRawMaterialDialogView"
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:vm="clr-namespace:BPA.SingleDevice.ViewModel"
xmlns:ui="http://rubyer.io/winfx/xaml/toolkit"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="500">

<UserControl.DataContext>
<vm:AddRawMaterialDialogViewModel/>
</UserControl.DataContext>

<Grid Margin="10" ui:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="130"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>

<TextBlock Grid.Row="0" FontSize="16" Foreground="#ddd" HorizontalAlignment="Right" Grid.Column="0" Text="原料名称:"/>
<TextBox Grid.Row="0" Grid.Column="1" Width="200" Style="{StaticResource DarkTextBox}" Text="{Binding RawMaterResultInfo.Name}" />

<TextBlock Grid.Row="1" FontSize="16" Foreground="#ddd" HorizontalAlignment="Right" Grid.Column="0" Text="设备编号:"/>
<ComboBox Grid.Row="1" Grid.Column="1" ItemsSource="{Binding DeviceNums}" SelectedIndex="0" Text="{Binding RawMaterResultInfo.DeviceNum}" />

<TextBlock Grid.Row="2" FontSize="16" Foreground="#ddd" HorizontalAlignment="Right" Grid.Column="0" Text="设备料仓编号:"/>
<ComboBox Grid.Row="2" Grid.Column="1" ItemsSource="{Binding ChNum}" SelectedIndex="0" Text="{Binding RawMaterResultInfo.ChNum}" />

<Grid Margin="0 5" Grid.Row="3" Grid.ColumnSpan="2" ui:PanelHelper.Spacing="10">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0" Content="确认" Command="{Binding SaveCommand}"/>
<Button Grid.Column="1" Content="取消"/>
</Grid>

</Grid>
</UserControl>

+ 28
- 0
BPA.SingleDevice/View/AddRawMaterialDialogView.xaml.cs View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 BPA.SingleDevice.View
{
/// <summary>
/// AddRawMaterialDialogView.xaml 的交互逻辑
/// </summary>
public partial class AddRawMaterialDialogView : UserControl
{
public AddRawMaterialDialogView()
{
InitializeComponent();
}
}
}

+ 57
- 10
BPA.SingleDevice/View/MainView.xaml View File

@@ -1,4 +1,4 @@
<Window
<ui:RubyerWindow
x:Class="BPA.SingleDevice.View.MainView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -6,25 +6,26 @@
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"
Title="味魔方自动配料系统"
Width="1200"
Topmost="True"
Height="800"
Background="Transparent"
TitleBackground="#2d2d2d"
TitleHeight="40"
Topmost="True"
WindowStartupLocation="CenterScreen"
mc:Ignorable="d">

<Window.DataContext>
<ui:RubyerWindow.DataContext>
<vm:MainViewModel />
</Window.DataContext>
</ui:RubyerWindow.DataContext>


<Grid>

<!--#region 菜单栏设置-->
<ui:HamburgerMenu
<!--<ui:HamburgerMenu
ui:ControlHelper.CornerRadius="0"
ui:ControlHelper.FocusedBrush="{DynamicResource Dark}"
ui:ControlHelper.FocusedForegroundBrush="{StaticResource WhiteForeground}"
@@ -67,7 +68,8 @@
Content="{Binding MainContent}"
Header="配方管理"
IconType="NewspaperFill" />
<!--<ui:HamburgerMenuItem
-->
<!--<ui:HamburgerMenuItem
Command="{Binding SelecteCommand}"
CommandParameter="{Binding Content, RelativeSource={RelativeSource Self}}"
Content="自定义"
@@ -76,8 +78,53 @@
<Image Source="..\rubyer.ico" />
</ui:HamburgerMenuItem.Icon>
</ui:HamburgerMenuItem>-->
</ui:HamburgerMenu>
<!--
</ui:HamburgerMenu>-->
<!--#endregion-->

<ui:HamburgerMenu
ui:ControlHelper.CornerRadius="0"
ui:ControlHelper.FocusedBrush="{DynamicResource Dark}"
ui:ControlHelper.SelectedBrush="{DynamicResource Dark}"
ui:HeaderHelper.FontSize="{Binding FontSize, RelativeSource={RelativeSource Self}}"
ui:HeaderHelper.Foreground="{DynamicResource WhiteForeground}"
ui:ItemsControlHelper.ItemMargin="0"
ui:ItemsControlHelper.ItemPadding="5 3"
Background="#2d2d2d"
ExpandedWidth="170"
Foreground="{DynamicResource WhiteForeground}"
Header="Controls"
ItemsSource="{Binding ViewItems}"
PaneBackground="{Binding TitleBackground, RelativeSource={RelativeSource AncestorType=ui:RubyerWindow}}"
SelectedItem="{Binding CurrentViewItem}"
TransitionDuration="0:0:0.7"
TransitionType="Fade">
<ui:HamburgerMenu.Resources>
<Grid
x:Key="headContent"
Height="30"
x:Shared="false">
<TextBlock Text="{Binding Name}" />
</Grid>
</ui:HamburgerMenu.Resources>
<ui:HamburgerMenu.ItemContainerStyle>
<Style TargetType="ui:HamburgerMenuItem">
<Setter Property="DataContext" Value="{Binding}" />
<Setter Property="IconType" Value="{Binding Icon}" />
<Setter Property="Header" Value="{StaticResource headContent}" />
</Style>
</ui:HamburgerMenu.ItemContainerStyle>
<ui:HamburgerMenu.ContentTemplate>
<DataTemplate>
<Border Background="{DynamicResource DefaultBackground}">
<ContentControl Margin="0" Content="{Binding Content}" />
</Border>
</DataTemplate>
</ui:HamburgerMenu.ContentTemplate>
</ui:HamburgerMenu>



</Grid>

</Window>
</ui:RubyerWindow>

+ 4
- 3
BPA.SingleDevice/View/MainView.xaml.cs View File

@@ -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
/// <summary>
/// MainView.xaml 的交互逻辑
/// </summary>
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);
}
}
}

+ 91
- 89
BPA.SingleDevice/View/RawMaterialManagementView.xaml View File

@@ -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 @@
<UserControl.DataContext>
<vm:RawMaterialManagementViewModel />
</UserControl.DataContext>
<ui:DialogContainer>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>

<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>

<!--#region 功能按钮-->
<StackPanel
Grid.Row="0"
Margin="10"
HorizontalAlignment="Right"
ui:PanelHelper.Spacing="15"
Orientation="Horizontal">
<Button
<!--#region 功能按钮-->
<StackPanel
Grid.Row="0"
Margin="10"
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Content="添加原料"
Style="{DynamicResource DarkButton}" />
ui:PanelHelper.Spacing="15"
Orientation="Horizontal">
<Button
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Content="添加原料"
Style="{DynamicResource DarkButton}" />

<Button
HorizontalAlignment="Right"
Command="{Binding SaveCommand}"
Content="保存修改"
Style="{DynamicResource SuccessButton}" />
</StackPanel>
<!--<Button
HorizontalAlignment="Right"
Command="{Binding SaveCommand}"
Content="保存修改"
Style="{DynamicResource SuccessButton}" />-->
</StackPanel>

<!--#endregion-->
<!--#endregion-->

<!--#region 列表-->
<controls:ControlDisplay Grid.Row="1">
<DataGrid
Grid.Row="1"
AutoGenerateColumns="False"
BorderBrush="Gray"
BorderThickness="1"
CanUserAddRows="False"
GridLinesVisibility="All"
IsReadOnly="True"
ItemsSource="{Binding RawMaterInfos}"
RowHeight="35"
SelectionMode="Single">
<!--<DataGrid.RowHeaderTemplate>
<!--#region 列表-->
<controls:ControlDisplay Grid.Row="1">
<DataGrid
Grid.Row="1"
AutoGenerateColumns="False"
BorderBrush="Gray"
BorderThickness="1"
CanUserAddRows="False"
GridLinesVisibility="All"
IsReadOnly="True"
ItemsSource="{Binding RawMaterInfos}"
RowHeight="35"
SelectionMode="Single">
<!--<DataGrid.RowHeaderTemplate>
<DataTemplate>
<Border>
<TextBlock HorizontalAlignment="Center" Text="{Binding RelativeSource={RelativeSource AncestorType=DataGridRow}, Converter={StaticResource DataGridRowIndexConverter}}" />
</Border>
</DataTemplate>
</DataGrid.RowHeaderTemplate>-->
<DataGrid.Columns>
<DataGridTextColumn
Width="*"
Binding="{Binding Name}"
Header="原料名称" />
<DataGridTextColumn
Width="100"
Binding="{Binding DeviceNum}"
Header="设备编号" />
<DataGridTextColumn
Width="120"
Binding="{Binding WarehouseNum}"
Header="设备料仓编号" />
<DataGridTextColumn
Width="180"
Binding="{Binding LastModified}"
Header="最后修改时间" />
<DataGridTemplateColumn Width="150" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<ui:Icon Type="Edit2Fill" />
</Button>
<Button
Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<ui:Icon Type="CopyleftFill" />
</Button>
<Button
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Style="{StaticResource TextErrorButton}">
<ui:Icon Type="DeleteBinFill" />
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</controls:ControlDisplay>
<!--#endregion-->
<DataGrid.Columns>
<DataGridTextColumn
Width="*"
Binding="{Binding Name}"
Header="原料名称" />
<DataGridTextColumn
Width="100"
Binding="{Binding DeviceNum}"
Header="设备编号" />
<DataGridTextColumn
Width="120"
Binding="{Binding WarehouseNum}"
Header="设备料仓编号" />
<DataGridTextColumn
Width="180"
Binding="{Binding LastModified}"
Header="最后修改时间" />
<DataGridTemplateColumn Width="150" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<ui:Icon Type="Edit2Fill" />
</Button>
<Button
Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Foreground="#2196F3"
Style="{StaticResource TextButton}">
<ui:Icon Type="CopyleftFill" />
</Button>
<Button
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}"
CommandParameter="{Binding Id}"
Style="{StaticResource TextErrorButton}">
<ui:Icon Type="DeleteBinFill" />
</Button>
</StackPanel>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</controls:ControlDisplay>
<ui:MessageContainer Grid.Row="1" Identifier="RawMaterialManagementView" />
<!--#endregion-->

</Grid>
</Grid>
</ui:DialogContainer>
</UserControl>

+ 23
- 11
BPA.SingleDevice/View/RecipeManagementView.xaml View File

@@ -1,22 +1,34 @@
<UserControl x:Class="BPA.SingleDevice.View.RecipeManagementView"
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:controls="clr-namespace:BPA.SingleDevice.Controls"
xmlns:local="clr-namespace:BPA.SingleDevice.View"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<UserControl
x:Class="BPA.SingleDevice.View.RecipeManagementView"
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: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="http://rubyer.io/winfx/xaml/toolkit"
xmlns:vm="clr-namespace:BPA.SingleDevice.ViewModel"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">

<UserControl.DataContext>
<vm:RecipeManagementViewModel/>
</UserControl.DataContext>

<Grid>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="50"
Background="Transparent"
FontSize="50"
Foreground="White"
Text="配方管理" />

<controls:ControlDisplay Width="500" Height="100" Grid.Row="1" >
<controls:ControlDisplay
Grid.Row="1"
Width="500"
Height="100">
<!--<DataGrid x:Name="DataGrid2" Height="180" AutoGenerateColumns="True" CanUserAddRows="False" ItemsSource="{Binding Weathers}" />-->
</controls:ControlDisplay>



+ 47
- 0
BPA.SingleDevice/ViewModel/AddRawMaterialDialogViewModel.cs View File

@@ -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<object> RequestClose;

public void OnDialogOpened(object parameters)
{
if (parameters is RawMaterResult rm) RawMaterResultInfo = rm;
//var par = (IParameters)parameters;
//RawMaterResultInfo = par.GetValue<RawMaterResult>("RawMaterResultInfo");
}

public ObservableCollection<int> DeviceNums { get; set; } = new ObservableCollection<int>();
public ObservableCollection<int> ChNum { get; set; } = new ObservableCollection<int>();

public RawMaterResult RawMaterResultInfo { get { return _mRawMaterResultInfo; } set { _mRawMaterResultInfo = value; OnPropertyChanged(); } }
private RawMaterResult _mRawMaterResultInfo = new RawMaterResult();

public BPARelayCommand SaveCommand { get; set; }
}
}

+ 7
- 7
BPA.SingleDevice/ViewModel/MainViewModel.cs View File

@@ -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<ViewItem>
//{
// new ViewItem("原料管理", "总览", new RawMaterialManagementView(), IconType.Home2Line),
// new ViewItem("设备管理", "按钮", new DeviceManagementView(), IconType.CheckboxBlankFill),
// new ViewItem("配方管理", "文本框", new RecipeManagementView(), IconType.TBoxLine),
//};
ViewItems = new ObservableCollection<ViewItem>
{
new ViewItem("原料管理", "总览", new RawMaterialManagementView(), IconType.Home2Line),
new ViewItem("设备管理", "按钮", new DeviceManagementView(), IconType.CheckboxBlankFill),
new ViewItem("配方管理", "文本框", new RecipeManagementView(), IconType.TBoxLine),
};

SelecteCommand = new BPARelayCommand<object>(DoNavChanged);
}


+ 96
- 3
BPA.SingleDevice/ViewModel/RawMaterialManagementViewModel.cs View File

@@ -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<RawMaterTB>().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<object>(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<object>(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<RawMaterTB>(o.ToString()).OnSuccess(() =>
{
RawMaterInfos.RemoveAt(index);
}).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); });
}
}
}
});

}

public ObservableCollection<RawMaterInfo> RawMaterInfos { get; set; } = new ObservableCollection<RawMaterInfo>();


Loading…
Cancel
Save