HuNan_NOSqlSugar/DM_Weight/Services/ChannelStockService.cs

38 lines
1.7 KiB
C#

using DM_Weight.Models;
using DM_Weight.util;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DM_Weight.Services
{
public class ChannelStockService
{
////private SqlSugarScope SqlSugarHelper.Db;
//public ChannelStockService(SqlSugarScope sqlSugarScope)
//{
// //this.SqlSugarHelper.Db = sqlSugarScope;
//}
public List<ChannelStockCount> GetAll()
{
string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
string SQL = $@"SELECT CS.drug_id as DrugId,CS.manu_no as ManuNo,sum(quantity) as Quantity,CS.eff_date as EffDate,DI.drug_name as DrugName,
DI.drug_spec as DrugSpec,DI.dosage as Dosage,DI.manufactory as ManuFactory,DI.small_unit as SmallUnit,DI.pack_unit as PackUnit,
CS.machine_id as MachineId FROM channel_stock CS
INNER JOIN drug_info DI ON CS.drug_id=DI.drug_id where CS.machine_id='{p_machine_id}' AND quantity>0 GROUP BY CS.drug_id";//,CS.manu_no ";
List<ChannelStockCount> accountList = SqlSugarHelper.Db.SqlQueryable<ChannelStockCount>(SQL).ToList();
//List<ChannelStock> accountList = SqlSugarHelper.Db.Queryable<ChannelStock>().Includes<DrugInfo>(cs=>cs.DrugInfo)
// .GroupBy(cs=>new { cs.DrugId, cs.ManuNo })
// .Where(cs => cs.MachineId.Equals(ConfigurationManager.AppSettings["machineId"]??"DM1"))
// .Where(cs=>cs.Quantity>0)
// .ToList();
return accountList;
}
}
}