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