提交 | 用户 | 时间
|
e46d3b
|
1 |
using System; |
懒 |
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Data; |
|
6 |
using System.Data.SqlClient; |
|
7 |
using YX.Entity; |
|
8 |
using System.Data.Entity; |
|
9 |
|
|
10 |
namespace YX.DAL |
|
11 |
{ |
|
12 |
public class SystemOrganization_Dal |
|
13 |
{ |
|
14 |
// static string _connectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString(); |
|
15 |
///// <summary> |
|
16 |
///// 获取所有部门 |
|
17 |
///// </summary> |
|
18 |
///// <returns></returns> |
|
19 |
//public DataTable GetOrganizations() |
|
20 |
//{ |
|
21 |
// DataTable dt = new DataTable(); |
|
22 |
// try |
|
23 |
// { |
|
24 |
// string sql = @"SELECT Organization_ID,ParentId,Organization_Name FROM [Base_Organization]"; |
|
25 |
|
|
26 |
// dt = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, sql).Tables[0]; |
|
27 |
|
|
28 |
// } |
|
29 |
// catch (Exception) |
|
30 |
// { |
|
31 |
|
|
32 |
// throw; |
|
33 |
// } |
|
34 |
// return dt; |
|
35 |
//} |
|
36 |
/// <summary> |
|
37 |
/// 部门详情 |
|
38 |
/// </summary> |
|
39 |
/// <param name="Organization_ID">部门ID</param> |
|
40 |
/// <returns></returns> |
|
41 |
public List<Base_Organization> GetOrganizationDetail(string Organization_ID) |
|
42 |
{ |
|
43 |
//DataTable dt = new DataTable(); |
|
44 |
//try |
|
45 |
//{ |
|
46 |
// string sql = @"SELECT |
|
47 |
// Organization_ID |
|
48 |
// ,[Organization_Code] as '部门编码' |
|
49 |
// ,[Organization_Name] as '部门名称' |
|
50 |
// ,[Organization_InnerPhone] as '内线电话' |
|
51 |
// ,[Organization_OuterPhone] as '外线电话' |
|
52 |
// ,[Organization_Manager] as '主负责人' |
|
53 |
// ,Organization_AssistantManager as '副负责人' |
|
54 |
// ,[Organization_Fax] as '传真号码' |
|
55 |
// ,[Organization_Zipcode]as '行政号码' |
|
56 |
// ,[Organization_Address] as '所在地址' |
|
57 |
// ,ParentId as '节点位置' |
|
58 |
//,[SortCode] as '排序' |
|
59 |
// ,Organization_Remark as '备注' |
|
60 |
// FROM [Base_Organization] where Organization_ID=@Organization_ID"; |
|
61 |
// SqlParameter[] par = new SqlParameter[] |
|
62 |
// { |
|
63 |
// new SqlParameter("@Organization_ID", Organization_ID) |
|
64 |
// }; |
|
65 |
// dt = SqlHelper.ExecuteDataset(_connectionString, CommandType.Text, sql,par).Tables[0]; |
|
66 |
//} |
|
67 |
//catch (Exception ex) |
|
68 |
//{ |
|
69 |
|
|
70 |
// throw ex; |
|
71 |
//} |
|
72 |
//return dt; |
|
73 |
try |
|
74 |
{ |
|
75 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
76 |
{ |
|
77 |
return db.Base_Organization.Where(o=>o.Organization_ID==Organization_ID).ToList(); |
|
78 |
} |
|
79 |
} |
|
80 |
catch (Exception) |
|
81 |
{ |
|
82 |
|
|
83 |
throw; |
|
84 |
} |
|
85 |
} |
|
86 |
public DataTable GetInitParentId() |
|
87 |
{ |
|
88 |
DataTable dt = new DataTable(); |
|
89 |
try |
|
90 |
{ |
|
91 |
using (Sam_DBEntities db=new Sam_DBEntities()) |
|
92 |
{ |
|
93 |
var sql = @"SELECT Organization_ID, |
|
94 |
Organization_Name + ' - ' + CASE ParentId WHEN '0' THEN '父节' ELSE '子节' END AS Organization_Name |
|
95 |
FROM Base_Organization WHERE DeleteMark = 1 ORDER BY SortCode ASC"; |
|
96 |
dt = SqlHelper.ExecuteDataset(db.Database.Connection.ConnectionString, CommandType.Text, sql).Tables[0]; |
|
97 |
} |
|
98 |
|
|
99 |
} |
|
100 |
catch (Exception ex) |
|
101 |
{ |
|
102 |
|
|
103 |
throw ex; |
|
104 |
} |
|
105 |
return dt; |
|
106 |
} |
|
107 |
|
|
108 |
public List<Base_Organization> GetOrganizations() |
|
109 |
{ |
|
110 |
try |
|
111 |
{ |
|
112 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
113 |
{ |
|
114 |
return db.Base_Organization.ToList(); |
|
115 |
} |
|
116 |
} |
|
117 |
catch (Exception ex) |
|
118 |
{ |
|
119 |
|
|
120 |
throw ex; |
|
121 |
} |
|
122 |
} |
|
123 |
/// <summary> |
|
124 |
/// 获取所在部门 |
|
125 |
/// </summary> |
|
126 |
/// <param name="User_ID"></param> |
|
127 |
/// <returns></returns> |
|
128 |
public List<Base_StaffOrganize> GetStaffOrganize(string User_ID) |
|
129 |
{ |
|
130 |
try |
|
131 |
{ |
|
132 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
133 |
{ |
|
134 |
return db.Base_StaffOrganize.Where(o => o.Base_UserInfo.User_ID == User_ID).ToList(); ; |
|
135 |
} |
|
136 |
} |
|
137 |
catch (Exception ex) |
|
138 |
{ |
|
139 |
|
|
140 |
throw ex; |
|
141 |
} |
|
142 |
} |
|
143 |
/// <summary> |
|
144 |
/// 添加部门 |
|
145 |
/// </summary> |
|
146 |
/// <param name="info"></param> |
|
147 |
public int AddSysOrganization(Base_Organization info) |
|
148 |
{ |
|
149 |
try |
|
150 |
{ |
|
151 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
152 |
{ |
|
153 |
db.Base_Organization.Add(info); |
|
154 |
return db.SaveChanges(); |
|
155 |
} |
|
156 |
} |
|
157 |
catch (Exception) |
|
158 |
{ |
|
159 |
|
|
160 |
throw; |
|
161 |
} |
|
162 |
} |
|
163 |
/// <summary> |
|
164 |
/// 修改部门 |
|
165 |
/// </summary> |
|
166 |
/// <param name="info"></param> |
|
167 |
/// <returns></returns> |
|
168 |
public int UpdateSysOrganization(Base_Organization info) |
|
169 |
{ |
|
170 |
try |
|
171 |
{ |
|
172 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
173 |
{ |
|
174 |
db.Base_Organization.Attach(info); |
|
175 |
//把当前实体的状态改为Modified |
|
176 |
db.Entry(info).State = EntityState.Modified; |
|
177 |
return db.SaveChanges(); |
|
178 |
} |
|
179 |
} |
|
180 |
catch (Exception) |
|
181 |
{ |
|
182 |
|
|
183 |
throw; |
|
184 |
} |
|
185 |
} |
|
186 |
/// <summary> |
|
187 |
/// 删除部门 |
|
188 |
/// </summary> |
|
189 |
/// <param name="key"></param> |
|
190 |
/// <returns></returns> |
|
191 |
public int DeleteSysOrganization(string key) |
|
192 |
{ |
|
193 |
try |
|
194 |
{ |
|
195 |
using (Sam_DBEntities db = new Sam_DBEntities()) |
|
196 |
{ |
|
197 |
var obj = new Base_Organization { Organization_ID = key }; |
|
198 |
db.Base_Organization.Attach(obj); |
|
199 |
db.Base_Organization.Remove(obj); |
|
200 |
return db.SaveChanges(); |
|
201 |
} |
|
202 |
} |
|
203 |
catch (Exception) |
|
204 |
{ |
|
205 |
|
|
206 |
throw; |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
} |