瀏覽代碼

菜品库代码上传

样式分支
yahaha 2 年之前
父節點
當前提交
3a6b461122
共有 5 個檔案被更改,包括 559 行新增143 行删除
  1. +1
    -1
      BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs
  2. +261
    -141
      BPASmartClient.MorkF/Control_MorkF.cs
  3. +77
    -0
      BPASmartClient.MorkF/Model/MaterialCoordinate.cs
  4. +14
    -1
      BPASmartClient.MorkF/Model/MaterialOperation.cs
  5. +206
    -0
      BPASmartClient.MorkF/Model/MaterialSurplus.cs

+ 1
- 1
BPASmartClient.JXJFoodBigStation/Properties/Settings.Designer.cs 查看文件

@@ -12,7 +12,7 @@ namespace BPASmartClient.JXJFoodBigStation.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.1.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));


+ 261
- 141
BPASmartClient.MorkF/Control_MorkF.cs 查看文件

@@ -33,7 +33,7 @@ namespace BPASmartClient.MorkF
/// <summary>
/// 菜品库while循环最大sleep次数
/// </summary>
private const int materialSleepCount = 400;
private const int materialSleepCount = 600;

/// <summary>
/// 菜品库while循环每次sleep时间
@@ -54,17 +54,17 @@ namespace BPASmartClient.MorkF
private const int materialHigh = 34500;

/// <summary>
///
/// 菜品库第一层的起始基点,为最下层盒子的中间点
/// </summary>
private const int materialOne = 34500;

/// <summary>
///
/// 菜品库第二层的起始基点,为最下层盒子的中间点
/// </summary>
private const int materialTwo = 34500;

/// <summary>
///
/// 菜品库第三层的起始基点,为最下层盒子的中间点
/// </summary>
private const int materialThree = 34500;

@@ -153,6 +153,8 @@ namespace BPASmartClient.MorkF
///初始化菜品库
//FoodLibInit();
Task2ReadMaterialData();

//Json<MaterialSurplus>.Read();
}

/// <summary>
@@ -900,25 +902,43 @@ namespace BPASmartClient.MorkF
/// <returns></returns>
public bool GetDistance(int x)
{
bool ret = true;
//是否在第一层菜品库
if (x > 0 && x <= materialLaserHigh)
{
//获取传感器1的距离
return GetDistance_1();
ret &= GetDistance_1();

Thread.Sleep(400);

//获取传感器1的距离
ret &= GetDistance_1();
}
//是否在第二层菜品库
else if (x > materialLaserHigh && x <= (2 * materialLaserHigh + clapboardLaserHigh))
{
//获取传感器1的距离
return GetDistance_2();
//获取传感器2的距离
ret &= GetDistance_2();

Thread.Sleep(400);

ret &= GetDistance_2();
}
//是否在第三层菜品库
else if (x > (2 * materialLaserHigh + clapboardLaserHigh) && x <= (3 * materialLaserHigh + 2 * clapboardLaserHigh))
{
//获取传感器1的距离
return GetDistance_3();
//获取传感器3的距离
ret &= GetDistance_3();

Thread.Sleep(400);

ret &= GetDistance_3();
}
if (!ret)
{
MessageLog.GetInstance.Show($"错误:X轴:{x}获取传感器数据出错");
}
return false;
return ret;
}

