using System; using System.Collections.Generic; using System.Data; using System.Runtime.CompilerServices; using System.Text; using Mesnac.Action.ChemicalWeighing.LjMaterial; using Mesnac.Action.ChemicalWeighing.LjPlanning; namespace Mesnac.Action.ChemicalWeighing.LjMixManager { public class LjMixManagerDb:DBHelp { public static LjMixManagerView GetById(int id) { var sql = " select Id, CreateTime, UpdateTime, MetageAId, MetageAName, MixAId, MixAName, MetageB1Id, MetageB1Name," + " MetageB2Id, MetageB2Name, MixBId, MixBName, MixCId, MixCName, RecipeType, Remark, DryId, DryName from lj_mix_manager where id=" + id; DataTable dt = GetTable(sql); LjMixManagerView view = new LjMixManagerView(); if (dt.Rows.Count == 1) { DataRow dr = dt.Rows[0]; if (dr["CreateTime"] != null) { view.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } if (dr["UpdateTime"] != null) { view.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]); } if (dr["MetageAId"] != null) { view.MetageAId = dr["MetageAId"].ToString(); } if (dr["MetageAName"] != null) { view.MetageAName = dr["MetageAName"].ToString(); } if (dr["MixAId"] != null) { view.MixAId = dr["MetageAId"].ToString(); } if (dr["MixAName"] != null) { view.MixAName = dr["MixAName"].ToString(); } if (dr["MetageB1Id"] != null) { view.MetageB1Id = dr["MetageB1Id"].ToString(); } if (dr["MetageB1Name"] != null) { view.MetageB1Name = dr["MetageB1Name"].ToString(); } if (dr["MetageB2Id"] != null) { view.MetageB2Id = dr["MetageB2Id"].ToString(); } if (dr["MetageB2Name"] != null) { view.MetageB2Name = dr["MetageB2Name"].ToString(); } if (dr["MixBId"] != null) { view.MixBId = dr["MixBId"].ToString(); } if (dr["MixBName"] != null) { view.MixBName = dr["MixBName"].ToString(); } if (dr["MixBId"] != null) { view.MixBId = dr["MixBId"].ToString(); } if (dr["MixBName"] != null) { view.MixBName = dr["MixBName"].ToString(); } if (dr["MixCId"] != null) { view.MixCId = dr["MixCId"].ToString(); } if (dr["MixCName"] != null) { view.MixCName = dr["MixCName"].ToString(); } // if (dr["RecipeType"] != null) // { // view.RecipeType = Convert.ToInt32(dr["RecipeType"]); // } if (dr["Remark"] != null) { view.Remark = dr["Remark"].ToString(); } view.DryId = Convert.ToInt32(dr["DryId"]); view.DryName = dr["DryName"].ToString(); view.Id = id; } return view; } public static void Update(LjMixManagerView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_planning "); //sb.Append($" CreateTime='{view.CreateTime}', "); sb.Append($" UpdateTime='{view.UpdateTime}', "); sb.Append($" MetageAId='{view.MetageAId}', "); sb.Append($" MetageAName='{view.MetageAName}', "); sb.Append($" MixAId='{view.MixAId}', "); sb.Append($" MixAName='{view.MixAName}', "); sb.Append($" MetageB1Id='{view.MetageB1Id}', "); sb.Append($" MetageB1Name='{view.MetageB1Name}', "); sb.Append($" MetageB2Id='{view.MetageB2Id}', "); sb.Append($" MetageB2Name='{view.MetageB2Name}', "); sb.Append($" MixBId='{view.MixBId}', "); sb.Append($" MixBName='{view.MixBName}', "); sb.Append($" MixCId='{view.MixCId}', "); sb.Append($" MixCName='{view.MixCName}', "); sb.Append($" RecipeType='{view.RecipeType}', "); sb.Append($" Remark='{view.Remark}', "); sb.Append($" DryId={view.DryId}, "); sb.Append($" DryName='{view.DryName}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static void UpdateMixA(LjMixManagerView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_mix_manager "); sb.Append($" set UpdateTime='{view.UpdateTime}', "); sb.Append($" MetageAId='{view.MetageAId}', "); sb.Append($" MetageAName='{view.MetageAName}', "); sb.Append($" MixAId='{view.MixAId}', "); sb.Append($" MixAName='{view.MixAName}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static void UpdateMixB(LjMixManagerView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_mix_manager "); sb.Append($" set UpdateTime='{view.UpdateTime}', "); sb.Append($" MetageB1Id='{view.MetageB1Id}', "); sb.Append($" MetageB1Name='{view.MetageB1Name}', "); sb.Append($" MetageB2Id='{view.MetageB2Id}', "); sb.Append($" MetageB2Name='{view.MetageB2Name}', "); sb.Append($" MixBId='{view.MixBId}', "); sb.Append($" MixBName='{view.MixBName}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static void UpdateMixC(LjMixManagerView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_mix_manager "); sb.Append($" set UpdateTime='{view.UpdateTime}', "); sb.Append($" MixCId='{view.MixCId}', "); sb.Append($" MixCName='{view.MixCName}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static List GetListRecipePlcView(string metageAId) { //MtypeId List ls = new List(); string sql = $"select Id, MetageId, MTypeId, MId, MName, Weight, Difference, DeviceId, DeviceName from lj_metage_detail where MetageId='{metageAId}'"; var dataTable = GetTable(sql); foreach (DataRow dr in dataTable.Rows) { var meId = Convert.ToInt32(dr["MTypeId"]); //大仓物料 if (meId == 1) { } var view = new RecipePlcView(); // view.TolErance= } return ls; } public static List GetRecip(string metageId) { string sql = $"select lsm.Code, a.Weight,a.Difference from lj_metage_detail a " + $"left join dbo.lj_stock_material lsm on a.DeviceId = lsm.Id where a.MetageId='{metageId}'"; var dataTable = GetTable(sql); List list = new List(); foreach (DataRow dataTableRow in dataTable.Rows) { RecipePlcView view = new RecipePlcView() { Bin = Convert.ToInt16(dataTableRow["Code"]), Set = Convert.ToSingle(dataTableRow["Weight"]), Tolerance = Convert.ToSingle(dataTableRow["Weight"]) }; list.Add(view); } return list; } public static List GetStep(string metageId) { string sql = $" select Id, MixId, ActionId, ActionName, SecondTime, Temperature, Speed, Weight, Difference, Remark " + $" from lj_mix_detail where MixId='{metageId}'"; var table = GetTable(sql); List list = new List(); foreach (DataRow tableRow in table.Rows) { Step step = new Step(); //代码 step.MixCode = Convert.ToInt16(tableRow["ActionId"]); //时间 step.MixTime = Convert.ToInt16(tableRow["SecondTime"]); //温度 step.MixTemp = Convert.ToInt32(tableRow["SecondTime"]); //速度 step.MixSpeed = Convert.ToInt32(tableRow["SecondTime"]); list.Add(step); } return list; } } }