public static string BorrowBook(string userId, string bookId) { string jsonStr = ""; BorrowDao dao = new BorrowDao(); string tablename = "queryIsBorrow"; DataSet data = dao.QueryIsBorrow(bookId, tablename); ArrayList arr = new ArrayList(); for (int i = 0; i < data.Tables[tablename].Rows.Count; i++) { string isBorrow = data.Tables[tablename].Rows[i]["IsBorrow"].ToString(); arr.Add(isBorrow); } if (arr.Count == 0) { jsonStr = JsonSerialize.GetResultsJsonStr(1001, "你所借阅的书籍不存在", null); } else { if (Convert.ToInt32(arr[0]) == 0) { dao.InsertBorrowList(userId, bookId); dao.UpdateBooksStatus(bookId); jsonStr = JsonSerialize.GetResultsJsonStr(1000, "借阅成功", null); } else { jsonStr = JsonSerialize.GetResultsJsonStr(1002, "你所借阅的书籍已被借出", null); } } dao.conn.CloseConn(); return(jsonStr); }
public static string queryBookListService(string tablename, string isBorrow) { BookListDao dao = new BookListDao(); DataSet data = dao.queryBookList(tablename, isBorrow); dao.conn.CloseConn(); ArrayList arr = new ArrayList(); for (int i = 0; i < data.Tables[tablename].Rows.Count; i++) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("bookId", data.Tables[tablename].Rows[i]["BookId"].ToString()); dic.Add("bookName", data.Tables[tablename].Rows[i]["BookName"].ToString()); dic.Add("author", data.Tables[tablename].Rows[i]["Author"].ToString()); dic.Add("summary", data.Tables[tablename].Rows[i]["Summary"].ToString()); dic.Add("IsBorrow", data.Tables[tablename].Rows[i]["IsBorrow"].ToString()); string bookCover = StaticSettings.BookCoverUrl + data.Tables[tablename].Rows[i]["Cover"].ToString(); dic.Add("Cover", bookCover); arr.Add(dic); } string jsonStr = ""; if (arr.Count > 0) { jsonStr = JsonSerialize.GetResultsJsonStr(1000, "查询成功", arr); } else { jsonStr = JsonSerialize.GetResultsJsonStr(1001, "无图书", null); } return(jsonStr); }
public static string RegisterUserService(string account, string password, string username, int isAdmin, string tablename) { string jsonStr = ""; if (account == null || password == null) { jsonStr = JsonSerialize.GetResultsJsonStr(1003, "用户名或密码不能为空", null); return(jsonStr); } RegisterDao dao = new RegisterDao(); DataSet ds = dao.SelectIsRepeat(account, "IsRepeat"); if (Convert.ToInt32(ds.Tables["IsRepeat"].Rows[0]["Count"]) > 0) { jsonStr = JsonSerialize.GetResultsJsonStr(1001, "你输入的账号已存在", null); dao.conn.CloseConn(); return(jsonStr); } else { int num = dao.RegisterUser(account, password, username, isAdmin, tablename); dao.conn.CloseConn(); if (num == 1) { jsonStr = JsonSerialize.GetResultsJsonStr(1000, "注册成功", null); } else { jsonStr = JsonSerialize.GetResultsJsonStr(1002, "注册失败", null); } return(jsonStr); } }
public static Dictionary <string, object> CreateCustomMenu(Dictionary <string, object> body, string accessToken) { string url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accessToken; string data = JsonSerialize.ObjectToJsonStr(body); string jsonStr = NetRequest.HttpPost(url, data); Dictionary <string, object> dic = JsonSerialize.JsonStrToDictionary(jsonStr); return(dic); }
public static string GetAccessToken() { string url = "https://api.weixin.qq.com/cgi-bin/token"; string data = "grant_type=client_credential&appid=" + WXStatic.appid + "&secret=" + WXStatic.secret; string jsonStr = NetRequest.HttpGet(url, data); Dictionary <string, object> dic = JsonSerialize.JsonStrToDictionary(jsonStr); string result = dic["access_token"].ToString(); //WXStatic.access_token = result; return(result); }
public static string SaveUpLoadImage(HttpPostedFile uploadFile, string directoryPath, string userId, string tablename) { string fileName = uploadFile.FileName; int fileSize = uploadFile.ContentLength; string fileExt = Path.GetExtension(fileName).ToLower(); string message = ""; if (!(fileExt == ".png" || fileExt == ".gif" || fileExt == ".jpg" || fileExt == ".jpeg")) { message = JsonSerialize.GetResultsJsonStr(1001, "图片类型只能为gif,png,jpg,jpeg", null); return(message); } else { if (fileSize > (int)(500 * 1024)) { message = JsonSerialize.GetResultsJsonStr(1002, "图片大小不能超过500KB", null); return(message); } else { Random r = new Random(); string uploadFileName = DateTime.Now.ToString("yyyyMMddhhmmss") + r.Next(100000, 999999) + fileExt; try { if (!Directory.Exists(directoryPath)) //不存在这个文件夹就创建这个文件夹 { Directory.CreateDirectory(directoryPath); } uploadFile.SaveAs(directoryPath + uploadFileName); //message = uploadFileName; UpLoadImageDao dao = new UpLoadImageDao(); dao.UpdateIcon(uploadFileName, userId, tablename); dao.conn.CloseConn(); message = JsonSerialize.GetResultsJsonStr(1000, "上传成功", null); return(message); } catch (Exception ex) { message = JsonSerialize.GetResultsJsonStr(1003, ex.Message, null); return(message); } } } }
public static string ReturnBooks(string bookId, string userId) { ReturnBookDao dao = new ReturnBookDao(); int num1 = dao.DeleteBorrowInfoList(bookId, userId); int num2 = dao.UpdateBooksStatus(bookId); string jsonstr = ""; if (num1 == 1 && num2 == 1) { jsonstr = JsonSerialize.GetResultsJsonStr(1000, "还书成功", ""); } else { jsonstr = JsonSerialize.GetResultsJsonStr(1001, "还书失败", ""); } return(jsonstr); }
public static string QueryUserInfoService(int userId, string directoryPath) { UserInfoDao dao = new UserInfoDao(); string tablename = "UsersInfo"; DataSet data = dao.QueryUsersInfoDao(userId, tablename); dao.conn.CloseConn(); string jsonStr = ""; if (data.Tables[tablename].Rows.Count > 0) { ArrayList userInfoList = new ArrayList(); for (int i = 0; i < data.Tables[tablename].Rows.Count; i++) { string username = data.Tables[tablename].Rows[i]["Username"].ToString(); string account = data.Tables[tablename].Rows[i]["Account"].ToString(); string password = data.Tables[tablename].Rows[i]["Password"].ToString(); string createTime = data.Tables[tablename].Rows[i]["CreateTime"].ToString(); string id = data.Tables[tablename].Rows[i]["UserId"].ToString(); int isAdmin = Convert.ToInt32(data.Tables[tablename].Rows[i]["IsAdmin"]); string icon = StaticSettings.ServerUrl + data.Tables[tablename].Rows[i]["Icon"].ToString(); UserModel user = new UserModel(Convert.ToInt32(id), username, account, password, createTime, isAdmin, icon); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("username", user.username); dic.Add("userId", user.userId.ToString()); dic.Add("account", user.account); dic.Add("password", user.password); dic.Add("createTime", user.createTime); dic.Add("isAdmin", user.isAdmin.ToString()); dic.Add("icon", user.icon); userInfoList.Add(dic); } jsonStr = JsonSerialize.GetResultsJsonStr(1000, "", userInfoList); } else { jsonStr = JsonSerialize.GetResultsJsonStr(1001, "您查找的用户不存在", null); } return(jsonStr); }
public static string VerifyLoginService(string account, string password) { string jsonStr = ""; if (!String.IsNullOrEmpty(account) && !String.IsNullOrEmpty(password)) { LoginDao dao = new LoginDao(); string tablename = "VerifyLogin"; DataSet data = dao.VerifyLoginDao(account, password, tablename); int count = Convert.ToInt32(data.Tables[tablename].Rows[0]["Count"]); if (count == 0) { jsonStr = JsonSerialize.GetResultsJsonStr((int)ReturnCode.NoAccount, "账号不存在或密码错误", null); } else { int isLogin = Convert.ToInt32(data.Tables[tablename].Rows[0]["IsLogin"]); if (isLogin == 1) { jsonStr = JsonSerialize.GetResultsJsonStr((int)ReturnCode.IsLogined, "账号已登录", null); } else { jsonStr = JsonSerialize.GetResultsJsonStr((int)ReturnCode.LoginSuccess, "登录成功", null); int userId = Convert.ToInt32(data.Tables[tablename].Rows[0]["UserId"]); dao.ChangeLoginStauts(userId, "ChangeLoginStauts"); } } dao.conn.CloseConn(); } else { jsonStr = JsonSerialize.GetResultsJsonStr((int)ReturnCode.CannotNull, "账号和密码不能为空", null); } return(jsonStr); }