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

214 lines
7.5 KiB

2 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Reflection;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.Model;
namespace MESClassLibrary.DAL.Injection
{
public class InjectionBoxDAL
{
public static string TableName = "tb_Injection_BoxRecord";
public bool AddInfo(InjectionBoxModel md)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO " + TableName + " (ID,BoxNo,BoxCount,IsFlag,StationNo, PartName,Mould,StandardQty,BoxType";
2 months ago
sql += ") VALUES (";
sql += "@ID,";
sql += "@BoxNo,";
sql += "@BoxCount,";
sql += "@IsFlag,";
sql += "@StationNo,";
sql += "@PartName,";
sql += "@Mould,";
sql += "@StandardQty,";
2 months ago
sql += "@BoxType)";
#region 添加参数
param = new SqlParameter[9];
2 months ago
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[1].Value = md.BoxNo;
param[2] = new SqlParameter("@BoxCount", SqlDbType.Int);
param[2].Value = md.BoxCount;
param[3] = new SqlParameter("@IsFlag", SqlDbType.Int);
param[3].Value = md.IsFlag;
param[4] = new SqlParameter("@StationNo", SqlDbType.VarChar);
param[4].Value = md.StationNo;
param[5] = new SqlParameter("@PartName", SqlDbType.NVarChar);
param[5].Value = md.PartName;
param[6] = new SqlParameter("@Mould", SqlDbType.NVarChar);
param[6].Value = md.Mould;
param[7] = new SqlParameter("@StandardQty", SqlDbType.NVarChar);
param[7].Value = md.StandardQty;
param[8] = new SqlParameter("@BoxType", SqlDbType.VarChar);
param[8].Value = md.BoxType;
2 months ago
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool UpdateInfo(string packageCode, int addCount, bool isFinish = false)
{
try
{
int i = 0;
if(addCount > 0)
{
i = 0;
}
else
{
i = 1;
}
#region 添加数据
string sql = "";
SqlParameter[] param = null;
if(isFinish == false)
{
sql = "update " + TableName + $" set BoxCount = BoxCount+ {addCount} ";
sql += $" where BoxCount >={i} and ";
sql += "BoxNo=@BoxNo";
}
else
{
sql = "update " + TableName + $" set BoxCount = 0, IsPrint=1 ,remark='整箱报废'";
sql += $" where (1=1) and ";
sql += "BoxNo=@BoxNo";
}
#region 添加参数
param = new SqlParameter[1];
param[0] = new SqlParameter("BoxNo", SqlDbType.VarChar);
param[0].Value = packageCode;
2 months ago
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool UpdatePrinted(string packageCode)
{
try
{
#region 添加数据
string sql = "";
SqlParameter[] param = null;
sql = "update " + TableName + " set IsPrint = 1, PrintTime=getdate() ";
sql += " where ";
sql += "BoxNo=@BoxNo";
#region 添加参数
param = new SqlParameter[1];
param[0] = new SqlParameter("BoxNo", SqlDbType.VarChar);
param[0].Value = packageCode;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
#endregion
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
2 months ago
public DataTable SeachInfoByBox(string partNo,string batchNo)
{
try
{
string sql = @"select top 1 * from " + TableName + " where substring(BoxNo,0,CHARINDEX('.',BoxNo))=@partNo and SUBSTRING(SUBSTRING(BoxNo,CHARINDEX('.',BoxNo)+1,LEN(BoxNo)),0,CHARINDEX('.',SUBSTRING(BoxNo,CHARINDEX('.',BoxNo)+1,LEN(BoxNo))))=@batchNo and IsFlag=0 order by [CreateTime] desc";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@partNo", SqlDbType.VarChar);
param[0].Value = partNo;
param[1] = new SqlParameter("@batchNo", SqlDbType.VarChar);
param[1].Value = batchNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchBox(string BoxNo)
{
try
{
string sql = @"select * from " + TableName + " where BoxNo=@BoxNo";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = BoxNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchUnBox(string stationID,string mould)
{
try
{
string sql = @"select * from " + TableName + " where StationNo=@StationNo and Mould=@Mould and IsPrint=0 order by CreateTime desc ";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@StationNo", SqlDbType.VarChar);
param[0].Value = stationID;
param[1] = new SqlParameter("@Mould", SqlDbType.VarChar);
param[1].Value = mould;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
2 months ago
}
}