You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjPlanning/LjPlanningDb.cs

287 lines
9.5 KiB
C#

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,@ProductLineId,@ProductLineName,@IsEnable)";
IDictionary<string, object> dic = new Dictionary<string, object>();
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;
dic["@ProductLineId"] = view.ProductLineId;
dic["@ProductLineName"] = view.ProductLineName;
dic["@IsEnable"] = 1;
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($" Status='{view.Status}', ");
//sb.Append($" CreateTime='{view.CreateTime}', ");
sb.Append($" UpdateTime='{view.UpdateTime}', ");
sb.Append($" BegTime='{view.BegTime}', ");
sb.Append($" EndTime='{view.EndTime}', ");
sb.Append($" NumCar='{view.NumCar}', ");
sb.Append($" Share='{view.Share}', ");
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($" ProductLineId={view.ProductLineId}, ");
sb.Append($" ProductLineName='{view.ProductLineName}' ");
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);
}
/// <summary>
/// 根据Id获取计划的Status
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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, No, Status, CreateTime, UpdateTime, BegTime, EndTime, " +
$"NumCar, Share, MetageAId, MetageAName, MixAId, MixAName," +
$" MetageB1Id, MetageB1Name, MetageB2Id, MetageB2Name, MixBId, MixBName, " +
$"MixCId, MixCName, RecipeType, Remark,ProductLineId,ProductLineName 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();
}
view.ProductLineId = Convert.ToInt32(dr["ProductLineId"]);
view.ProductLineName = dr["ProductLineName"].ToString();
view.Id = id;
}
return view;
}
}
}