public void PawTurnFront()
@@ -1055,26 +1075,18 @@ namespace BPASmartClient.MorkF
/// <param name="x">取菜x轴坐标</param>
/// <param name="y">取菜y轴坐标</param>
/// <param name="fryNum">炒锅编号</param>
public void GetMaterail(int x, int y, int fryNum = 0)
public bool GetMaterail(int x, int y, int fryNum)
{
//设置到抓菜处
if (!SetArmPosition(x, y))
{
return;
}

if (!GetDistance(x))
{
MessageLog.GetInstance.Show("错误:获取传感器数据出错");
return;
return false;
}

Thread.Sleep(200);

if (!GetDistance(x))
{
MessageLog.GetInstance.Show("错误:获取传感器数据出错");
return;
return false;
}

Thread.Sleep(1000);
@@ -1087,26 +1099,26 @@ namespace BPASmartClient.MorkF
if (laserHigh > 29)
{
MessageLog.GetInstance.Show("错误:传感器获取数据大于隔板与传感器之间的距离");
return;
return false;
}

int moveX = 0;
if (LaserDistance2Coordinate(laserHigh, out moveX) != Laser2CoordinateState.MaterialNormal)
{
MessageLog.GetInstance.Show("错误:传感器距离转坐标值失败");
return;
return false;
}

if(x < moveX)
{
MessageLog.GetInstance.Show("错误:传感器距离转坐标值大于当前x轴坐标");
return;
return false;
}

//设置到传感器感应的距离处
if (!SetArmPosition(x - moveX, y))
{
return;
return false;
}

////关闭电磁阀
@@ -1117,14 +1129,14 @@ namespace BPASmartClient.MorkF
//爪子去1号位抓菜
if (!PawToPoint1())
{
return;
return false;
}
#endif

//设置到该层菜品库最高处
if (!SetArmPosition(x - materialHigh, y))
{
return;
return false;
}

////移动前开启电磁阀
@@ -1135,13 +1147,13 @@ namespace BPASmartClient.MorkF
//爪子去2号位放菜
if (!PawToPoint2())
{
return;
return false;
}
#endif
////判断炒锅是否可以放盒
//for(int i = 0;materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut;i++)
//for (int i = 0; materialSleepCount > i && !morkFs[fryIndex].FryPot1_HOBTPut; i++)
//{
// Thread.Sleep(materialSleepTime);
// Thread.Sleep(materialSleepTime);
// if (i >= materialSleepCount - 1)
// {
// MessageLog.GetInstance.Show("等待炒锅允许放盒超时");
@@ -1169,14 +1181,14 @@ namespace BPASmartClient.MorkF
//设置到炒锅1出菜处
if (!SetArmPosition(x, y))
{
return;
return false;
}

#if true
//爪子去3号位放菜
if (!PawToPoint3())
{
return;
return false;
}
#endif

@@ -1188,14 +1200,14 @@ namespace BPASmartClient.MorkF
//设置到炒锅1出菜处
if (!SetArmPosition(x + materialToFryDistance, y))
{
return;
return false;
}

#if true
//爪子回到2号位
if (!PawToPoint2())
{
return;
return false;
}
#endif
////关闭电磁阀
@@ -1205,6 +1217,62 @@ namespace BPASmartClient.MorkF
{
morkFs[fryNum].GetMaterialComplete = true;
}
return true;
}

/// <summary>
/// 更新菜品库存量
/// </summary>
/// <returns></returns>
public bool UpdateMaterialLibraryStock()
{
try
{
//判断是否初始化
if(!ml_morkf.InitialComplete)
{
return false;
}

foreach(var item in MaterialCoordinate.dicNoMaterialCoordinate)
{
//设置到抓菜处
if (!SetArmPosition(item.Value.X, item.Value.Y))
{
return false;
}

//获取该处的距离
if (!GetDistance(item.Value.X))
{
MessageLog.GetInstance.Show("错误:获取传感器数据出错");
return false;
}

Thread.Sleep(1000);

//获取传感器的距离
int laserHigh = ml_morkf.LaserDistance;
int surplus = 0;
//根据距离算出菜品余量
Laser2CoordinateState state = LaserDistance2MaterialCount(laserHigh, out surplus);
if (state != Laser2CoordinateState.MaterialNormal || state != Laser2CoordinateState.MaterialEmpty)
{
return false;
}

//更新菜品余量
if (!MaterialSurplusOperation.GetInstance().UpdateSurplus(item.Key, surplus))
{
return false;
}
}
return true;
}
catch(Exception ex)
{
return false;
}
}

/// <summary>
@@ -1259,50 +1327,86 @@ namespace BPASmartClient.MorkF
}
}

