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

151 lines
5.6 KiB

3 months ago
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using MESClassLibrary.BLL.Log;
namespace MESClassLibrary.DAL.ZPPlan
{
public class ZPStepRecordDAL
{
public bool DelInfoByStation(string station, string barcode)
{
try
{
string sql = @"delete from tb_ZPStepRecord where StationID=(select StationID from dbo.tb_Station where StationNo ='" +
station + @"' ) and BarCode='" + barcode + @"'";
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, null);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchStepByStation(string station,string PlanID,string barCode)
{
try
{
// string sql = @"SELECT r.*, s.StationNo
// FROM dbo.tb_ZPStepRecord AS r LEFT OUTER JOIN
// dbo.tb_Station AS s ON r.StationID = s.StationID
// where s.StationNo='" + station + @"'
// and r.BarCode='" + barcode + @"' order by r.ID";
string sql =
@"SELECT r.ID, r.BarCode, r.StationID, r.Step, r.MouldNo, r.KeyBarCode, r.IsOK, r.CreateTime, r.PlanID, s.StationNo,
dbo.tb_ZPPlan.PartNo
FROM dbo.tb_ZPStepRecord AS r LEFT OUTER JOIN
dbo.tb_ZPPlan ON r.PlanID = dbo.tb_ZPPlan.ID LEFT OUTER JOIN
dbo.tb_Station AS s ON r.StationID = s.StationID
where s.StationNo='" + station + @"' and r.PlanID='" + PlanID + @"'
and isnull(r.BarCode,'')='" + barCode + @"' and r.IsOK=1 ";
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>
/// <param name="step"></param>
/// <returns></returns>
public DataTable SearchBeforStep(string station, int step)
{
try
{
string sql = @"declare @i int,
@station nvarchar(200),
@s1 nvarchar(max);
set @i=" + step+ @";
set @station='"+station+ @"';
set @s1='(select stationID from tb_station where stationNo=' + ''''+@station+''')'
select top '+ @i+ ' * from tb_ZPStepRecord where stationID='+ @s1 + ' order by ID DESC";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return null;
}
}
public bool UpdateBarCode(string stationID,string barcode,string planID)
{
try
{
string sql = @"update tb_ZPStepRecord set BarCode='" + barcode + @"' where StationID='" + stationID + @"' and PlanID='" + planID + @"' and BarCode is null";
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, null);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return false;
}
}
public int CompleteStep(string barcode)
{
try
{
string sql = @"select Count(*) as aa from tb_ZPStepRecord where BarCode='" + barcode + @"' and IsOK=1 ";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null & dt.Rows.Count > 0)
{
return Convert.ToInt32(dt.Rows[0]["aa"]);
}
else
{
return 0;
}
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return 0;
}
}
public int isScan(string barCode, string stationID,int step)
{
try
{
int res = 0;
string sql = @"select BarCode from tb_ZPStepRecord where BarCode='" + barCode + @"'and StationID='" +
stationID + @"' and Step=" + step;
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
res = dt.Rows.Count;
}
return res;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return 0;
}
}
}
}