Browse Source

配方修改

master
pry 1 year ago
parent
commit
8fde2b48a1
4 changed files with 237 additions and 18 deletions
  1. +35
    -0
      BPA.Model/RecipeInfo.cs
  2. +1
    -0
      BPA.SingleDevice/View/RawMaterialManagementView.xaml
  3. +89
    -16
      BPA.SingleDevice/View/RecipeManagementView.xaml
  4. +112
    -2
      BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs

+ 35
- 0
BPA.Model/RecipeInfo.cs View File

@@ -0,0 +1,35 @@
using BPA.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;

namespace BPA.Model
{
public class RecipeInfo : NotifyBase
{
/// <summary>
/// 配方ID
/// </summary>
public string Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } }
private string _mId;

/// <summary>
/// 配方名称
/// </summary>
public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } }
private string _mName;

/// <summary>
/// 原料名称集合
/// </summary>
public ObservableCollection<string> RawMaters { get; set; } = new ObservableCollection<string>();

/// <summary>
/// 原料id列表
/// </summary>
public List<string> RawMaterIds { get; set; } = new List<string>();
}
}

+ 1
- 0
BPA.SingleDevice/View/RawMaterialManagementView.xaml View File

@@ -15,6 +15,7 @@
<UserControl.DataContext>
<vm:RawMaterialManagementViewModel />
</UserControl.DataContext>

<ui:DialogContainer>
<Grid Margin="10">
<Grid.RowDefinitions>


+ 89
- 16
BPA.SingleDevice/View/RecipeManagementView.xaml View File

@@ -13,24 +13,97 @@
mc:Ignorable="d">

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

<Grid>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
Background="Transparent"
FontSize="50"
Foreground="White"
Text="配方管理" />
<ui:DialogContainer>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition />
</Grid.RowDefinitions>

<controls:ControlDisplay
Grid.Row="1"
Width="500"
Height="100">
<!--<DataGrid x:Name="DataGrid2" Height="180" AutoGenerateColumns="True" CanUserAddRows="False" ItemsSource="{Binding Weathers}" />-->
</controls:ControlDisplay>
<!--#region 功能按钮-->
<StackPanel
Grid.Row="0"
Margin="10"
HorizontalAlignment="Right"
ui:PanelHelper.Spacing="15"
Orientation="Horizontal">
<Button
HorizontalAlignment="Right"
Command="{Binding AddCommand}"
Content="添加原料"
Style="{DynamicResource DarkButton}" />
</StackPanel>

<!--#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.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>
</ui:DialogContainer>

</Grid>
</UserControl>

+ 112
- 2
BPA.SingleDevice/ViewModel/RecipeManagementViewModel.cs View File

@@ -1,12 +1,122 @@
using System;
using BPA.Helper;
using BPA.Model.Table;
using BPA.Model;
using BPA.SingleDevice.Helper;
using BPA.SingleDevice.View;
using Rubyer.Models;
using Rubyer;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPA.SingleDevice.ViewModel
{
internal class RecipeManagementViewModel
public class RecipeManagementViewModel : NotifyBase
{
public RecipeManagementViewModel()
{

SqlHelper.GetInstance.GetListAsync<RecipeTB>().Result.OnSuccess(s =>
{
s.ForEach(item =>
{
RawMaterInfos.Add(new RecipeInfo() { });
});
});

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<RecipeInfo> RawMaterInfos { get; set; } = new ObservableCollection<RecipeInfo>();

public BPARelayCommand AddCommand { get; set; }
public BPARelayCommand<object> CopyCommand { get; set; }
public BPARelayCommand<object> EditCommand { get; set; }
public BPARelayCommand<object> RemoveCommand { get; set; }


}
}

Loading…
Cancel
Save