using System; using System.Collections.Generic; using System.Data; using System.Runtime.CompilerServices; using System.Text; using Mesnac.Action.ChemicalWeighing.LjMaterial; namespace Mesnac.Action.ChemicalWeighing.LjPlanning { public class LjPlanningDb:DBHelp { public static void Add(LjPlanningView view) { string sql = $"insert into lj_planning " + $"values (@No,@Status,@CreateTime,@UpdateTime,@BegTime,@EndTime,@NumCar," + $"@Share,@MetageAId,@MetageAName,@MixAId,@MixAName,@MetageB1Id,@MetageB1Name,@MetageB2Id,@MetageB2Name,@MixBId,@MixBName,@MixCId,@MixCName,@RecipeType,@Remark)"; IDictionary dic = new Dictionary(); dic["@No"] = view.No; dic["@Status"] = view.Status; dic["@CreateTime"] = view.CreateTime; dic["@UpdateTime"] = view.UpdateTime; dic["@BegTime"] = view.BegTime; dic["@EndTime"] = view.EndTime; dic["@NumCar"] = view.NumCar; dic["@Share"] = view.Share; dic["@MetageAId"] = view.MetageAId; dic["@MetageAName"] = view.MetageAName; dic["@MixAId"] = view.MixAId; dic["@MixAName"] = view.MixAName; dic["@MetageB1Id"] = view.MetageB1Id; dic["@MetageB1Name"] = view.MetageB1Name; dic["@MetageB2Id"] = view.MetageB2Id; dic["@MetageB2Name"] = view.MetageB2Name; dic["@MixBId"] = view.MixBId; dic["@MixBName"] = view.MixBName; dic["@MixCId"] = view.MixCId; dic["@MixCName"] = view.MixCName; dic["@RecipeType"] = view.RecipeType; dic["@Remark"] = view.Remark; ExecuteNonQuery(sql,dic); } public static void Update(LjPlanningView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_planning "); sb.Append($" set No='{view.No}', "); sb.Append($" set Status='{view.Status}', "); sb.Append($" set CreateTime='{view.CreateTime}', "); sb.Append($" set UpdateTime='{view.UpdateTime}', "); sb.Append($" set BegTime='{view.BegTime}', "); sb.Append($" set EndTime='{view.EndTime}', "); sb.Append($" set NumCar='{view.NumCar}', "); sb.Append($" set Share='{view.Share}', "); sb.Append($" set MetageAId='{view.MetageAId}', "); sb.Append($" set MetageAName='{view.MetageAName}', "); sb.Append($" set MixAId='{view.MixAId}', "); sb.Append($" set MixAName='{view.MixAName}', "); sb.Append($" set MetageB1Id='{view.MetageB1Id}', "); sb.Append($" set MetageB1Name='{view.MetageB1Name}', "); sb.Append($" set MetageB2Id='{view.MetageB2Id}', "); sb.Append($" set MetageB2Name='{view.MetageB2Name}', "); sb.Append($" set MixBId='{view.MixBId}', "); sb.Append($" set MixBName='{view.MixBName}', "); sb.Append($" set MixCId='{view.MixCId}', "); sb.Append($" set MixCName='{view.MixCName}', "); sb.Append($" set RecipeType='{view.RecipeType}', "); sb.Append($" set Remark='{view.Remark}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static LjPlanningView GetById(int id) { string sql = $"select Id, No, Status, CreateTime, UpdateTime, BegTime, EndTime, " + $"NumCar, Share, MetageAId, MetageAName, MixAId, MixAName," + $" MetageB1Id, MetageB1Name, MetageB2Id, MetageB2Name, MixBId, MixBName, " + $"MixCId, MixCName, RecipeType, Remark from lj_planning where id={id}"; DataTable dt = GetTable(sql); LjPlanningView view = new LjPlanningView(); if (dt.Rows.Count == 1) { DataRow dr = dt.Rows[0]; if (dr["No"] != null) { view.No = dr["No"].ToString(); } if (dr["Status"] != null) { view.Status = dr["Status"].ToString(); } if (dr["CreateTime"] != null) { view.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } if (dr["UpdateTime"] != null) { view.UpdateTime = Convert.ToDateTime(dr["UpdateTime"]); } if (dr["BegTime"] != null) { view.BegTime = dr["BegTime"].ToString(); } if (dr["EndTime"] != null) { view.EndTime = dr["EndTime"].ToString(); } if (dr["NumCar"] != null) { view.NumCar = Convert.ToInt32(dr["NumCar"]); } if (dr["Share"] != null) { view.Share = Convert.ToInt32(dr["Share"]); } 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(); } } return view; } } }