/// <summary> /// 获取 Model /// </summary> /// <param name="model"></param> /// <returns></returns> public AdminInfo GetModel(AdminInfo model) { string sql = "select * from T_AdminInfo where UserName=@Name and Password=@Pwd;"; SqlParameter[] pms = { new SqlParameter("@Name", SqlDbType.VarChar, 16) { Value = model.UserName }, new SqlParameter("@Pwd", SqlDbType.VarChar, 32) { Value = model.Password } }; DataTable tb = SqlHelper.ExecuteDataTable(sql, CommandType.Text, pms); List <AdminInfo> list = DataTableToList(tb); if (list.Count > 0) { return(list[0]); } else { return(null); } }
//存数据库 public int Insert(AdminInfo admininfo) { string sql = "insert into AdminInfo values(@AdminID,@AdminName,@Password)"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@AdminID", admininfo.AdminID), new SqlParameter("@AdminName", admininfo.AdminName), new SqlParameter("@Password", admininfo.Password) }; return(DBHelper.GetExcuteNonQuery(sql, sp)); }
public void Delete(AdminInfo t) { string sql = "DELETE FROM CBManageInfo WHERE ID =@ID"; using (IDbConnection connection = DbConnectionFactory.Create()) { connection.Execute(sql, t); } }
public int InsertAdminInfo(AdminInfo a) { try { string sql = string.Format("insert into Users values('{0}','{1}')", a.UserName, a.PassWord); return(db.ExecuteCommand(sql)); } catch (Exception ex) { throw ex; } }
public void Update(AdminInfo t) { string sql = @"UPDATE CBManageInfo SET ManageName=@ManageName ,UserName=@UserName ,ManagePwd=@ManagePwd ,ManageType=@ManageType;"; using (IDbConnection connection = DbConnectionFactory.Create()) { connection.Execute(sql, t); } }
/// <summary> /// DataTable转 List集合 /// </summary> /// <param name="tb"></param> /// <returns></returns> private List <AdminInfo> DataTableToList(DataTable tb) { List <AdminInfo> list = new List <AdminInfo>(); foreach (DataRow dr in tb.Rows) { AdminInfo admin = new AdminInfo(); admin.Id = int.Parse(dr[0].ToString()); admin.UserName = dr[1].ToString(); admin.Password = dr[2].ToString(); list.Add(admin); } return(list); }
public int Add(AdminInfo t) { string sql = @"INSERT INTO CBManageInfo(ManageName ,UserName ,ManagePwd ,ManageType) VALUES(@ManageName ,@UserName ,@ManagePwd ,@ManageType); SELECT LAST_INSERT_ROWID();"; using (IDbConnection connection = DbConnectionFactory.Create()) { return(connection.Query <int>(sql).FirstOrDefault()); } }
public List <AdminInfo> SelectAllAdminInfo() { List <AdminInfo> list = new List <AdminInfo>(); string sql = "select * from AdminInfo"; DataSet ds = db.ExcuteQuery(sql); foreach (DataRow dr in ds.Tables[0].Rows) { AdminInfo ai = new AdminInfo { Uid = Convert.ToInt32(dr["Uid"]), UserName = dr["UserName"].ToString(), }; list.Add(ai); } return(list); }
public DataTable GetAdminInfo(AdminInfo ai) { using (SqlConnection conn = new SqlConnection(strsql)) { conn.Open(); string sql = "select * from AdminInfo where Admin_Name=@AddminName and Admin_Password=@AddminPwd "; SqlDataAdapter sda = new SqlDataAdapter(sql, conn); sda.SelectCommand.Parameters.Clear(); sda.SelectCommand.Parameters.AddWithValue("@AddminName", ai.AdminName); sda.SelectCommand.Parameters.AddWithValue("@AddminPwd", ai.AdminPwd); DataSet ds = new DataSet(); sda.Fill(ds, "UserInfo"); return(ds.Tables["UserInfo"]); } }
public bool InsertAdminInfo(AdminInfo ai) { using (SqlConnection conn = new SqlConnection(strsql)) { conn.Open(); string sql = string.Format("insert into AdminInfo values ('{0}','{1}','{2}')", ai.AdminName, ai.AdminPwd, ai.AdminLevel); SqlCommand cmd = new SqlCommand(sql, conn); int i = cmd.ExecuteNonQuery(); if (i > 0) { return(true); } else { return(false); } } }
/// <summary> /// 更新一条数据 /// </summary> public int Upadate(AdminInfo model) { string sql = "update T_AdminInfo set UserName=@UserName,Password=@Password where Id=@Id"; SqlParameter[] pms = { new SqlParameter("@UserName", SqlDbType.VarChar, 16) { Value = model.UserName }, new SqlParameter("@Password", SqlDbType.VarChar, 32) { Value = model.Password }, new SqlParameter("@Id", SqlDbType.Int) { Value = model.Id } }; return(SqlHelper.ExecuteNonQuery(sql, CommandType.Text, pms)); }
/// <summary> /// 由账号密码查询管理员信息,验证登陆 /// </summary> /// <param name="a">AdminInfo实体</param> /// <returns>查询到的用户信息</returns> public AdminInfo SelectAdminInfo(AdminInfo admininfo) { bool isConn = db.chkConnection(); if (isConn) { string sqlGetAdmin = @"select * from Users where Username = '******' and PassWord = '******'"; DataSet ds = db.ExcuteQuery(sqlGetAdmin); if (ds.Tables[0].Rows.Count > 0) { DALUtil.Output(this, ds.Tables[0].Rows[0][0].ToString()); admininfo.Uid = int.Parse(ds.Tables[0].Rows[0][0].ToString()); return(admininfo); } else { return(null); } } else { return(null); } }
public int DeleteAdminInfo(AdminInfo admininfo) { return(0); }
public int UpdateAdminInfo(AdminInfo admininfo) { return(0); }
public int InsertAdminInfo(AdminInfo admininfo) { return(0); }
public AdminInfo SelectAdminInfo(AdminInfo admininfo) { AdminInfo admin = new AdminInfo(); return(admin); }