using System.Data;
|
using System.Data.SqlClient;
|
using Masuit.Tools;
|
using Masuit.Tools.Hardware;
|
using NewPdaSqlServer.DB;
|
using NewPdaSqlServer.Dto.service;
|
using NewPdaSqlServer.entity;
|
using SqlSugar;
|
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
|
|
namespace NewPdaSqlServer.service.Warehouse;
|
|
public class MesBarCFManager : Repository<MesCgthSq>
|
{
|
public MesInvItemStocks GetBarInfo(WarehouseQuery unity)
|
{
|
var barInfo = Db.Queryable<MesInvItemStocks>()
|
.Where(s => s.ItemBarcode == unity.barcode)
|
.First();
|
if (barInfo is null) throw new Exception("该条码库存不存在!");
|
|
return barInfo; // 返回第一行数据,如果没有则返回 null
|
}
|
|
public MesItems GetItemNo(decimal strItemId)
|
{
|
var itemInfo = Db.Queryable<MesItems>()
|
.Where(s => s.Id == strItemId && s.Fforbidstatus == "A")
|
.First();
|
if (itemInfo is null) throw new Exception("该条码对应物料信息不存在或已禁用!");
|
|
return itemInfo;
|
}
|
|
public ProductionPickDto BarCF(WarehouseQuery unity)
|
{
|
var _strMsg = "";
|
var _intSum = "";
|
var _cfBar = "";//拆分后条码
|
using (var conn = new SqlConnection(DbHelperSQL.strConn))
|
{
|
if (unity.userName.IsNullOrEmpty()) throw new Exception("用户名不允许为空");
|
if (unity.CfNum <= 0) throw new Exception("拆分数量需大于等于0");
|
if (unity.barcode.IsNullOrEmpty()) throw new Exception("条码不允许为空");
|
|
using (var cmd = new SqlCommand("[prc_pda_bar_cf]", conn))
|
{
|
try
|
{
|
conn.Open();
|
cmd.CommandType = CommandType.StoredProcedure;
|
SqlParameter[] parameters =
|
{
|
new("@outMsg", SqlDbType.NVarChar, 300),
|
new("@outSum", SqlDbType.NVarChar, 300),
|
new("@barcode_new", SqlDbType.NVarChar, 300),
|
new("@c_user", unity.userName),
|
new("@p_old_barcode", unity.barcode),
|
new("@p_qty", unity.CfNum),
|
|
};
|
parameters[0].Direction = ParameterDirection.Output;
|
parameters[1].Direction = ParameterDirection.Output;
|
parameters[2].Direction = ParameterDirection.Output;
|
|
foreach (var parameter in parameters)
|
cmd.Parameters.Add(parameter);
|
cmd.ExecuteNonQuery();
|
_strMsg = parameters[0].Value.ToString();
|
_intSum = parameters[1].Value.ToString();
|
_cfBar = parameters[2].Value.ToString();
|
|
|
var result = Convert.ToInt32(_intSum);
|
if (result <= 0) throw new Exception(_strMsg);
|
|
var dto = new ProductionPickDto
|
{
|
barcode = unity.barcode,//原条码
|
cfBarcode = _cfBar//拆分后条码
|
};
|
return dto;
|
|
//var result = Convert.ToInt32(_intSum);
|
//if (result <= 0) throw new Exception(_strMsg);
|
|
//return _strMsg;
|
|
//return 0;
|
|
}
|
catch (Exception ex)
|
{
|
throw new Exception(ex.Message);
|
}
|
finally
|
{
|
conn.Close();
|
}
|
}
|
}
|
}
|
}
|