You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.5 KiB
C#

using SqlSugar;
using System;
using ZJ_BYD.Model;
using ZJ_BYD.Untils;
namespace ZJ_BYD.DB
{
public class BranchInfoHelper
{
public BranchInfoHelper() : base()
{
}
/// <summary>
/// 查询支线信息
/// </summary>
/// <returns></returns>
public static ISugarQueryable<T_BranchInfo> QueryBranchInfo()
{
try
{
return DBHelper.sqlSugarDb.Queryable<T_BranchInfo>();
}
catch (Exception ex)
{
var msg = ex == null ? "执行QueryBranchInfo方法时异常" : ex.Message;
LogHelper.WriteLog($"执行QueryBranchInfo方法时异常{msg}");
return null;
}
}
/// <summary>
/// 根据工位编码和机壳码查询支线信息
/// </summary>
/// <param name="stationCode"></param>
/// <param name="productSfcCode"></param>
/// <returns></returns>
public static T_BranchInfo GetBranchInfoByStationCodeAndProductSfcCode(string stationCode, string productSfcCode)
{
try
{
return DBHelper.sqlSugarDb.Queryable<T_BranchInfo>().First(m => m.StationCode == stationCode && SqlFunc.Replace(m.ProductSfcCode, "*", "") == SqlFunc.Substring(productSfcCode, 0, SqlFunc.Length(SqlFunc.Replace(m.ProductSfcCode, "*", ""))));
}
catch (Exception ex)
{
var msg = ex == null ? "执行GetBranchInfoByStationCodeAndProductSfcCode方法时异常" : ex.Message;
LogHelper.WriteLog($"执行GetBranchInfoByStationCodeAndProductSfcCode方法时异常{msg}");
return null;
}
}
/// <summary>
/// 根据工位编码和机壳码查询支线信息
/// </summary>
/// <param name="stationCode"></param>
/// <param name="productSfcCode"></param>
/// <returns></returns>
public static T_BranchInfo GetBranchInfoByStationCodeAndProductSfcCodeTrim(string stationCode, string productSfcCode)
{
try
{
return DBHelper.sqlSugarDb.Queryable<T_BranchInfo>().First(m => m.StationCode == stationCode && SqlFunc.Replace(m.ProductSfcCode, "*", "") == SqlFunc.Substring(productSfcCode, 0, SqlFunc.Length(SqlFunc.Replace(m.ProductSfcCode, "*", ""))));
}
catch (Exception ex)
{
var msg = ex == null ? "执行GetBranchInfoByStationCodeAndProductSfcCode方法时异常" : ex.Message;
LogHelper.WriteLog($"执行GetBranchInfoByStationCodeAndProductSfcCode方法时异常{msg}");
return null;
}
}
/// <summary>
/// 根据工位编码和机壳码查询支线信息
/// </summary>
/// <param name="stationCode"></param>
/// <param name="productSfcCode"></param>
/// <returns></returns>
public static ISugarQueryable<T_BranchInfo> QueryBranchInfoByStationCodeAndProductSfcCode(string stationCode, string productSfcCode)
{
try
{
return DBHelper.sqlSugarDb.Queryable<T_BranchInfo>().Where(m => m.StationCode == stationCode && m.ProductSfcCode == productSfcCode);
}
catch (Exception ex)
{
var msg = ex == null ? "执行QueryBranchInfoByStationCodeAndProductSfcCode方法时异常" : ex.Message;
LogHelper.WriteLog($"执行QueryBranchInfoByStationCodeAndProductSfcCode方法时异常{msg}");
return null;
}
}
/// <summary>
/// 新增支线信息
/// </summary>
/// <param name="t_BranchInfo"></param>
/// <returns></returns>
public static bool AddBranchInfo(T_BranchInfo t_BranchInfo)
{
var result = DBHelper.sqlSugarDb.UseTran(() =>
{
DBHelper.sqlSugarDb.Insertable(t_BranchInfo).ExecuteCommand();
MskCodeHelper.UpdateMaskCodeIsUseStator(t_BranchInfo.StationCode, t_BranchInfo.ProductSfcCode, true);
});
return result.IsSuccess;
}
/// <summary>
/// 修改支线信息
/// </summary>
/// <param name="t_BranchInfo"></param>
/// <returns></returns>
public static int UpdateBranchInfo(T_BranchInfo t_BranchInfo)
{
return DBHelper.sqlSugarDb.Updateable(t_BranchInfo).ExecuteCommand();
}
/// <summary>
/// 删除支线信息
/// </summary>
/// <param name="stationcode"></param>
/// <param name="productsfccode"></param>
/// <returns></returns>
public static bool delBranchInfo(string stationcode, string productsfccode)
{
try
{
var result = DBHelper.sqlSugarDb.UseTran(() =>
{
//DBHelper.sqlSugarDb.Deleteable<T_BranchInfo>().Where(m => m.StationCode == stationcode && m.ProductSfcCode == productsfccode).ExecuteCommand();
MskCodeHelper.UpdateMaskCodeIsUseStator(stationcode, productsfccode, false);
});
return result.IsSuccess;
}
catch (Exception ex)
{
var msg = ex == null ? "执行delBranchInfo方法时异常" : ex.Message;
LogHelper.WriteLog($"执行delBranchInfo方法时异常{msg}");
return false;
}
}
}
}