using System; using System.IO; using System.Reflection; using System.Xml; using System.Data; using Mesnac.Equips; using Mesnac.Action.Feeding.ProducingPlan; using Mesnac.Action.Base; using Mesnac.Codd.Session; using Mesnac.Basic; using System.Xml.Serialization; using System.Collections.Generic; namespace Mesnac.Action.Feeding.BasicInfo { public class RecipeData { #region 基本函数 /// /// 获取本地连接 /// /// private DbHelper getLocalHelper() { return new DatabaseAction().NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local); } /// /// 获取网络连接 /// /// private DbHelper getServerHelper() { return new DatabaseAction().NewDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Server); } /// /// Xml序列化DataTable /// /// /// private string SerializeDataTable(DataTable dt) { StringWriter strWriter = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(DataTable)); serializer.Serialize(strWriter, dt); return strWriter.ToString(); } #endregion #region 基本类型 /// /// 称量类型 /// public enum WeightType { 炭黑 = 0, 油 = 1, 胶料 = 2, 粉料 = 3, 小料 = 4, } public class PptPlanInfo { /// /// 计划号 /// public string PlanID { get; set; } /// /// 生产日期 /// public string PlanDate { get; set; } /// /// 机台代码 /// public string RecipeEquipCode { get; set; } /// /// 物料代码 /// public string RecipeMaterialCode { get; set; } /// /// 配方名称 /// public string RecipeMaterialName { get; set; } /// /// 配方版本号 /// public string RecipeVersionID { get; set; } /// /// 用户配方版本号 /// public string RecipeUserVersion { get; set; } /// /// 生产班次 /// public string ShiftID { get; set; } /// /// 生产班组 /// public string ClassID { get; set; } /// /// 顺序号 /// public string SerialNum { get; set; } /// /// 优先级 /// public string PriLevel { get; set; } /// /// 配方别名 /// public string RecipeName { get; set; } /// /// 配方类型 /// public string RecipeType { get; set; } /// /// 运行方式 /// public string RunType { get; set; } /// /// 打印方式 /// public string PrintType { get; set; } /// /// 计划来源 /// public string PlanSource { get; set; } /// /// 每车重量 /// public string TotalWeight { get; set; } /// /// 计数 /// public int PlanNum { get; set; } /// /// 计划重量 /// public string PlanWeight { get; set; } /// /// 完成数量 /// public string RealNum { get; set; } /// /// 完成重量 /// public string RealWeight { get; set; } /// /// 计划紧急状态 /// public string UrgencyState { get; set; } /// /// 计划状态 /// public string PlanState { get; set; } /// /// 计划编制日期 /// public string OperDatetime { get; set; } /// /// 计划结束日期 /// public string PlanEndTime { get; set; } /// /// 实际开始日期 /// public string RealStartTime { get; set; } /// /// 实际结束日期 /// public string RealEndtime { get; set; } /// /// 计划制定者 /// public string OperCode { get; set; } /// /// 接收标志 /// public string ReviseSgn { get; set; } /// /// 小料计划已生成 /// public string Smallcreate { get; set; } /// /// 平均车时间 /// public string AvgTime { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 删除标志 /// public string DeleteFlag { get; set; } /// /// 生成计划标志 /// public string CreatePlanFlag { get; set; } } /// /// 配方信息 /// public class RecipeInfo { /// ///编号 /// public int ObjID { get; set; } /// ///机台编码 /// public string RecipeEquipCode { get; set; } /// ///物料编码 /// public string RecipeMaterialCode { get; set; } /// ///版本号 /// public string RecipeVersionID { get; set; } /// ///配方名称 /// public string RecipeName { get; set; } /// ///配方类型 /// public int RecipeType { get; set; } /// ///物料名称 /// public string RecipeMaterialName { get; set; } /// ///用户配方版本 /// public int RecipeUserVersion { get; set; } /// ///配方状态 /// public int RecipeState { get; set; } /// ///配方创建时间 /// public int RecipeDefineDate { get; set; } /// ///最后一次修改日期 /// public int RecipeModifyTime { get; set; } /// ///每车时间 /// public int LotDoneTime { get; set; } /// ///每架车数 /// public int ShelfLotCount { get; set; } /// ///每车重量 /// public int LotTotalWeight { get; set; } /// ///炭黑回收方式 /// public int CarbonRecycleType { get; set; } /// ///炭黑回收时间 /// public int CarbonRecycleTime { get; set; } /// ///超温排胶最短时间 /// public int OverTempMinTime { get; set; } /// ///超时排胶时间 /// public int OverTimeSetTime { get; set; } /// ///超温排胶温度 /// public int OverTempSetTemp { get; set; } /// ///最高进料温度 /// public int InPolyMaxTemp { get; set; } /// ///最低进胶温度 /// public int InPolyMinTemp { get; set; } /// ///加胶时间 /// public int InPolySetTime { get; set; } /// ///加炭黑时间 /// public int InCarbonSetTime { get; set; } /// ///加油时间 /// public int InOilSetTime { get; set; } /// ///加粉料时间 /// public int InPowderSetTime { get; set; } /// ///转速允许偏差 /// public int RollSpeedDiff { get; set; } /// ///上顶栓压力允许偏差 /// public int RamPressDiff { get; set; } /// ///是否使用三区温度 /// public int IsUseAreaTemp { get; set; } /// ///侧壁温度 /// public int SideTemp { get; set; } /// ///侧壁温度偏差 /// public int SideTempDiff { get; set; } /// ///转子温度 /// public int RollTemp { get; set; } /// ///转子温度偏差 /// public int RollTempDiff { get; set; } /// ///卸料门温度 /// public int DdoorTemp { get; set; } /// ///卸料门温度偏差 /// public int DdoorTempDiff { get; set; } /// ///操作者 /// public int OperCode { get; set; } /// ///备注 /// public int Remark { get; set; } /// ///开始使用时间 /// public int StartDatetime { get; set; } /// ///结束使用时间 /// public int EndDatetime { get; set; } /// ///审核人 /// public int AuditUser { get; set; } /// ///审核日期 /// public int AuditDateTime { get; set; } /// ///工艺指导说明 /// public int RecipeDic { get; set; } /// ///工艺停放时间要求 /// public int StayTimeSpand { get; set; } /// ///研发版本号 /// public int RearchCode { get; set; } /// ///补偿温度 /// public int MakeUpTemp { get; set; } /// ///最新标识 /// public int NewFlag { get; set; } /// ///计划数量 /// public int SetNumber { get; set; } /// ///超能量排胶最短时间 /// public int OverEnergySetTime { get; set; } /// ///超能量排胶能量 /// public int OverEnergySetEnergy { get; set; } } /// /// 密炼信息 /// public class RecipeMixingInfo { /// ///编号 /// public int ObjID { get; set; } /// ///配方编号 /// public int RecipeObjID { get; set; } /// ///物料编码 /// public int RecipeMaterialCode { get; set; } /// ///版本号 /// public int RecipeVersionID { get; set; } /// ///密炼序号 /// public int MixingStep { get; set; } /// ///条件代码 /// public string TermCode { get; set; } /// ///条件名称 /// public string TermName { get; set; } /// ///条件地址 /// public int TermCodeAddress { get; set; } /// ///时间 /// public int MixingTime { get; set; } /// ///温度 /// public int MixingTemp { get; set; } /// ///能量 /// public int MixingEnergy { get; set; } /// ///功率 /// public int MixingPower { get; set; } /// ///压力 /// public int MixingPress { get; set; } /// ///转速 /// public int MixingSpeed { get; set; } /// ///动作代码 /// public string ActionCode { get; set; } /// ///动作地址 /// public int ActionCodeAddress { get; set; } #region 同步执行的密炼信息集合,包括当前步骤 private List _synchMixingInfos = new List(); /// /// 同步执行的密炼信息集合,包括当前步骤 /// public List SynchMixingInfos { get { return _synchMixingInfos; } set { _synchMixingInfos = value; } } #endregion } /// /// 称量信息 /// public class RecipeWeightInfo { /// ///编号 /// public int ObjID { get; set; } /// ///料仓编号 /// public int JarNum { get; set; } /// ///配方编号 /// public int RecipeObjID { get; set; } /// ///物料编码 /// public int RecipeMaterialCode { get; set; } /// ///版本号 /// public int RecipeVersionID { get; set; } /// ///称量序号 /// public int WeightID { get; set; } /// ///称量类型 /// public int WeightType { get; set; } /// ///称编号 /// public int ScaleID { get; set; } /// ///称量动作 /// public int ActCode { get; set; } /// ///称量物料代码 /// public string MaterialCode { get; set; } /// ///称量物料名称 /// public string MaterialName { get; set; } /// ///设定重量 /// public double SetWeight { get; set; } /// ///原定重量 /// public double OldSetWeight { get; set; } /// ///允许误差 /// public double ErrorAllow { get; set; } } #endregion #region 计划信息 /// /// 计划数量 /// /// public int GetPlansCount() { PlanLog log = PlanCommon.PlanLog; int result = 0; if (log != null) { result = PlanCommon.GetPlanCount(Basic.DataSourceFactory.MCDbType.Local, new BaseAction().CurrEquipCode, log.LastSelectDate, log.LastSelectShiftID); } return result; } /// /// 执行的计划索引 /// /// public int GetCurrentPlanIndex() { PlanLog log = PlanCommon.PlanLog; int iResult = 0; if (log != null) { iResult = PlanCommon.GetCurrentPlanIndex(Basic.DataSourceFactory.MCDbType.Local, log.LastPlanID); } return iResult; } /// /// 获取当前计划号 /// /// public string GetCurrentPlanID() { PlanLog log = PlanCommon.PlanLog; if (log != null) { return log.LastPlanID; } return string.Empty; } /// /// 获取计划车数 /// /// /// public int GetPlanLotCount(string planid) { DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.CommandText = "SELECT plan_num FROM ppt_plan where plan_id = @PlanID"; dbHelper.ClearParameter(); dbHelper.AddParameter("@PlanID", planid); object obj = dbHelper.ToScalar(); int iResult = 0; if (obj != null && obj != DBNull.Value && int.TryParse(obj.ToString(), out iResult)) { return iResult; } return 0; } /// /// 获取当前计划车数 /// /// public int GetCurrentPlanLotCount() { string planid = GetCurrentPlanID(); return GetPlanLotCount(planid); } #region 获取当前计划信息 /// /// 获取当前计划信息 /// /// 返回计划对象 public PptPlanInfo GetCurrentPptPlanInfo() { PptPlanInfo plan = new PptPlanInfo(); string planid = GetCurrentPlanID(); DataRow row = PlanCommon.GetPlanData(Basic.DataSourceFactory.MCDbType.Local, planid); if (row != null) { plan.PlanID = DataProcessor.RowValue(row, "PlanID", string.Empty); plan.PlanDate = DataProcessor.RowValue(row, "PlanDate", string.Empty); plan.RecipeEquipCode = DataProcessor.RowValue(row, "RecipeEquipCode", string.Empty); plan.RecipeMaterialCode = DataProcessor.RowValue(row, "RecipeMaterialCode", string.Empty); plan.RecipeMaterialName = DataProcessor.RowValue(row, "RecipeMaterialName", string.Empty); plan.RecipeVersionID = DataProcessor.RowValue(row, "RecipeVersionID", string.Empty); //plan.RecipeUserVersion = DataProcessor.RowValue(row, "RecipeUserVersion", string.Empty); plan.ShiftID = DataProcessor.RowValue(row, "ShiftID", string.Empty); plan.ClassID = DataProcessor.RowValue(row, "ClassID", string.Empty); //plan.SerialNum = DataProcessor.RowValue(row, "SerialNum", string.Empty); plan.PriLevel = DataProcessor.RowValue(row, "PriLevel", string.Empty); //plan.RecipeName = DataProcessor.RowValue(row, "RecipeName", string.Empty); //plan.RecipeType = DataProcessor.RowValue(row, "RecipeType", string.Empty); //plan.RunType = DataProcessor.RowValue(row, "RunType", string.Empty); //plan.PrintType = DataProcessor.RowValue(row, "PrintType", string.Empty); //plan.PlanSource = DataProcessor.RowValue(row, "PlanSource", string.Empty); plan.TotalWeight = DataProcessor.RowValue(row, "TotalWeight", string.Empty); plan.PlanNum = DataProcessor.RowValue(row, "PlanNum", 1); plan.PlanWeight = DataProcessor.RowValue(row, "PlanWeight", string.Empty); plan.RealNum = DataProcessor.RowValue(row, "RealNum", string.Empty); plan.RealWeight = DataProcessor.RowValue(row, "RealWeight", string.Empty); //plan.UrgencyState = DataProcessor.RowValue(row, "UrgencyState", string.Empty); plan.PlanState = DataProcessor.RowValue(row, "PlanState", string.Empty); plan.OperDatetime = DataProcessor.RowValue(row, "OperDatetime", string.Empty); //plan.PlanEndTime = DataProcessor.RowValue(row, "PlanEndTime", string.Empty); //plan.RealStartTime = DataProcessor.RowValue(row, "RealStartTime", string.Empty); plan.RealEndtime = DataProcessor.RowValue(row, "RealEndtime", string.Empty); plan.OperCode = DataProcessor.RowValue(row, "OperCode", string.Empty); plan.ReviseSgn = DataProcessor.RowValue(row, "ReviseSgn", string.Empty); //plan.Smallcreate = DataProcessor.RowValue(row, "Smallcreate", string.Empty); //plan.AvgTime = DataProcessor.RowValue(row, "AvgTime", string.Empty); //plan.Remark = DataProcessor.RowValue(row, "Remark", string.Empty); //plan.DeleteFlag = DataProcessor.RowValue(row, "DeleteFlag", string.Empty); //plan.CreatePlanFlag = DataProcessor.RowValue(row, "CreatePlanFlag", string.Empty); } return plan; } #endregion #endregion #region 配方信息 /// /// 根据计划号获取配方号 /// /// 计划号 /// 返回对应计划的配方号,如果没有对应则返回0 public string GetRecipeID(string planid) { string Result = string.Empty; DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.CommandText = @"SELECT t2.ObjID FROM dbo.ppt_plan t1 INNER JOIN dbo.pmt_recipe t2 ON substring(t1.equip_code,4,2)=t2.equip_code AND t1.mater_code=t2.mater_code AND t1.edt_code=t2.edt_code WHERE t1.plan_id=@PlanID"; dbHelper.ClearParameter(); dbHelper.AddParameter("@PlanID", planid); object result = dbHelper.ToScalar(); if (result != null && result != System.DBNull.Value) { return result.ToString(); } else { return "0"; } } /// /// 获取当前配方号 /// /// public string GetCurrentRecipeID() { string planid = GetCurrentPlanID(); return GetRecipeID(planid); } /// /// 设置当前配方号 /// public void SetCurrentRecipeID() { string recipeid = GetCurrentRecipeID(); DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.CommandText = "UPDATE SysKeyValue SET ssValue=@RecipeID WHERE ssKey='RecipeID'"; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.ExecuteNonQuery(); dbHelper.CommandText = "UPDATE SysKeyValue SET ssValue = t.mater_name FROM pmt_recipe t WHERE ssKey='RecipeMixingName' AND t.ObjID=@RecipeID"; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.ExecuteNonQuery(); dbHelper.CommandText = "SELECT ssRemark FROM SysKeyValue WHERE ssKey='RecipeMixing'"; string sqlstr = dbHelper.ToScalar().ToString(); sqlstr = string.Format(sqlstr, recipeid); dbHelper.CommandText = sqlstr; DataTable dt = dbHelper.ToDataTable(); dt.TableName = "tableName"; string xml = SerializeDataTable(dt); dbHelper.CommandText = "INSERT INTO dbo.PmtRecipeMixingXml(RecipeID, DataXml) VALUES (@RecipeID,@DataXml);SELECT SCOPE_IDENTITY();"; dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.AddParameter("@DataXml", xml); sqlstr = dbHelper.ToScalar().ToString(); dbHelper.CommandText = "UPDATE SysKeyValue SET ssValue =@ssValue WHERE ssKey='RecipeMixing'"; dbHelper.ClearParameter(); dbHelper.AddParameter("@ssValue", sqlstr); dbHelper.ExecuteNonQuery(); } /// /// 获取配方主信息 /// /// /// public DataTable GetRecipeData(string recipeid) { DataTable dt_recipe = new DataTable(); string sqlstr = @"select ObjID,mater_code as RecipeMaterialCode,mater_name as RecipeMaterialName,equip_code as RecipeEquipCode,edt_code as RecipeVersionID,recipe_code as RecipeName,recipe_state as RecipeState,oper_code as OperCode,total_weight as LotTotalWeight,ever_used as EverUsed,black_reuse as CarbonRecycleType,reuse_time as CarbonRecycleTime,mini_time as OverTimeSetTime,max_temp as InPloyMaxTemp,mini_temp as InPloyMinTemp,over_temp as OverTempSetTemp,fill_coef as MakeUpTemp,shelf_num as ShelfLotCount,mem_note as Remark,define_date as RecipeDefineDate,sds_temp as SideTemp,zz_temp as RollTemp,xlm_temp as DdoorTemp,if_not as IsUseAreaTemp,expire_time as OverTempMinTime,OverEnergy,MinEnergyTime,FlagJP,RecipeType as RecipeType from pmt_recipe WHERE ObjID = @RecipeID"; DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.CommandText = sqlstr; dt_recipe = dbHelper.ToDataTable(); return dt_recipe; } /// /// 获取当前配方主信息 /// /// public DataTable GetCurrentRecipeData() { string recipeid = GetCurrentRecipeID(); return GetRecipeData(recipeid); } #region 获取配方主信息 /// /// 初始化填充配方主信息 /// /// /// public RecipeInfo FillRecipeInfo(DataTable dt_recipe) { RecipeInfo recipe = new RecipeInfo(); if (dt_recipe.Rows.Count == 0) { return recipe; } recipe.ObjID = DataProcessor.RowValue(dt_recipe.Rows[0], "ObjID", 0); recipe.RecipeEquipCode = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeEquipCode", string.Empty); recipe.RecipeMaterialCode = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeMaterialCode", string.Empty); recipe.RecipeVersionID = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeVersionID", string.Empty); recipe.RecipeName = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeName", string.Empty); recipe.RecipeType = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeType", 0); recipe.RecipeMaterialName = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeMaterialName", string.Empty); //recipe.RecipeUserVersion = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeUserVersion", 0); recipe.RecipeState = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeState", 0); recipe.RecipeDefineDate = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeDefineDate", 0); //recipe.RecipeModifyTime = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeModifyTime", 0); //recipe.LotDoneTime = DataProcessor.RowValue(dt_recipe.Rows[0], "LotDoneTime", 0); recipe.ShelfLotCount = DataProcessor.RowValue(dt_recipe.Rows[0], "ShelfLotCount", 3); recipe.LotTotalWeight = DataProcessor.RowValue(dt_recipe.Rows[0], "LotTotalWeight", 0); recipe.CarbonRecycleType = DataProcessor.RowValue(dt_recipe.Rows[0], "CarbonRecycleType", 0); recipe.CarbonRecycleTime = DataProcessor.RowValue(dt_recipe.Rows[0], "CarbonRecycleTime", 0); recipe.OverTempMinTime = DataProcessor.RowValue(dt_recipe.Rows[0], "OverTempMinTime", 0); recipe.OverTimeSetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "OverTimeSetTime", 0); recipe.OverTempSetTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "OverTempSetTemp", 0); //recipe.InPolyMaxTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "InPolyMaxTemp", 0); //recipe.InPolyMinTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "InPolyMinTemp", 0); //recipe.InPolySetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "InPolySetTime", 0); //recipe.InCarbonSetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "InCarbonSetTime", 0); //recipe.InOilSetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "InOilSetTime", 0); //recipe.InPowderSetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "InPowderSetTime", 0); //recipe.RollSpeedDiff = DataProcessor.RowValue(dt_recipe.Rows[0], "RollSpeedDiff", 0); //recipe.RamPressDiff = DataProcessor.RowValue(dt_recipe.Rows[0], "RamPressDiff", 0); recipe.IsUseAreaTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "IsUseAreaTemp", 0); recipe.SideTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "SideTemp", 0); //recipe.SideTempDiff = DataProcessor.RowValue(dt_recipe.Rows[0], "SideTempDiff", 0); recipe.RollTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "RollTemp", 0); //recipe.RollTempDiff = DataProcessor.RowValue(dt_recipe.Rows[0], "RollTempDiff", 0); recipe.DdoorTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "DdoorTemp", 0); //recipe.DdoorTempDiff = DataProcessor.RowValue(dt_recipe.Rows[0], "DdoorTempDiff", 0); recipe.OperCode = DataProcessor.RowValue(dt_recipe.Rows[0], "OperCode", 0); recipe.Remark = DataProcessor.RowValue(dt_recipe.Rows[0], "Remark", 0); //recipe.StartDatetime = DataProcessor.RowValue(dt_recipe.Rows[0], "StartDatetime", 0); //recipe.EndDatetime = DataProcessor.RowValue(dt_recipe.Rows[0], "EndDatetime", 0); //recipe.AuditUser = DataProcessor.RowValue(dt_recipe.Rows[0], "AuditUser", 0); //recipe.AuditDateTime = DataProcessor.RowValue(dt_recipe.Rows[0], "AuditDateTime", 0); //recipe.RecipeDic = DataProcessor.RowValue(dt_recipe.Rows[0], "RecipeDic", 0); //recipe.StayTimeSpand = DataProcessor.RowValue(dt_recipe.Rows[0], "StayTimeSpand", 0); //recipe.RearchCode = DataProcessor.RowValue(dt_recipe.Rows[0], "RearchCode", 0); recipe.MakeUpTemp = DataProcessor.RowValue(dt_recipe.Rows[0], "MakeUpTemp", 0); //recipe.NewFlag = DataProcessor.RowValue(dt_recipe.Rows[0], "NewFlag", 0); //recipe.OverEnergySetEnergy = DataProcessor.RowValue(dt_recipe.Rows[0], "OverEnergySetEnergy", 0); //recipe.OverEnergySetTime = DataProcessor.RowValue(dt_recipe.Rows[0], "OverEnergySetTime", 0); if (recipe.IsUseAreaTemp == 0) { recipe.SideTemp = 0; recipe.RollTemp = 0; recipe.DdoorTemp = 0; } return recipe; } /// /// 获取当前配方主信息 /// /// public RecipeInfo GetCurrentRecipeInfo() { DataTable dt = GetCurrentRecipeData(); return FillRecipeInfo(dt); } #endregion /// /// 获取配方密炼信息 /// /// /// public DataTable GetRecipeMixingData(string recipeid) { DataTable dt_mixing = new DataTable(); string sqlstr = @"SELECT t1.ObjID,t1.RecipeObjID,t1.father_code as RecipeMaterialCode,t1.edt_code as RecipeVersionID,t1.mix_id as MixingStep,t1.term_code as TermCode,t1.set_time as MixingTime,t1.set_temp as MixingTemp,t1.set_ener as MixingEnergy,t1.set_power as MixingPower,t1.set_pres as MixingPress,t1.set_rota as MixingSpeed,t1.act_code as ActionCode,t2.ActionAddress,t3.TermAddress FROM pmt_mix t1 LEFT JOIN dbo.PmtAction t2 ON t1.act_code=t2.ActionCode LEFT JOIN dbo.PmtTerm t3 ON t1.term_code=t3.TermCode WHERE t1.RecipeObjID = @RecipeID order by t1.mix_id"; DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.CommandText = sqlstr; dt_mixing = dbHelper.ToDataTable(); return dt_mixing; } /// /// 获取当前配方密炼信息 /// /// public DataTable GetCurrentRecipeMixingData() { string recipeid = GetCurrentRecipeID(); return GetRecipeMixingData(recipeid); } #region 获取配方密炼步骤信息 /// /// 将密炼信息填充至类 /// /// /// public List FillRecipeMixingInfo(DataTable dt_mixing) { //DbHelper dbHelper = getLocalHelper(); //DataTable dt_termaddress = new DataTable(); //dbHelper.CommandType = CommandType.Text; //dbHelper.CommandText = "SELECT * FROM dbo.PmtTerm"; //dt_termaddress = dbHelper.ToDataTable(); //DataTable dt_actionaddress = new DataTable(); //dbHelper.CommandType = CommandType.Text; //dbHelper.CommandText = "SELECT * FROM dbo.PmtAction"; //dt_actionaddress = dbHelper.ToDataTable(); List mixinglst = new List(); //要下传的密炼信息集合 foreach (DataRow row in dt_mixing.Rows) { RecipeMixingInfo mixing = new RecipeMixingInfo(); mixing.ActionCode = DataProcessor.RowValue(row, "ActionCode", string.Empty); mixing.ActionCodeAddress = DataProcessor.RowValue(row, "ActionAddress", 0); //foreach (DataRow _dr in dt_actionaddress.Rows) //{ // if (_dr["ActionCode"].ToString().Trim().Equals(mixing.ActionCode, StringComparison.CurrentCultureIgnoreCase)) // { // mixing.ActionCodeAddress = DataProcessor.RowValue(_dr, "ActionAddress", 0); // break; // } //} mixing.TermCode = DataProcessor.RowValue(row, "TermCode", string.Empty); mixing.TermCodeAddress = DataProcessor.RowValue(row, "TermAddress", 0); //foreach (DataRow _dr in dt_termaddress.Rows) //{ // if (_dr["TermCode"].ToString().Trim().Equals(mixing.TermCode.Trim(), StringComparison.CurrentCultureIgnoreCase)) // { // mixing.TermCodeAddress = DataProcessor.RowValue(_dr, "TermAddress", 0); // mixing.TermName = DataProcessor.RowValue(_dr, "ShowName", string.Empty); // break; // } //} #region 保存同步执行的密炼信息和当前密炼信息 RecipeMixingInfo sychnMixing = new RecipeMixingInfo(); sychnMixing.ObjID = DataProcessor.RowValue(row, "ObjID", 0); sychnMixing.RecipeObjID = DataProcessor.RowValue(row, "RecipeObjID", 0); sychnMixing.RecipeMaterialCode = DataProcessor.RowValue(row, "RecipeMaterialCode", 0); sychnMixing.RecipeVersionID = DataProcessor.RowValue(row, "RecipeVersionID", 0); sychnMixing.TermCode = mixing.TermCode; sychnMixing.TermCodeAddress = mixing.TermCodeAddress; sychnMixing.TermName = mixing.TermName; sychnMixing.MixingStep = DataProcessor.RowValue(row, "MixingStep", 0); sychnMixing.MixingTime = DataProcessor.RowValue(row, "MixingTime", 0); sychnMixing.MixingTemp = DataProcessor.RowValue(row, "MixingTemp", 0); sychnMixing.MixingEnergy = DataProcessor.RowValue(row, "MixingEnergy", 0); sychnMixing.MixingPower = DataProcessor.RowValue(row, "MixingPower", 0); sychnMixing.ActionCode = mixing.ActionCode; sychnMixing.ActionCodeAddress = mixing.ActionCodeAddress; sychnMixing.MixingPress = DataProcessor.RowValue(row, "MixingPress", 0); sychnMixing.MixingSpeed = DataProcessor.RowValue(row, "MixingSpeed", 0); #endregion if (!string.IsNullOrEmpty(mixing.TermName) && mixing.TermName.Trim() == "同时执行") { mixinglst[mixinglst.Count - 1].ActionCodeAddress += mixing.ActionCodeAddress; mixinglst[mixinglst.Count - 1].SynchMixingInfos.Add(sychnMixing); //合并同步执行的密炼步骤信息 continue; } mixing.ObjID = DataProcessor.RowValue(row, "ObjID", 0); mixing.RecipeObjID = DataProcessor.RowValue(row, "RecipeObjID", 0); mixing.RecipeMaterialCode = DataProcessor.RowValue(row, "RecipeMaterialCode", 0); mixing.RecipeVersionID = DataProcessor.RowValue(row, "RecipeVersionID", 0); mixing.MixingStep = DataProcessor.RowValue(row, "MixingStep", 0); mixing.MixingTime = DataProcessor.RowValue(row, "MixingTime", 0); mixing.MixingTemp = DataProcessor.RowValue(row, "MixingTemp", 0); mixing.MixingEnergy = DataProcessor.RowValue(row, "MixingEnergy", 0); mixing.MixingPower = DataProcessor.RowValue(row, "MixingPower", 0); mixing.MixingPress = DataProcessor.RowValue(row, "MixingPress", 0); mixing.MixingSpeed = DataProcessor.RowValue(row, "MixingSpeed", 0); mixing.SynchMixingInfos.Add(sychnMixing); mixinglst.Add(mixing); } return mixinglst; } /// /// 获取当前密炼信息 /// /// public List GetCurrentRecipeMixingInfo() { DataTable dt = GetCurrentRecipeMixingData(); return FillRecipeMixingInfo(dt); } #endregion private string ToString(object obj) { if (obj == null || obj == DBNull.Value) { return string.Empty; } return obj.ToString().Trim(); } /// /// 称量动作信息转义 /// /// /// private int WeightAction(DataRow row) { int iresult = 0; int.TryParse(ToString(row["ActCode"]), out iresult); return iresult; } /// /// 获取配方称量信息 /// /// /// public DataTable GetRecipeWeigthData(string recipeid) { DataTable dt_weight = new DataTable(); // string sqlstr = @"SELECT t1.ObjID,t1.RecipeObjID,t1.weight_id as WeightID,t1.father_code as RecipeMaterialCode,t1.equip_code as RecipeEquipCode,t1.edt_code as RecipeVersionID,t1.weigh_type as WeightType,t1.act_code as ActCode,t1.child_code as MaterialCode,t1.child_name as MaterialName,t1.set_weight as SetWeight,t1.error_allow as ErrorAllow,t3.JarSerial // FROM pmt_weigh t1 // LEFT JOIN pmt_material t2 ON t1.child_code=t2.mater_code // LEFT JOIN SytJar t3 ON t2.mater_name=t3.MaterialName and JarUsed = '使用' // WHERE t1.RecipeObjID = @RecipeID order by t1.weigh_type,t1.weight_id"; // string sqlstr = @"SELECT t1.ObjID,t1.RecipeObjID,t1.weight_id as WeightID,t1.father_code as RecipeMaterialCode,t1.equip_code as RecipeEquipCode,t1.edt_code as RecipeVersionID,t1.weigh_type as WeightType,t1.act_code as ActCode,t1.child_code as MaterialCode,t1.child_name as MaterialName,t1.set_weight as SetWeight,t1.error_allow as ErrorAllow,t3.JarSerial,t1.Auto_ploy // FROM pmt_weigh t1 // LEFT JOIN pmt_material t2 ON t1.child_code=t2.mater_code // LEFT JOIN (select jartype,MaterialName,jarused,deleteflag,maxcapacity,mincapacity,curvalue,curstate,min(jarserial) as jarserial from SytJar where JarUsed = '使用' group by jartype,MaterialName,jarused,deleteflag,maxcapacity,mincapacity,curvalue,curstate) t3 ON t2.mater_name=t3.MaterialName and JarUsed = '使用' // WHERE t1.RecipeObjID = @RecipeID order by t1.weigh_type,t1.weight_id"; //语句中增加了罐的类型 string sqlstr = @"SELECT t1.ObjID,t1.RecipeObjID,t1.weight_id as WeightID,t1.father_code as RecipeMaterialCode,t1.equip_code as RecipeEquipCode,t1.edt_code as RecipeVersionID,t1.weigh_type as WeightType,t1.act_code as ActCode,t1.child_code as MaterialCode,t1.child_name as MaterialName,t1.set_weight as SetWeight,t1.error_allow as ErrorAllow,t3.JarSerial,t1.Auto_ploy FROM pmt_weigh t1 LEFT JOIN pmt_material t2 ON t1.child_code=t2.mater_code LEFT JOIN (select jartype,MaterialName,jarused,deleteflag,maxcapacity,mincapacity,curvalue,curstate,min(jarserial) as jarserial from SytJar where JarUsed = '使用' group by jartype,MaterialName,jarused,deleteflag,maxcapacity,mincapacity,curvalue,curstate) t3 ON t2.mater_type=t3.JarType and t2.mater_name=t3.MaterialName and JarUsed = '使用' WHERE t1.RecipeObjID = @RecipeID order by t1.weigh_type,t1.weight_id"; DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.ClearParameter(); dbHelper.AddParameter("@RecipeID", recipeid); dbHelper.CommandText = sqlstr; dt_weight = dbHelper.ToDataTable(); foreach (DataRow row in dt_weight.Rows) { //数据库ActCode为0:称量,1:称道,2:卸料;PLC为1:称量,2:称道,3:卸料;因此要为ActCode加1 row["ActCode"] = WeightAction(row) + 1; //if (!string.IsNullOrEmpty(row["MaterialCode"].ToString()) && row["WeightType"].ToString() == "2")//如果是胶料特殊处理 //{ // if (Convert.ToInt32(row["MaterialCode"].ToString().Substring(0, 1)) < 3) // row["ActCode"] = 0; // else // row["ActCode"] = 1; //} //row["ActCode"] = WeightAction(row); } dt_weight.TableName = recipeid; return dt_weight; } /// /// 获取当前配方称量信息 /// /// public DataTable GetCurrentRecipeWeigthData() { string recipeid = GetCurrentRecipeID(); return GetRecipeWeigthData(recipeid); } #region 获取配方称量信息 /// /// 获取当前物料的罐号 /// /// 称量类型 /// 物料代码 /// 成功返回对应的罐号,失败返回0 private int GetJarNum(int weightType, string materCode) { // string sqlstr = @"SELECT t1.JarSerial FROM SytJar t1 // INNER JOIN pmt_material t2 ON t1.MaterialName=t2.mater_name // WHERE t2.mater_code=@MaterialCode and t1.JarUsed = '使用'"; string sqlstr = @"SELECT t1.JarSerial FROM SytJar t1 INNER JOIN pmt_material t2 ON t1.MaterialName=t2.mater_name and t1.JarType = t2.mater_Type WHERE t1.JarType=@JarType and t2.mater_code=@MaterialCode and t1.JarUsed = '使用'"; DbHelper dbHelper = getLocalHelper(); dbHelper.CommandType = CommandType.Text; dbHelper.CommandText = sqlstr; dbHelper.ClearParameter(); dbHelper.AddParameter("@JarType", Global.GetJarTypeByWeightType(weightType.ToString())); dbHelper.AddParameter("@MaterialCode", materCode); object obj = dbHelper.ToScalar(); if (obj != null && obj != DBNull.Value) { int iResult = 0; if (int.TryParse(obj.ToString(), out iResult)) { return iResult; } } return 0; } /// /// 将称量转化为类信息 /// /// /// public List FillRecipeWeightInfo(DataTable dt_weight) { List weightlst = new List(); foreach (DataRow row in dt_weight.Rows) { RecipeWeightInfo weight = new RecipeWeightInfo(); weight.ObjID = DataProcessor.RowValue(row, "ObjID", 0); weight.RecipeObjID = DataProcessor.RowValue(row, "RecipeObjID", 0); weight.RecipeMaterialCode = DataProcessor.RowValue(row, "RecipeMaterialCode", 0); weight.RecipeVersionID = DataProcessor.RowValue(row, "RecipeVersionID", 0); weight.WeightID = DataProcessor.RowValue(row, "WeightID", 0); weight.WeightType = DataProcessor.RowValue(row, "WeightType", 0); //weight.ScaleID = DataProcessor.RowValue(row, "ScaleID", 0); weight.ActCode = DataProcessor.RowValue(row, "ActCode", 0); weight.MaterialCode = DataProcessor.RowValue(row, "MaterialCode", string.Empty); weight.MaterialName = DataProcessor.RowValue(row, "MaterialName", string.Empty); weight.SetWeight = DataProcessor.RowValue(row, "SetWeight", 0.00); //weight.OldSetWeight = DataProcessor.RowValue(row, "OldSetWeight", 0.00); weight.ErrorAllow = DataProcessor.RowValue(row, "ErrorAllow", 0.00); weight.JarNum = GetJarNum(weight.WeightType, weight.MaterialCode); weightlst.Add(weight); } return weightlst; } /// /// 获取当前配方称量类信息 /// /// public List GetCurrentRecipeWeightInfo() { DataTable dt = GetCurrentRecipeWeigthData(); return FillRecipeWeightInfo(dt); } /// /// 获取下一个计划编号 /// /// public string GetNextPlanID() { string result = string.Empty; PlanLog planLog = PlanCommon.PlanLog; result = PlanCommon.GetNextPlanID(planLog.LastPlanID, new BaseAction().CurrEquipCode, planLog.LastSelectDate, planLog.LastSelectShiftID); return result; } #endregion #endregion } }