using System; using System.Linq; namespace iWareSql.DataAccess { public class SysDictDataHandler { /// /// 获取 数据字典中的值 /// /// /// public static string GetDictValue(string code) { try { using (iWareSql.MyDbContext.MyDbContext edm = new iWareSql.MyDbContext.MyDbContext()) { var data = edm.sys_dict_data.Where(x => x.Code == code).FirstOrDefault(); if (data == null) { throw new System.Exception($"没有找到代码为{code}的字典数据"); } return data.Value; } } catch (System.Exception) { return "NO FOUND";//数据库中未配置,就赋值一个不存在的工厂代码 } } public static bool UpdateDictValue(string code,string codeValue) { try { using (iWareSql.MyDbContext.MyDbContext edm = new iWareSql.MyDbContext.MyDbContext()) { var data = edm.sys_dict_data.Where(x => x.Code == code).FirstOrDefault(); if (data == null) { return false; } data.Value = codeValue; data.UpdatedTime = DateTime.Now; return edm.SaveChanges()>1; } } catch (System.Exception) { return false; } } } }