注塑喷涂
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.
 
 
 
 
 

215 lines
9.1 KiB

using MESClassLibrary.BLL.Log;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using MESClassLibrary.DAL;
namespace MESClassLibrary.BLL.Stock
{
public class StockInBLL
{
BBMPTEntities dbe = new BBMPTEntities();
BasicBLL<tb_StockIn> db = new BasicBLL<tb_StockIn>();
BasicBLL<tb_InspectResult> Resultdb = new BasicBLL<tb_InspectResult>();
/// <summary>
/// 查询信息
/// </summary>
/// <returns></returns>
public string SearchInfo(string page, string pagesize, string StartTime, string EndTime, string workClass, string color, string productInfo)
{
try
{
string jsonStr = "[]";
int total = 0;//总行数
//DateTime start = Convert.ToDateTime(StartTime);
//DateTime end = Convert.ToDateTime(EndTime);
//List<StockInModel> list = new List<StockInModel>();
//string sql = @"IF object_id(N'tempdb..#c',N'U') is not null
// BEGIN
// DROP Table #c
// END
// CREATE TABLE #c (barcode NVARCHAR(50),workClass NVARCHAR(100),productInfo NVARCHAR(200))
// INSERT INTO #c
// ( barcode,workClass, productInfo )
// SELECT d.barcode,d.workClass, d.productInfo FROM (
// SELECT *,cre_date_idx = ROW_NUMBER() OVER (PARTITION BY barcode ORDER BY createTime DESC)
// FROM dbo.tb_InspectResult
// WHERE barcode IN (SELECT barcode FROM dbo.tb_StockIn WHERE createTime >='"+ start+ @"' AND createTime <='"+ end+ @"')
// ) d
// WHERE d.cre_date_idx =1
// CREATE INDEX IX_TempTable ON #c(workClass,productInfo)
// SELECT a.ID,a.barcode,a.pass,a.createTime,#c.productInfo,#c.workClass FROM dbo.tb_StockIn a
// LEFT OUTER JOIN
// #c ON a.barcode=#c.barcode
// WHERE createTime >='" + start+ @"' AND createTime <='"+ end+ @"'";
//if (!string.IsNullOrEmpty(workClass))
//{
// sql += " and #c.workClass like '%" + workClass + @"%' ";
//}
//if (!string.IsNullOrEmpty(color))
//{
// sql += " and #c.productInfo like '%" + color + @"%' ";
//}
//if (!string.IsNullOrEmpty(productInfo))
//{
// sql += " and #c.productInfo like '%" + productInfo + @"%' ";
//}
//sql += " order by a.createTime";
//DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0];
//if (dt != null && dt.Rows.Count > 0)
//{
// list = Tool.ConvertTo<StockInModel>(dt).ToList();
//}
List<StockInModel> list = GetStockData(StartTime, EndTime, workClass, color, productInfo);
if (list.Count > 0)
{
total = list.Count;
int Skipcount = (Convert.ToInt32(page) - 1) * Convert.ToInt32(pagesize);
list = list.Skip(Skipcount).Take(Convert.ToInt32(pagesize)).ToList();;
JsonDataModel<StockInModel> md = new JsonDataModel<StockInModel>();
md.total = total.ToString();
md.rows = list;
jsonStr = JSONTools.ScriptSerialize<JsonDataModel<StockInModel>>(md);
}
return jsonStr;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return "";
}
}
List<StockInModel> GetStockData(string StartTime, string EndTime, string workClass, string color, string productInfo)
{
DateTime start = Convert.ToDateTime(StartTime);
DateTime end = Convert.ToDateTime(EndTime);
List<StockInModel> list = new List<StockInModel>();
string sql = @"IF object_id(N'tempdb..#c',N'U') is not null
BEGIN
DROP Table #c
END
CREATE TABLE #c (barcode NVARCHAR(50),workClass NVARCHAR(100),productInfo NVARCHAR(200))
INSERT INTO #c
( barcode,workClass, productInfo )
SELECT d.barcode,d.workClass, d.productInfo FROM (
SELECT *,cre_date_idx = ROW_NUMBER() OVER (PARTITION BY barcode ORDER BY createTime DESC)
FROM dbo.tb_InspectResult
WHERE barcode IN (SELECT barcode FROM dbo.tb_StockIn WHERE createTime >='" + start + @"' AND createTime <='" + end + @"')
) d
WHERE d.cre_date_idx =1
CREATE INDEX IX_TempTable ON #c(workClass,productInfo)
SELECT a.ID,a.barcode,a.pass,a.createTime,#c.productInfo,#c.workClass FROM dbo.tb_StockIn a
LEFT OUTER JOIN
#c ON a.barcode=#c.barcode
WHERE createTime >='" + start + @"' AND createTime <='" + end + @"'";
if (!string.IsNullOrEmpty(workClass))
{
sql += " and #c.workClass like '%" + workClass + @"%' ";
}
if (!string.IsNullOrEmpty(color))
{
sql += " and #c.productInfo like '%" + color + @"%' ";
}
if (!string.IsNullOrEmpty(productInfo))
{
sql += " and #c.productInfo like '%" + productInfo + @"%' ";
}
sql += " order by a.createTime";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
list = Tool.ConvertTo<StockInModel>(dt).ToList();
}
return list;
}
/// <summary>
/// 查询信息
/// </summary>
/// <returns></returns>
public List<StockInModel> SearchInfoAll(string StartTime, string EndTime, string workClass, string color, string productInfo)
{
try
{
//List<tb_StockIn> list = db.SearchAllInfo();
//DateTime start = Convert.ToDateTime(StartTime);
//DateTime end = Convert.ToDateTime(EndTime);
//list = list.Where(p => p.createTime >= start && p.createTime <= end && "1".Equals(p.pass)).ToList();
//List<string> barcodeList = list.Select(m => m.barcode).ToList();
//var resultList = dbe.tb_InspectResult.Where(p => barcodeList.Contains(p.barcode) && p.inspectResult.Contains("合格")).ToList();
//if (!String.IsNullOrEmpty(workClass))
//{
// resultList = resultList.Where(p => p.workClass.Contains(workClass)).ToList();
//}
//if (!String.IsNullOrEmpty(color))
//{
// resultList = resultList.Where(p => p.productInfo.Contains(color)).ToList();
//}
//if (!String.IsNullOrEmpty(productInfo))
//{
// resultList = resultList.Where(p => p.productInfo.Contains(productInfo)).ToList();
//}
//list = list.Where(p => resultList.Select(m => m.barcode).ToList().Contains(p.barcode)).ToList();
//List<StockInModel> StockInList = new List<StockInModel>();
//if (list.Count > 0)
//{
// foreach (var item in list)
// {
// StockInModel dm = Tool.Mapper<StockInModel, tb_StockIn>(item);
// var info = resultList.FirstOrDefault(p => p.barcode == item.barcode);
// if (info != null)
// {
// dm.workClass = info.workClass;
// dm.productInfo = info.productInfo;
// }
// StockInList.Add(dm);
// }
//}
//return StockInList;
List<StockInModel> StockInList = GetStockData(StartTime, EndTime, workClass, color, productInfo);
return StockInList;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
}
}