/// <summary> /// 得到一个对象实体 /// </summary> static SMS.Model.SysAccount DataRowToModel(DataRow row) { SMS.Model.SysAccount model = new SMS.Model.SysAccount(); if (row != null) { if (row["UserCode"] != null) { model.UserCode = row["UserCode"].ToString(); } if (row["UserName"] != null) { model.UserName = row["UserName"].ToString(); } if (row["UserPassword"] != null) { model.PassWord = row["UserPassword"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } if (row["UserStatus"] != null && row["UserStatus"].ToString() != "") { model.Status = (ushort)row["UserStatus"] == 1 ? true : false; } } model.Roles = GetAccountRoles(model.UserCode); return(model); }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(SMS.Model.SysAccount account) { StringBuilder strSql = new StringBuilder(); strSql.Append("update plat_Account set "); strSql.Append("UserName=@UserName,"); strSql.Append("UserPassword=@UserPassword,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("UserStatus=@UserStatus"); strSql.Append(" where UserCode=@UserCode "); MySqlParameter[] parameters = { new MySqlParameter("@UserName", MySqlDbType.VarChar, 32), new MySqlParameter("@UserPassword", MySqlDbType.VarChar, 64), new MySqlParameter("@AddTime", MySqlDbType.DateTime), new MySqlParameter("@UserStatus", MySqlDbType.Int16, 5), new MySqlParameter("@UserCode", MySqlDbType.VarChar, 16) }; parameters[0].Value = account.UserName; parameters[1].Value = account.PassWord; parameters[2].Value = account.AddTime; parameters[3].Value = account.Status == true ? 1 : 0; parameters[4].Value = account.UserCode; int rows = DBUtility.MySqlHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { if (DelAccountRole(account.UserCode)) { foreach (var v in account.Roles) { AddAccountRole(account.UserCode, v); } return(true); } } return(false); }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(SMS.Model.SysAccount account) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into plat_Account("); strSql.Append("UserCode,UserName,UserPassword,AddTime,UserStatus)"); strSql.Append(" values ("); strSql.Append("@UserCode,@UserName,@UserPassword,@AddTime,@UserStatus)"); MySqlParameter[] parameters = { new MySqlParameter("@UserCode", MySqlDbType.VarChar, 16), new MySqlParameter("@UserName", MySqlDbType.VarChar, 32), new MySqlParameter("@UserPassword", MySqlDbType.VarChar, 64), new MySqlParameter("@AddTime", MySqlDbType.DateTime), new MySqlParameter("@UserStatus", MySqlDbType.Int16, 5) }; parameters[0].Value = account.UserCode; parameters[1].Value = account.UserName; parameters[2].Value = account.PassWord; parameters[3].Value = account.AddTime; parameters[4].Value = account.Status == true ? 1 : 0; int rows = DBUtility.MySqlHelper.ExecuteNonQuery(strSql.ToString(), parameters); if (rows > 0) { foreach (var v in account.Roles) { AddAccountRole(account.UserCode, v); } return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public static SMS.Model.SysAccount GetAccount(string account) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from plat_Account "); strSql.Append(" where UserCode=@UserCode "); MySqlParameter[] parameters = { new MySqlParameter("@UserCode", MySqlDbType.VarChar, 16) }; parameters[0].Value = account; SMS.Model.SysAccount model = new SMS.Model.SysAccount(); DataSet ds = DBUtility.MySqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public static bool Update(SMS.Model.SysAccount account) { return(DAL.SysAccount.Update(account)); }
/// <summary> /// 增加一条数据 /// </summary> public static bool Add(SMS.Model.SysAccount account) { account.PassWord = DESEncrypt.Encrypt(account.PassWord); return(DAL.SysAccount.Add(account)); }
public static int Logon(string accountID, string pass) { StringBuilder strSql = new StringBuilder(); strSql.Append("select * from plat_Account "); strSql.Append(" where UserCode=@UserCode and UserPassword=@UserPassword"); MySqlParameter[] parameters = { new MySqlParameter("@UserCode", MySqlDbType.VarChar, 16), new MySqlParameter("@UserPassword", MySqlDbType.VarChar, 16) }; parameters[0].Value = accountID; parameters[1].Value = pass; SMS.Model.SysAccount account = new SMS.Model.SysAccount(); DataSet ds = DBUtility.MySqlHelper.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["UserStatus"].ToString() == "0") { //帐号禁用 return(2); } DataTable dt = DBUtility.MySqlHelper.Query("select r.* from plat_AccountRole as ar left join plat_Role as r on ar.RoleID = r.RoleID and ar.UserCode='" + accountID + "'").Tables[0]; account.UserCode = ds.Tables[0].Rows[0]["UserCode"].ToString(); account.UserName = ds.Tables[0].Rows[0]["UserName"].ToString(); List <string> roles = new List <string>(); if (dt.Rows.Count > 0) { foreach (DataRow row in dt.Rows) { SMS.Model.Role role = new SMS.Model.Role(); role.RoleID = row["RoleID"].ToString(); role.RoleName = row["RoleName"].ToString(); if (!string.IsNullOrEmpty(role.RoleID)) { roles.Add(role.RoleID); } } } account.Roles = roles; System.Web.HttpContext.Current.Session["Login"] = account; //strSql.Remove(0, strSql.Length); //strSql.Append("select groupid from mastergroup where masterid='" + model.MASTERID + "'"); //object obj = OracleHelper.ExecuteScalar(strSql.ToString()); //if (obj != null) //{ // System.Web.HttpContext.Current.Session["GroupId"] = obj; //} //else //{ // System.Web.HttpContext.Current.Session["GroupId"] = 1; //} //string ip = Helper.GetIpAddress(); //if (HttpRuntime.Cache[model.MASTERID] == null) //{ // HttpRuntime.Cache.Insert(model.MASTERID, ip, null, DateTime.Now.AddHours(3.0), TimeSpan.Zero); //} //else //{ // if (ip != HttpRuntime.Cache[model.MASTERID].ToString()) // { // HttpRuntime.Cache.Insert(model.MASTERID, ip, null, DateTime.Now.AddHours(3.0), TimeSpan.Zero); // } //} return(1); } else { //用户名或密码不正确 return(0); } }