using DevExpress.Office.Utils; using DevExpress.Utils.DPI; using DevExpress.XtraRichEdit.Fields; using Mesnac.Action.ChemicalWeighing.LjMaterial; using Mesnac.Action.ChemicalWeighing.LjPlanning.Entity; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Mesnac.Action.ChemicalWeighing.LjPlanning.Db { public class LjFormulaDb: DBHelp { public static LjFormula GetById(int id) { string sql = "select Id, FormulaNo, FormulaName, RecipeTypeId,\r\n RecipeTypeName, IsEnable, FormulaVersion, " + "CreateTime, UpdateTime, Unit,CbSiloC,CbSiloH,CbWeterH,Status from Lj_Formula\r\nwhere Id=" + id; var dataTable=GetTable(sql); if(dataTable.Rows.Count ==1) { var dr= dataTable.Rows[0]; LjFormula lj = new LjFormula(); lj.Id = id; lj.FormulaNo = dr["FormulaNo"].ToString(); lj.FormulaName = dr["FormulaName"].ToString(); lj.RecipeTypeId = Convert.ToInt32(dr["RecipeTypeId"].ToString()); lj.RecipeTypeName = dr["FormulaName"].ToString(); lj.FormulaVersion = dr["FormulaVersion"].ToString(); lj.CreateTime = Convert.ToDateTime(dr["CreateTime"]); lj.Unit = Convert.ToInt32(dr["Unit"]); lj.CbSiloC = Convert.ToBoolean(dr["CbSiloC"]); lj.CbSiloH = Convert.ToBoolean(dr["CbSiloH"]); lj.CbWeterH = Convert.ToBoolean(dr["CbWeterH"]); return lj; } return null; } public static List GetDrp() { string sql = "select Id, FormulaNo, FormulaName from Lj_Formula where IsEnable = 1"; var dataTable = GetTable(sql); List < MyNameValue> myNames=new List(); foreach (DataRow item in dataTable.Rows) { myNames.Add(new MyNameValue() { Id = Convert.ToInt32(item["Id"]), Name = item["FormulaName"].ToString() }); } return myNames; } public static DataTable GetMainTable() { string sql = "select Id, FormulaNo, FormulaName, RecipeTypeId, RecipeTypeName, IsEnable, FormulaVersion, " + "CreateTime, UpdateTime, Unit from Lj_Formula where IsEnable=1 order by CreateTime desc"; return GetTable(sql); } public static DataTable GetMainTable(string recipeTypeId, string formulaName) { string sql = "select Id, FormulaNo, FormulaName, RecipeTypeId, RecipeTypeName, IsEnable, FormulaVersion, " + "CreateTime, UpdateTime, Unit from Lj_Formula where IsEnable=1 "; if(!string.IsNullOrEmpty(recipeTypeId) && recipeTypeId!="-1") { sql += " and RecipeTypeId=" + recipeTypeId; } if(!string.IsNullOrEmpty(formulaName) && formulaName.Length > 0) { sql += $" and FormulaName like '%{formulaName}%'"; } sql += " order by CreateTime desc"; return GetTable(sql); } public static DataTable GetDetailTable(int formulaId) { string sql = "select Id, FormulaId, BinNo, MId, MName, Weight, Tolerance, Machine, MachineType,\r\n FormulaType, ActionCode, ActionName, TimeInfo, Temp, Speed, SetValue, SetTolerance,StockMaterialId,ActionId from Lj_Formula_Detail where FormulaId=" + formulaId; var dataTable = GetTable(sql); return dataTable; } public static List GetDetail(int formulaId) { string sql = "select Id, FormulaId, BinNo, MId, MName, Weight, Tolerance, Machine, MachineType,\r\n FormulaType, ActionCode, ActionName, TimeInfo, Temp, Speed, SetValue, SetTolerance,StockMaterialId,ActionId from Lj_Formula_Detail where FormulaId=" + formulaId; var dataTable = GetTable(sql); List ls = new List(dataTable.Rows.Count); foreach (DataRow item in dataTable.Rows) { LjFormulaDetail detail = new LjFormulaDetail(); detail.Id = Convert.ToInt32(item["id"].ToString()); detail.FormulaId = formulaId; detail.BinNo = Convert.ToInt32(item["BinNo"]); detail.MId = Convert.ToInt32(item["MId"]); detail.MName = item["MName"].ToString(); detail.Weight = Convert.ToSingle(item["Weight"]); detail.Tolerance = Convert.ToSingle(item["Tolerance"]); detail.Machine = Convert.ToString(item["Machine"]); detail.MachineType = item["MachineType"].ToString(); detail.FormulaType = Convert.ToInt32(item["FormulaType"]); detail.ActionCode = Convert.ToInt32(item["ActionCode"]); detail.ActionName = item["ActionName"].ToString(); detail.TimeInfo = Convert.ToInt32(item["TimeInfo"].ToString()); detail.Temp = Convert.ToSingle(item["Temp"].ToString()); detail.Speed = Convert.ToSingle(item["Speed"].ToString()); detail.SetValue = Convert.ToSingle(item["SetValue"].ToString()); detail.SetTolerance = Convert.ToSingle(item["SetTolerance"].ToString()); detail.StockMaterialId = Convert.ToInt32(item["StockMaterialId"]); detail.ActionId = Convert.ToInt32(item["ActionId"]); ls.Add(detail); } return ls; } } }