|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity;
|
|
|
|
|
using Mesnac.Action.ChemicalWeighing.Entity.PptPlan;
|
|
|
|
|
using Mesnac.Codd.Session;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Mesnac.Action.ChemicalWeighing.Report
|
|
|
|
|
{
|
|
|
|
|
public class SolventDBHelper
|
|
|
|
|
{
|
|
|
|
|
#region 拼音检索配方物料列表
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 拼音检索配方物料列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>返回配方列表</returns>
|
|
|
|
|
public static List<SimplePmtRecipe> GetRecipeMaterialListPY()
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
string sqlstr = "select ROW_NUMBER() OVER(Order by GETDATE()) ID, recipe_Name from(select distinct recipe_Name from Pmt_recipe where Recipe_Verify=1) t ";
|
|
|
|
|
dbHelper.CommandText = sqlstr;
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
List<SimplePmtRecipe> lst = new List<SimplePmtRecipe>();
|
|
|
|
|
SimplePmtRecipe recipe = null;
|
|
|
|
|
foreach (DataRow row in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
recipe = new SimplePmtRecipe();
|
|
|
|
|
recipe.ID = Mesnac.Basic.DataProcessor.RowValue(row, "ID", String.Empty);
|
|
|
|
|
//recipe.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Id", String.Empty);
|
|
|
|
|
recipe.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Name", String.Empty);
|
|
|
|
|
//recipe.Recipe_type = Mesnac.Basic.DataProcessor.RowValue(row, "recipe_Type", String.Empty);
|
|
|
|
|
lst.Add(recipe);
|
|
|
|
|
}
|
|
|
|
|
return lst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取List
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取List<LR_weigh>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="recipeId">计划号</param>
|
|
|
|
|
/// <returns>返回符合条件List<LR_weigh></returns>
|
|
|
|
|
public static DataTable GetLRWeighDataTable(string Dosing_Id)
|
|
|
|
|
{
|
|
|
|
|
List<Pmt_weigh> lR_Weighs = new List<Pmt_weigh>();
|
|
|
|
|
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
string strSql = "SELECT * FROM Pmt_weigh where Dosing_Id = @Dosing_Id order by ID";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@Dosing_Id", Dosing_Id);
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return table;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 获取LR_plan
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取RT_Plan
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planID">计划号</param>
|
|
|
|
|
/// <returns>返回符合条件List<LR_weigh></returns>
|
|
|
|
|
public static Hw_plan GetRtPlan(string planID, int realNum)
|
|
|
|
|
{
|
|
|
|
|
Hw_plan entity = new Hw_plan();
|
|
|
|
|
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
string strSql = "SELECT top 1 * FROM Hw_plan where Plan_Id = @Plan_Id and Real_Num=@Real_Num";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.AddParameter("@Plan_Id", planID);
|
|
|
|
|
dbHelper.AddParameter("@Real_Num", realNum);
|
|
|
|
|
DataTable table = dbHelper.ToDataTable();
|
|
|
|
|
if (table != null && table.Rows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
foreach (DataRow dr in table.Rows)
|
|
|
|
|
{
|
|
|
|
|
entity = ConvertDataRowToHwPlan(dr);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return entity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Hw_plan ConvertDataRowToHwPlan(DataRow dr)
|
|
|
|
|
{
|
|
|
|
|
if (dr != null)
|
|
|
|
|
{
|
|
|
|
|
Hw_plan plan = new Hw_plan();
|
|
|
|
|
plan.ID = Mesnac.Basic.DataProcessor.RowValue(dr, "ID", 0);
|
|
|
|
|
plan.Dosing_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_Id", String.Empty);
|
|
|
|
|
plan.Plan_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Id", String.Empty);
|
|
|
|
|
plan.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_Code", String.Empty);
|
|
|
|
|
plan.Plan_Serial = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Serial", 0);
|
|
|
|
|
plan.Recipe_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_ID", String.Empty);
|
|
|
|
|
plan.Recipe_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Code", String.Empty);
|
|
|
|
|
plan.Recipe_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Name", String.Empty);
|
|
|
|
|
plan.Version = Mesnac.Basic.DataProcessor.RowValue(dr, "Version", 0);
|
|
|
|
|
plan.Recipe_Type = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_Type", 0);
|
|
|
|
|
plan.Shift_Id = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Id", 0);
|
|
|
|
|
plan.Shift_Class = Mesnac.Basic.DataProcessor.RowValue(dr, "Shift_Class", String.Empty);
|
|
|
|
|
plan.Plan_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Num", 0);
|
|
|
|
|
plan.Real_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Num", 0);
|
|
|
|
|
plan.Duration_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Duration_Time", 0);
|
|
|
|
|
plan.Start_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Start_Date", String.Empty);
|
|
|
|
|
plan.End_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "End_Date", String.Empty);
|
|
|
|
|
plan.Weight_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Man", String.Empty);
|
|
|
|
|
plan.Stock_Man = Mesnac.Basic.DataProcessor.RowValue(dr, "Stock_Man", String.Empty);
|
|
|
|
|
plan.Plan_Batch = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Batch", String.Empty);
|
|
|
|
|
plan.Plan_State = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_State", 0);
|
|
|
|
|
plan.Plan_Date = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_Date", String.Empty);
|
|
|
|
|
plan.Total_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Weight", 0);
|
|
|
|
|
plan.Total_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Total_Error", 0);
|
|
|
|
|
plan.IF_FLAG = Mesnac.Basic.DataProcessor.RowValue(dr, "IF_FLAG", 0);
|
|
|
|
|
plan.IsRetransmission = Mesnac.Basic.DataProcessor.RowValue(dr, "IsRetransmissionv", 0);
|
|
|
|
|
|
|
|
|
|
return plan;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 添加生产计划报表(Hw_plan)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加生产计划
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lrPlan">LR_plan实体类</param>
|
|
|
|
|
/// <returns>返回新加计划的计划号</returns>
|
|
|
|
|
public static bool AddHwPlan(Hw_plan plan)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
|
|
|
|
|
//添加计划的SQL语句
|
|
|
|
|
string strSql3 = @"INSERT INTO Hw_plan(Dosing_Id,Plan_Id,Equip_Code,Plan_Serial,Recipe_ID,Recipe_Code,Recipe_Name,Version,Recipe_Type,Shift_Id,Shift_Class,Plan_Num,Real_Num,Duration_Time,Start_Date,End_Date,Weight_Man,Stock_Man,Plan_Batch,Plan_State,Plan_Date,Total_Weight,Total_Error,IF_FLAG,IsRetransmission)
|
|
|
|
|
VALUES(@Dosing_Id,@Plan_Id,@Equip_Code,@Plan_Serial,@Recipe_ID,@Recipe_Code,@Recipe_Name,@Version,@Recipe_Type,@Shift_Id,@Shift_Class,@Plan_Num,@Real_Num,@Duration_Time,@Start_Date,@End_Date,@Weight_Man,@Stock_Man,@Plan_Batch,@Plan_State,@Plan_Date,@Total_Weight,@Total_Error,@IF_FLAG,@IsRetransmission)";
|
|
|
|
|
dbHelper.CommandText = strSql3;
|
|
|
|
|
|
|
|
|
|
dbHelper.AddParameter("@Dosing_Id", 0);
|
|
|
|
|
dbHelper.AddParameter("@Plan_Id", plan.Plan_Id); //计划号
|
|
|
|
|
dbHelper.AddParameter("@Equip_Code", plan.Equip_Code); //机台号
|
|
|
|
|
dbHelper.AddParameter("@Plan_Serial", plan.Plan_Serial); //排序字段(优先级,在此与ActionOrder相同)
|
|
|
|
|
dbHelper.AddParameter("@Recipe_ID", plan.Recipe_ID);
|
|
|
|
|
dbHelper.AddParameter("@Recipe_Code", plan.Recipe_Code); //配方编码
|
|
|
|
|
dbHelper.AddParameter("@Recipe_Name", plan.Recipe_Name); //配方别名
|
|
|
|
|
dbHelper.AddParameter("@Version", plan.Version); //配方版本号
|
|
|
|
|
//dbHelper.AddParameter("@Mixer_Line", plan.Mixer_Line); //配方版本号
|
|
|
|
|
dbHelper.AddParameter("@Recipe_Type", plan.Recipe_Type); //配方类型
|
|
|
|
|
dbHelper.AddParameter("@Shift_Id", plan.Shift_Id); //班次ID
|
|
|
|
|
dbHelper.AddParameter("@Shift_Class", 0); //班组ID
|
|
|
|
|
dbHelper.AddParameter("@Plan_Num", plan.Plan_Num); //计划数
|
|
|
|
|
dbHelper.AddParameter("@Real_Num", plan.Real_Num); //完成数量
|
|
|
|
|
dbHelper.AddParameter("@Duration_Time", plan.Duration_Time); //持续时间
|
|
|
|
|
dbHelper.AddParameter("@Start_Date", plan.Start_Date); //开始时间
|
|
|
|
|
dbHelper.AddParameter("@End_Date", plan.End_Date); //结束时间
|
|
|
|
|
dbHelper.AddParameter("@Weight_Man", plan.Weight_Man); //称量工
|
|
|
|
|
dbHelper.AddParameter("@Stock_Man", plan.Stock_Man); //投料工
|
|
|
|
|
dbHelper.AddParameter("@Plan_Batch", plan.Plan_Batch); //批次号,不同的现场有不同的命令规则。
|
|
|
|
|
dbHelper.AddParameter("@Plan_State", plan.Plan_State); //计划状态
|
|
|
|
|
dbHelper.AddParameter("@Plan_Date", plan.Plan_Date); //计划日期
|
|
|
|
|
dbHelper.AddParameter("@IF_FLAG", plan.IF_FLAG); //暂时无用
|
|
|
|
|
dbHelper.AddParameter("@Total_Weight", plan.Total_Weight);
|
|
|
|
|
dbHelper.AddParameter("@Total_Error", plan.Total_Error);
|
|
|
|
|
dbHelper.AddParameter("@IsRetransmission", plan.IsRetransmission);
|
|
|
|
|
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 添加物料报表(LR_weigh)
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 添加物料报表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="lrPlan">LR_plan实体类</param>
|
|
|
|
|
/// <returns>返回新加计划的计划号</returns>
|
|
|
|
|
public static bool AddHwWeigh(Hw_weigh weigh,int b)
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
|
|
|
|
|
//添加计划的SQL语句
|
|
|
|
|
string strSql3 = @"INSERT INTO Hw_weigh(Dosing_ID,Plan_ID,Recipe_ID,Material_ID,Material_Name,Set_Weight,Set_Error,Real_Weight,Real_Error,EndTime)
|
|
|
|
|
VALUES(@Dosing_ID,@Plan_ID,@Recipe_ID,@Material_ID,@Material_Name,@Set_Weight,@Set_Error,@Real_Weight,@Real_Error,@EndTime)";
|
|
|
|
|
dbHelper.CommandText = strSql3;
|
|
|
|
|
|
|
|
|
|
dbHelper.AddParameter("@Dosing_ID", b);//批次
|
|
|
|
|
dbHelper.AddParameter("@Plan_ID", weigh.Plan_ID); //计划号
|
|
|
|
|
dbHelper.AddParameter("@Recipe_ID", weigh.Recipe_ID); //配方号
|
|
|
|
|
dbHelper.AddParameter("@Material_ID", weigh.Material_ID); //物料号
|
|
|
|
|
dbHelper.AddParameter("@Material_Name", weigh.Material_Name); //物料名称
|
|
|
|
|
dbHelper.AddParameter("@Set_Weight", weigh.Set_Weight); //设置重量
|
|
|
|
|
dbHelper.AddParameter("@Set_Error", weigh.Set_Error); //设置误差
|
|
|
|
|
dbHelper.AddParameter("@Real_Weight", weigh.Real_Weight); //称量重量
|
|
|
|
|
dbHelper.AddParameter("@Real_Error", weigh.Real_Error); //称量误差
|
|
|
|
|
dbHelper.AddParameter("@EndTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); //完成时间
|
|
|
|
|
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 更新计划状态
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 更新计划状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planId">计划号</param>
|
|
|
|
|
/// <param name="state">任务状态 3:正在运行;4:已下传;5:未启动;7:已终止;8:已完成</param>
|
|
|
|
|
/// <param name="IfFlag">是否完成</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static bool UpdateHwPlan(string planId, decimal total_Weight, decimal total_Error)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
|
|
|
|
|
if (dbHelper == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
|
|
|
|
|
}
|
|
|
|
|
dbHelper.ClearParameter();
|
|
|
|
|
dbHelper.CommandType = CommandType.Text;
|
|
|
|
|
string strSql = "update Hw_plan set Total_Weight = @Total_Weight, Total_Error = @Total_Error where Plan_Id = @PlanID";
|
|
|
|
|
dbHelper.CommandText = strSql;
|
|
|
|
|
|
|
|
|
|
dbHelper.AddParameter("@Total_Weight", total_Weight);
|
|
|
|
|
dbHelper.AddParameter("@Total_Error", total_Error);
|
|
|
|
|
dbHelper.AddParameter("@PlanID", planId);
|
|
|
|
|
dbHelper.ExecuteNonQuery();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|