/// <summary>
/// 传感器距离转为菜品数量
/// </summary>
/// <param name="distance"></param>
/// <param name="x"></param>
/// <returns></returns>
public Laser2CoordinateState LaserDistance2MaterialCount(int distance, out int count)
{
count = 0;
try
{
//菜盒放多了
if (distance < 6)
{
return Laser2CoordinateState.MaterialOverdo;
}
else if (distance >= 6 && distance < 10)
{
count = 5;
return Laser2CoordinateState.MaterialNormal;
}
else if (distance >= 10 && distance < 14)
{
count = 4;
return Laser2CoordinateState.MaterialNormal;
}
else if (distance >= 14 && distance < 19)
{
count = 3;
return Laser2CoordinateState.MaterialNormal;
}
else if (distance >= 19 && distance < 23)
{
count = 2;
return Laser2CoordinateState.MaterialNormal;
}
else if (distance >= 23 && distance < 28)
{
count = 1;
return Laser2CoordinateState.MaterialNormal;
}
else
{
count = 0;
return Laser2CoordinateState.MaterialEmpty;
}
}
catch (Exception ex)
{
return Laser2CoordinateState.MaterialUnkown;
}
}

/// <summary>
/// 获取菜品测试
/// </summary>
/// <param name="isGet"></param>
private void GetMaterailTest(Coordinate coordinate)
private void GetMaterailTest(MaterialOperation materialOperation)
{
ThreadManage.GetInstance().Start(new Action(() => {
//int x1 = 0, x2 = 0, y = 0;

//if (getNum % 2 == 0)
//{
// x2 = 35000;
// y = 82000;

//}
//else if (getNum % 2 == 1)
//{
// x2 = 35000;
// y = 9000;
//}
//else
//{
// MessageLog.GetInstance.Show("菜品库无效操作");
// return;
//}
bool ret = false;
try
{
Coordinate myCoordinate = new Coordinate();
//获取坐标,根据菜品的位置信息
if (!NoMaterial2Coordinate(materialOperation.materialInfo.Loc, out myCoordinate))
{
MessageLog.GetInstance.Show($"炒锅{materialOperation.fryNum}获取菜品[{materialOperation.materialInfo.Name}]失败,找不到对应位置");
return;
}
lock (lock_Materail)
{
ml_morkf.MaterailIsWorking = true;
}
//取菜操作
GetMaterail(coordinate.X, coordinate.Y);

////机械臂回原点
//if (!SetArmPosition(0, 0))
//{
// MessageLog.GetInstance.Show("菜品库[机械臂操作失败]");
// return;
//}
ret =GetMaterail(myCoordinate.X, myCoordinate.Y, materialOperation.fryNum);
}
catch (Exception ex)
{

ret = false;
}
finally
{
@@ -1310,6 +1414,11 @@ namespace BPASmartClient.MorkF
{
ml_morkf.MaterailIsWorking = false;
}
if (ret == true)
{
//指定位置菜品减一
MaterialSurplusOperation.GetInstance().ReduceSurplus(materialOperation.materialInfo.Loc);
}
}

}), $"菜品库操作");
@@ -1469,48 +1578,52 @@ namespace BPASmartClient.MorkF
Thread.Sleep(200);
}
//倒菜
public void OutFood(int num)
public void OutFood(int num,bool isMaterial = false)
{
if (!morkFs.ContainsKey(num))
{
return;
}
int i = 0;
//判断是否完成取菜
for (i = 0; i < sleepCount * 2 && !morkFs[num].GetMaterialComplete; i++)
if(isMaterial)
{
if (i == 3)
//判断是否完成取菜
for (i = 0; i < materialSleepCount && !morkFs[num].GetMaterialComplete; i++)
{
//停止搅拌
StopStir(num);
//火力设置为2档
SetFire(new List<int> { 2 }, num);
if (i == 10)
{
//停止搅拌
StopStir(num);
//火力设置为2档
SetFire(new List<int> { 2 }, num);
}
Thread.Sleep(materialSleepTime);
if (i >= materialSleepCount - 1)
{
MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成");
return;
}
}
Thread.Sleep(sleepTime);
if (i >= sleepCount * 2 - 1)
if (i > 9)
{
MessageLog.GetInstance.Show($"炒锅{num}倒菜超时:未能等到取菜完成");
return;
//开启搅拌
StartStir(num);
//火力设置回原本火力
SetFire(new List<int> { morkFs[num].Fire }, num);
}
}

if (i > 3)
{
//开启搅拌
StartStir(num);
//火力设置回原本火力
SetFire(new List<int> { morkFs[num].Fire }, num);
}

FirePot_Write("LB3", true, num);
MessageLog.GetInstance.Show("倒菜启动");

Thread.Sleep(200);
Thread.Sleep(500);

for (i = 0; i < sleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++)
for (i = 0; i < materialSleepCount && !morkFs[num].FryPot1_MaterialIntoPot; i++)
{
Thread.Sleep(sleepTime);
if (i >= sleepCount - 1)
Thread.Sleep(materialSleepTime);
if (i >= materialSleepCount - 1)
{
MessageLog.GetInstance.Show($"炒锅{num}倒菜超时");
}
@@ -1519,6 +1632,7 @@ namespace BPASmartClient.MorkF
FirePot_Write("LB3", false, num);
Thread.Sleep(200);
MessageLog.GetInstance.Show("倒菜完成");
morkFs[num].GetMaterialComplete = false;
}
//搅拌臂去原点位
public void StirArmGoOrigin(int num)
@@ -1645,7 +1759,17 @@ namespace BPASmartClient.MorkF
FirePot_Write("LB8", true, num);
Thread.Sleep(200);
}
#endregion
#endregion

