一厂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.
 
 
 
 
 

194 lines
6.7 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.EFModel;
using MESClassLibrary.Model;
namespace MESClassLibrary.DAL.BasicInfo
{
public class BadInjectionDAL
{
public static string TableName = "tb_Bad_Injection";
public bool AddInfo(BadInjectionModel md)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO tb_Bad_Injection (ID,OneBarCode,[BarCode],[BadPosition],[BadReason],StationID";
sql += ") VALUES (";
sql += "@ID,";
sql += "@OneBarCode,";
sql += "@BarCode,";
sql += "@BadPosition,";
sql += "@BadReason,";
sql += "@StationID)";
#region 添加参数
param = new SqlParameter[6];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@OneBarCode", SqlDbType.VarChar);
param[1].Value = md.OneBarCode;
param[2] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[2].Value = md.BarCode;
param[3] = new SqlParameter("@BadPosition", SqlDbType.VarChar);
param[3].Value = md.BadPosition;
param[4] = new SqlParameter("@BadReason", SqlDbType.VarChar);
param[4].Value = md.BadReason;
param[5] = new SqlParameter("@StationID", SqlDbType.VarChar);
param[5].Value = md.StationID;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchByCode(string code)
{
try
{
string sql = "";
if (code.Contains("."))
{
sql = @"select * from " + TableName + " where BarCode=@BarCode";
}
else
{
sql = @"select * from " + TableName + " where OneBarCode=@BarCode";
}
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BarCode", SqlDbType.VarChar);
param[0].Value = code;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchInfoAll(string barcode, string starttime, string endtime)
{
try
{
string sql = @"SELECT t2.* FROM
(
SELECT [ID]
,CASE ISNULL([OneBarCode],'') WHEN '' THEN BarCode ELSE OneBarCode END as code
,[BarCode]
,[BadPosition]
,[BadReason]
,[CreateTime]
,[PlanID]
,StationID
FROM [BBMPT1].[dbo].[tb_Bad_Injection]) t2 where StationID <> 'ab38fdad-28ba-4711-8e49-3669d1abaad8'";
if (!String.IsNullOrEmpty(barcode))
{
sql += " and code like '%" + barcode + @"%'";
}
if (!String.IsNullOrEmpty(starttime))
{
sql += " and t2.CreateTime between '" + starttime + @"' and '" + endtime + @"'";
}
sql += " order by t2.CreateTime desc";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchZpInfoAll(string barcode, string starttime, string endtime)
{
try
{
string sql = @"SELECT t2.* FROM
(
SELECT [ID]
,CASE ISNULL([OneBarCode],'') WHEN '' THEN BarCode ELSE OneBarCode END as code
,[BarCode]
,[BadPosition]
,[BadReason]
,[CreateTime]
,[PlanID]
,StationID
FROM [BBMPT1].[dbo].[tb_Bad_Injection]) t2 where StationID = 'ab38fdad-28ba-4711-8e49-3669d1abaad8'";
if (!String.IsNullOrEmpty(barcode))
{
sql += " and code like '%" + barcode + @"%'";
}
if (!String.IsNullOrEmpty(starttime))
{
sql += " and t2.CreateTime between '" + starttime + @"' and '" + endtime + @"'";
}
sql += " order by t2.CreateTime desc";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string BadCount(string startTime, string endTime, string stationId)
{
string res = "0";
try
{
string sql = @"select count(OneBarCode) as badCount from tb_Bad_Injection with (noLock) where CreateTime between '" +
startTime + @"' and '" + endTime + @"' and StationID='" + stationId + @"'";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
res = dt.Rows[0]["badCount"].ToString();
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
}
return res;
}
}
}