懒羊羊
2023-12-28 e46d3baaf3e8d7d85f4bafec3aad75e52b078408
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using YX.Entity;
using System.Data.Entity;
 
namespace YX.DAL
{
    public class SystemOrganization_Dal
    {
       // static string _connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString();
        ///// <summary>
        ///// 获取所有部门
        ///// </summary>
        ///// <returns></returns>
        //public DataTable GetOrganizations()
        //{
        //    DataTable dt = new DataTable();
        //    try
        //    {
        //        string sql = @"SELECT  Organization_ID,ParentId,Organization_Name FROM [Base_Organization]";
           
        //        dt = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, sql).Tables[0];
 
        //    }
        //    catch (Exception)
        //    {
                
        //        throw;
        //    }
        //    return dt;
        //}
        /// <summary>
        /// 部门详情
        /// </summary>
        /// <param name="Organization_ID">部门ID</param>
        /// <returns></returns>
        public List<Base_Organization> GetOrganizationDetail(string Organization_ID)
        {
            //DataTable dt = new DataTable();
            //try
            //{
            //    string sql = @"SELECT  
            //    Organization_ID
            //  ,[Organization_Code] as '部门编码'
            //  ,[Organization_Name] as '部门名称'
            //  ,[Organization_InnerPhone] as '内线电话'
            //  ,[Organization_OuterPhone] as '外线电话'
            //  ,[Organization_Manager] as '主负责人'
            //  ,Organization_AssistantManager as '副负责人'
            //  ,[Organization_Fax] as '传真号码'
            //  ,[Organization_Zipcode]as '行政号码'
            //  ,[Organization_Address] as '所在地址'
            //  ,ParentId as '节点位置'
            //,[SortCode]  as '排序'  
            //  ,Organization_Remark as '备注'  
            //   FROM [Base_Organization] where Organization_ID=@Organization_ID";
            // SqlParameter[] par = new SqlParameter[]
            // {
            //    new SqlParameter("@Organization_ID", Organization_ID)
            // };
            // dt = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, sql,par).Tables[0];
            //}            
            //catch (Exception ex)
            //{
 
            //    throw ex;
            //}
            //return dt;
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    return db.Base_Organization.Where(o=>o.Organization_ID==Organization_ID).ToList();
                }
            }
            catch (Exception)
            {
 
                throw;
            }
        }
        public DataTable GetInitParentId()
        {
            DataTable dt = new DataTable();
            try
            {
                using (Sam_DBEntities db=new Sam_DBEntities())
                {
                    var sql = @"SELECT Organization_ID,
                            Organization_Name + ' - ' + CASE ParentId WHEN '0' THEN '父节' ELSE  '子节' END AS Organization_Name
                            FROM Base_Organization WHERE DeleteMark = 1 ORDER BY SortCode ASC";
                    dt = SqlHelper.ExecuteDataset(db.Database.Connection.ConnectionString, CommandType.Text, sql).Tables[0];
                }         
 
            }
            catch (Exception ex)
            {
 
                throw ex;
            }
            return dt;
        }
 
        public List<Base_Organization> GetOrganizations()
        {
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    return db.Base_Organization.ToList();
                }
            }
            catch (Exception ex)
            {
 
                throw ex;
            }
        }
        /// <summary>
        /// 获取所在部门
        /// </summary>
        /// <param name="User_ID"></param>
        /// <returns></returns>
        public List<Base_StaffOrganize> GetStaffOrganize(string User_ID)
        {
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    return db.Base_StaffOrganize.Where(o => o.Base_UserInfo.User_ID == User_ID).ToList(); ;
                }
            }
            catch (Exception ex)
            {
 
                throw ex;
            }
        }
        /// <summary>
        /// 添加部门
        /// </summary>
        /// <param name="info"></param>
        public int AddSysOrganization(Base_Organization info)
        {
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    db.Base_Organization.Add(info);
                    return db.SaveChanges();
                }
            }
            catch (Exception)
            {
 
                throw;
            }
        }
        /// <summary>
        /// 修改部门
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public int UpdateSysOrganization(Base_Organization info)
        {
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    db.Base_Organization.Attach(info);
                    //把当前实体的状态改为Modified
                    db.Entry(info).State = EntityState.Modified;
                    return db.SaveChanges();
                }
            }
            catch (Exception)
            {
 
                throw;
            }
        }
        /// <summary>
        /// 删除部门
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public int DeleteSysOrganization(string key)
        {
            try
            {
                using (Sam_DBEntities db = new Sam_DBEntities())
                {
                    var obj = new Base_Organization { Organization_ID = key };
                    db.Base_Organization.Attach(obj);
                    db.Base_Organization.Remove(obj);
                    return db.SaveChanges();
                }
            }
            catch (Exception)
            {
 
                throw;
            }
        }
    }
}