using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Mesnac.Action.Feeding.Qingquan.BasicInfo { /// /// 配方称量公共类 /// public class RecipeWeightCommon { #region 称量信息解析 /// /// 称量信息解析 /// 9998:200:0.4:0:0:0:0:|0.3:0.1:0:0:0:0:|106:0:0:0:0:0:0:0:|0.3:0:0:0:0:0:0:0:|0:0:0:0:0:0:0:0:|0:0:0:0:0:0:0:0:|1010000000015:1070000000063:::::|2010000030099:::|21.82:0:0:|0.1:0:0:|/ /// /// 返回可以向Scoket客户端发送的字符串 /// 成功返回字符串:,失败返回String.Empty public static string ParserRecipeWeighString(List allWeightInfo) { try { StringBuilder strJLS = new StringBuilder(); StringBuilder strJLE = new StringBuilder(); StringBuilder strFLS = new StringBuilder(); StringBuilder strFLE = new StringBuilder(); StringBuilder strTHS = new StringBuilder(); StringBuilder strTHE = new StringBuilder(); StringBuilder strYS = new StringBuilder(); StringBuilder strYE = new StringBuilder(); StringBuilder strY2S = new StringBuilder(); StringBuilder strY2E = new StringBuilder(); StringBuilder strMaterial = new StringBuilder(); StringBuilder strXL = new StringBuilder(); StringBuilder strXLS = new StringBuilder(); StringBuilder strXLE = new StringBuilder(); foreach (RecipeData.RecipeWeightInfo rw in allWeightInfo) { if (rw.ActCode - 1 == 2)//斜料 continue; switch (rw.WeightType) { case 0://碳黑 strTHS.AppendFormat("{0}:", rw.SetWeight); strTHE.AppendFormat("{0}:", rw.ErrorAllow); break; case 1://油1 strYS.AppendFormat("{0}:", rw.SetWeight); strYE.AppendFormat("{0}:", rw.ErrorAllow); break; case 3://粉料 strFLS.AppendFormat("{0}:", rw.SetWeight); strFLE.AppendFormat("{0}:", rw.ErrorAllow); break; case 4://小料 strXLS.AppendFormat("{0}:", rw.SetWeight); strXLE.AppendFormat("{0}:", rw.ErrorAllow); strXL.AppendFormat("{0}:", rw.MaterialCode); break; case 5://油2 strY2S.AppendFormat("{0}:", rw.SetWeight); strY2E.AppendFormat("{0}:", rw.ErrorAllow); break; default://胶料 strJLS.AppendFormat("{0}:", rw.SetWeight); strJLE.AppendFormat("{0}:", rw.ErrorAllow); strMaterial.AppendFormat("{0}:", rw.MaterialCode); break; } } //如果长度不够,补全后面位数 int splength = strJLS.ToString().Split(':').Length; for (int i = 0; i < 6 - (splength == 0 ? splength : splength - 1); i++) { strJLS.Append("0:"); } splength = strJLE.ToString().Split(':').Length; for (int i = 0; i < 6 - (splength == 0 ? splength : splength - 1); i++) { strJLE.Append("0:"); } splength = strTHS.ToString().Split(':').Length; for (int i = 0; i < 8 - (splength == 0 ? splength : splength - 1); i++) { strTHS.Append("0:"); } splength = strTHE.ToString().Split(':').Length; for (int i = 0; i < 8 - (splength == 0 ? splength : splength - 1); i++) { strTHE.Append("0:"); } splength = strYS.ToString().Split(':').Length; for (int i = 0; i < 8 - (splength == 0 ? splength : splength - 1); i++) { strYS.Append("0:"); } splength = strYE.ToString().Split(':').Length; for (int i = 0; i < 8 - (splength == 0 ? splength : splength - 1); i++) { strYE.Append("0:"); } splength = strMaterial.ToString().Split(':').Length; for (int i = 0; i < 6 - (splength == 0 ? splength : splength - 1); i++) { strMaterial.Append(":"); } splength = strXL.ToString().Split(':').Length; for (int i = 0; i < 3 - (splength == 0 ? splength : splength - 1); i++) { strXL.Append(":"); } splength = strXLS.ToString().Split(':').Length; for (int i = 0; i < 3 - (splength == 0 ? splength : splength - 1); i++) { strXLS.Append("0:"); } splength = strXLE.ToString().Split(':').Length; for (int i = 0; i < 3 - (splength == 0 ? splength : splength - 1); i++) { strXLE.Append("0:"); } string sendMsg = Global.ProtocalHeader.ReceiveWeighParamIpNumber + ":" + strJLS.ToString() + "|" + strJLE.ToString() + "|" + strTHS.ToString() + "|" + strTHE.ToString() + "|" + strYS.ToString() + "|" + strYE.ToString() + "|" + strMaterial.ToString() + "|" + strXL.ToString() + "|" + strXLS.ToString() + "|" + strXLE.ToString() + "|" + strFLS.ToString() + "|" + strFLE.ToString() + "|" + strY2S.ToString() + "|" + strY2E.ToString() + "|/"; return sendMsg; } catch (Exception ex) { ICSharpCode.Core.LoggingService.Error("解析称量信息失败:" + ex.Message); return String.Empty; } } #endregion } }