You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
6.4 KiB

using ICSSoft.ERPWMS.Entity;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ICSSoft.ERPWMS.SQL
{
public class GetInventoryInfo
{
public static Result Get(InventoryCondition condition)
{
Result res = new Result();
try
{
if (condition.PageIndex == null)
{
throw new Exception("页码未传!");
}
if (condition.PageSize == null)
{
throw new Exception("每页数量未传!");
}
if (string.IsNullOrWhiteSpace(condition.WorkPoint))
{
throw new Exception("站点未传!");
}
string WorkPoint = ICSHelper.GetConnectStringTest(condition.WorkPoint);
if (WorkPoint== "NotExit")
{
throw new Exception("站点编码不存在!");
}
string sql = @"select a.cInvCode as '物料编码',a.cInvAddCode as '物料代码',a.cInvName as '物料名称',a.cInvStd as '规格型号',
a.cComUnitCode as '主计量单位',a.cAssComUnitCode as '辅计量单位',a.cInvMnemCode as '助记码',a.iTaxRate as '税率',
a.dSDate as '启用日期',a.dEDate as '停用日期',a.cCurrencyName as '通用名称',a.cInvCCode as '存货大类编码',
b.cInvCName as '存货大类名称',a.cEnglishName as '物料英文名称',a.cPurPersonCode as '采购员',a.bSale as '是否销售',
a.bPurchase as '是否采购',a.bSelf as '是否自制',a.dModifyDate as '修改日期',a.cInvPersonCode as '计划员'
from {0}.dbo.Inventory a
left join {0}.dbo.InventoryClass b on a.cInvCCode = b.cInvCCode
where 1=1";
sql = string.Format(sql, WorkPoint);
if (condition.dModifyDateFrom != null)
{
sql += " and a.dModifyDate >= '{0}'";
sql = string.Format(sql, condition.dModifyDateFrom);
}
if (condition.dModifyDateTo != null)
{
sql += " and a.dModifyDate <= '{0}'";
sql = string.Format(sql, condition.dModifyDateTo);
}
if (condition.cInvCode != null)
{
sql += " and a.cInvCode like '%{0}%'";
sql = string.Format(sql, condition.cInvCode);
}
string sqlNew = @" select * from (select aa.*,rn=ROW_NUMBER() over(order by 物料编码) from( ";
sqlNew += sql;
sqlNew += ") aa)bb where bb.rn between {0} and {1} ";
sqlNew = string.Format(sqlNew, (condition.PageIndex - 1) * condition.PageSize + 1, condition.PageIndex * condition.PageSize);
DataTable dt = ICSHelper.GetDataTableERP(sqlNew);
List<InventoryEntity> entityList = new List<InventoryEntity>();
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow dr in dt.Rows)
{
InventoryEntity entity = new InventoryEntity();
entity.cInvCode = dr["物料编码"].ToString();
entity.cInvAddCode = dr["物料代码"].ToString();
entity.cInvName = dr["物料名称"].ToString();
entity.cInvStd = dr["规格型号"].ToString();
entity.cComUnitCode = dr["主计量单位"].ToString();
entity.cAssComUnitCode = dr["辅计量单位"].ToString();
entity.cInvMnemCode = dr["助记码"].ToString();
if (string.IsNullOrWhiteSpace(dr["税率"].ToString()))
{
entity.iTaxRate = 0.00f;
}
else
{
entity.iTaxRate = float.Parse(dr["税率"].ToString());
}
if (string.IsNullOrWhiteSpace(dr["启用日期"].ToString()))
{
entity.dSDate = null;
}
else
{
entity.dSDate = Convert.ToDateTime(dr["启用日期"].ToString());
}
if (string.IsNullOrWhiteSpace(dr["停用日期"].ToString()))
{
entity.dEDate = null;
}
else
{
entity.dEDate = Convert.ToDateTime(dr["停用日期"].ToString());
}
entity.cCurrencyName = dr["通用名称"].ToString();
entity.cInvCName = dr["存货大类名称"].ToString();
entity.cEnglishName = dr["物料英文名称"].ToString();
entity.cPurPersonCode = dr["采购员"].ToString();
entity.bSale = Convert.ToBoolean(dr["是否销售"].ToString());
entity.bPurchase = Convert.ToBoolean(dr["是否采购"].ToString());
entity.bSelf = Convert.ToBoolean(dr["是否自制"].ToString());
entity.dModifyDate = dr["修改日期"].ToString();
entity.cInvPersonCode = dr["计划员"].ToString();
entityList.Add(entity);
}
res.IsSuccess = true;
res.Message = "执行成功!";
res.data = entityList;
return res;
}
else
{
res.IsSuccess = true;
res.Message = "查询无数据!";
res.data = entityList;
return res;
}
}
catch (Exception ex)
{
res.IsSuccess = false;
res.Message = ex.Message;
return res;
}
}
}
}