private static object saveMaterialLock = new object();
private void SaveMaterialData()
{
lock(saveMaterialLock)
{
Json<MaterialSurplus>.Data = MaterialSurplusOperation.GetInstance().materialSurplus;
Json<MaterialSurplus>.Save();
}
}

bool isInitialArrive = false;

@@ -1698,6 +1822,22 @@ namespace BPASmartClient.MorkF
});
}
}
if(stirFry.stirFrymessage.materials.Count > 0)
{
MaterialSurplusOperation.GetInstance().UpdateSurplusAll(stirFry.stirFrymessage.materials);
//foreach (var item in stirFry.stirFrymessage.materials)
//{
// MaterialSurplusOperation.GetInstance().materialSurplus.dicSurplus.Add(new MaterialInfo
// {
// Id = item.Id,
// Key = item.Key,
// Name = item.Name,
// Loc = item.Loc,
// Qty = item.Qty,
// });
//}
SaveMaterialData();
}
}

MessageLog.GetInstance.Show("接收到小炒流程信息");
@@ -2005,22 +2145,41 @@ namespace BPASmartClient.MorkF
case nameof(StirFryPotActionEnum.取原料):
//炒锅取菜状态置为未取到
morkFs[i].GetMaterialComplete = false;
if(getMaterailNum == 0)
if(potActions.MaterialLists != null)
{
if (NoMaterial2Coordinate("A2", out myCoordinate))
foreach (var item in potActions.MaterialLists)
{
materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
getMaterailNum++;
//通过ID获取有效的菜品对象
MaterialInfo materialInfo = MaterialSurplusOperation.GetInstance().GetVailedMaterial(item.MaterialId);
if (materialInfo == null)
{
MessageLog.GetInstance.Show($"炒锅{i}获取菜品[{materialInfo.Name}]失败,库存不足");
continue;
}

materialOperationQuenes.Enqueue(new MaterialOperation { materialInfo = materialInfo, fryNum = i });
}
}
else if(getMaterailNum == 1)
else
{
if (NoMaterial2Coordinate("B2", out myCoordinate))
{
materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
getMaterailNum++;
}
MessageLog.GetInstance.Show($"炒锅{i}获取菜品失败,菜品列表为空");
}
//if(getMaterailNum == 0)
//{
// if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[1], out myCoordinate))
// {
// materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
// getMaterailNum++;
// }
//}
//else if(getMaterailNum == 1)
//{
// if (NoMaterial2Coordinate(MaterialCoordinate.MLNumberList[4], out myCoordinate))
// {
// materialOperationQuenes.Enqueue(new MaterialOperation() { fryNum = i, coordinate = myCoordinate });
// getMaterailNum++;
// }
//}
MessageLog.GetInstance.Show(potActions.Actions);
break;
case nameof(StirFryPotActionEnum.开启搅拌):
@@ -2047,7 +2206,7 @@ namespace BPASmartClient.MorkF
MessageLog.GetInstance.Show(potActions.Actions);
break;
case nameof(StirFryPotActionEnum.道菜启动):
OutFood(i);
OutFood(i, true);
break;
case nameof(StirFryPotActionEnum.炒制菜品):
Thread.Sleep(potActions.During * 1000);
@@ -2099,8 +2258,6 @@ namespace BPASmartClient.MorkF
}
}

