示例#1
0
        public async Task<bool> AddListQRCode(List<string> listReceiveNo)
        {
            var checkCreate = true;
            Random ran = new Random();
            foreach (var item in listReceiveNo)
            {
                // Tạo QrCodeMain để thêm vào database
                var qrCodeDto = new QRCode_Main_Dto();
                var packing = await _repoPacking.GetAll().Where(x => x.Receive_No.Trim() == item.Trim()).FirstOrDefaultAsync();
                packing.Generated_QRCode = "Y";
                int so = ran.Next(100,999);
                string qrCodeId = "B" + packing.MO_No.Trim() + so.ToString();
                qrCodeDto.QRCode_ID = qrCodeId;
                qrCodeDto.Receive_No = packing.Receive_No.Trim();
                qrCodeDto.QRCode_Version = 1;
                qrCodeDto.Valid_Status = "Y";
                qrCodeDto.Is_Scanned = "N";
                qrCodeDto.QRCode_Type = packing.Sheet_Type.Trim();
                await _repoPacking.SaveAll();
                var qrCodeMain = _mapper.Map<WMSB_QRCode_Main>(qrCodeDto);
                _repoQrcode.Add(qrCodeMain);

                // Tạo QrCodeDetail để thêm vào database
                var listPackingDetail = await _repoPackingDetail.GetAll().Where(x => x.Receive_No.Trim() == item.Trim()).ToListAsync();
                foreach (var packingItem in listPackingDetail)
                    {
                        var qrCodeDetailDto = new QRCode_Detail_Dto();
                        qrCodeDetailDto.QRCode_ID = qrCodeId;
                        qrCodeDetailDto.QRCode_Version = 1;
                        qrCodeDetailDto.Order_Size = packingItem.Order_Size;
                        qrCodeDetailDto.Model_Size = packingItem.Model_Size;
                        qrCodeDetailDto.Tool_Size = packingItem.Tool_Size;
                        qrCodeDetailDto.Spec_Size = packingItem.Spec_Size;
                        qrCodeDetailDto.Qty = packingItem.Received_Qty;
                        qrCodeDetailDto.Updated_By = "Emma";
                        var qrCodeDetail = _mapper.Map<WMSB_QRCode_Detail>(qrCodeDetailDto);
                        _repoQrCodeDetail.Add(qrCodeDetail);
                        if (!await _repoQrCodeDetail.SaveAll()) {
                            checkCreate = false;
                            break;
                        }
                    }
            }
            await _repoQrcode.SaveAll();
            return checkCreate;
        }
示例#2
0
        public async Task <bool> AddListQRCode(List <string> listReceiveNo, string updateBy)
        {
            listReceiveNo = listReceiveNo.Select(x => x.Trim()).ToList();
            var packingLists = await _repoPacking.FindAll(x => listReceiveNo.Contains(x.Receive_No.Trim())).ToListAsync();

            var checkCreate = true;

            foreach (var item in listReceiveNo)
            {
                // Tạo QrCodeMain để thêm vào database
                var qrCodeDto = new QRCode_Main_Dto();
                var packing   = packingLists.Where(x => x.Receive_No.Trim() == item).FirstOrDefault();
                // Nếu Generated_QrCode khác Y thì mới Tạo QrCode
                if (packing.Generated_QRCode != "Y")
                {
                    packing.Generated_QRCode = "Y";
                    string qrCodeId = "";
                    if (packing.Sheet_Type.Trim() == "R" || packing.Sheet_Type.Trim() == "M")
                    {
                        do
                        {
                            var    po = packing.MO_No.Trim().Length == 9 ? packing.MO_No.Trim() + "Z" : packing.MO_No.Trim();
                            string so = CodeUtility.RandomNumber(3);
                            qrCodeId = "A" + po + so + CodeUtility.RandomStringUpper(1);
                        } while (await this.CheckQrCodeID(qrCodeId));
                    }
                    else if (packing.Sheet_Type.Trim() == "B")
                    {
                        do
                        {
                            var    po = packing.MO_No.Trim().Length == 9 ? packing.MO_No.Trim() + "Z" : packing.MO_No.Trim();
                            string so = CodeUtility.RandomNumber(3);
                            qrCodeId = "B" + po + so + CodeUtility.RandomStringUpper(1);
                        } while (await this.CheckQrCodeID(qrCodeId));
                    }
                    qrCodeDto.QRCode_ID      = qrCodeId;
                    qrCodeDto.Receive_No     = packing.Receive_No.Trim();
                    qrCodeDto.QRCode_Version = 1;
                    qrCodeDto.Valid_Status   = "Y";
                    qrCodeDto.Is_Scanned     = "N";
                    qrCodeDto.QRCode_Type    = packing.Sheet_Type.Trim();
                    qrCodeDto.Updated_By     = updateBy;
                    await _repoPacking.SaveAll();

                    var qrCodeMain = _mapper.Map <WMSB_QRCode_Main>(qrCodeDto);
                    _repoQrcode.Add(qrCodeMain);

                    // Tạo QrCodeDetail để thêm vào database
                    var listPackingDetail = await _repoPackingDetail.FindAll(x => x.Receive_No.Trim() == item).ToListAsync();

                    foreach (var packingItem in listPackingDetail)
                    {
                        var qrCodeDetailDto = new QRCode_Detail_Dto();
                        qrCodeDetailDto.QRCode_ID      = qrCodeId;
                        qrCodeDetailDto.QRCode_Version = 1;
                        qrCodeDetailDto.Order_Size     = packingItem.Order_Size;
                        qrCodeDetailDto.Model_Size     = packingItem.Model_Size;
                        qrCodeDetailDto.Tool_Size      = packingItem.Tool_Size;
                        qrCodeDetailDto.Spec_Size      = packingItem.Spec_Size;
                        qrCodeDetailDto.Qty            = packingItem.Received_Qty;
                        qrCodeDetailDto.Updated_By     = updateBy;
                        var qrCodeDetail = _mapper.Map <WMSB_QRCode_Detail>(qrCodeDetailDto);
                        _repoQrCodeDetail.Add(qrCodeDetail);
                        if (!await _repoQrCodeDetail.SaveAll())
                        {
                            checkCreate = false;
                            break;
                        }
                    }
                }
            }
            await _repoQrcode.SaveAll();

            return(checkCreate);
        }