@@ -0,0 +1,4 @@ | |||
[*.cs] | |||
# Default severity for all analyzer diagnostics | |||
dotnet_analyzer_diagnostic.severity = none |
@@ -0,0 +1,32 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.Model | |||
{ | |||
public enum EDeviceType : int | |||
{ | |||
/// <summary> | |||
/// 味魔方1 | |||
/// </summary> | |||
WeimoCube1 = 1, | |||
/// <summary> | |||
/// 味魔方2 | |||
/// </summary> | |||
WeimoCube2 = 2, | |||
/// <summary> | |||
/// 味魔方3 | |||
/// </summary> | |||
WeimoCube3 = 3, | |||
/// <summary> | |||
/// 味魔方4 | |||
/// </summary> | |||
WeimoCube4 = 4, | |||
/// <summary> | |||
/// 输送带 | |||
/// </summary> | |||
Conveyor = 5, | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Collections.Concurrent; | |||
namespace BPA.Model | |||
{ | |||
public class GlobalData | |||
{ | |||
public static ConcurrentQueue<GoodsModel> GoodsModels { get; set; } = new ConcurrentQueue<GoodsModel>(); | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
using BPA.Model.Table; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.Model | |||
{ | |||
public class GoodsModel | |||
{ | |||
/// <summary> | |||
/// 原料信息 | |||
/// </summary> | |||
public List<RawMaterModel> RawMaters { get; set; } = new List<RawMaterModel>(); | |||
} | |||
} |
@@ -16,6 +16,12 @@ namespace BPA.Model | |||
public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } } | |||
private string _mName; | |||
/// <summary> | |||
/// 原料需求量 | |||
/// </summary> | |||
public ushort Weight { get { return _mWeight; } set { _mWeight = value; OnPropertyChanged(); } } | |||
private ushort _mWeight; | |||
public bool IsChecked { get { return _mIsChecked; } set { _mIsChecked = value; OnPropertyChanged(); } } | |||
private bool _mIsChecked; | |||
@@ -0,0 +1,17 @@ | |||
using BPA.Model.Table; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.Model | |||
{ | |||
public class RawMaterModel : RawMaterTB | |||
{ | |||
/// <summary> | |||
/// 需求重量 | |||
/// </summary> | |||
public ushort Weight { get; set; } | |||
} | |||
} |
@@ -23,13 +23,36 @@ namespace BPA.Model | |||
private string _mName; | |||
/// <summary> | |||
/// 原料名称集合 | |||
/// 是否启用 | |||
/// </summary> | |||
public ObservableCollection<string> RawMaters { get; set; } = new ObservableCollection<string>(); | |||
public bool IsEnable | |||
{ | |||
get { return _mIsEnable; } | |||
set | |||
{ | |||
_mIsEnable = value; | |||
OnPropertyChanged(); | |||
EnableChange?.Invoke(Id); | |||
} | |||
} | |||
private bool _mIsEnable = true; | |||
/// <summary> | |||
/// 原料id列表 | |||
/// 最后修改时间 | |||
/// </summary> | |||
public List<string> RawMaterIds { get; set; } = new List<string>(); | |||
public string LastModified { get { return _mLastModified; } set { _mLastModified = value; OnPropertyChanged(); } } | |||
private string _mLastModified; | |||
public static Action<string> EnableChange { get; set; } | |||
///// <summary> | |||
///// 原料名称集合 | |||
///// </summary> | |||
//public ObservableCollection<string> RawMaters { get; set; } = new ObservableCollection<string>(); | |||
///// <summary> | |||
///// 原料id列表 | |||
///// </summary> | |||
//public List<string> RawMaterIds { get; set; } = new List<string>(); | |||
} | |||
} |
@@ -0,0 +1,32 @@ | |||
using BPA.Helper; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.Model | |||
{ | |||
public class RecipeModel : NotifyBase | |||
{ | |||
/// <summary> | |||
/// 配方名称 | |||
/// </summary> | |||
public string Name { get { return _mName; } set { _mName = value; OnPropertyChanged(); } } | |||
private string _mName; | |||
/// <summary> | |||
/// 配方ID | |||
/// </summary> | |||
public string Id { get { return _mId; } set { _mId = value; OnPropertyChanged(); } } | |||
private string _mId; | |||
/// <summary> | |||
/// 商品数量 | |||
/// </summary> | |||
public double Count { get { return _mCount; } set { _mCount = value; OnPropertyChanged(); } } | |||
private double _mCount; | |||
} | |||
} |
@@ -0,0 +1,29 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.Model.Table | |||
{ | |||
/// <summary> | |||
/// 配方数据表 | |||
/// </summary> | |||
public class RecipeRawMaterTB : SqlBase | |||
{ | |||
/// <summary> | |||
/// 配方ID | |||
/// </summary> | |||
public string RecipeId { get; set; } | |||
/// <summary> | |||
/// 原料ID | |||
/// </summary> | |||
public string RawMaterId { get; set; } | |||
/// <summary> | |||
/// 需求重量 | |||
/// </summary> | |||
public ushort Weight { get; set; } | |||
} | |||
} |
@@ -3,6 +3,7 @@ using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Windows.Documents; | |||
namespace BPA.Model.Table | |||
{ | |||
@@ -11,20 +12,20 @@ namespace BPA.Model.Table | |||
/// </summary> | |||
public class RecipeTB : SqlBase | |||
{ | |||
/// <summary> | |||
/// 原料ID | |||
/// 配方名称 | |||
/// </summary> | |||
public string RawMaterId { get; set; } | |||
public string Name { get; set; } | |||
/// <summary> | |||
/// 配方名称 | |||
/// 是否激活配方 | |||
/// </summary> | |||
public string Name { get; set; } | |||
public bool IsEnable { get; set; } | |||
/// <summary> | |||
/// 创建时间 | |||
/// 最后修改时间 | |||
/// </summary> | |||
public DateTime CreateDate { get; set; } | |||
public string LastModified { get; set; } | |||
} | |||
} |
@@ -5,10 +5,15 @@ VisualStudioVersion = 17.5.33414.496 | |||
MinimumVisualStudioVersion = 10.0.40219.1 | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPA.SingleDevice", "BPA.SingleDevice\BPA.SingleDevice.csproj", "{DA921F9F-BE4E-4553-9453-BC8B35DE0C50}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BPA.Model", "BPA.Model\BPA.Model.csproj", "{CC3E5D6F-AE46-4116-8326-EFF82685EF29}" | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPA.Model", "BPA.Model\BPA.Model.csproj", "{CC3E5D6F-AE46-4116-8326-EFF82685EF29}" | |||
EndProject | |||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BPA.UIControl", "BPA.UIControl\BPA.UIControl.csproj", "{19BBBC01-3914-43EA-8A71-0A5DA9D8AAE1}" | |||
EndProject | |||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1C56EB4D-1297-4B33-9408-FAB3D8EBCACF}" | |||
ProjectSection(SolutionItems) = preProject | |||
.editorconfig = .editorconfig | |||
EndProjectSection | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
@@ -1,4 +1,5 @@ | |||
using BPA.SingleDevice.Helper; | |||
using BPA.SingleDevice.Business; | |||
using BPA.SingleDevice.Helper; | |||
using BPA.SingleDevice.View; | |||
using System; | |||
using System.Collections.Generic; | |||
@@ -19,6 +20,7 @@ namespace BPA.SingleDevice | |||
{ | |||
base.OnStartup(e); | |||
SqlHelper.GetInstance.Init(); | |||
MainControl.GetInstance.Start(); | |||
MainView mv = new MainView(); | |||
mv.Show(); | |||
} | |||
@@ -26,6 +28,7 @@ namespace BPA.SingleDevice | |||
protected override void OnExit(ExitEventArgs e) | |||
{ | |||
base.OnExit(e); | |||
MainControl.GetInstance.Stop(); | |||
} | |||
} | |||
} |
@@ -8,15 +8,15 @@ | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<PackageReference Include="Rubyer" Version="2.11.9" /> | |||
<None Include="..\.editorconfig" Link=".editorconfig" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<ProjectReference Include="..\BPA.Model\BPA.Model.csproj" /> | |||
<PackageReference Include="Rubyer" Version="2.11.9" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Folder Include="Business\" /> | |||
<ProjectReference Include="..\BPA.Model\BPA.Model.csproj" /> | |||
</ItemGroup> | |||
</Project> |
@@ -0,0 +1,84 @@ | |||
using BPA.Communication; | |||
using BPA.SingleDevice.Interface; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using BPA.Helper; | |||
using BPA.Model; | |||
using BPA.SingleDevice.Helper; | |||
using System.Threading; | |||
namespace BPA.SingleDevice.Business | |||
{ | |||
public abstract class DeviceAbs : IDeviceAbs | |||
{ | |||
string IpAddress { get; set; } | |||
EDeviceType DeviceType { get; set; } | |||
public Action<EDeviceType> Complete { get; set; } | |||
ModbusTcp mt { get; set; } = new ModbusTcp(); | |||
public Action<int> ArrivalFingerPos { get; set; } | |||
public bool AllowBatching { get; set; } | |||
public bool[] DeviceStationDetection { get; set; } = new bool[4]; | |||
public void SetPar(string ip, EDeviceType deviceType) | |||
{ | |||
IpAddress = ip; | |||
DeviceType = deviceType; | |||
} | |||
public void Start() | |||
{ | |||
mt.WithModbusTcp(IpAddress).UseConnected(() => | |||
{ | |||
TaskManage.GetInstance.StartLong(new Action(() => | |||
{ | |||
if (DeviceType != EDeviceType.Conveyor) | |||
{ | |||
mt.Read<bool>("LB12").OnSuccess(s => | |||
{ | |||
if (RTrig.GetInstance(DeviceType.ToString()).Start(s)) | |||
{ | |||
Complete?.Invoke(DeviceType); | |||
} | |||
}); | |||
} | |||
else | |||
{ | |||
mt.Read<bool[]>("1", (ushort)DeviceStationDetection.Length).OnSuccess(s => | |||
{ | |||
for (int i = 0; i < s.Length; i++) | |||
{ | |||
DeviceStationDetection[i] = s[i]; | |||
if (RTrig.GetInstance($"输送带到位{i + 1}").Start(s[i])) | |||
{ | |||
ArrivalFingerPos?.Invoke(i + 1); | |||
} | |||
} | |||
}); | |||
AllowBatching = mt.Read<bool>("5").Content; | |||
} | |||
Thread.Sleep(1); | |||
}), DeviceType.ToString(), true); | |||
}); | |||
} | |||
public void Stop() | |||
{ | |||
TaskManage.GetInstance.StopTask(DeviceType.ToString()); | |||
} | |||
public void WriteControl(ushort[] value) | |||
{ | |||
mt.Write("LW30".ToModbusAdd(), value); | |||
mt.Write("LB10".ToModbusAdd(), true); | |||
} | |||
public void ConveyorControl(bool value) | |||
{ | |||
mt.Write("0", value); | |||
} | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using BPA.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SingleDevice.Business | |||
{ | |||
public class DeviceControl : DeviceAbs | |||
{ | |||
} | |||
} |
@@ -0,0 +1,86 @@ | |||
using BPA.SingleDevice.Interface; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Collections.Concurrent; | |||
using BPA.Communication; | |||
using BPA.Model; | |||
using BPA.Helper; | |||
using System.Threading; | |||
using Microsoft.Extensions.FileSystemGlobbing.Internal.PathSegments; | |||
namespace BPA.SingleDevice.Business | |||
{ | |||
public class MainControl : IMainControl | |||
{ | |||
private volatile static MainControl _Instance; | |||
public static IMainControl GetInstance => _Instance ?? (_Instance = new MainControl()); | |||
private MainControl() { } | |||
/// <summary> | |||
/// 通讯集合(key=1-4代表1号味魔方到4号味魔方,5为输送带的控制) | |||
/// </summary> | |||
ConcurrentDictionary<EDeviceType, IDeviceAbs> Comm { get; set; } = new ConcurrentDictionary<EDeviceType, IDeviceAbs>(); | |||
private void CommInit() | |||
{ | |||
Enum.GetNames(typeof(EDeviceType)).ToList().ForEach(x => { Comm.TryAdd(x.ToEnum<EDeviceType>(), new DeviceControl()); }); | |||
Comm[EDeviceType.WeimoCube1].SetPar("192.168.1.100", EDeviceType.WeimoCube1); | |||
Comm[EDeviceType.WeimoCube2].SetPar("192.168.1.100", EDeviceType.WeimoCube2); | |||
Comm[EDeviceType.WeimoCube3].SetPar("192.168.1.100", EDeviceType.WeimoCube3); | |||
Comm[EDeviceType.WeimoCube4].SetPar("192.168.1.100", EDeviceType.WeimoCube4); | |||
Comm[EDeviceType.Conveyor].SetPar("192.168.1.100", EDeviceType.Conveyor); | |||
Task.Run(() => | |||
{ | |||
Parallel.ForEach(Comm, (s) => { s.Value.Stop(); }); | |||
}); | |||
} | |||
public void Start() | |||
{ | |||
CommInit(); | |||
TaskManage.GetInstance.StartLong(() => | |||
{ | |||
while (GlobalData.GoodsModels.Count > 0 && !Comm[EDeviceType.Conveyor].AllowBatching) | |||
{ | |||
Task.Run(() => | |||
{ | |||
if (GlobalData.GoodsModels.TryDequeue(out GoodsModel gm)) | |||
{ | |||
var res = gm.RawMaters.GroupBy(p => p.DeviceNum).ToDictionary(p => p.Key, p => p.ToList()); | |||
res.ToList().ForEach(item => | |||
{ | |||
int index = item.Key - 1; | |||
if (index >= 0 && index < Comm[EDeviceType.Conveyor].DeviceStationDetection.Length) | |||
{ | |||
if (Comm[EDeviceType.Conveyor].DeviceStationDetection[index]) | |||
{ | |||
Comm[EDeviceType.Conveyor].ConveyorControl(false); | |||
ushort[] weights = new ushort[14]; | |||
item.Value.ForEach(s => | |||
{ | |||
int tempIndex = s.WarehouseNum - 1; | |||
if (tempIndex >= 0 && tempIndex < weights.Length) | |||
{ | |||
weights[tempIndex] = s.Weight; | |||
} | |||
}); | |||
Comm[(EDeviceType)item.Key].WriteControl(weights); | |||
} | |||
} | |||
}); | |||
} | |||
}); | |||
} | |||
Thread.Sleep(10); | |||
}, "配料任务", true); | |||
} | |||
public void Stop() | |||
{ | |||
} | |||
} | |||
} |
@@ -0,0 +1,79 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SingleDevice.Helper | |||
{ | |||
/// <summary> | |||
/// 地址转换类 | |||
/// </summary> | |||
internal static class ExtensionMethod | |||
{ | |||
/// <summary> | |||
/// Modbus 地址转换 | |||
/// </summary> | |||
/// <param name="address"></param> | |||
/// <returns></returns> | |||
public static string ToModbusAdd(this string address) | |||
{ | |||
if (address == null) return ""; | |||
if (address.Length > 0) | |||
{ | |||
address = address.Trim(); | |||
if (address.ToUpper().Contains("GM") && address.Length >= 3) | |||
{ | |||
var res = address.Remove(0, 2); | |||
if (res != null && res.Length > 0) return (int.Parse(res) + 4096).ToString(); | |||
} | |||
else if (address.ToUpper().Contains("M") && address.Length >= 4) | |||
{ | |||
var res = address.Substring(1).Split('.'); | |||
if (res != null && res.Length == 2) | |||
{ | |||
if (int.TryParse(res[0], out int firstAddress) && int.TryParse(res[1], out int ExitAddress)) | |||
{ | |||
if (ExitAddress >= 0 && ExitAddress <= 7) | |||
{ | |||
return ((firstAddress * 8) + 320 + ExitAddress).ToString(); | |||
} | |||
} | |||
} | |||
} | |||
else if (address.ToUpper().Contains("GI") && address.Length >= 3) | |||
{ | |||
var res = address.Remove(0, 2); | |||
if (res != null && res.Length > 0) return res; | |||
} | |||
else if (address.ToUpper().Contains("LB") && address.Length >= 3) | |||
{ | |||
var res = address.Substring(2); | |||
if (res != null && res.Length > 0) | |||
{ | |||
if (int.TryParse(res, out int firstAddress)) return firstAddress.ToString(); | |||
} | |||
} | |||
else if ((address.ToUpper().Contains("VW") || address.ToUpper().Contains("VD")) && address.Length >= 3) | |||
{ | |||
var res = address.Substring(2); | |||
if (res != null && int.TryParse(res, out int tempAddress)) | |||
{ | |||
return ((tempAddress / 2) + 100).ToString(); | |||
} | |||
} | |||
else if (address.ToUpper().Contains("LW") && address.Length >= 3) | |||
{ | |||
var res = address.Substring(2); | |||
if (res != null && int.TryParse(res, out int LwAddress)) | |||
{ | |||
return LwAddress.ToString(); | |||
} | |||
} | |||
} | |||
return ""; | |||
} | |||
} | |||
} |
@@ -81,6 +81,21 @@ namespace BPA.SingleDevice.Helper | |||
} | |||
} | |||
public async Task<OperateResult> AddAsync<T>(List<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 | |||
@@ -88,20 +103,6 @@ namespace BPA.SingleDevice.Helper | |||
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) | |||
{ | |||
@@ -110,36 +111,12 @@ namespace BPA.SingleDevice.Helper | |||
} | |||
} | |||
//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); | |||
var removeList = await Db.Queryable<T>().Where(p => p.Id == id).ToListAsync(); | |||
if (removeList != null) | |||
{ | |||
var res = await Db.Deleteable(removeList).ExecuteCommandHasChangeAsync(); | |||
@@ -191,148 +168,49 @@ namespace BPA.SingleDevice.Helper | |||
return result; | |||
} | |||
public async Task<OperateResult<List<RecipeRawMaterTB>>> GetRawMaterIds(string RecipeId) | |||
{ | |||
OperateResult<List<RecipeRawMaterTB>> result = new OperateResult<List<RecipeRawMaterTB>>(); | |||
try | |||
{ | |||
if (Db == null) return new OperateResult<List<RecipeRawMaterTB>>("DB 实例为空"); | |||
var res = await Db.Queryable<RecipeRawMaterTB>().Where(p => p.RecipeId == RecipeId).ToListAsync(); | |||
if (res != null) | |||
{ | |||
result.Content = res; | |||
result.IsSuccess = true; | |||
} | |||
else { result.SetMsg("查询数据为空"); } | |||
} | |||
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; | |||
//} | |||
public async Task<OperateResult> DeleteRawMaterAsync(string id) | |||
{ | |||
try | |||
{ | |||
if (Db == null) return new OperateResult("DB 实例为空"); | |||
var removeList = await Db.Queryable<RecipeRawMaterTB>().Where(p => p.RecipeId == id).ToListAsync(); | |||
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()); | |||
} | |||
} | |||
} | |||
} |
@@ -0,0 +1,54 @@ | |||
using BPA.Model; | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SingleDevice.Interface | |||
{ | |||
public interface IDeviceAbs | |||
{ | |||
void Start(); | |||
void Stop(); | |||
/// <summary> | |||
/// 输入控制参数 | |||
/// </summary> | |||
/// <param name="value"></param> | |||
void WriteControl(ushort[] value); | |||
/// <summary> | |||
/// 输送带控制 | |||
/// </summary> | |||
/// <param name="value"></param> | |||
void ConveyorControl(bool value); | |||
/// <summary> | |||
/// 味魔方配料完成通知 | |||
/// </summary> | |||
Action<EDeviceType> Complete { get; set; } | |||
/// <summary> | |||
/// 设备通讯参数设置 | |||
/// </summary> | |||
/// <param name="ip"></param> | |||
/// <param name="deviceType"></param> | |||
void SetPar(string ip, EDeviceType deviceType); | |||
/// <summary> | |||
/// 定位完成通知 | |||
/// </summary> | |||
Action<int> ArrivalFingerPos { get; set; } | |||
/// <summary> | |||
/// 允许配料 | |||
/// </summary> | |||
bool AllowBatching { get; set; } | |||
/// <summary> | |||
/// 设备工位检测 | |||
/// </summary> | |||
bool[] DeviceStationDetection { get; set; } | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
namespace BPA.SingleDevice.Interface | |||
{ | |||
public interface IMainControl | |||
{ | |||
void Start(); | |||
void Stop(); | |||
} | |||
} |
@@ -34,6 +34,14 @@ namespace BPA.SingleDevice.Interface | |||
/// <returns></returns> | |||
Task<OperateResult> AddAsync<T>(T data) where T : class, new(); | |||
/// <summary> | |||
/// 批量添加数据 | |||
/// </summary> | |||
/// <typeparam name="T"></typeparam> | |||
/// <param name="data"></param> | |||
/// <returns></returns> | |||
Task<OperateResult> AddAsync<T>(List<T> data) where T : class, new(); | |||
/// <summary> | |||
/// 更新信息 | |||
/// </summary> | |||
@@ -48,6 +56,13 @@ namespace BPA.SingleDevice.Interface | |||
/// <returns></returns> | |||
Task<OperateResult> DeleteAsync<T>(string id) where T : SqlBase, new(); | |||
/// <summary> | |||
/// 批量移除配方原料 | |||
/// </summary> | |||
/// <param name="id"></param> | |||
/// <returns></returns> | |||
Task<OperateResult> DeleteRawMaterAsync(string id); | |||
/// <summary> | |||
/// 获取所有数据 | |||
/// </summary> | |||
@@ -61,67 +76,11 @@ namespace BPA.SingleDevice.Interface | |||
/// <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(); | |||
/// <summary> | |||
/// 通过配方ID获取物料ID集合 | |||
/// </summary> | |||
/// <param name="RecipeId"></param> | |||
/// <returns></returns> | |||
Task<OperateResult<List<RecipeRawMaterTB>>> GetRawMaterIds(string RecipeId); | |||
} | |||
} |
@@ -10,10 +10,7 @@ | |||
<Setter Property="Template"> | |||
<Setter.Value> | |||
<ControlTemplate TargetType="{x:Type controls:ControlDisplay}"> | |||
<Grid | |||
Margin="0,5,0,0" | |||
ui:GridHelper.RowDefinitions="Auto, Auto, *" | |||
ui:PanelHelper.Spacing="10"> | |||
<Grid ui:GridHelper.RowDefinitions="Auto, Auto, *" ui:PanelHelper.Spacing="10"> | |||
<!--<TextBlock Style="{StaticResource Head3TextBlock}" Text="{TemplateBinding Title}" /> | |||
<TextBox | |||
x:Name="descriptionText" | |||
@@ -1,47 +1,92 @@ | |||
<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 | |||
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: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="300" | |||
d:DesignWidth="500" | |||
mc:Ignorable="d"> | |||
<UserControl.DataContext> | |||
<vm:AddRawMaterialDialogViewModel/> | |||
<vm:AddRawMaterialDialogViewModel /> | |||
</UserControl.DataContext> | |||
<Grid Margin="10" ui:PanelHelper.Spacing="10"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition Width="130"/> | |||
<ColumnDefinition/> | |||
<ColumnDefinition Width="130" /> | |||
<ColumnDefinition /> | |||
</Grid.ColumnDefinitions> | |||
<Grid.RowDefinitions> | |||
<RowDefinition/> | |||
<RowDefinition/> | |||
<RowDefinition/> | |||
<RowDefinition/> | |||
<RowDefinition/> | |||
<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="0" | |||
Grid.Column="0" | |||
HorizontalAlignment="Right" | |||
FontSize="16" | |||
Foreground="#ddd" | |||
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="1" | |||
Grid.Column="0" | |||
HorizontalAlignment="Right" | |||
FontSize="16" | |||
Foreground="#ddd" | |||
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}" /> | |||
<TextBlock | |||
Grid.Row="2" | |||
Grid.Column="0" | |||
HorizontalAlignment="Right" | |||
FontSize="16" | |||
Foreground="#ddd" | |||
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 | |||
Grid.Row="3" | |||
Grid.ColumnSpan="2" | |||
Margin="0,5" | |||
ui:PanelHelper.Spacing="10"> | |||
<Grid.ColumnDefinitions> | |||
<ColumnDefinition/> | |||
<ColumnDefinition/> | |||
<ColumnDefinition /> | |||
<ColumnDefinition /> | |||
</Grid.ColumnDefinitions> | |||
<Button Grid.Column="0" Content="确认" Command="{Binding SaveCommand}"/> | |||
<Button Grid.Column="1" Content="取消"/> | |||
<Button | |||
Grid.Column="0" | |||
Command="{Binding SaveCommand}" | |||
Content="确认" /> | |||
<Button | |||
Grid.Column="1" | |||
Command="{Binding CancelCommand}" | |||
Content="取消" /> | |||
</Grid> | |||
</Grid> | |||
@@ -28,23 +28,33 @@ | |||
Grid.Column="1" | |||
Margin="0,5" | |||
Style="{StaticResource DarkTextBox}" | |||
Text="{Binding RawMaterResultInfo.Name}" /> | |||
Text="{Binding RecipeName}" /> | |||
</Grid> | |||
<ScrollViewer Grid.Row="1"> | |||
<ListView ItemsSource="{Binding NewRecipeModels}"> | |||
<ListView.ItemsPanel> | |||
<ItemsPanelTemplate> | |||
<UniformGrid Columns="5" /> | |||
<UniformGrid Columns="2" /> | |||
</ItemsPanelTemplate> | |||
</ListView.ItemsPanel> | |||
<ListView.ItemTemplate> | |||
<DataTemplate> | |||
<CheckBox | |||
Margin="10,5" | |||
Content="{Binding Name}" | |||
FontSize="16" | |||
IsChecked="{Binding IsChecked}" /> | |||
<Grid | |||
Margin="5,0,0,0" | |||
HorizontalAlignment="Right" | |||
ui:GridHelper.ColumnDefinitions="Auto,Auto"> | |||
<CheckBox | |||
Margin="10,5" | |||
Content="{Binding Name}" | |||
FontSize="16" | |||
IsChecked="{Binding IsChecked}" /> | |||
<TextBox | |||
Grid.Column="1" | |||
Width="100" | |||
IsEnabled="{Binding IsChecked}" | |||
Text="{Binding Weight}" /> | |||
</Grid> | |||
</DataTemplate> | |||
</ListView.ItemTemplate> | |||
</ListView> | |||
@@ -59,7 +69,10 @@ | |||
Grid.Column="0" | |||
Command="{Binding SaveCommand}" | |||
Content="确认" /> | |||
<Button Grid.Column="1" Content="取消" /> | |||
<Button | |||
Grid.Column="1" | |||
Command="{Binding CancelCommand}" | |||
Content="取消" /> | |||
</Grid> | |||
</Grid> | |||
@@ -23,32 +23,53 @@ | |||
</UserControl.Resources> | |||
<Grid Margin="10"> | |||
<ListView ui:ItemsControlHelper.ItemPadding="0" ItemsSource="{Binding Goods}"> | |||
<ListView | |||
VerticalAlignment="Top" | |||
ui:ItemsControlHelper.ItemPadding="0" | |||
ItemsSource="{Binding Goods}"> | |||
<ListView.ItemsPanel> | |||
<ItemsPanelTemplate> | |||
<UniformGrid Columns="4"/> | |||
<UniformGrid Columns="5" /> | |||
</ItemsPanelTemplate> | |||
</ListView.ItemsPanel> | |||
<ListView.ItemTemplate> | |||
<DataTemplate> | |||
<controls:ControlDisplay Margin="10" Grid.Row="1" ui:PanelHelper.Spacing="10"> | |||
<controls:ControlDisplay Margin="5"> | |||
<Grid> | |||
<Grid.RowDefinitions> | |||
<RowDefinition Height="120" /> | |||
<RowDefinition Height="30" /> | |||
<RowDefinition Height="40" /> | |||
<RowDefinition /> | |||
</Grid.RowDefinitions> | |||
<Border Width="120" Background="Gray" /> | |||
<TextBlock Grid.Row="1" Text="{Binding}" /> | |||
<Grid Grid.Row="2" ui:GridHelper.ColumnDefinitions="*,*"> | |||
<TextBlock | |||
Grid.Row="1" | |||
HorizontalAlignment="Center" | |||
FontSize="16" | |||
Foreground="#ddd" | |||
Text="{Binding Name}" /> | |||
<Border | |||
Grid.Row="1" | |||
BorderBrush="#505050" | |||
BorderThickness="0,0,0,1" /> | |||
<Grid | |||
Grid.Row="2" | |||
Margin="0,5,0,0" | |||
ui:GridHelper.ColumnDefinitions="*,*"> | |||
<ui:NumericBox | |||
ui:ControlHelper.FocusBorderBrush="{DynamicResource Secondary}" | |||
BorderThickness="0" | |||
IsReadOnly="True" | |||
Style="{StaticResource FrontBackNumericBox}" | |||
Value="1" /> | |||
Value="{Binding Count}" /> | |||
<Button | |||
Grid.Column="1" | |||
Margin="10,0,0,0" | |||
Content="开始下单" /> | |||
Command="{Binding DataContext.DownRecipeCommand, RelativeSource={RelativeSource AncestorType=local:OrderMainView}}" | |||
CommandParameter="{Binding Id}" | |||
Content="开始下单" | |||
Foreground="#ddd" | |||
Style="{DynamicResource SecondaryButton}" /> | |||
</Grid> | |||
</Grid> | |||
</controls:ControlDisplay> | |||
@@ -33,7 +33,7 @@ | |||
<Button | |||
HorizontalAlignment="Right" | |||
Command="{Binding AddCommand}" | |||
Content="添加原料" | |||
Content="添加配方" | |||
Style="{DynamicResource DarkButton}" /> | |||
</StackPanel> | |||
@@ -48,8 +48,8 @@ | |||
BorderThickness="1" | |||
CanUserAddRows="False" | |||
GridLinesVisibility="All" | |||
IsReadOnly="True" | |||
ItemsSource="{Binding RawMaterInfos}" | |||
IsReadOnly="False" | |||
ItemsSource="{Binding RecipeInfos}" | |||
RowHeight="35" | |||
SelectionMode="Single"> | |||
<DataGrid.Columns> | |||
@@ -57,10 +57,10 @@ | |||
Width="*" | |||
Binding="{Binding Name}" | |||
Header="配方名称" /> | |||
<DataGridTextColumn | |||
Width="100" | |||
Binding="{Binding DeviceNum}" | |||
Header="是否启用" /> | |||
<DataGridCheckBoxColumn | |||
Width="50" | |||
Binding="{Binding IsEnable,UpdateSourceTrigger=PropertyChanged}" | |||
Header="启用" /> | |||
<DataGridTextColumn | |||
Width="180" | |||
Binding="{Binding LastModified}" | |||
@@ -70,21 +70,21 @@ | |||
<DataTemplate> | |||
<StackPanel Orientation="Horizontal"> | |||
<Button | |||
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}" | |||
Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}" | |||
CommandParameter="{Binding Id}" | |||
Foreground="#2196F3" | |||
Style="{StaticResource TextButton}"> | |||
<ui:Icon Type="Edit2Fill" /> | |||
</Button> | |||
<Button | |||
Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}" | |||
Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}" | |||
CommandParameter="{Binding Id}" | |||
Foreground="#2196F3" | |||
Style="{StaticResource TextButton}"> | |||
<ui:Icon Type="CopyleftFill" /> | |||
</Button> | |||
<Button | |||
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RawMaterialManagementView}}" | |||
Command="{Binding DataContext.RemoveCommand, RelativeSource={RelativeSource AncestorType=local:RecipeManagementView}}" | |||
CommandParameter="{Binding Id}" | |||
Style="{StaticResource TextErrorButton}"> | |||
<ui:Icon Type="DeleteBinFill" /> | |||
@@ -96,7 +96,7 @@ | |||
</DataGrid.Columns> | |||
</DataGrid> | |||
</controls:ControlDisplay> | |||
<ui:MessageContainer Grid.Row="1" Identifier="RawMaterialManagementView" /> | |||
<ui:MessageContainer Grid.Row="1" Identifier="RecipeManagementView" /> | |||
<!--#endregion--> | |||
</Grid> | |||
@@ -17,12 +17,8 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
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); | |||
}); | |||
SaveCommand = new BPARelayCommand(() => { RequestClose?.Invoke(RawMaterResultInfo); }); | |||
CancelCommand = new BPARelayCommand(() => { RequestClose?.Invoke(null); }); | |||
} | |||
public string Title => "添加原料"; | |||
@@ -32,8 +28,6 @@ namespace BPA.SingleDevice.ViewModel | |||
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>(); | |||
@@ -43,5 +37,6 @@ namespace BPA.SingleDevice.ViewModel | |||
private RawMaterResult _mRawMaterResultInfo = new RawMaterResult(); | |||
public BPARelayCommand SaveCommand { get; set; } | |||
public BPARelayCommand CancelCommand { get; set; } | |||
} | |||
} |
@@ -31,6 +31,21 @@ namespace BPA.SingleDevice.ViewModel | |||
public BPARelayCommand<object> SelecteCommand { get; set; } | |||
public ViewItem CurrentViewItem | |||
{ | |||
get { return _mCurrentViewItem; } | |||
set | |||
{ | |||
_mCurrentViewItem = value; | |||
OnPropertyChanged(); | |||
var res = ViewItems.FirstOrDefault(p => p.Name == value.Name); | |||
res.Content = Activator.CreateInstance(res.Content.GetType()); | |||
} | |||
} | |||
private ViewItem _mCurrentViewItem = new ViewItem(); | |||
private void DoNavChanged(object obj) | |||
{ | |||
if (obj != null) | |||
@@ -7,6 +7,9 @@ using System.Threading.Tasks; | |||
using System.Collections.ObjectModel; | |||
using BPA.Model; | |||
using Rubyer; | |||
using Rubyer.Models; | |||
using BPA.SingleDevice.Helper; | |||
using BPA.Model.Table; | |||
namespace BPA.SingleDevice.ViewModel | |||
{ | |||
@@ -14,12 +17,45 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
public NewRecipeViewModel() | |||
{ | |||
for (int i = 0; i < 60; i++) | |||
SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.OnSuccess(s => | |||
{ | |||
NewRecipeModels.Add(new NewRecipeModel() | |||
s.ForEach(item => | |||
{ | |||
Name = $"原料-{i}" | |||
NewRecipeModels.Add(new NewRecipeModel() { Name = item.Name, Id = item.Id }); | |||
}); | |||
}); | |||
SaveCommand = new BPARelayCommand(() => | |||
{ | |||
var result = new Parameters(); | |||
result.Add("Name", RecipeName); | |||
result.Add("RawMater", NewRecipeModels.Where(p => p.IsChecked == true).ToList()); | |||
RequestClose?.Invoke(result); | |||
}); | |||
CancelCommand = new BPARelayCommand(() => { RequestClose?.Invoke(null); }); | |||
} | |||
public string Title => ""; | |||
public event Action<object> RequestClose; | |||
public void OnDialogOpened(object parameters) | |||
{ | |||
if (parameters is Parameters par) | |||
{ | |||
if (par.TryGetValue("Name", out string name) && par.TryGetValue("RawMater", out List<NewRecipeModel> rms)) | |||
{ | |||
RecipeName = name; | |||
rms.ForEach(item => | |||
{ | |||
var res = NewRecipeModels.FirstOrDefault(p => p.Id == item.Id); | |||
if (res != null) | |||
{ | |||
res.Weight = item.Weight; | |||
res.IsChecked = true; | |||
} | |||
}); | |||
} | |||
} | |||
} | |||
@@ -28,12 +64,8 @@ namespace BPA.SingleDevice.ViewModel | |||
public string RecipeName { get { return _mRecipeName; } set { _mRecipeName = value; OnPropertyChanged(); } } | |||
private string _mRecipeName; | |||
public string Title => ""; | |||
public BPARelayCommand SaveCommand { get; set; } | |||
public event Action<object> RequestClose; | |||
public void OnDialogOpened(object parameters) | |||
{ | |||
} | |||
public BPARelayCommand CancelCommand { get; set; } | |||
} | |||
} |
@@ -5,6 +5,9 @@ using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Collections.ObjectModel; | |||
using BPA.Model.Table; | |||
using BPA.SingleDevice.Helper; | |||
using BPA.Model; | |||
namespace BPA.SingleDevice.ViewModel | |||
{ | |||
@@ -12,12 +15,69 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
public OrderMainViewModel() | |||
{ | |||
for (int i = 0; i < 20; i++) | |||
SqlHelper.GetInstance.GetListAsync<RecipeTB>().Result.OnSuccess(s => | |||
{ | |||
Goods.Add($"商品-{i}"); | |||
} | |||
s.ForEach(item => | |||
{ | |||
if (item.IsEnable) | |||
Goods.Add(new RecipeModel() { Id = item.Id, Name = item.Name, Count = 1 }); | |||
}); | |||
}); | |||
RawMaters = SqlHelper.GetInstance.GetListAsync<RawMaterTB>().Result.Content; | |||
DownRecipeCommand = new BPARelayCommand<object>(o => | |||
{ | |||
if (o != null && !string.IsNullOrEmpty(o.ToString())) | |||
{ | |||
var res = Goods.FirstOrDefault(p => p.Id == o.ToString()); | |||
if (res != null) | |||
{ | |||
List<RawMaterModel> rawMaters = new List<RawMaterModel>(); | |||
SqlHelper.GetInstance.GetRawMaterIds(res.Id).Result.OnSuccess(s => | |||
{ | |||
s.ForEach(item => | |||
{ | |||
var rmtb = RawMaters.FirstOrDefault(p => p.Id == item.RawMaterId); | |||
if (rmtb != null) | |||
{ | |||
rawMaters.Add(new RawMaterModel() | |||
{ | |||
Weight = item.Weight, | |||
DeviceNum = rmtb.DeviceNum, | |||
Id = rmtb.Id, | |||
LastModified = rmtb.LastModified, | |||
Name = rmtb.Name, | |||
WarehouseNum = rmtb.WarehouseNum, | |||
}); | |||
} | |||
}); | |||
}); | |||
for (int i = 0; i < res.Count; i++) | |||
{ | |||
List<RawMaterModel> temp = new List<RawMaterModel>(); | |||
rawMaters.ForEach(item => | |||
{ | |||
temp.Add(new RawMaterModel() | |||
{ | |||
Weight = item.Weight, | |||
WarehouseNum = item.WarehouseNum, | |||
Name = item.Name, | |||
LastModified = item.LastModified, | |||
Id = item.Id, | |||
DeviceNum = item.DeviceNum | |||
}); | |||
}); | |||
GlobalData.GoodsModels.Enqueue(new GoodsModel() { RawMaters = temp }); | |||
} | |||
} | |||
} | |||
}); | |||
} | |||
private List<RawMaterTB> RawMaters { get; set; } = new List<RawMaterTB>(); | |||
public ObservableCollection<RecipeModel> Goods { get; set; } = new ObservableCollection<RecipeModel>(); | |||
public ObservableCollection<string> Goods { get; set; } = new ObservableCollection<string>(); | |||
public BPARelayCommand<object> DownRecipeCommand { get; set; } | |||
} | |||
} |
@@ -11,6 +11,7 @@ using System.Collections.ObjectModel; | |||
using System.Linq; | |||
using System.Text; | |||
using System.Threading.Tasks; | |||
using System.Xml.Linq; | |||
namespace BPA.SingleDevice.ViewModel | |||
{ | |||
@@ -23,7 +24,7 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
s.ForEach(item => | |||
{ | |||
RawMaterInfos.Add(new RecipeInfo() { }); | |||
RecipeInfos.Add(new RecipeInfo() { Id = item.Id, IsEnable = item.IsEnable, Name = item.Name, LastModified = item.LastModified }); | |||
}); | |||
}); | |||
@@ -32,21 +33,33 @@ namespace BPA.SingleDevice.ViewModel | |||
var content = new NewRecipeView(); | |||
var para = await Dialog.Show(content, new Parameters(), "添加配方", (d) => { }, (d, o) => | |||
{ | |||
if (o is RawMaterResult rm) | |||
if (o is Parameters par) | |||
{ | |||
string id = Guid.NewGuid().ToString(); | |||
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | |||
SqlHelper.GetInstance.AddAsync(new RawMaterTB() | |||
if (par.TryGetValue("Name", out string name) && par.TryGetValue("RawMater", out List<NewRecipeModel> rms)) | |||
{ | |||
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}"); }); | |||
string id = Guid.NewGuid().ToString();//配方ID | |||
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | |||
//添加配方 | |||
SqlHelper.GetInstance.AddAsync(new RecipeTB() | |||
{ | |||
Id = id, | |||
Name = name, | |||
LastModified = time, | |||
IsEnable = true, | |||
}).Result.OnSuccess(() => | |||
{ | |||
List<RecipeRawMaterTB> rrmtb = new List<RecipeRawMaterTB>(); | |||
rms.ForEach(item => | |||
{ | |||
rrmtb.Add(new RecipeRawMaterTB() { Id = Guid.NewGuid().ToString(), RawMaterId = item.Id, RecipeId = id, Weight = item.Weight }); | |||
}); | |||
SqlHelper.GetInstance.AddAsync(rrmtb).Result.OnSuccess(() => | |||
{ | |||
RecipeInfos.Add(new RecipeInfo() { Id = id, IsEnable = true, LastModified = time, Name = name }); | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"添加失败:{s}"); }); | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"添加失败:{s}"); }); | |||
} | |||
} | |||
}); | |||
}); | |||
@@ -55,34 +68,52 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
if (o != null && !string.IsNullOrEmpty(o.ToString())) | |||
{ | |||
var index = RawMaterInfos.ToList().FindIndex(p => p.Id == o.ToString()); | |||
var index = RecipeInfos.ToList().FindIndex(p => p.Id == o.ToString()); | |||
if (index >= 0) | |||
{ | |||
var para = await Dialog.Show(new AddRawMaterialDialogView(), new RawMaterResult() | |||
var parameters = new Parameters(); | |||
List<NewRecipeModel> nrm = new List<NewRecipeModel>(); | |||
SqlHelper.GetInstance.GetRawMaterIds(RecipeInfos.ElementAt(index).Id).Result.OnSuccess((s) => | |||
{ | |||
Name = RawMaterInfos[index].Name, | |||
//DeviceNum = RawMaterInfos[index].DeviceNum, | |||
//ChNum = RawMaterInfos[index].WarehouseNum, | |||
Id = RawMaterInfos[index].Id, | |||
}, "原料编辑", (d) => { }, (d, o) => | |||
s.ForEach(item => | |||
{ | |||
nrm.Add(new NewRecipeModel() { Id = item.RawMaterId, Weight = item.Weight }); | |||
}); | |||
}); | |||
parameters.Add("Name", RecipeInfos.ElementAt(index).Name); | |||
parameters.Add("RawMater", nrm); | |||
var para = await Dialog.Show(new NewRecipeView(), parameters, "配方编辑", (d) => { }, (d, resPar) => | |||
{ | |||
if (o is RawMaterResult rm) | |||
if (resPar is Parameters par) | |||
{ | |||
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | |||
SqlHelper.GetInstance.UpdateAsync(new RawMaterTB() | |||
if (par.TryGetValue("Name", out string name) && par.TryGetValue("RawMater", out List<NewRecipeModel> rms)) | |||
{ | |||
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}"); }); | |||
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | |||
//添加配方 | |||
SqlHelper.GetInstance.UpdateAsync(new RecipeTB() | |||
{ | |||
Id = o.ToString(), | |||
Name = name, | |||
LastModified = time, | |||
IsEnable = RecipeInfos[index].IsEnable | |||
}).Result.OnSuccess(() => | |||
{ | |||
SqlHelper.GetInstance.DeleteRawMaterAsync(o.ToString()).Result.OnSuccess(() => | |||
{ | |||
List<RecipeRawMaterTB> rrmtb = new List<RecipeRawMaterTB>(); | |||
rms.ForEach(item => | |||
{ | |||
rrmtb.Add(new RecipeRawMaterTB() { Id = Guid.NewGuid().ToString(), RawMaterId = item.Id, RecipeId = o.ToString(), Weight = item.Weight }); | |||
}); | |||
SqlHelper.GetInstance.AddAsync(rrmtb).Result.OnSuccess(() => | |||
{ | |||
RecipeInfos[index].Name = name; | |||
RecipeInfos[index].LastModified = time; | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新添加失败:{s}"); }); | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新时删除失败:{s}"); }); | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); }); | |||
} | |||
} | |||
}); | |||
} | |||
@@ -93,24 +124,45 @@ namespace BPA.SingleDevice.ViewModel | |||
{ | |||
if (o != null && !string.IsNullOrEmpty(o.ToString())) | |||
{ | |||
var index = RawMaterInfos.ToList().FindIndex(p => p.Id == o.ToString()); | |||
var index = RecipeInfos.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(() => | |||
SqlHelper.GetInstance.DeleteAsync<RecipeTB>(o.ToString()).OnSuccess(() => | |||
{ | |||
RawMaterInfos.RemoveAt(index); | |||
SqlHelper.GetInstance.DeleteRawMaterAsync(o.ToString()).OnSuccess(() => | |||
{ | |||
RecipeInfos.RemoveAt(index); | |||
}).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); }); | |||
}).OnFail(s => { Message.Error("RawMaterialManagementView", $"删除失败:{s}"); }); | |||
} | |||
} | |||
} | |||
}); | |||
RecipeInfo.EnableChange = (s => | |||
{ | |||
var index = RecipeInfos.ToList().FindIndex(p => p.Id == s); | |||
if (index >= 0) | |||
{ | |||
string time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); | |||
SqlHelper.GetInstance.UpdateAsync(new RecipeTB() | |||
{ | |||
Id = s, | |||
Name = RecipeInfos[index].Name, | |||
LastModified = time, | |||
IsEnable = RecipeInfos[index].IsEnable | |||
}).Result.OnSuccess(() => | |||
{ | |||
RecipeInfos[index].LastModified = time; | |||
}).OnFail(s => { Message.Error("RecipeManagementView", $"更新失败:{s}"); }); | |||
} | |||
}); | |||
} | |||
public ObservableCollection<RecipeInfo> RawMaterInfos { get; set; } = new ObservableCollection<RecipeInfo>(); | |||
public ObservableCollection<RecipeInfo> RecipeInfos { get; set; } = new ObservableCollection<RecipeInfo>(); | |||
public BPARelayCommand AddCommand { get; set; } | |||
public BPARelayCommand<object> CopyCommand { get; set; } | |||