private int testNum = 0;

/// <summary>
/// 菜品库主流程
/// </summary>
@@ -2114,13 +2271,13 @@ namespace BPASmartClient.MorkF
//待菜品库操作列出队列
if (materialOperationQuenes.TryDequeue(out var res))
{

ml_morkf.MaterailIsWorking = true;
MessageLog.GetInstance.Show("开始操作菜品库");
//ThreadManage.GetInstance().Start(new Action(()=>{
// GetMaterail(res.x, res.y, res.fryNum);
//}),"菜品库操作");
GetMaterailTest(res.coordinate);
testNum++;
GetMaterailTest(res);
}
}
}
@@ -2194,9 +2351,9 @@ namespace BPASmartClient.MorkF

try
{
if(dicNoMaterialCoordinate.ContainsKey(no))
if(MaterialCoordinate.dicNoMaterialCoordinate.ContainsKey(no))
{
coordinate = dicNoMaterialCoordinate[no];
coordinate = MaterialCoordinate.dicNoMaterialCoordinate[no];
return true;
}
else
@@ -2214,43 +2371,6 @@ namespace BPASmartClient.MorkF
}
}

/// <summary>
/// 每个取菜点的编号与坐标字典
/// </summary>
private static Dictionary<string, Coordinate> dicNoMaterialCoordinate { get; set; } = new Dictionary<string, Coordinate>()
{
{"A1",new Coordinate(){ X = 34500,Y=0} },
{"A2",new Coordinate(){ X = 34500,Y=9000} },
{"A3",new Coordinate(){ X = 34500,Y=0} },
{"B1",new Coordinate(){ X = 34500,Y=0} },
{"B2",new Coordinate(){ X = 34500,Y=83000} },
{"B3",new Coordinate(){ X = 34500,Y=0} },
{"C1",new Coordinate(){ X = 34500,Y=0} },
{"C2",new Coordinate(){ X = 34500,Y=0} },
{"C3",new Coordinate(){ X = 34500,Y=0} },
{"D1",new Coordinate(){ X = 0,Y=0} },
{"D2",new Coordinate(){ X = 0,Y=0} },
{"D3",new Coordinate(){ X = 0,Y=0} },
{"E1",new Coordinate(){ X = 0,Y=0} },
{"E2",new Coordinate(){ X = 0,Y=0} },
{"E3",new Coordinate(){ X = 0,Y=0} },
{"F1",new Coordinate(){ X = 0,Y=0} },
{"F2",new Coordinate(){ X = 0,Y=0} },
{"F3",new Coordinate(){ X = 0,Y=0} },
{"G1",new Coordinate(){ X = 0,Y=0} },
{"G2",new Coordinate(){ X = 0,Y=0} },
{"G3",new Coordinate(){ X = 0,Y=0} },
{"H1",new Coordinate(){ X = 0,Y=0} },
{"H2",new Coordinate(){ X = 0,Y=0} },
{"H3",new Coordinate(){ X = 0,Y=0} },
{"I1",new Coordinate(){ X = 0,Y=0} },
{"I2",new Coordinate(){ X = 0,Y=0} },
{"I3",new Coordinate(){ X = 0,Y=0} },
{"J1",new Coordinate(){ X = 0,Y=0} },
{"J2",new Coordinate(){ X = 0,Y=0} },
{"J3",new Coordinate(){ X = 0,Y=0} },
};

