using Dapper;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
namespace VueWebApi.Tools
{
public class LabCodeStatusMessage
{
public static ToMessage mes = new ToMessage(); //定义全局返回信息对象
#region[生产开报工:自制工序任务开报工判断:工单+工序条码]
///
/// 扫码信息为工单+工序条码
///
/// 功能编码
/// 单据类型
/// 条形码
///
public static ToMessage LabCodeStatus(string rightcode, string hbilltype,string hbarcode)
{
var sql = "";
DataTable dt;
var dynamicParams = new DynamicParameters();
mes.code = "200";
try
{
//0.判断条码是否为当前功能扫描条码
sql = @"select rightcode,hbilltype from T_BarCodeBill where hbarcode=@hbarcode";
dynamicParams.Add("@hbarcode", hbarcode);
dt = DapperHelper.selectdata(sql, dynamicParams);
if (dt.Rows.Count>0)
{
if (dt.Rows[0]["rightcode"].ToString() != rightcode && dt.Rows[0]["hbilltype"].ToString() != hbilltype)
{
mes.code = "300";
mes.count = 0;
mes.Message = "当前条码状态不满足此功能!";
mes.data = null;
return mes;
}
}
//1.判断当前功能条码是否为系统生成有效条码
sql = @"select * from T_BarCodeBill where hbarcode=@hbarcode";
dynamicParams.Add("@hbarcode", hbarcode);
dt = DapperHelper.selectdata(sql, dynamicParams);
if (dt.Rows.Count<=0)
{
mes.code = "300";
mes.count = 0;
mes.Message = "当前条码在系统中不存在!";
mes.data = null;
return mes;
}
//2.判断当前功能条码是否为有效条码
sql = @"select * from T_BarCodeBill where hbarcode=@hbarcode and hbarcodestatus='Y'";
dynamicParams.Add("@hbarcode", hbarcode);
dt = DapperHelper.selectdata(sql, dynamicParams);
if (dt.Rows.Count <= 0)
{
mes.code = "300";
mes.count = 0;
mes.Message = "当前条码已停用!";
mes.data = null;
return mes;
}
//2.判断当前功能条码质量状态是否为不合格
sql = @"select * from T_BarCodeBill where hbarcode=@hbarcode and hbarcodestatus='Y'and qualitystatus='NG' ";
dynamicParams.Add("@hbarcode", hbarcode);
dt = DapperHelper.selectdata(sql, dynamicParams);
if (dt.Rows.Count > 0)
{
mes.code = "300";
mes.count = 0;
mes.Message = "当前条码质量状态不通过!";
mes.data = null;
return mes;
}
}
catch (Exception e)
{
mes.code = "300";
mes.count = 0;
mes.Message = e.Message;
mes.data = null;
return mes;
}
return mes;
}
#endregion
}
}