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; using System.Collections.Generic; using System.Data; using System.Threading.Tasks; namespace Opsoft.NetCore.O3App.Repositories.WMS { [MapTo(typeof(IPickInventoryRepository), ServiceLifetime.Transient)] public class PickInventoryRepository : RepositoryBase, IPickInventoryRepository { public DataTable SqlQuery(string sql) { try { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); return dbContext.Database.SqlQuery(sql); } catch (Exception e) { throw new O3AppException(e.Message); } } public List SqlQuery(string sql) where T : class, new() { try { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); return dbContext.Database.SqlQuery(sql); } catch (Exception e) { throw new O3AppException(e.Message); } } public async Task> SqlQueryAsync(string sql) where T : class, new() { try { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); return await dbContext.Database.SqlQueryAsync(sql); } catch (Exception e) { throw new O3AppException(e.Message); } } public List GetBarcodeInfos(string sql) { try { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); return dbContext.Database.SqlQuery(sql); } catch (Exception e) { throw new O3AppException(e.Message); } } public async Task ExecuteSqlAsync(List sqlList) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { var count = 0; await dbContext.Database.BeginTransactionAsync().ConfigureAwait(false); foreach (var sql in sqlList) { 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 async Task ExecuteSqlAsync(string sql) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { var count = 0; await dbContext.Database.BeginTransactionAsync().ConfigureAwait(false); 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 async Task CreateBillNo(string billInfoJson) { await using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { return CreateBilllNO(dbContext, billInfoJson, "STK_PICKINVENTORY", "T_STK_PICKINVENTORY", "FBILLNO", null, null); } catch (Exception e) { throw new O3AppException(e.Message); } } public decimal QtyUnitConvert(string materialId, string unitFrom, string unitTo, decimal qty) { using APPServerContext dbContext = new APPServerContext(LoginInfo.DBAias, LoginInfo.UserID); try { return GetMaterQty2(dbContext, materialId, unitFrom, unitTo, qty); } catch (Exception e) { throw new O3AppException(e.Message); } } } }