public enum Laser2CoordinateState
{
MaterialOverdo = 0,//菜品过量


+ 77
- 0
BPASmartClient.MorkF/Model/MaterialCoordinate.cs 查看文件

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

namespace BPASmartClient.MorkF.Model
{
internal class MaterialCoordinate
{
public static List<string> MLNumberList = new List<string>() { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"
, "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27" };

public static List<Coordinate> MLCoordinateList = new List<Coordinate>()
{ new Coordinate() { X = 34500, Y = 0 }, new Coordinate() { X = 34500, Y = 9000 } , new Coordinate() { X = 34500, Y = 0 } , //第1层
new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 83000 }, new Coordinate(){ X = 34500,Y=0}, //第1层
new Coordinate(){ X = 34500,Y=0} , new Coordinate() { X = 34500, Y = 0 }, new Coordinate(){ X = 34500,Y=0}, //第1层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第2层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第3层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0}, //第3层
new Coordinate(){ X = 0,Y=0} , new Coordinate() { X = 0, Y = 0 }, new Coordinate(){ X = 0,Y=0} //第3层
};

public MaterialCoordinate()
{
if(MLNumberList.Count == MLCoordinateList.Count && MLNumberList.Count == 27)
{
for(int i = 0;i<MLNumberList.Count;i++)
{
//判断是否已经有该值了
if (!dicNoMaterialCoordinate.ContainsKey(MLNumberList[i]))
{
dicNoMaterialCoordinate.Add(MLNumberList[i], MLCoordinateList[i]);
}
}
}
}
/// <summary>
/// 每个取菜点的编号与坐标字典
/// </summary>
public static Dictionary<string, Coordinate> dicNoMaterialCoordinate { get; set; } = new Dictionary<string, Coordinate>();
//{
// {"A1",new Coordinate(){ X = 34500,Y=0} },
// {"A2",new Coordinate(){ X = 34500,Y=9000} },
// {"A3",new Coordinate(){ X = 34500,Y=0} },
// {"B1",new Coordinate(){ X = 34500,Y=0} },
// {"B2",new Coordinate(){ X = 34500,Y=83000} },
// {"B3",new Coordinate(){ X = 34500,Y=0} },
// {"C1",new Coordinate(){ X = 34500,Y=0} },
// {"C2",new Coordinate(){ X = 34500,Y=0} },
// {"C3",new Coordinate(){ X = 34500,Y=0} },
// {"D1",new Coordinate(){ X = 0,Y=0} },
// {"D2",new Coordinate(){ X = 0,Y=0} },
// {"D3",new Coordinate(){ X = 0,Y=0} },
// {"E1",new Coordinate(){ X = 0,Y=0} },
// {"E2",new Coordinate(){ X = 0,Y=0} },
// {"E3",new Coordinate(){ X = 0,Y=0} },
// {"F1",new Coordinate(){ X = 0,Y=0} },
// {"F2",new Coordinate(){ X = 0,Y=0} },
// {"F3",new Coordinate(){ X = 0,Y=0} },
// {"G1",new Coordinate(){ X = 0,Y=0} },
// {"G2",new Coordinate(){ X = 0,Y=0} },
// {"G3",new Coordinate(){ X = 0,Y=0} },
// {"H1",new Coordinate(){ X = 0,Y=0} },
// {"H2",new Coordinate(){ X = 0,Y=0} },
// {"H3",new Coordinate(){ X = 0,Y=0} },
// {"I1",new Coordinate(){ X = 0,Y=0} },
// {"I2",new Coordinate(){ X = 0,Y=0} },
// {"I3",new Coordinate(){ X = 0,Y=0} },
// {"J1",new Coordinate(){ X = 0,Y=0} },
// {"J2",new Coordinate(){ X = 0,Y=0} },
// {"J3",new Coordinate(){ X = 0,Y=0} },
//};
}
}

BPASmartClient.MorkF/MaterialOperation.cs → BPASmartClient.MorkF/Model/MaterialOperation.cs 查看文件

