schangxiang@126.com
2025-09-23 ea04aef49691444ed8ac1e7e7b94feabcbb5326f
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using iWareCommon.Common.Service;
using iWareCommon.Utils;
using iWareDataCore.BASE.Entity;
using iWareDataCore.Check.Dao;
using iWareDataCore.Check.Entity;
using iWareDataCore.ORM;
using iWareDataCore.Properties;
using System;
using System.Collections.Generic;
using System.Linq;
 
namespace iWareDataCore.Check.Service
{
    public class  PlanViewService: CommonService<PlanViewEntity, CheckPlanView, DbModelCore>
    {
 
        private static object Lock = new object();
 
        private PlanViewService() : base(PlanViewDao.GetInstance()) { }
 
        private static PlanViewService Instance = null;
 
        /// <summary>
        /// 获取单例的方法
        /// </summary>
        /// <returns>角色服务的单例实体</returns>
        public static PlanViewService GetInstance()
        {
 
            if (Instance == null)
            {
                lock (Lock)
                {
                    if (Instance == null)
                    {
                        Instance = new PlanViewService();
                    }
                }
            }
            return Instance;
        }
 
        /// <summary>
        /// 盘点计划明细
        /// </summary>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public List<PlanViewEntity> GetPlaceMaterialByPlanNo(string planno, out string msg)
        {
            using(var DbModel = new DbModelCore()){
                try
                {
                    msg = "";
                    List<PlanViewEntity> plans = new List<PlanViewEntity>();
                    var planView = DbModel.CheckPlanViews.Where(x => x.planno == planno).ToList();
                    planView.ForEach(x => plans.Add(new PlanViewEntity(x)));
 
                    return plans;
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    return null;
                }
            }
            
        }
 
        /// <summary>
        /// 根据盘点单号
        /// </summary>
        public List<PlanViewEntity> GetPlan(string plannl)
        {
            using (DbModelCore context = new DbModelCore())
            {
                try
                {
                    string sql = "select distinct planno,begintime,endtime,updatetime,quantity,planstatus from CheckPlanView";
                    List<PlanViewEntity> data = context.Database.SqlQuery<PlanViewEntity>(sql).ToList();
                    return data;
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLine("InOutService", "GetInMaterial", ex.ToString());
                    return null;
                }
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public int UpdateByPlanNo(string planno)
        {
            using (var DbModel = new DbModelCore())
            {
                try
                {
                    string sql = "update CheckPlan set status = 2 where planno = ";
                    sql += planno;
                    int count = DbModel.Database.ExecuteSqlCommand(sql);
                    return count;
                }
                catch (Exception ex)
                {
                    LogTextHelper.WriteLog(Resources.LogDir, this.ToString(), "UpdateByPlanNo", ex.Message);
                    return -1;
                }
            }
 
        }
 
    }
}