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.
740 lines
49 KiB
740 lines
49 KiB
6 months ago
|
using DBUtility;
|
||
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Configuration;
|
||
|
using System.Data;
|
||
|
using System.Reflection;
|
||
|
using System.Web;
|
||
|
|
||
|
/// <summary>
|
||
|
/// Function 的摘要说明
|
||
|
/// </summary>
|
||
|
public class Function
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 获取页面所需数据
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public static List<Model> GetData()
|
||
|
{
|
||
|
List<Model> list = new List<Model>();
|
||
|
|
||
|
try
|
||
|
{
|
||
|
string sql = @"
|
||
|
select a.CylinderNo, d.StationNo, b.BarCode, b.Time1
|
||
|
from tb_Cylinder a
|
||
|
left join tb_CylinderAndRaw b
|
||
|
on a.CylinderID = b.CylinderID and b.Time2 is null
|
||
|
left join tb_StationAndCylinder c
|
||
|
on a.CylinderID = c.CylinderID and c.Time2 is null
|
||
|
left join tb_Station d
|
||
|
on c.StationID = d.StationID
|
||
|
--WHERE datediff(dd,b.Time1,GETDATE())=0
|
||
|
order by a.CylinderNo
|
||
|
";
|
||
|
DataTable dt1 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
||
|
if (dt1 != null && dt1.Rows.Count > 0)
|
||
|
{
|
||
|
for (int i = 0; i < dt1.Rows.Count; i++)
|
||
|
{
|
||
|
string stockNo = "";
|
||
|
string batchNo = "";
|
||
|
string partNo = "";
|
||
|
GetCode(dt1.Rows[i]["BarCode"].ToString(), out stockNo, out batchNo, out partNo);
|
||
|
|
||
|
DataTable dt2 = new DataTable();
|
||
|
if (!string.IsNullOrWhiteSpace(stockNo))
|
||
|
{
|
||
|
string sql2 = " select PartName, ProductName from tb_Product where StockNo = '" + stockNo.Trim() + "' ";
|
||
|
dt2 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
|
||
|
}
|
||
|
else if (!string.IsNullOrWhiteSpace(partNo))
|
||
|
{
|
||
|
string sql2 = " select PartName, ProductName from tb_Product where PartNo = '" + partNo.Trim() + "' ";
|
||
|
dt2 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
|
||
|
}
|
||
|
|
||
|
Model model = new Model();
|
||
|
model.Drum = dt1.Rows[i]["CylinderNo"].ToString();
|
||
|
model.Station = dt1.Rows[i]["StationNo"].ToString();
|
||
|
model.BatchNo = batchNo;
|
||
|
model.Time1 = dt1.Rows[i]["Time1"].ToString();
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
model.MaterialName = dt2.Rows[0]["ProductName"].ToString();
|
||
|
//model.ProductName = dt2.Rows[0]["PartName"].ToString();
|
||
|
}
|
||
|
|
||
|
DataTable dt_product = GetProductName(model.Station);
|
||
|
if (dt_product != null && dt_product.Rows.Count > 0)
|
||
|
{
|
||
|
model.ProductName = dt_product.Rows[0]["Plan"].ToString();
|
||
|
}
|
||
|
|
||
|
list.Add(model);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return list;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteLogManager(ex);
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
return list;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 根据注塑机查询计划要生产的产品信息
|
||
|
/// </summary>
|
||
|
/// <param name="machineCode"></param>
|
||
|
/// <returns></returns>
|
||
|
private static DataTable GetProductName(string machineCode)
|
||
|
{
|
||
|
DataTable res = new DataTable();
|
||
|
try
|
||
|
{
|
||
|
string sql = @"
|
||
|
select top 1 ProductName as [Plan] from tb_Product where StockNo = (
|
||
|
select top 1 StockNo from tb_InjectionPlan where StationID = (
|
||
|
select StationID from tb_Station where StationNo = '" + machineCode + @"' )
|
||
|
AND (IsFinish is null or IsFinish = 0)
|
||
|
ORDER BY BeginTime ASC
|
||
|
)
|
||
|
";
|
||
|
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
||
|
|
||
|
if (res == null || res.Rows.Count < 1)
|
||
|
{
|
||
|
string sql2 = @" select top 1 ProductName as [Plan] from tb_Product where PartNo = (
|
||
|
select top 1 PartNo from tb_InjectionPlan where StationID = (
|
||
|
select StationID from tb_Station where StationNo = '" + machineCode + @"' )
|
||
|
AND (IsFinish is null or IsFinish = 0)
|
||
|
ORDER BY BeginTime ASC
|
||
|
)
|
||
|
";
|
||
|
res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
|
||
|
}
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteLogManager(ex);
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
return res;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 解析条码(一维码返回存货代码,二维码返回零件号)
|
||
|
/// </summary>
|
||
|
/// <param name="code">条码</param>
|
||
|
/// <param name="stockNo">存货代码</param>
|
||
|
/// <param name="batchNo">批次</param>
|
||
|
/// /// <param name="partNo">零件号</param>
|
||
|
public static void GetCode(string code, out string stockNo, out string batchNo, out string partNo)
|
||
|
{
|
||
|
//解析塑料粒子条码,长度为20的为一维码22000000821906090201,否则为二维码
|
||
|
//二维码样例Z-340.180411.000001;5000;S35001;20180411;P1710401.[#Line#];180411;
|
||
|
//第一个分号之前的数据,即Z-340.180411.000001; Z-340为零件号,180411为批次号,000001为流水号
|
||
|
//一维码前十位为零件号,tb_Product PartNo,11~16位为批次
|
||
|
|
||
|
stockNo = ""; //存货代码
|
||
|
batchNo = ""; //批次
|
||
|
partNo = ""; //零件号
|
||
|
try
|
||
|
{
|
||
|
if (code.Contains(".") == false)
|
||
|
{
|
||
|
//一维码
|
||
|
if (code.Length > 9)
|
||
|
{
|
||
|
stockNo = code.Substring(0, 10);
|
||
|
batchNo = code.Substring(10, 6);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//二维码
|
||
|
string[] strs = code.Split(';');
|
||
|
if (strs.Length > 0)
|
||
|
{
|
||
|
string str = strs[0];
|
||
|
string[] props = str.Split('.');
|
||
|
if (props.Length >= 3)
|
||
|
{
|
||
|
partNo = props[0];
|
||
|
batchNo = props[1];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteLogManager(ex);
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 注塑车间计划看板数据
|
||
|
/// lx 20190531
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public static string GetPlanTable()
|
||
|
{
|
||
|
string res = "";
|
||
|
PlanModel model = new PlanModel();
|
||
|
try
|
||
|
{
|
||
|
//string stationNo = ConfigurationManager.AppSettings["StationNo"].ToString();
|
||
|
|
||
|
#region 获取端口号,查工位号--注销
|
||
|
|
||
|
//int ipPort = HttpContext.Current.Request.Url.Port;
|
||
|
//string sqlStation = @" select StationNo from tb_PlanScreenConfig where IP = '" + ipPort + @"' ";
|
||
|
//string stationNo = "";
|
||
|
//object aa = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sqlStation, null);
|
||
|
//if (aa != null)
|
||
|
//{
|
||
|
// stationNo = aa.ToString();
|
||
|
//}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 工位号
|
||
|
|
||
|
string stationNo = ConfigurationManager.AppSettings["StationNo"].ToString();
|
||
|
model.Station = stationNo;
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 查询生产计划
|
||
|
|
||
|
string stockNo = "";
|
||
|
string partNo = "";
|
||
|
DataTable dtPlan = new DataTable();
|
||
|
string sqlPlan1 = @"
|
||
|
select top 1 ProductName as [Plan],StockNo,PartNo from tb_Product where StockNo = (
|
||
|
select top 1 StockNo from tb_InjectionPlan where StationID = (
|
||
|
select StationID from tb_Station where StationNo = '" + stationNo + @"' )
|
||
|
AND (IsFinish IS NULL OR IsFinish = 0)
|
||
|
ORDER BY BeginTime ASC
|
||
|
)
|
||
|
";
|
||
|
dtPlan = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqlPlan1, null);
|
||
|
|
||
|
if (dtPlan == null || dtPlan.Rows.Count < 1)
|
||
|
{
|
||
|
string sqlPlan2 = @" select top 1 ProductName as [Plan],StockNo,PartNo from tb_Product where PartNo = (
|
||
|
select top 1 PartNo from tb_InjectionPlan where StationID = (
|
||
|
select StationID from tb_Station where StationNo = '" + stationNo + @"' )
|
||
|
AND (IsFinish IS NULL OR IsFinish = 0)
|
||
|
ORDER BY BeginTime ASC
|
||
|
)
|
||
|
";
|
||
|
dtPlan = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sqlPlan2, null);
|
||
|
}
|
||
|
if (dtPlan != null && dtPlan.Rows.Count > 0)
|
||
|
{
|
||
|
model.PartNo = dtPlan.Rows[0]["PartNo"].ToString();
|
||
|
stockNo = dtPlan.Rows[0]["StockNo"].ToString();
|
||
|
partNo = dtPlan.Rows[0]["PartNo"].ToString();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 查询产品信息
|
||
|
|
||
|
DataTable dtProduct = GetProductName(stationNo);
|
||
|
if (dtProduct != null && dtProduct.Rows.Count > 0)
|
||
|
{
|
||
|
model.ProductName = dtProduct.Rows[0][0].ToString();
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 查询数量
|
||
|
|
||
|
#region 查询StationID
|
||
|
|
||
|
string stationID = "";
|
||
|
string sqlStationID = " select StationID from tb_Station where StationNo = '" + stationNo + "' ";
|
||
|
stationID = SqlHelper.ExecuteScalar(SqlHelper.SqlConnString, CommandType.Text, sqlStationID, null).ToString();
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
|
||
|
#region 计划数量
|
||
|
DataTable dt3 = new DataTable();
|
||
|
string sql3 = "";
|
||
|
if (!string.IsNullOrWhiteSpace(stockNo))
|
||
|
{
|
||
|
sql3 = @" SELECT InjectionPlanID, PlanCount FROM tb_InjectionPlan WHERE StationID = '" + stationID + @"' AND StockNo = '" + stockNo +
|
||
|
"' AND (IsFinish is null or IsFinish = 0) ORDER BY BeginTime ASC ";
|
||
|
}
|
||
|
else if (!string.IsNullOrWhiteSpace(partNo))
|
||
|
{
|
||
|
sql3 = @" SELECT InjectionPlanID, PlanCount FROM tb_InjectionPlan WHERE StationID = '" + stationID + @"' AND PartNo = '" + partNo +
|
||
|
"' AND (IsFinish is null or IsFinish = 0) ORDER BY BeginTime ASC ";
|
||
|
}
|
||
|
dt3 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql3, null);
|
||
|
string injectionPlanID = "";
|
||
|
if (dt3 != null && dt3.Rows.Count > 0)
|
||
|
{
|
||
|
model.PlanCount = dt3.Rows[0]["PlanCount"].ToString();
|
||
|
injectionPlanID = dt3.Rows[0]["InjectionPlanID"].ToString();
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 完成数量等
|
||
|
|
||
|
DataTable dt4 = new DataTable();
|
||
|
string sql4 = "";
|
||
|
|
||
|
string date = DateTime.Now.ToString("yyyy-MM-dd");
|
||
|
if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 8)
|
||
|
{
|
||
|
date = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd");
|
||
|
}
|
||
|
|
||
|
if (!string.IsNullOrWhiteSpace(stockNo))
|
||
|
{
|
||
|
sql4 = @" SELECT ISNULL(SUM(ISNULL(ProductCount,0)),0) ProductCount, ISNULL(SUM(ISNULL(BadCount,0)),0) BadCount
|
||
|
FROM tb_Product_Injection
|
||
|
WHERE StationID = '" + stationID + @"'
|
||
|
AND StockNo = '" + stockNo + @"'
|
||
|
AND ProductDate = '" + date + @"'
|
||
|
AND ClassName = '" + GetWorkClass() + @"'
|
||
|
AND PlanID = '" + injectionPlanID + @"'
|
||
|
";
|
||
|
}
|
||
|
else if (!string.IsNullOrWhiteSpace(partNo))
|
||
|
{
|
||
|
sql4 = @" SELECT ISNULL(SUM(ISNULL(ProductCount,0)),0) ProductCount, ISNULL(SUM(ISNULL(BadCount,0)),0) BadCount
|
||
|
FROM tb_Product_Injection
|
||
|
WHERE StationID = '" + stationID + @"'
|
||
|
AND PartNo = '" + partNo + @"'
|
||
|
AND ProductDate = '" + date + @"'
|
||
|
AND ClassName = '" + GetWorkClass() + @"'
|
||
|
AND PlanID = '" + injectionPlanID + @"'
|
||
|
";
|
||
|
}
|
||
|
dt4 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql4, null);
|
||
|
if (dt4 != null && dt4.Rows.Count > 0)
|
||
|
{
|
||
|
model.CompleteCount = dt4.Rows[0]["ProductCount"].ToString();
|
||
|
|
||
|
|
||
|
int prc = 0; int badc = 0;
|
||
|
Int32.TryParse(dt4.Rows[0]["ProductCount"].ToString(), out prc);
|
||
|
Int32.TryParse(dt4.Rows[0]["BadCount"].ToString(), out badc);
|
||
|
model.PassCount = (prc - badc).ToString();
|
||
|
|
||
|
int passc = 0;
|
||
|
double compc = 0.0;
|
||
|
Int32.TryParse(model.PassCount, out passc);
|
||
|
Double.TryParse(model.CompleteCount, out compc);
|
||
|
if (compc == 0.0)
|
||
|
{
|
||
|
model.CompleteRate = "0.0%";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
model.CompleteRate = (passc / compc * 100).ToString("0.00") + "%";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 查询剩余计划零件号和计划数量
|
||
|
|
||
|
//string sql_plan = @" select PartNo, PlanCount from tb_InjectionPlan where StationID = '" + dt.Rows[0]["StationID"].ToString() + "' AND (IsFinish is null or IsFinish = 0) ORDER BY BeginTime ASC ";
|
||
|
string sql_plan = @"
|
||
|
SELECT tb_Product.ProductName ProductName, PlanCount from tb_InjectionPlan
|
||
|
JOIN tb_Product ON tb_Product.StockNo = tb_InjectionPlan.StockNo
|
||
|
WHERE StationID = '" + stationID + @"' AND (IsFinish is null or IsFinish = 0) ORDER BY BeginTime ASC
|
||
|
";
|
||
|
DataTable dt_plan = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql_plan, null);
|
||
|
if (dt_plan != null && dt_plan.Rows.Count > 0)
|
||
|
{
|
||
|
if (dt_plan.Rows.Count >= 2)
|
||
|
{
|
||
|
//model.PartNo2 = dt_plan.Rows[1]["PartNo"].ToString();
|
||
|
model.PartNo2 = dt_plan.Rows[1]["ProductName"].ToString();
|
||
|
model.PlanCount2 = dt_plan.Rows[1]["PlanCount"].ToString();
|
||
|
}
|
||
|
if (dt_plan.Rows.Count >= 3)
|
||
|
{
|
||
|
//model.PartNo3 = dt_plan.Rows[2]["PartNo"].ToString();
|
||
|
model.PartNo3 = dt_plan.Rows[2]["ProductName"].ToString();
|
||
|
model.PlanCount3 = dt_plan.Rows[2]["PlanCount"].ToString();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
string sql = @"
|
||
|
select a.CylinderNo, d.StationNo, d.StationID, b.BarCode, b.Time1
|
||
|
from tb_Cylinder a
|
||
|
left join tb_CylinderAndRaw b
|
||
|
on a.CylinderID = b.CylinderID and b.Time2 is null
|
||
|
left join tb_StationAndCylinder c
|
||
|
on a.CylinderID = c.CylinderID and c.Time2 is null
|
||
|
left join tb_Station d
|
||
|
on c.StationID = d.StationID
|
||
|
where d.StationNo = '" + stationNo + @"'
|
||
|
";
|
||
|
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
||
|
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
model.Drum = dt.Rows[0]["CylinderNo"].ToString();
|
||
|
model.Time1 = dt.Rows[0]["Time1"].ToString();
|
||
|
|
||
|
string batchNo = "";
|
||
|
GetCode(dt.Rows[0]["BarCode"].ToString(), out stockNo, out batchNo, out partNo);
|
||
|
|
||
|
model.BatchNo = batchNo;
|
||
|
|
||
|
#region 查询原料信息
|
||
|
|
||
|
DataTable dt2 = new DataTable();
|
||
|
string sql2 = "";
|
||
|
if (!string.IsNullOrWhiteSpace(stockNo))
|
||
|
{
|
||
|
sql2 = " select PartNo, PartName, ProductName from tb_Product where StockNo = '" + stockNo + "' ";
|
||
|
}
|
||
|
else if (!string.IsNullOrWhiteSpace(partNo))
|
||
|
{
|
||
|
sql2 = " select PartNo, PartName, ProductName from tb_Product where PartNo = '" + partNo + "' ";
|
||
|
}
|
||
|
dt2 = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql2, null);
|
||
|
if (dt2 != null && dt2.Rows.Count > 0)
|
||
|
{
|
||
|
model.MaterialName = dt2.Rows[0]["ProductName"].ToString();
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#region 存储报表数据
|
||
|
|
||
|
Function.InsertInjectPlanReport(injectionPlanID, model.ProductName, model.MaterialName, model.Drum, model.BatchNo, model.Time1);
|
||
|
|
||
|
#endregion
|
||
|
}
|
||
|
|
||
|
res = JSONHelper.ObjectToJSON(model);
|
||
|
return res;
|
||
|
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteLogManager(ex);
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
return res;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void InsertInjectPlanReport(string injectionPlanID, string ProductName, string MaterialName, string Drum, string BatchNo, string Time1)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string sql = @"
|
||
|
IF NOT EXISTS ( SELECT * FROM tb_InjectPlanReport WHERE InjectionPlanID = '"+ injectionPlanID +@"' )
|
||
|
BEGIN
|
||
|
INSERT INTO tb_InjectPlanReport
|
||
|
([ID]
|
||
|
,[InjectionPlanID]
|
||
|
,[ProductName]
|
||
|
,[MaterialName]
|
||
|
,[Drum]
|
||
|
,[BatchNo]
|
||
|
,[Time1]
|
||
|
)
|
||
|
VALUES(
|
||
|
(SELECT NEWID())
|
||
|
,'"+ injectionPlanID +@"'
|
||
|
,'"+ ProductName +@"'
|
||
|
,'"+ MaterialName +@"'
|
||
|
,'"+ Drum +@"'
|
||
|
,'"+ BatchNo +@"'
|
||
|
,'"+ Time1 + @"'
|
||
|
)
|
||
|
END
|
||
|
else
|
||
|
begin
|
||
|
delete from tb_InjectPlanReport where InjectionPlanID = '"+ injectionPlanID +@"'
|
||
|
INSERT INTO tb_InjectPlanReport
|
||
|
([ID]
|
||
|
,[InjectionPlanID]
|
||
|
,[ProductName]
|
||
|
,[MaterialName]
|
||
|
,[Drum]
|
||
|
,[BatchNo]
|
||
|
,[Time1]
|
||
|
)
|
||
|
VALUES(
|
||
|
(SELECT NEWID())
|
||
|
,'" + injectionPlanID + @"'
|
||
|
,'" + ProductName + @"'
|
||
|
,'" + MaterialName + @"'
|
||
|
,'" + Drum + @"'
|
||
|
,'" + BatchNo + @"'
|
||
|
,'" + Time1 + @"'
|
||
|
)
|
||
|
end
|
||
|
";
|
||
|
SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteLogManager(ex);
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static StockModel getBar()
|
||
|
{
|
||
|
StockModel md = new StockModel();
|
||
|
md.c1 = new List<int>();
|
||
|
md.c2 = new List<int>();
|
||
|
md.h1 = new List<string>();
|
||
|
string sql = "";
|
||
|
try
|
||
|
{
|
||
|
if (DateTime.Now > DateTime.Parse(DateTime.Now.ToShortDateString() + " 08:00:00") && DateTime.Now < DateTime.Parse(DateTime.Now.ToShortDateString() + " 20:00:00"))
|
||
|
{
|
||
|
sql =
|
||
|
@"IF OBJECT_ID('TEMPDB..#a') IS NOT NULL
|
||
|
DROP TABLE #a
|
||
|
create table #a (BarCode nvarchar(100),productInfo nvarchar(100),color NVARCHAR(50),paintCode NVARCHAR(100),createTime DATETIME)
|
||
|
|
||
|
INSERT INTO #a SELECT dbo.tb_StockIn.barcode, dbo.tb_Product.ProductName,dbo.View_Color.Des,paintCode,dbo.tb_StockIn.createTime
|
||
|
FROM dbo.tb_Product RIGHT OUTER JOIN
|
||
|
dbo.tb_StockIn ON dbo.tb_Product.StockNo = SUBSTRING(dbo.tb_StockIn.barcode, 1, 10) LEFT OUTER JOIN
|
||
|
dbo.View_Color ON SUBSTRING(dbo.tb_StockIn.paintCode, LEN(dbo.tb_StockIn.paintCode) - 3, 4) = dbo.View_Color.ColorNo
|
||
|
WHERE createTime BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:00:01')
|
||
|
AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00') AND pass=1
|
||
|
|
||
|
|
||
|
SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:59:59.999')) AND productInfo LIKE '%槛%') c2,08 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 09:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 09:59:59.999')) AND productInfo LIKE '%槛%') c2,09 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 09:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 09:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 10:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 10:59:59.999')) AND productInfo LIKE '%槛%') c2,10 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 10:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 10:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 11:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 11:59:59.999')) AND productInfo LIKE '%槛%' ) c2,11 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 11:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 11:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 12:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 12:59:59.999')) AND productInfo LIKE '%槛%' ) c2,12 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 12:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 12:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 13:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 13:59:59.999')) AND productInfo LIKE '%槛%' ) c2,13 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 13:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 13:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 14:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 14:59:59.999')) AND productInfo LIKE '%槛%') c2,14 AS h
|
||
|
FROM #a WHERE ([createTime]BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 14:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 14:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 15:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 15:59:59.999')) AND productInfo LIKE '%槛%') c2,15 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 15:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 15:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 16:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 16:59:59.999')) AND productInfo LIKE '%槛%') c2,16 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 16:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 16:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 17:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 17:59:59.999')) AND productInfo LIKE '%槛%') c2,17 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 17:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 17:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 18:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 18:59:59.999')) AND productInfo LIKE '%槛%' ) c2,18 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 18:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 18:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION ALL SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 19:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 19:59:59.999')) AND productInfo LIKE '%槛%') c2,19 AS h
|
||
|
FROM #a WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 19:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 19:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
ORDER BY h asc ";
|
||
|
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (DateTime.Now > DateTime.Parse(DateTime.Now.ToShortDateString() + " 20:00:00") && DateTime.Now < DateTime.Parse(DateTime.Now.ToShortDateString() + " 23:59:59"))
|
||
|
{
|
||
|
sql = @"IF OBJECT_ID('TEMPDB..#b') IS NOT NULL
|
||
|
DROP TABLE #b
|
||
|
create table #b (BarCode nvarchar(100),productInfo nvarchar(100),color NVARCHAR(50),paintCode NVARCHAR(100),createTime DATETIME)
|
||
|
|
||
|
INSERT INTO #b SELECT dbo.tb_StockIn.barcode, dbo.tb_Product.ProductName,dbo.View_Color.Des,paintCode,dbo.tb_StockIn.createTime
|
||
|
FROM dbo.tb_Product RIGHT OUTER JOIN
|
||
|
dbo.tb_StockIn ON dbo.tb_Product.StockNo = SUBSTRING(dbo.tb_StockIn.barcode, 1, 10) LEFT OUTER JOIN
|
||
|
dbo.View_Color ON SUBSTRING(dbo.tb_StockIn.paintCode, LEN(dbo.tb_StockIn.paintCode) - 3, 4) = dbo.View_Color.ColorNo
|
||
|
WHERE createTime BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000')
|
||
|
AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:59:59.999') AND pass=1
|
||
|
|
||
|
|
||
|
SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:59:59.999')) AND productInfo LIKE '%槛%') c2,20 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:59:59.999')) AND productInfo LIKE '%槛%') c2,21 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:59:59.999')) AND productInfo LIKE '%槛%') c2,22 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:59:59.999')) AND productInfo LIKE '%槛%' ) c2,23 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:00:00.000') AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:59:59.999'))) AND productInfo LIKE '%槛%') c2,00 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:00:00.000') AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,01 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,02 AS h
|
||
|
FROM #b WHERE ([createTime]BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,03 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,04 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:59:59.999'))) AND productInfo LIKE '%槛%') c2,05 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,06 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:59:59.999'))) AND productInfo LIKE '%槛%' ) c2,07 AS h
|
||
|
FROM #b WHERE ([createTime] BETWEEN DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:00:00.000')) AND DATEADD(DAY,1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
sql = @"IF OBJECT_ID('TEMPDB..#c') IS NOT NULL
|
||
|
DROP TABLE #b
|
||
|
create table #c (BarCode nvarchar(100),productInfo nvarchar(100),color NVARCHAR(50),paintCode NVARCHAR(100),createTime DATETIME)
|
||
|
|
||
|
INSERT INTO #c SELECT dbo.tb_StockIn.barcode, dbo.tb_Product.ProductName,dbo.View_Color.Des,paintCode,dbo.tb_StockIn.createTime
|
||
|
FROM dbo.tb_Product RIGHT OUTER JOIN
|
||
|
dbo.tb_StockIn ON dbo.tb_Product.StockNo = SUBSTRING(dbo.tb_StockIn.barcode, 1, 10) LEFT OUTER JOIN
|
||
|
dbo.View_Color ON SUBSTRING(dbo.tb_StockIn.paintCode, LEN(dbo.tb_StockIn.paintCode) - 3, 4) = dbo.View_Color.ColorNo
|
||
|
WHERE createTime BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000'))
|
||
|
AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 08:00:00.000') AND pass=1
|
||
|
|
||
|
|
||
|
SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:59:59.999'))) AND productInfo LIKE '%槛%') c2,20 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 20:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:59:59.999'))) AND productInfo LIKE '%槛%') c2,21 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 21:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:59:59.999'))) AND productInfo LIKE '%槛%') c2,22 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 22:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:59:59.999'))) AND productInfo LIKE '%槛%') c2,23 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:00:00.000')) AND DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 23:59:59.999'))) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:00:00.000')) AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:59:59.999')) AND productInfo LIKE '%槛%') c2,00 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN DATEADD(DAY,-1,CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:00:00.000')) AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 00:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:59:59.999')) AND productInfo LIKE '%槛%') c2,01 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 01:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:59:59.999')) AND productInfo LIKE '%槛%') c2,02 AS h
|
||
|
FROM #c WHERE ([createTime]BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 02:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:59:59.999')) AND productInfo LIKE '%槛%' ) c2,03 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 03:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:59:59.999')) AND productInfo LIKE '%槛%') c2,04 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 04:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:59:59.999')) AND productInfo LIKE '%槛%') c2,05 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 05:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:59:59.999')) AND productInfo LIKE '%槛%') c2,06 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 06:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
UNION all SELECT COUNT(*) AS c1 ,
|
||
|
(SELECT COUNT(*) FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:59:59.999')) AND productInfo LIKE '%槛%') c2,07 AS h
|
||
|
FROM #c WHERE ([createTime] BETWEEN CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:00:00.000') AND CONVERT(DATETIME,SUBSTRING(CONVERT(NVARCHAR(50),GETDATE(),120),1,10)+ ' 07:59:59.999')) AND productInfo LIKE '%保%'
|
||
|
";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null);
|
||
|
if (dt != null && dt.Rows.Count > 0)
|
||
|
{
|
||
|
|
||
|
for (int i = 0; i < dt.Rows.Count; i++)
|
||
|
{
|
||
|
md.c1.Add(int.Parse(dt.Rows[i]["c1"].ToString()));
|
||
|
md.c2.Add(int.Parse(dt.Rows[i]["c2"].ToString()));
|
||
|
md.h1.Add(dt.Rows[i]["h"].ToString() + ":00");
|
||
|
}
|
||
|
}
|
||
|
return md;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
return md;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取班次,规定早8至晚8为A班
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
public static string GetWorkClass()
|
||
|
{
|
||
|
bool classA = IsBetweenTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "2019-06-12 08:00:00", "2019-06-12 20:00:00");
|
||
|
if (classA)
|
||
|
{
|
||
|
return "A班";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return "B班";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 判断传入时间是否在工作时间段内
|
||
|
/// </summary>
|
||
|
/// <param name="timeStr"></param>
|
||
|
/// <param name="startTime"></param>
|
||
|
/// <param name="endTime"></param>
|
||
|
/// <returns></returns>
|
||
|
public static bool IsBetweenTime(string timeStr, string startTime, string endTime)
|
||
|
{
|
||
|
//判断传入时间是否在工作时间段内
|
||
|
try
|
||
|
{
|
||
|
TimeSpan startSpan = DateTime.Parse(startTime).TimeOfDay;
|
||
|
TimeSpan endSpan = DateTime.Parse(endTime).TimeOfDay;
|
||
|
|
||
|
DateTime t1 = Convert.ToDateTime(timeStr);
|
||
|
TimeSpan dspNow = t1.TimeOfDay;
|
||
|
if (dspNow > startSpan && dspNow < endSpan)
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|