@@ -1,4 +1,5 @@
using System;
using BPA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@@ -20,6 +21,18 @@ namespace BPASmartClient.MorkF
{
public Coordinate coordinate { get; set; } = new Coordinate();

/// <summary>
/// 菜品编号
/// </summary>
public string id;

/// <summary>
/// 菜品位置
/// </summary>
public string loc;

public MaterialInfo materialInfo;

/// <summary>
/// 炒锅编号
/// </summary>

+ 206
- 0
BPASmartClient.MorkF/Model/MaterialSurplus.cs 查看文件

@@ -0,0 +1,206 @@
using BPA.Helper;
using BPA.Models;
using BPASmartClient.MorkF.Model;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPASmartClient.MorkF
{
internal class MaterialSurplusOperation : Singleton<MaterialSurplusOperation>
{
public MaterialSurplus materialSurplus { get; set; } = new MaterialSurplus();

/// <summary>
/// 更新余量
/// </summary>
/// <param name="number">编号</param>
/// <param name="surplus">余量</param>
public bool UpdateSurplus(string id, int surplus)
{
//找到所有id对应的
MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id);
if(material == null)
{
return false;
}
else
{
material.Qty = decimal.Parse(surplus.ToString());
return true;
}
}

/// <summary>
/// 返回有效的菜品库对象
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public MaterialInfo GetVailedMaterial(string id)
{
int surplus = 0;
//获取该菜品所有的余量
if(!GetAllSurplus(id,out surplus))
{
return null;
}

//判断库存数量是否有效
if(surplus <= 0)
{
return null;
}

return GetMaterial(id);
}

/// <summary>
/// 根据编号返回余量
/// </summary>
/// <param name="number">编号</param>
/// <param name="surplus">余量</param>
/// <returns></returns>
private MaterialInfo GetMaterial(string id)
{
//找到所有id对应的
MaterialInfo material = materialSurplus.dicSurplus.Find(t => t.Id == id && t.Qty != 0);

return material;
}

/// <summary>
/// 根据编号返回余量
/// </summary>
/// <param name="number">编号</param>
/// <param name="surplus">余量</param>
/// <returns></returns>
private bool GetAllSurplus(string id, out int surplus)
{
surplus = 0;
//找到所有id对应的
List<MaterialInfo> materials = materialSurplus.dicSurplus.FindAll(t=>t.Id == id);
if (materials != null)
{
foreach(MaterialInfo material in materials)
{
surplus += int.Parse(material.Qty.ToString());
}
return true;
}
else
{
return false;
}
}

/// <summary>
/// 余量减少
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public bool ReduceSurplus(string loc)
{
MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
if (materialInfo != null)
{
materialInfo.Qty--;
return true;
}
else
{
return false;
}
}

/// <summary>
/// 余量增加
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
public bool AddSurplus(string loc)
{
MaterialInfo materialInfo = materialSurplus.dicSurplus.Find(t => t.Loc == loc);
if (materialInfo != null)
{
materialInfo.Qty++;
return true;
}
else
{
return false;
}
}

/// <summary>
///
/// </summary>
/// <param name="newMaterialSurplus"></param>
public void UpdateSurplusAll(List<MaterialInfo> newMaterialSurplus)
{
if (newMaterialSurplus != null)
{
List<MaterialInfo> materialInfos = materialSurplus.dicSurplus;
if(materialInfos.Count != newMaterialSurplus.Count)
{
materialInfos.Clear();
materialSurplus.dicSurplus = newMaterialSurplus;
}
else
{
MaterialInfo findMaterial = null;
//遍历旧菜品库,是否与服务器的新菜品库一致
foreach (MaterialInfo materialInfo in materialSurplus.dicSurplus)
{
//查找该菜品是否还在
findMaterial = newMaterialSurplus.Find(t => (t.Id == materialInfo.Id && t.Loc == materialInfo.Loc));
//不存在则准备移除
if (findMaterial == null)
{
//查找该菜品是否还在
//位置上的菜品可能会更变
findMaterial = newMaterialSurplus.Find(t => (t.Loc == materialInfo.Loc));
if (findMaterial != null)
{
materialInfo.Qty = findMaterial.Qty;
materialInfo.Key = findMaterial.Key;
materialInfo.Id = findMaterial.Id;
materialInfo.Name = findMaterial.Name;
}
}
//存在则更新菜品库数据
else
{
materialInfo.Qty = findMaterial.Qty;
materialInfo.Key = findMaterial.Key;
materialInfo.Name = findMaterial.Name;
}
}
}
}
else
{
//materialSurplus.dicSurplus.Clear();
}
}
}
internal class MaterialSurplus
{
/// <summary>
/// 余量字典,key:菜品库编号,value:余量
/// </summary>
public List<MaterialInfo> dicSurplus = new List<MaterialInfo>();

//public MaterialSurplus()
//{
// //增加新的
// foreach (var item in MaterialCoordinate.MLNumberList)
// {
// dicSurplus.Add(item, 0);
// }
//}

}
}

Loading…
取消
儲存