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.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/FinishBatch/SaveHelper/LotSaveHelper.cs

164 lines
7.2 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 System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Mesnac.Basic;
using Mesnac.Codd.Session;
using System.Configuration;
namespace Mesnac.Action.ChemicalWeighing.FinishBatch.SaveHelper
{
/// <summary>
/// 数据存盘辅助类
/// </summary>
public class LotSaveHelper
{
#region 数据验证方法
/// <summary>
/// 判断车条码对应的数据是否存在
/// </summary>
/// <param name="barcode">车条码</param>
/// <returns>存在返回true否则返回false</returns>
public static bool Exists(string barcode)
{
try
{
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 = "select COUNT(Barcode) from PptLotData where Barcode=@Barcode";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Barcode", barcode);
object result = dbHelper.ToScalar();
if (result != null && result != System.DBNull.Value)
{
int intResult = 0;
int.TryParse(result.ToString(), out intResult);
if (intResult > 0)
{
return true;
}
}
return false;
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<LotSaveHelper>.Error(ex.Message, ex);
return false;
}
}
#endregion
#region 数据查询
#endregion
#region 报表存盘基础信息数据追加
/// <summary>
/// 追加报表存盘基础信息数据至数据库
/// </summary>
/// <param name="lotData">报表头数据对象</param>
public static void InsertLRLotData(Entity.LR_lot lotData)
{
try
{
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 = @"insert into LR_lot(Dosing_id,Plan_id,Equip_code,Serial_Num,Prd_date,Real_weight,Real_Error,Waste_Time,Warning_sgn,Net_Weight,Ng_sgn,ResetFlag,ResetStationNo,Lot_Barcode)
values(@Dosing_id,@Plan_id,@Equip_code,@Serial_Num,@Prd_date,@Real_weight,@Real_Error,@Waste_Time,@Warning_sgn,@Net_Weight,@Ng_sgn,@ResetFlag,@ResetStationNo,@Lot_Barcode)";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
dbHelper.AddParameter("@Dosing_id", 0);
dbHelper.AddParameter("@Plan_id", lotData.Plan_id);
dbHelper.AddParameter("@Equip_code", ConfigurationManager.AppSettings["EquipCode"]);
dbHelper.AddParameter("@Serial_Num", lotData.Serial_Num);
dbHelper.AddParameter("@Prd_date", lotData.Prd_date);
dbHelper.AddParameter("@Real_weight", lotData.Real_weight / 1000);
dbHelper.AddParameter("@Real_Error", lotData.Real_Error / 1000);
dbHelper.AddParameter("@Waste_Time", lotData.Waste_Time);
dbHelper.AddParameter("@Warning_sgn", lotData.Warning_sgn);
dbHelper.AddParameter("@Net_Weight", lotData.Net_Weight / 1000);
dbHelper.AddParameter("@Ng_sgn", lotData.Ng_sgn);
dbHelper.AddParameter("@ResetFlag", 0);
dbHelper.AddParameter("@ResetStationNo", 0);
dbHelper.AddParameter("@Lot_Barcode", null);
dbHelper.ExecuteNonQuery();
}
catch(Exception ex)
{
ICSharpCode.Core.LoggingService<LotSaveHelper>.Error("车报表数据保存异常:" + ex.Message, ex);
}
}
#endregion
#region 报表存盘物料信息数据追加
/// <summary>
/// 追加报表存盘基础信息数据至数据库
/// </summary>
/// <param name="lotData">报表头数据对象</param>
public static void InsertLRweighData(Entity.LR_weigh weighData)
{
try
{
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 = @"insert into LR_weigh(Dosing_id,Plan_id,Equip_code,Serial_Num,Weight_ID,Material_Code,Real_Weight,Real_Error,Over_Weight,Over_Error,Waste_Time,Warning_Sign,Weight_Time,Batch_Number,Recipe_code)
values(@Dosing_id,@Plan_id,@Equip_code,@Serial_Num,@Weight_ID,@Material_Code,@Real_Weight,@Real_Error,@Over_Weight,@Over_Error,@Waste_Time,@Warning_Sign,@Weight_Time,@Batch_Number,@Recipe_code)";
dbHelper.CommandText = sqlstr;
dbHelper.ClearParameter();
if (weighData.Real_Error > 32767)
{
weighData.Real_Error = weighData.Real_Error - 65536;
}
dbHelper.AddParameter("@Dosing_id", weighData.Dosing_id);
dbHelper.AddParameter("@Plan_id", weighData.Plan_id);
dbHelper.AddParameter("@Equip_code", ConfigurationManager.AppSettings["EquipCode"]);
dbHelper.AddParameter("@Serial_Num", weighData.Serial_Num);
dbHelper.AddParameter("@Weight_ID", weighData.Weight_ID);
dbHelper.AddParameter("@Material_Code", weighData.Material_Code);
dbHelper.AddParameter("@Real_Weight", weighData.Real_Weight / 1000);
dbHelper.AddParameter("@Real_Error", weighData.Real_Error / 1000);
dbHelper.AddParameter("@Over_Weight", weighData.Over_Weight / 1000);
dbHelper.AddParameter("@Over_Error", weighData.Over_Error / 1000);
dbHelper.AddParameter("@Waste_Time", weighData.Waste_Time);
dbHelper.AddParameter("@Warning_Sign", weighData.Warning_sgn);
dbHelper.AddParameter("@Weight_Time", weighData.Weight_Time);
dbHelper.AddParameter("@Batch_Number", null);
dbHelper.AddParameter("@Recipe_code", null);
dbHelper.ExecuteNonQuery();
}
catch (Exception ex)
{
ICSharpCode.Core.LoggingService<LotSaveHelper>.Error("车报表数据保存异常:" + ex.Message, ex);
}
}
#endregion
#region 数据更新
#endregion
}
}