注塑喷涂
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.
 
 
 
 
 

610 lines
20 KiB

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using MESClassLibrary.BLL.Log;
using MESClassLibrary.Model;
namespace MESClassLibrary.DAL.Mistake247
{
public class RecordDAL
{
public static string TableName = "tb_Record_247";
public static string TableName1 = "tb_Record_243";
/// <summary>
/// 查找半成品是否已经装配
/// </summary>
/// <param name="PartNo"></param>
/// <returns></returns>
public DataTable SearchByPartNo1(string PartNo)
{
try
{
string sql = @"SELECT * from " + TableName + " where PartNo1=@PartNo";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = PartNo;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchCountByBox(string boxNo)
{
try
{
string sql = @"SELECT count(*) as sum from " + TableName + " where BoxNo=@BoxNo and Flag <>2";
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 bool AddInfo(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO " + TableName + " (ID,PartNo1,PartNo2,OrderNo,Type,DeviceNo";
sql += ") VALUES (";
sql += "@ID,";
sql += "@PartNo1,";
sql += "@PartNo2,";
sql += "@OrderNo,";
sql += "@Type,";
sql += "@DeviceNo)";
#region 添加参数
param = new SqlParameter[6];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@PartNo1", SqlDbType.VarChar);
param[1].Value = md.PartNo1;
param[2] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[2].Value = md.PartNo2;
param[3] = new SqlParameter("@OrderNo", SqlDbType.VarChar);
param[3].Value = md.OrderNo;
param[4] = new SqlParameter("@Type", SqlDbType.Int);
param[4].Value = md.Type;
param[5] = new SqlParameter("@DeviceNo", SqlDbType.VarChar);
param[5].Value = md.DeviceNo;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool UpdateCreateTime1(string partNo)
{
try
{
string sql = @"update " + TableName + " set CreateTime1=(select getdate()) where PartNo2='" + partNo + @"'";
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, null);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return false;
}
}
public bool updateBoxInfo(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = @"update " + TableName + " set BoxNo=@BoxNo,CreateTime2=(select getdate()),Flag=@Flag where PartNo2=@PartNo2";
#region 添加参数
param = new SqlParameter[3];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = md.BoxNo;
param[1] = new SqlParameter("@Flag", SqlDbType.Int);
param[1].Value = md.Flag;
param[2] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[2].Value = md.PartNo2;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchState(int type1,int type2,int type3)
{
try
{
//string sql = @"SELECT * from " + TableName + " where Type in (@type1,@type2,@type3) and Flag =0 order by CreateTime1";
//string sql = @"SELECT * from " + TableName + " where Type in (@type1,@type2,@type3) and Flag =0 order by CreateTime1";
//string sql = @"SELECT * from " + TableName + " where Type in (@type1,@type2,@type3) and Flag =0 order by CreateTime1";
string sql = @"
SELECT * from tb_record_247 where Type in (@type1,@type2,@type3) and Flag =0 AND CreateTime1 >= CONVERT(VARCHAR(10),GETDATE(),120) AND CreateTime1 < (CONVERT(VARCHAR(10),GETDATE(),120)+' 23:59:59') order by CreateTime1
";
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@type1", SqlDbType.Int);
param[0].Value = type1;
param[1] = new SqlParameter("@type2", SqlDbType.Int);
param[1].Value = type2;
param[2] = new SqlParameter("@type3", SqlDbType.Int);
param[2].Value = type3;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public bool DelInfo(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = @"update " + TableName + " set Flag=@Flag where PartNo2=@PartNo2";
#region 添加参数
param = new SqlParameter[2];
param[0] = new SqlParameter("@Flag", SqlDbType.Int);
param[0].Value = md.Flag;
param[1] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[1].Value = md.PartNo2;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchBoxByPart(string part)
{
try
{
string sql = @"SELECT top 1 * from " + TableName + " where SUBSTRING(PartNo2,1,11)=@PartNo2 order by CreateTime2 desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[0].Value = part;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchByPartNo2(string partno)
{
try
{
string sql = @"SELECT * from " + TableName + " where PartNo2=@PartNo";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = partno;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchIsVisualByPartNo2(string partno)
{
try
{
string sql = @"SELECT ToVisual from " + TableName + " where PartNo2 like '" + partno + @"%' and ToVisual=1";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable GetCount(string part,string batch)
{
try
{
string sql = @"SELECT count(*) as sum from " + TableName + " where SUBSTRING(PartNo2,1,11)=@PartNo2 and SUBSTRING(PartNo2,13,6)=@batch ";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[0].Value = part;
param[1] = new SqlParameter("@batch", SqlDbType.VarChar);
param[1].Value = batch;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable GetRecord(string boxNo)
{
try
{
string sql = @"
SELECT PartNo2,CreateTime1 FROM tb_record_247 WHERE boxno = '" + boxNo + @"' ORDER BY createtime1
";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
/// <summary>
///根据改订单的生产数量
/// </summary>
/// <param name="orderno"></param>
/// <returns></returns>
public DataTable GetOrderNum(string orderno)
{
try
{
string sql = @"SELECT count(*) as sum from tb_record_247 where OrderNo=@OrderNo";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@OrderNo", SqlDbType.VarChar);
param[0].Value = orderno;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public string GetDeviceNo()
{
try
{
string res = "";
string sql =
@"select top 1 DeviceNo from tb_Record_247 where ToVisual=0 and isnull(CreateTime2,'')='' order by CreateTime1 ";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, null).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
res = dt.Rows[0]["DeviceNo"].ToString();
}
return res;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(),MethodBase.GetCurrentMethod());
return "";
}
}
#region 243
public bool AddInfo1(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = "INSERT INTO " + TableName1 + " (ID,PartNo1,PartNo2,OrderNo,Type";
sql += ") VALUES (";
sql += "@ID,";
sql += "@PartNo1,";
sql += "@PartNo2,";
sql += "@OrderNo,";
sql += "@Type)";
#region 添加参数
param = new SqlParameter[5];
param[0] = new SqlParameter("@ID", SqlDbType.VarChar);
param[0].Value = md.ID;
param[1] = new SqlParameter("@PartNo1", SqlDbType.VarChar);
param[1].Value = md.PartNo1;
param[2] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[2].Value = md.PartNo2;
param[3] = new SqlParameter("@OrderNo", SqlDbType.VarChar);
param[3].Value = md.OrderNo;
param[4] = new SqlParameter("@Type", SqlDbType.Int);
param[4].Value = md.Type;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable GetCount1(string part, string batch)
{
try
{
string sql = @"SELECT count(*) as sum from " + TableName1 + " where SUBSTRING(PartNo2,1,11)=@PartNo2 and SUBSTRING(PartNo2,13,6)=@batch ";
SqlParameter[] param = new SqlParameter[2];
param[0] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[0].Value = part;
param[1] = new SqlParameter("@batch", SqlDbType.VarChar);
param[1].Value = batch;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchByPartNo4(string partno)
{
try
{
string sql = @"SELECT * from " + TableName1 + " where PartNo2=@PartNo";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo", SqlDbType.VarChar);
param[0].Value = partno;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchBoxByPart1(string part)
{
try
{
string sql = @"SELECT top 1 * from " + TableName1 + " where SUBSTRING(PartNo2,1,11)=@PartNo2 order by CreateTime2 desc";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[0].Value = part;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable SearchCountByBox1(string boxNo)
{
try
{
string sql = @"SELECT count(*) as sum from " + TableName1 + " where BoxNo=@BoxNo and Flag <>2";
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 bool updateBoxInfo1(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = @"update " + TableName1 + " set BoxNo=@BoxNo,CreateTime2=(select getdate()),Flag=@Flag where PartNo2=@PartNo2";
#region 添加参数
param = new SqlParameter[3];
param[0] = new SqlParameter("@BoxNo", SqlDbType.VarChar);
param[0].Value = md.BoxNo;
param[1] = new SqlParameter("@Flag", SqlDbType.Int);
param[1].Value = md.Flag;
param[2] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[2].Value = md.PartNo2;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public bool DelInfo1(RecordModel md)
{
try
{
string sql = "";
SqlParameter[] param = null;
sql = @"update " + TableName1 + " set Flag=@Flag where PartNo2=@PartNo2";
#region 添加参数
param = new SqlParameter[2];
param[0] = new SqlParameter("@Flag", SqlDbType.Int);
param[0].Value = md.Flag;
param[1] = new SqlParameter("@PartNo2", SqlDbType.VarChar);
param[1].Value = md.PartNo2;
#endregion
SqlHelper.ExecuteNonQuery(SqlHelper.GetConnSting(), CommandType.Text, sql, param);
return true;
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return false;
}
}
public DataTable SearchState1(int type1, int type2, int type3)
{
try
{
string sql = @"
SELECT * from tb_record_243 where Type in (@type1,@type2,@type3) and Flag =0 AND CreateTime1 >= CONVERT(VARCHAR(10),GETDATE(),120) AND CreateTime1 < (CONVERT(VARCHAR(10),GETDATE(),120)+' 23:59:59') order by CreateTime1
";
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@type1", SqlDbType.Int);
param[0].Value = type1;
param[1] = new SqlParameter("@type2", SqlDbType.Int);
param[1].Value = type2;
param[2] = new SqlParameter("@type3", SqlDbType.Int);
param[2].Value = type3;
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql, param).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
public DataTable GetRecord1(string boxNo)
{
try
{
string sql = @"
SELECT PartNo2,CreateTime1 FROM tb_record_243 WHERE boxno = '" + boxNo + @"' ORDER BY createtime1
";
return SqlHelper.ExecuteDataset(SqlHelper.GetConnSting(), CommandType.Text, sql).Tables[0];
}
catch (Exception ex)
{
LogErrBLL.AddInfo(ex.ToString(), MethodBase.GetCurrentMethod());
return null;
}
}
#endregion
}
}