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.

433 lines
20 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using Mesnac.Action.ChemicalWeighing.Entity;
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 ReportHelper
{
#region 获取List<LR_lot>
/// <summary>
/// 获取List<LR_lot>
/// </summary>
/// <param name="recipeId">计划号</param>
/// <returns>返回符合条件List<LR_lot></returns>
public static List<LR_lot> GetLR_lotList(string planID)
{
List<LR_lot> lR_Lots = new List<LR_lot>();
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 LR_lot where Plan_id = @Plan_id order by Serial_Num";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_id", planID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
LR_lot entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToLR_lot(dr);
lR_Lots.Add(entity);
}
}
return lR_Lots;
}
#endregion
#region 把DataRow数据行转换为LR_lot实体对象
/// <summary>
/// 把DataRow数据行转换为LR_lot实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static LR_lot ConvertDataRowToLR_lot(DataRow dr)
{
if (dr != null)
{
LR_lot lR_Lot = new LR_lot();
lR_Lot.Dosing_id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_id", 0);
lR_Lot.Plan_id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_id", String.Empty);
lR_Lot.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_code", String.Empty);
lR_Lot.Serial_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Serial_Num", 0);
lR_Lot.Prd_date = Mesnac.Basic.DataProcessor.RowValue(dr, "Prd_date", String.Empty);
lR_Lot.Real_weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_weight", 0.0f);
lR_Lot.Real_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Error", 0.0f);
lR_Lot.Waste_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Waste_Time", 0);
lR_Lot.Warning_sgn = Mesnac.Basic.DataProcessor.RowValue(dr, "warning_sgn", 0);
lR_Lot.Net_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Net_Weight", 0.0f);
lR_Lot.Ng_sgn = Mesnac.Basic.DataProcessor.RowValue(dr, "Ng_sgn", 0);
lR_Lot.ResetFlag = Mesnac.Basic.DataProcessor.RowValue(dr, "resetFlag", 0);
lR_Lot.ResetStationNo = Mesnac.Basic.DataProcessor.RowValue(dr, "resetStationNo", 0);
lR_Lot.Lot_Barcode = Mesnac.Basic.DataProcessor.RowValue(dr, "lot_Barcode", String.Empty);
return lR_Lot;
}
else
{
return null;
}
}
#endregion
#region 获取List<LR_recipe>
/// <summary>
/// 获取List<LR_recipe>
/// </summary>
/// <param name="recipeId">计划号</param>
/// <returns>返回符合条件List<LR_recipe></returns>
public static List<LR_recipe> GetLR_recipeList(string planID)
{
List<LR_recipe> lR_Recipes = new List<LR_recipe>();
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 LR_recipe where Plan_id = @Plan_id order by Weight_ID";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Plan_id", planID);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
LR_recipe entity = null;
foreach (DataRow dr in table.Rows)
{
entity = ConvertDataRowToLR_recipe(dr);
lR_Recipes.Add(entity);
}
}
return lR_Recipes;
}
#endregion
#region 把DataRow数据行转换为LR_recipe实体对象
/// <summary>
/// 把DataRow数据行转换为LR_recipe实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
public static LR_recipe ConvertDataRowToLR_recipe(DataRow dr)
{
if (dr != null)
{
LR_recipe lR_Recipe = new LR_recipe();
lR_Recipe.Plan_id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_id", String.Empty);
lR_Recipe.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_code", String.Empty);
lR_Recipe.Weight_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_ID", 0);
lR_Recipe.Material_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_Code", String.Empty);
lR_Recipe.Material_Name = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_Name", String.Empty);
lR_Recipe.Set_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Weight", 0.0f);
lR_Recipe.Set_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Set_Error", 0.0f);
lR_Recipe.CPK_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "CPK_Error", decimal.Zero);
lR_Recipe.Batch_number = Mesnac.Basic.DataProcessor.RowValue(dr, "Batch_number", String.Empty);
lR_Recipe.remark = Mesnac.Basic.DataProcessor.RowValue(dr, "remark", String.Empty);
return lR_Recipe;
}
else
{
return null;
}
}
#endregion
#region 获取List<LR_weigh>
/// <summary>
/// 获取List<LR_weigh>
/// </summary>
/// <param name="recipeId">计划号</param>
/// <returns>返回符合条件List<LR_weigh></returns>
//public static List<LR_weigh> GetLR_weighList(string planID)
//{
// List<LR_weigh> lR_Weighs = new List<LR_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 LR_weigh where Plan_id = @Plan_id order by Serial_Num,Weight_ID";
// dbHelper.CommandText = strSql;
// dbHelper.ClearParameter();
// dbHelper.AddParameter("@Plan_id", planID);
// DataTable table = dbHelper.ToDataTable();
// if (table != null && table.Rows.Count > 0)
// {
// LR_weigh entity = null;
// foreach (DataRow dr in table.Rows)
// {
// entity = ConvertDataRowToLR_weigh(dr);
// lR_Weighs.Add(entity);
// }
// }
// return lR_Weighs;
//}
#endregion
#region 把DataRow数据行转换为LR_weigh实体对象
/// <summary>
/// 把DataRow数据行转换为LR_weigh实体对象
/// </summary>
/// <param name="dr">要转换的数据行</param>
/// <returns>返回转换后的计划实体对象</returns>
//public static LR_weigh ConvertDataRowToLR_weigh(DataRow dr)
//{
// if (dr != null)
// {
// LR_weigh lR_Weigh = new LR_weigh();
// lR_Weigh.Dosing_id = Mesnac.Basic.DataProcessor.RowValue(dr, "Dosing_id", 0);
// lR_Weigh.Plan_id = Mesnac.Basic.DataProcessor.RowValue(dr, "Plan_id", String.Empty);
// lR_Weigh.Equip_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Equip_code", String.Empty);
// lR_Weigh.Serial_Num = Mesnac.Basic.DataProcessor.RowValue(dr, "Serial_Num", 0);
// lR_Weigh.Weight_ID = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_ID", 0);
// lR_Weigh.Material_Code = Mesnac.Basic.DataProcessor.RowValue(dr, "Material_Code", String.Empty);
// lR_Weigh.Real_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Weight", 0.0f);
// lR_Weigh.Real_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Real_Error", 0.0f);
// lR_Weigh.Over_Weight = Mesnac.Basic.DataProcessor.RowValue(dr, "Over_Weight", decimal.Zero);
// lR_Weigh.Over_Error = Mesnac.Basic.DataProcessor.RowValue(dr, "Over_Error", decimal.Zero);
// lR_Weigh.Waste_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Waste_Time", 0);
// lR_Weigh.Warning_sgn = Mesnac.Basic.DataProcessor.RowValue(dr, "Warning_Sign", 0);
// lR_Weigh.Weight_Time = Mesnac.Basic.DataProcessor.RowValue(dr, "Weight_Time", String.Empty);
// lR_Weigh.Batch_Number = Mesnac.Basic.DataProcessor.RowValue(dr, "Batch_Number", String.Empty);
// lR_Weigh.Recipe_code = Mesnac.Basic.DataProcessor.RowValue(dr, "Recipe_code", String.Empty);
// return lR_Weigh;
// }
// else
// {
// return null;
// }
//}
#endregion
/// <summary>
/// 获取计划ID
/// </summary>
/// <param name="start"></param>
/// <param name="end"></param>
/// <param name="recipeName"></param>
/// <returns></returns>
public static List<string> GetPlanIDList(string start, string end, string recipeName)
{
List<string> planIDs = new List<string>();
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 Plan_Id FROM LR_plan WHERE Recipe_Name = @RecipeName and Start_Date > @Start and Start_Date < @End";
dbHelper.CommandText = strSql;
dbHelper.ClearParameter();
dbHelper.AddParameter("@RecipeName", recipeName);
dbHelper.AddParameter("@Start", start);
dbHelper.AddParameter("@End", end);
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
string id = null;
foreach (DataRow dr in table.Rows)
{
id = dr["Plan_Id"].ToString();
planIDs.Add(id);
}
}
return planIDs;
}
/// <summary>
/// 保存扫码记录信息
/// </summary>
/// <param name="LR_BarcodeLog">保存扫码记录信息</param>
public static void InsertLR_BarcodeLog(Entity.LR_BarcodeLog lR_BarcodeLog)
{
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 sqlstr = String.Empty;
//添加新配方
sqlstr = @"insert into LR_BarcodeLog(Equip_Code, Scan_Time, Scan_Bar, Material, Bin, Scan_State, IF_Flag)
values(@Equip_Code, @Scan_Time, @Scan_Bar, @Material, @Bin, @Scan_State, @IF_Flag)";
dbHelper.ClearParameter();
dbHelper.CommandText = sqlstr;
dbHelper.AddParameter("@Equip_Code", lR_BarcodeLog.Equip_Code);
dbHelper.AddParameter("@Scan_Time", lR_BarcodeLog.Scan_Time);
dbHelper.AddParameter("@Scan_Bar", lR_BarcodeLog.Scan_Bar);
dbHelper.AddParameter("@Material", lR_BarcodeLog.Material);
dbHelper.AddParameter("@Bin", lR_BarcodeLog.Bin);
dbHelper.AddParameter("@Scan_State", lR_BarcodeLog.Scan_State);
dbHelper.AddParameter("@IF_Flag", null);
dbHelper.ExecuteNonQuery();
}
public static List<LR_lot> GetAllLR_lotList(List<string> PlanIds)
{
List<LR_lot> lR_Lots = new List<LR_lot>();
DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
dbHelper.ClearParameter();
if (dbHelper == null)
{
throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
}
StringBuilder sbSql = new StringBuilder("SELECT * FROM LR_lot WHERE 2<1 ");
foreach (string pID in PlanIds)
{
sbSql.Append("OR Plan_id = '"+pID+"'");
}
sbSql.Append(" ORDER BY Plan_id");
dbHelper.CommandText = sbSql.ToString();
dbHelper.CommandType = System.Data.CommandType.Text;
DataTable table = dbHelper.ToDataTable();
if (table != null && table.Rows.Count > 0)
{
LR_lot entity = null;
int i = 0;
foreach (DataRow dr in table.Rows)
{
i++;
entity = ConvertDataRowToLR_lot(dr);
entity.Serial_Num = i;
lR_Lots.Add(entity);
}
}
return lR_Lots;
}
//public static List<LR_weigh> GetAllLR_weighList(List<string> PlanIds, int mNum)
//{
// List<LR_weigh> lR_Weighs = new List<LR_weigh>();
// DbHelper dbHelper = Mesnac.Basic.DataSourceFactory.Instance.GetDbHelper(Mesnac.Basic.DataSourceFactory.MCDbType.Local);
// dbHelper.ClearParameter();
// if (dbHelper == null)
// {
// throw new Exception(Mesnac.Basic.LanguageHelper.DataBaseConnectError);
// }
// StringBuilder sbSql = new StringBuilder("SELECT * FROM LR_weigh WHERE 2<1 ");
// foreach (string pID in PlanIds)
// {
// sbSql.Append("OR Plan_id = '" + pID + "'");
// }
// sbSql.Append(" ORDER BY Plan_id");
// dbHelper.CommandText = sbSql.ToString();
// dbHelper.CommandType = System.Data.CommandType.Text;
// DataTable table = dbHelper.ToDataTable();
// if (table != null && table.Rows.Count > 0)
// {
// LR_weigh entity = null;
// int i = 0;
// int j = 1;
// int k = mNum;
// foreach (DataRow dr in table.Rows)
// {
// i++;
// entity = ConvertDataRowToLR_weigh(dr);
// if (i > k)
// {
// j++;
// k += mNum;
// }
// entity.Serial_Num = j;
// lR_Weighs.Add(entity);
// }
// }
// return lR_Weighs;
//}
#region 添加生产计划—— 报表LR_plan
/// <summary>
/// 添加生产计划
/// </summary>
/// <param name="lrPlan">LR_plan实体类</param>
/// <returns>返回新加计划的计划号</returns>
public static string LRAddPlan(LR_plan lrPlan)
{
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;
//添加计划的SQL语句
string strSql3 = @"INSERT INTO LR_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", lrPlan.Plan_Id); //计划号
dbHelper.AddParameter("@Equip_Code", lrPlan.Equip_Code); //机台号
dbHelper.AddParameter("@Plan_Serial", lrPlan.Plan_Serial); //排序字段优先级在此与ActionOrder相同
dbHelper.AddParameter("@Recipe_ID", lrPlan.Recipe_ID);
dbHelper.AddParameter("@Recipe_Code", lrPlan.Recipe_Code); //配方编码
dbHelper.AddParameter("@Recipe_Name", lrPlan.Recipe_Name); //配方别名
dbHelper.AddParameter("@Version", lrPlan.Version); //配方版本号
//dbHelper.AddParameter("@Mixer_Line", lrPlan.Mixer_Line); //配方版本号
dbHelper.AddParameter("@Recipe_Type", lrPlan.Recipe_Type); //配方类型
dbHelper.AddParameter("@Shift_Id", lrPlan.Shift_Id); //班次ID
dbHelper.AddParameter("@Shift_Class", 0); //班组ID
dbHelper.AddParameter("@Plan_Num", lrPlan.Plan_Num); //计划数
dbHelper.AddParameter("@Real_Num", lrPlan.Real_Num); //完成数量
dbHelper.AddParameter("@Duration_Time", lrPlan.Duration_Time); //持续时间
dbHelper.AddParameter("@Start_Date", lrPlan.Start_Date); //开始时间
dbHelper.AddParameter("@End_Date", lrPlan.End_Date); //结束时间
dbHelper.AddParameter("@Weight_Man", lrPlan.Weight_Man); //称量工
dbHelper.AddParameter("@Stock_Man", lrPlan.Stock_Man); //投料工
dbHelper.AddParameter("@Plan_Batch", lrPlan.Plan_Batch); //批次号,不同的现场有不同的命令规则。
dbHelper.AddParameter("@Plan_State", lrPlan.Plan_State); //计划状态
dbHelper.AddParameter("@Plan_Date", lrPlan.Plan_Date); //计划日期
dbHelper.AddParameter("@IF_FLAG", lrPlan.IF_FLAG); //暂时无用
dbHelper.AddParameter("@Total_Weight", lrPlan.Total_Weight);
dbHelper.AddParameter("@Total_Error", lrPlan.Total_Error);
dbHelper.AddParameter("@IsRetransmission", lrPlan.IsRetransmission);
dbHelper.ExecuteNonQuery();
return lrPlan.Plan_Id;
}
#endregion
}
}