using System; using System.Collections; using Microsoft.Extensions.DependencyInjection; using Opsoft.Data; using Opsoft.NetCore.O3App.Domain; using Opsoft.NetCore.O3App.Domain.Interface; using Opsoft.NetCore.O3App.Domain.UnitOfWork.WMS.IRepositories; using Opsoft.NetCore.O3App.Domain.UnitOfWork.WMS.Model; using Opsoft.NetCore.O3App.Shared; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Exception = System.Exception; namespace Opsoft.NetCore.O3App.Repositories.WMS { [MapTo(typeof(IPickMtrlRepository), ServiceLifetime.Transient)] public class PickMtrlRepository : RepositoryBase, IPickMtrlRepository { public async Task> GetBarcodeCheckInfoAsync(string barcode) { try { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); var sqlStr = $@"SELECT * FROM T_BD_BARCODERS WHERE FBARCODE ='{barcode}'"; return await dbContext.Database.SqlQueryAsync(sqlStr); } catch (Exception e) { throw new O3AppException(e.Message); } } public async Task> GetSourceBillDataAsync(string sqlStr) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { return await dbContext.Database.SqlQueryAsync(sqlStr); } catch (Exception e) { throw new O3AppException(e.Message); } } public async Task CreateBillNo(string strJson, int billType) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { switch (billType) { case 1: return CreateBilllNO(dbContext, strJson, "PRD_PICKMTRL", "T_PRD_PICKMTRL", "FBILLNO", null, null); case 2: return CreateBilllNO(dbContext, strJson, "PRD_RETURNMTRL", "T_PRD_RETURNMTRL", "FBILLNO", null, null); } return ""; } catch (Exception e) { throw new O3AppException(e.Message); } } public async Task GetSystemParameters(string key) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { return dbContext.PBValue(key); } catch (Exception e) { throw new O3AppException(e.Message); } } public decimal GetQty2(string materialId, string unitFrom, string unitTo, decimal qty) { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); return GetMaterQty2(dbContext, materialId, unitFrom, unitTo, qty); } public async Task ExecuteTransactionAsync(List sqlStrList) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { var count = 0; await dbContext.Database.BeginTransactionAsync().ConfigureAwait(false); foreach (var sql in sqlStrList) { count += await dbContext.Database.SqlNonQueryAsync(sql); } await dbContext.Database.CommitTransactionAsync().ConfigureAwait(false); return count; } catch (Exception e) { await dbContext.Database.RollbackTransactionAsync().ConfigureAwait(false); throw new O3AppException(e.Message); } } public string GetUpdateInventoryQtySqlStr( string orgID, List> inputMaterialList, bool isPlus, ref List exeSqlStrList) { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { //操作库存 return APPWmsCommonFunc.CalculateInventory(dbContext, orgID, inputMaterialList, isPlus, ref exeSqlStrList); } catch (Exception e) { throw new O3AppException(e.Message); } } } }