|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using Mesnac.Codd.Session;
|
|
|
using System.Data;
|
|
|
using Mesnac.Action.Feeding.BasicInfo;
|
|
|
|
|
|
namespace Mesnac.Action.Feeding.FinishBatch
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 车条码
|
|
|
/// </summary>
|
|
|
public class LotBarcode
|
|
|
{
|
|
|
private string planID = string.Empty;
|
|
|
private int finishedNumber = 1;
|
|
|
private int _llSerialId = 0; //玲珑车次
|
|
|
public LotBarcode(DbHelper _localHelper, DbHelper _serverHelper, string _planID, int _finishedNumber)
|
|
|
{
|
|
|
this.planID = _planID;
|
|
|
this.finishedNumber = _finishedNumber;
|
|
|
getLotBarcode(_localHelper);
|
|
|
}
|
|
|
|
|
|
private string barcode = string.Empty;
|
|
|
private int serialBatchId = 1;
|
|
|
/// <summary>
|
|
|
/// 条码
|
|
|
/// </summary>
|
|
|
public string Barcode { get { return barcode; } }
|
|
|
/// <summary>
|
|
|
/// 计划ID
|
|
|
/// </summary>
|
|
|
public string PlanID { get { return planID; } }
|
|
|
private string firstPlanID = string.Empty;
|
|
|
/// <summary>
|
|
|
/// 第一个计划
|
|
|
/// </summary>
|
|
|
public string FirstPlanID { get { return firstPlanID.Trim(); } }
|
|
|
/// <summary>
|
|
|
/// 车次
|
|
|
/// </summary>
|
|
|
public int SerialId { get { return finishedNumber; } }
|
|
|
/// <summary>
|
|
|
/// 玲珑车次
|
|
|
/// </summary>
|
|
|
public int LLSerialId { get { return _llSerialId; } }
|
|
|
/// <summary>
|
|
|
/// 当班同物料累计车次
|
|
|
/// </summary>
|
|
|
public int SerialBatchId { get { return serialBatchId; } }
|
|
|
|
|
|
/// <summary>
|
|
|
/// 判断车报表中条码是否存在
|
|
|
/// </summary>
|
|
|
/// <param name="localHelper"></param>
|
|
|
/// <param name="barcode"></param>
|
|
|
/// <returns>存在返回true,不存在返回false</returns>
|
|
|
private bool hasSaveBarCode(DbHelper localHelper, string barcode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
string sqlstr = "SELECT 1 FROM dbo.PptLotData WHERE Barcode=@Barcode";
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.AddParameter("@Barcode", barcode);
|
|
|
DataTable dt = localHelper.ToDataTable();
|
|
|
return dt.Rows.Count > 0;
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("存盘业务-判断车报表中条码是否存在失败:" + ex.Message);
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
private void getLotBarcode(DbHelper localHelper)
|
|
|
{
|
|
|
string barcode = planID.Trim() + finishedNumber.ToString("D4");
|
|
|
//ICSharpCode.Core.LoggingService.Debug("每车存盘barcode=" + barcode);
|
|
|
if (hasSaveBarCode(localHelper, barcode))
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Debug("返回了2222每车存盘barcode=" + barcode);
|
|
|
return;
|
|
|
}
|
|
|
//ICSharpCode.Core.LoggingService.Debug("赋值了每车存盘barcode=" + barcode);
|
|
|
this.barcode = barcode;
|
|
|
}
|
|
|
public void IniLotBarcode(DbHelper localHelper, RecipeData.PptPlanInfo planInfo)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
#region 获取当班物料生产数量 SerialBatchId
|
|
|
|
|
|
localHelper.CommandType = CommandType.Text;
|
|
|
string sqlstr = @"SELECT * FROM PptLotBatchCount t1
|
|
|
INNER JOIN ppt_plan t2 ON t1.FirstPlanID=t2.plan_id
|
|
|
INNER JOIN ppt_plan t3
|
|
|
ON t2.down_date=t3.down_date AND t2.shift=t3.shift
|
|
|
AND t2.mater_code=t3.mater_code
|
|
|
AND t2.edt_code=t3.edt_code
|
|
|
WHERE t3.plan_id=@PlanID";
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.AddParameter("@PlanID", this.planID);
|
|
|
DataTable dt = localHelper.ToDataTable();
|
|
|
int iLotBatchCount = 0;
|
|
|
if (dt != null && dt.Rows.Count > 0)
|
|
|
{
|
|
|
object maxCode = dt.Rows[0]["PCount"];
|
|
|
if (maxCode != null && maxCode != DBNull.Value)
|
|
|
{
|
|
|
int.TryParse(maxCode.ToString(), out iLotBatchCount);
|
|
|
}
|
|
|
this.firstPlanID = dt.Rows[0]["FirstPlanID"].ToString().Trim();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
sqlstr = @"INSERT INTO dbo.PptLotBatchCount ( FirstPlanID ,PCount) VALUES ( @FirstPlanID, 0);";
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
localHelper.AddParameter("@FirstPlanID", this.planID.Trim());
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
this.firstPlanID = this.planID;
|
|
|
}
|
|
|
iLotBatchCount++;
|
|
|
sqlstr = @"UPDATE PptLotBatchCount SET PCount=PCount+1 WHERE FirstPlanID=@FirstPlanID";
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.CommandText = sqlstr;
|
|
|
localHelper.AddParameter("@FirstPlanID", this.firstPlanID);
|
|
|
localHelper.ExecuteNonQuery();
|
|
|
this.serialBatchId = iLotBatchCount;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 获取玲珑车次
|
|
|
this._llSerialId = this.GetLLSerialID(localHelper, planInfo.RecipeMaterialCode.Trim());
|
|
|
#endregion
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("存盘业务-判断车报表中条码是否存在失败:" + ex.Message);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取玲珑车次
|
|
|
/// </summary>
|
|
|
/// <param name="localHelper">本地数据访问对象</param>
|
|
|
/// <param name="materCode">配方物料代码</param>
|
|
|
/// <returns>返回玲珑车次</returns>
|
|
|
public int GetLLSerialID(DbHelper localHelper, string materCode)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
FeedingAction action = new FeedingAction();
|
|
|
string hrCode = action.GetConfigValue("LastUserID", "");
|
|
|
localHelper.CommandType = CommandType.StoredProcedure;
|
|
|
localHelper.ClearParameter();
|
|
|
localHelper.CommandText = "GetMaxSerialIDNew";
|
|
|
localHelper.AddParameter("@HrCode", hrCode);
|
|
|
localHelper.AddParameter("@MaterialCode", materCode);
|
|
|
localHelper.AddParameter("@ZJSCode", "");
|
|
|
object result = localHelper.ToScalar();
|
|
|
if (result == null || result == System.DBNull.Value)
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
int IntResult = 0;
|
|
|
int.TryParse(result.ToString(), out IntResult);
|
|
|
return IntResult;
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
|
ICSharpCode.Core.LoggingService.Error("存盘业务-获取玲珑车次失败:" + ex.Message);
|
|
|
return 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|