南骏 池
2025-05-16 a04ee7ab3b4cb4e4bb73cda632233f043e7422f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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();
                }
            }
        }
    }
}