您目前尚未登陆,请选择【登陆】或【注册
首页->行政办公->无忧劳保库存系统源码>>SqlHelper/Helper.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:无忧劳保库存系统源码
当前文件:文件类型 Labor/SqlHelper/Helper.cs打开代码结构图
普通视图
		            
1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.Data.SqlClient; 5using System.Configuration; 6using System.Data; 7namespace SqlHelper 8{ 9 //通用数据库类 10 11 public class Helper 12 { 13 //多个选择 14 15 static String XZ; 16 17 //定义返回数组 18 static string[] array; 19 //管理员 20 DataSet ds=null; 21 22 //定义连接对象 23 SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbuser"].ConnectionString); 24 //1.定义用户登录方法LoginSys(); 25 public String LoginSys(String Name, String Pass) 26 { 27 String sql = "select * from UserInfo where UserName='" + Name + "' and UserPass='" + Pass + "' "; 28 29 SqlCommand cmd = new SqlCommand(sql, conn); 30 31 try 32 { 33 conn.Open(); 34 35 SqlDataReader MyReader = cmd.ExecuteReader(); 36 37 if (MyReader.Read()) 38 { 39 return "true"; 40 } 41 else 42 { 43 return "false"; 44 } 45 } 46 catch (Exception ex) 47 { 48 return "Exption"; 49 } 50 finally 51 { 52 conn.Close(); 53 } 54 } 55 public bool LoginSys(String Name) 56 { 57 String sql = "select * from UserInfo where UserName='" + Name + "' "; 58 59 SqlCommand cmd = new SqlCommand(sql, conn); 60 61 try 62 { 63 conn.Open(); 64 65 SqlDataReader MyReader = cmd.ExecuteReader(); 66 67 if (MyReader.Read()) 68 { 69 return true; 70 } 71 else 72 { 73 return false; 74 } 75 } 76 catch (Exception ex) 77 { 78 return false; 79 } 80 finally 81 { 82 conn.Close(); 83 } 84 } 85 //定义增删改通用方法 86 87 public bool ExecSQL(String sQLstr) 88 { 89 conn.Open(); 90 91 SqlCommand cmd = new SqlCommand(sQLstr, conn); 92 93 try 94 { 95 cmd.ExecuteNonQuery(); 96 97 conn.Close(); 98 } 99 catch 100 { 101 conn.Close(); 102 103 return false; 104 } 105 finally 106 { 107 conn.Close(); 108 } 109 return true; 110 } 111 //定义填充数据库--管理员设置 112 public DataSet BindInfo() 113 { 114 String sql = "select * from UserInfo"; 115 116 SqlDataAdapter da = new SqlDataAdapter(sql, conn); 117 118 conn.Open(); 119 120 ds = new DataSet(); 121 122 da.Fill(ds); 123 124 conn.Close(); 125 126 return ds; 127 } 128 129 //定义根据用户ID查询名字和密码并返回 130 public String[] GetUserBasicInfo(String UserID) 131 { 132 String sql = "select * from UserInfo where UserID='" + UserID + "'"; 133 SqlCommand cmd = new SqlCommand(sql, conn); 134 try 135 { 136 conn.Open(); 137 138 SqlDataReader MyReader = cmd.ExecuteReader(); 139 140 if (MyReader.Read()) 141 { 142 array = new string[] { MyReader.GetString(1), MyReader.GetString(2) }; 143 } 144 } 145 catch (Exception ex) 146 { 147 throw (ex); 148 } 149 finally 150 { 151 conn.Close(); 152 } 153 return array; 154 } 155 //判断时候是管理员 156 public bool IsAdmin(String Name) 157 { 158 String sql = "select * from UserInfo where IsAdmin=" + 1 + " and UserName='" + Name + "'"; 159 160 SqlCommand cmd = new SqlCommand(sql, conn); 161 162 try 163 { 164 conn.Open(); 165 166 SqlDataReader MyReader = cmd.ExecuteReader(); 167 168 if (MyReader.Read()) 169 { 170 return true; 171 } 172 else 173 { 174 return false; 175 } 176 } 177 catch (Exception ex) 178 { 179 throw (ex); 180 } 181 finally 182 { 183 conn.Close(); 184 } 185 } 186 //判断是否存在此部门 187 public bool IsDepartment(String DepartmentName) 188 { 189 String sql = "select * from division where DepartmentName='" + DepartmentName + "'"; 190 191 SqlCommand cmd = new SqlCommand(sql, conn); 192 193 try 194 { 195 conn.Open(); 196 197 SqlDataReader MyReader = cmd.ExecuteReader(); 198 199 if (MyReader.Read()) 200 { 201 return true; 202 } 203 else 204 { 205 return false; 206 } 207 } 208 catch (Exception ex) 209 { 210 throw (ex); 211 } 212 finally 213 { 214 conn.Close(); 215 } 216 } 217 //填充职员 218 //定义填充数据库--管理员设置 219 public DataSet EmpBindInfo() 220 { 221 String sql = "select * from Emp"; 222 223 SqlDataAdapter da = new SqlDataAdapter(sql, conn); 224 225 conn.Open(); 226 227 ds = new DataSet(); 228 229 da.Fill(ds); 230 231 conn.Close(); 232 233 return ds; 234 } 235 //定义根据员工ID信息并返回 236 public String[] GetEmpBasicInfo(String EmpID) 237 { 238 String sql = "select * from Emp where EmpID='" + EmpID + "'"; 239 SqlCommand cmd = new SqlCommand(sql, conn); 240 try 241 { 242 conn.Open(); 243 244 SqlDataReader MyReader = cmd.ExecuteReader(); 245 246 if (MyReader.Read()) 247 { 248 array = new string[] { MyReader.GetString(1), MyReader.GetString(2), MyReader.GetString(3), MyReader.GetString(4), MyReader.GetString(5) }; 249 } 250 } 251 catch (Exception ex) 252 { 253 throw (ex); 254 } 255 finally 256 { 257 conn.Close(); 258 } 259 return array; 260 } 261 //填充部门 262 public DataSet BinddivisionInfo() 263 { 264 String sql = "select * from division"; 265 266 SqlDataAdapter da = new SqlDataAdapter(sql, conn); 267 268 conn.Open(); 269 270 ds = new DataSet(); 271 272 da.Fill(ds); 273 274 conn.Close(); 275 276 return ds; 277 } 278 //判断是否存在此部门 279 public bool IsDName(String DName) 280 { 281 String sql = "select * from division where DepartmentName='" + DName + "'"; 282 283 SqlCommand cmd = new SqlCommand(sql, conn); 284 285 try 286 { 287 conn.Open(); 288 289 SqlDataReader MyReader = cmd.ExecuteReader(); 290 291 if (MyReader.Read()) 292 { 293 return true; 294 } 295 else 296 { 297 return false; 298 } 299 } 300 catch (Exception ex) 301 { 302 throw (ex); 303 } 304 finally 305 { 306 conn.Close(); 307 } 308 } 309 //判断部门编号是否存在 310 public bool IsDID(String DID) 311 { 312 String sql = "select * from division where DepartmentID='" + DID + "'"; 313 314 SqlCommand cmd = new SqlCommand(sql, conn); 315 316 try 317 { 318 conn.Open(); 319 320 SqlDataReader MyReader = cmd.ExecuteReader(); 321 322