一厂MES,含注塑,喷涂,冲孔
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.
 
 
 
 
 

173 lines
7.0 KiB

using MESClassLibrary.BLL.Log;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using MESClassLibrary.Model;
namespace MESClassLibrary.DAL.ZPPlan
{
public class ZPPlanDAL
{
public DataTable PageInfo(int pageIndex, int pageSize, string startTime, string endTime, string partNo)
{
try
{
int skip = (pageIndex - 1) * pageSize;
string sql =
@"select * FROM[dbo].[tb_ZPPlan]
where CreatTime <= @StartTime and CreateTime >= @EndTime and PartNo = @PartNo
order by CreateTime desc";
sql += " offset " + skip + " rows ";
sql += " fetch next " + pageSize + " rows only";
SqlParameter[] param = new SqlParameter[] {
new SqlParameter("@StartTime", SqlDbType.VarChar)
{
Value = startTime
},
new SqlParameter("@EndTime", SqlDbType.VarChar)
{
Value = endTime
},
};
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 获取工位正在生产、未生产的计划
/// </summary>
/// <param name="station"></param>
/// <returns></returns>
public DataTable GetProductingPlan(string station)
{
try
{
string sql = @"SELECT top 1 dbo.tb_Station.StationNo,dbo.tb_ZPPlan.ID, dbo.tb_ZPPlan.OrderNo, dbo.tb_ZPPlan.PartNo, dbo.tb_Product.ProductName,
dbo.tb_ZPPlan.OrderCount, dbo.tb_ZPPlan.ProductCount, dbo.tb_ZPPlan.IsFinish, dbo.tb_ZPPlan.BadCount,dbo.tb_ZPPlan.CreateTime
FROM dbo.tb_ZPPlan LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_ZPPlan.PartNo = dbo.tb_Product.PartNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_ZPPlan.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo =@station and dbo.tb_ZPPlan.IsFinish<>3
order by dbo.tb_ZPPlan.CreateTime ";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@station", SqlDbType.VarChar);
param[0].Value = station;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
/// 获取工位上一计划、下一计划
/// </summary>
/// <param name="station"></param>
/// <returns></returns>
public DataTable GetPlan(string station,int flag,string planTime)
{
try
{
string sql = "";
if (flag == 1) //上一计划
{
sql = @"SELECT top 1 dbo.tb_Station.StationNo,dbo.tb_ZPPlan.ID, dbo.tb_ZPPlan.OrderNo, dbo.tb_ZPPlan.PartNo, dbo.tb_Product.ProductName,
dbo.tb_ZPPlan.OrderCount, dbo.tb_ZPPlan.ProductCount, dbo.tb_ZPPlan.IsFinish, dbo.tb_ZPPlan.BadCount,dbo.tb_ZPPlan.CreateTime
FROM dbo.tb_ZPPlan LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_ZPPlan.PartNo = dbo.tb_Product.PartNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_ZPPlan.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo =@station and dbo.tb_ZPPlan.IsFinish<>3 and dbo.tb_ZPPlan.CreateTime < DATEADD(SECOND,-1, @planTime)
order by dbo.tb_ZPPlan.CreateTime desc";
}
if (flag == 2) //下一计划
{
sql = @"SELECT top 1 dbo.tb_Station.StationNo,dbo.tb_ZPPlan.ID, dbo.tb_ZPPlan.OrderNo, dbo.tb_ZPPlan.PartNo, dbo.tb_Product.ProductName,
dbo.tb_ZPPlan.OrderCount, dbo.tb_ZPPlan.ProductCount, dbo.tb_ZPPlan.IsFinish, dbo.tb_ZPPlan.BadCount,dbo.tb_ZPPlan.CreateTime
FROM dbo.tb_ZPPlan LEFT OUTER JOIN
dbo.tb_Product ON dbo.tb_ZPPlan.PartNo = dbo.tb_Product.PartNo LEFT OUTER JOIN
dbo.tb_Station ON dbo.tb_ZPPlan.StationID = dbo.tb_Station.StationID
where dbo.tb_Station.StationNo =@station and dbo.tb_ZPPlan.IsFinish<>3 and dbo.tb_ZPPlan.CreateTime > DATEADD(SECOND,1, @planTime)
order by dbo.tb_ZPPlan.CreateTime ";
}
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@station", SqlDbType.VarChar);
param[0].Value = station;
param[1] = new SqlParameter("@planTime", SqlDbType.VarChar);
param[1].Value = planTime;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool updateQty(ZPPlanModel md)
{
try
{
string sql = @"update tb_ZPPlan set ProductCount=ProductCount+1 where ID=@ID";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool updateBad(ZPPlanModel md)
{
try
{
string sql = @"update tb_ZPPlan set ProductCount=ProductCount-1,BadCount=BadCount+1 where ID=@ID";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
}
}