sjz
2025-06-13 fbb0bc175c8788f2f6ce4202d2630b01506bff80
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
using AngleSharp.Dom;
using MES.Service.DB;
using MES.Service.Dto.webApi;
using MES.Service.Modes;
using SqlSugar;
 
namespace MES.Service.service.BasicData;
 
public class MesDeliveryNoteBarcodeManager : Repository<MesDeliveryNoteBarcode>
{
    //private readonly MesDeliveryNoteBarcodeManager mesDeliveryNoteBarcode = new();
    public bool Save(ErpBarcode barcode)
    {
        var mesDeliveryNoteBarcode = GetMesDeliveryNoteBarcode(barcode);
 
        return UseTransaction(db =>
        {
            switch (barcode.Type)
            {
                case "2":
                case "4":
                case "5":
                    return SaveOrUpdateData(db, mesDeliveryNoteBarcode) ? 1 : 0;
                case "3":
                case "6":
                    return DeleteData(db, mesDeliveryNoteBarcode) ? 1: 0;
                default:
                    throw new ArgumentNullException($"type没有{barcode.Type}这个类型的参数");
            }
 
            throw new NotImplementedException("操作失败");
        }) > 0;
    }
 
    // 更新数据的方法
    private bool DeleteData(SqlSugarScope db, MesDeliveryNoteBarcode mesDeliveryNoteBarcode)
    {
        var detect = base.DeleteById(mesDeliveryNoteBarcode.Id);
 
        if (detect) return true;
        throw new NotImplementedException("更新失败");
    }
 
    // 删除数据的方法
    private bool DeleteBarcode(SqlSugarScope db, DelBarcode barcode)
    {
        var del = db.Deleteable<MesDeliveryNoteBarcode>().Where(s => s.SmallBarcode == barcode.SmallBarcode).ExecuteCommand() > 0;
 
        if (del)
        {
            return true;
        }
        throw new NotImplementedException("删除失败");
    }
 
    public dynamic Delete(DelBarcode barcode)
    {
        return UseTransaction(db =>
        {
            return DeleteBarcode(db, barcode) ? 1 : 0;
        }) > 0;
    }
 
    public dynamic DeleteList(List<DelBarcode> barcode)
    {
        var result = barcode.Select(Delete).ToList();
        return result.All(b => b);
    }
 
    // 插入或更新数据的方法
    private bool SaveOrUpdateData(SqlSugarScope db, MesDeliveryNoteBarcode mesDeliveryNoteBarcode)
    {
        if (mesDeliveryNoteBarcode.Id != null) base.DeleteById(mesDeliveryNoteBarcode.Id);
 
        var orUpdate = base.Insert(mesDeliveryNoteBarcode);
        if (orUpdate) return true;
        throw new NotImplementedException("插入或更新失败");
    }
 
 
    // 批量保存记录的方法
    public bool SaveList(List<ErpBarcode> barcodes)
    {
        var result = barcodes.Select(Save).ToList();
        return result.All(b => b);
    }
 
    public MesDeliveryNoteBarcode GetMesDeliveryNoteBarcode(ErpBarcode barcode)
    {
        var mesDeliveryNoteBarcode = new MesDeliveryNoteBarcode();
        var single = base.GetSingle(it => it.SmallBarcode == barcode.SmallBarcode);
        if (single != null) mesDeliveryNoteBarcode.Id = single.Id;
 
 
        mesDeliveryNoteBarcode.DeliveryNo = barcode.DeliveryNo;
        mesDeliveryNoteBarcode.ProductCode = barcode.ProductCode;
        mesDeliveryNoteBarcode.SmallBarcode= barcode.SmallBarcode;
        mesDeliveryNoteBarcode.IncludeQty= Convert.ToDecimal(barcode.IncludeQty);
        mesDeliveryNoteBarcode.LineNo=Convert.ToDecimal(barcode.LineNo);
        mesDeliveryNoteBarcode.CreateDate = DateTime.Now;
        mesDeliveryNoteBarcode.SuppNo = barcode.SupplierId;
 
        return mesDeliveryNoteBarcode;
    }
 
 
}