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 (\"PlanNo\", Status, CreateTime, UpdateTime, BegTime, EndTime, NumCar, Unit, Remark, IsEnable,\r\n " + $" FormulaId, FormulaName, PlanName, ClassName)\r\nvalues (@PlanNo,@Status,@CreateTime,@UpdateTime,@BegTime,@EndTime,@NumCar,@Unit," + $" @Remark ,@IsEnable,@FormulaId,@FormulaName,@PlanName,@ClassName);"; IDictionary dic = new Dictionary(); dic["@PlanNo"] = view.PlanNo; dic["@Status"] = view.Status; dic["@CreateTime"] = view.CreateTime; dic["@UpdateTime"] = null; dic["@BegTime"] = view.BegTime; dic["@EndTime"] = view.EndTime; dic["@NumCar"] = view.NumCar; dic["@Unit"] = view.Unit; dic["@Remark"] = view.Remark; dic["@IsEnable"] = 1; dic["@FormulaId"] = view.FormulaId; dic["@FormulaName"] = view.FormulaName; dic["@PlanName"] = view.PlanName; dic["@ClassName"] = view.ClassName; ExecuteNonQuery(sql,dic); } public static void Update(LjPlanningView view) { StringBuilder sb = new StringBuilder(); sb.Append(" update lj_planning "); sb.Append($" set PlanNo='{view.PlanNo}', "); sb.Append($" UpdateTime='{view.UpdateTime}', "); sb.Append($" BegTime='{view.BegTime}', "); sb.Append($" EndTime='{view.EndTime}', "); sb.Append($" NumCar='{view.NumCar}', "); sb.Append($" Unit='{view.Unit}', "); sb.Append($" FormulaId='{view.FormulaId}', "); sb.Append($" FormulaName='{view.FormulaName}', "); sb.Append($" PlanName='{view.PlanName}', "); sb.Append($" ClassName='{view.ClassName}', "); sb.Append($" Remark='{view.Remark}' "); sb.Append($" where id={view.Id}"); ExecuteNonQuery(sb.ToString()); } public static void SoftDel(int id) { string sql = $"update lj_planning set IsEnable=0 where Id={id}"; ExecuteNonQuery(sql); } /// /// 根据Id获取计划的Status /// /// /// public static int GetStatusById(int id) { string sql = $"select Id, No, Status from lj_planning where id={id}"; DataTable dt = GetTable(sql); if (dt.Rows.Count == 1) { DataRow dr = dt.Rows[0]; return Convert.ToInt32(dr["Status"].ToString()); } return -1000; } public static int UpdateStatus(int status, int id) { string sql = $"update lj_planning set Status='{status}' where id={id}"; ExecuteNonQuery(sql); return 1; } public static LjPlanningView GetById(int id) { string sql = $"select Id, PlanNo, Status, CreateTime, UpdateTime, BegTime, EndTime, NumCar, Unit, Remark, IsEnable, FormulaId, FormulaName, PlanName, ClassName 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["PlanNo"] != null) { view.PlanNo = dr["PlanNo"].ToString(); } if (dr["Status"] != null) { view.Status = dr["Status"].ToString(); } if (dr["CreateTime"] != null) { view.CreateTime = Convert.ToDateTime(dr["CreateTime"]); } if (dr["UpdateTime"] != null && dr["UpdateTime"]!=DBNull.Value) { 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["Unit"] != null) { view.Unit = Convert.ToInt32(dr["Unit"]); } if (dr["Remark"] != null) { view.Remark = dr["Remark"].ToString(); } if (dr["FormulaId"] != null) { view.FormulaId = Convert.ToInt32(dr["FormulaId"]); } if (dr["ClassName"] != null) { view.ClassName = dr["ClassName"].ToString(); } if (dr["PlanName"] != null) { view.PlanName = dr["PlanName"].ToString(); } view.Id = id; } return view; } } }