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.
377 lines
16 KiB
C#
377 lines
16 KiB
C#
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;
|
|
}
|
|
|
|
}
|
|
}
|