333
schangxiang@126.com
2024-11-26 f23e0223221ec2b96543761bc0ab743d9e0a6294
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Linq;
 
 
namespace iWareSql.DataAccess
{
    public class SysDictDataHandler
    {
        /// <summary>
        /// 获取 数据字典中的值
        /// </summary>
        /// <param name="edm"></param>
        /// <returns></returns>
        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;
            }
        }
 
    }
}