sjz
2025-05-09 701edfd77c2dbfce5a77bd047c7d93777a3918d5
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
using Masuit.Tools;
using MES.Service.DB;
using MES.Service.Dto.webApi.SRM;
using MES.Service.Modes.SRM;
using SqlSugar;
 
public class MesDeliveryNoteBarcodeManager : Repository<MesDeliveryNoteBarcode>
{
 
    public dynamic Save(PrintBarcode barcode)
    {
        var mesDeliveryBarcode= GetMesDeliveryBarcode(barcode);
 
        return UseTransaction(db =>
        {
            return SaveOrUpdateData(db, mesDeliveryBarcode) ? 1 : 0;
        }) > 0;
    }
 
    public dynamic SaveList(List<PrintBarcode> barcode)
    {
        var result = barcode.Select(Save).ToList();
        return result.All(b => b);
    }
 
    public dynamic DeleteBarcode(ErpBarcode barcode)
    {
        return UseTransaction(db =>
        {
            return DeleteData(db, barcode) ? 1 : 0;
        }) > 0;
    }
    public dynamic DeleteBarcodeList(List<ErpBarcode> barcode)
    {
        var result = barcode.Select(DeleteBarcode).ToList();
        return result.All(b => b);
    }
 
    // 删除数据的方法
    private bool DeleteData(SqlSugarScope db, ErpBarcode barcode)
    {
        var del = db.Deleteable<MesDeliveryNoteBarcode>().Where(s => s.SmallBarcode == barcode.SmallBarcode).ExecuteCommand() > 0;
 
        if (del) { 
            return true;
        } 
        throw new NotImplementedException("删除失败");
    }
 
    // 插入或更新数据的方法
    private bool SaveOrUpdateData(SqlSugarScope db, MesDeliveryNoteBarcode mesDeliveryBarcode)
    {
        if (mesDeliveryBarcode.Id != null)
        {
            base.DeleteById(mesDeliveryBarcode.Id);
        }
 
        var orUpdate = base.Insert(mesDeliveryBarcode);
        if (orUpdate)
        {
            return true;
        }
        throw new NotImplementedException("插入或更新失败");
    }
 
 
 
    public MesDeliveryNoteBarcode GetMesDeliveryBarcode(PrintBarcode barcode)
    {
        var mesDeliveryBarcode = new MesDeliveryNoteBarcode();
        var single = base.GetSingle(it => it.SmallBarcode == barcode.SmallBarcode);
        if (single != null)
        {
            mesDeliveryBarcode.Id = single.Id;
        }
 
        mesDeliveryBarcode.DeliveryNo = barcode.DeliveryNo;
        mesDeliveryBarcode.ProductCode = barcode.ProductCode;
 
        mesDeliveryBarcode.LineNo = barcode.LineNo;
        mesDeliveryBarcode.SmallBarcode = barcode.SmallBarcode;
        mesDeliveryBarcode.IncludeQty = Convert.ToDecimal(barcode.IncludeQty);
        mesDeliveryBarcode.CreateDate = DateTime.Now;
        mesDeliveryBarcode.OuterBarcode = barcode.OuterBarcode;
        mesDeliveryBarcode.BarcodeType = barcode.BarcodeType;
        mesDeliveryBarcode.IsMegre = Convert.ToDecimal(barcode.IsMerge);
 
        return mesDeliveryBarcode;
    }
 
}