南骏 池
6 天以前 52d1e37bb116c995b601728bfe81e3816c3944c9
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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 dynamic GetBarInfoBefore(WarehouseQuery unity)
    {
 
        // 使用参数化查询防止SQL注入
        var sqlParams = new List<SugarParameter> { new("@barcode", unity.barcode) };
 
        var sql1 = @"SELECT 1 FROM MES_INV_ITEM_STOCKS WHERE ITEM_BARCODE =@barcode ";
 
        var KcInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams);
 
        if(KcInfo.Count > 0) throw new Exception("该条码已入库不能进行入库前拆分!");
 
        var sql2 = @"SELECT ITEM_ID,QUANTITY FROM MES_INV_ITEM_BARCODES WHERE ITEM_BARCODE =@barcode ";
 
        var barInfo = Db.Ado.SqlQuery<dynamic>(sql2, sqlParams).First();
 
        if (barInfo is null) throw new Exception("该条码信息不存在!");
 
        return barInfo;
    }
 
    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();
                }
            }
        }
    }
 
    public ProductionPickDto BarCfBefore(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_before]", 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();
                }
            }
        }
    }
}