// Lookup one Episode and return it if is found public Episode Load(int episodeNumber, string episodeIdiom) { var sqlCommand = new SqlCommand("SELECT * FROM EPISODES WHERE EPISODENUMBER = @EPISODENUMBER"); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episodeNumber); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } //Setting a loaded episode var episode = new Episode(); episode.EpisodeNumber = Int16.Parse(dt.Tables[0].Rows[0]["EPISODENUMBER"].ToString()); episode.Idiom = dt.Tables[0].Rows[0]["idiom"].ToString(); // Loading all Episode pages var pageRep = new PageRepository(); episode.Pages = pageRep.LoadFromEpisode(episode.EpisodeNumber); // Sending the episode return(episode); }
// Save the map to the context public void Save(Episode episode) { // First, find if another episode was inserted before if (this.EpisodeHasBeenLoaded(episode.EpisodeNumber, episode.Idiom) == false) { // If is not, insert a new episode var sqlCommand = new SqlCommand("INSERT INTO EPISODES(EpisodeNumber, IDIOM, Prologue, Title, ImgHeaderPath) VALUES(@EPISODENUMBER, @IDIOM, @Prologue, @Title, @ImgHeaderPath)"); // Set parameters sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episode.EpisodeNumber); sqlCommand.Parameters.AddWithValue("IDIOM", episode.Idiom); sqlCommand.Parameters.AddWithValue("Prologue", episode.Prologue); sqlCommand.Parameters.AddWithValue("Title", episode.Title); sqlCommand.Parameters.AddWithValue("ImgHeaderPath", episode.ImgHeaderPath); SQLOperation.ExecuteSQLCommand(sqlCommand); } // Adding all pages var pageRep = new PageRepository(); foreach (Page page in episode.Pages) { page.episodeNumber = episode.EpisodeNumber; pageRep.Save(page); } }
protected void btnZoneSave_Click(object sender, EventArgs e) { try { SQLOperation sql = new SQLOperation(); string userID = Session["NowUserId"].ToString(); if (txtZoneTitle == null) { helper.alertHelper(this, "空间标题不可以为空!"); } else { string limit = dplstLimit.SelectedValue.ToString(); sql.update(" zoneInfo ", " title='" + txtZoneTitle.Text + "',WhoCanSee='" + limit + "' ", " userid= " + userID); btnZoneChange.Text = "空间设置修改"; txtZoneTitle.Visible = false; dplstLimit.Visible = false; btnZoneSave.Visible = false; helper.alertHelper(this, "空间修改成功!", "PersonalInfoPage.aspx"); } } catch (Exception exception) { helper.alertHelper(this, "空间修改失败!"); } }
protected void rptAllAlbum_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (Request.QueryString["id"] != null) { string visitedID = Request.QueryString["id"].ToString(); string visitorID = Session["NowUserId"].ToString(); Button btn = (Button)e.Item.FindControl("btnDelAlbum"); string combinedID = btn.CommandArgument.ToString(); SQLOperation sql = new SQLOperation(); DataTable dt = sql.select(" whocansee ", " a_album ", " id=" + combinedID); string limit = dt.Rows[0][0].ToString(); if (limit == "仅好友可见") { if (!helper.onlyFriendsJudge(visitorID, visitedID)) { e.Item.Visible = false; } } else if (limit == "部分好友不可见") { if (!helper.someFriendsCantSee(visitorID, visitedID, combinedID, "相册")) { e.Item.Visible = false; } } else if (limit == "仅自己可见") { e.Item.Visible = false; } } }
public void Post([FromBody] string value) { var data = (SensorData)JsonConvert.DeserializeObject(value); var time = DateTime.Now; if (data.From == "dht") { //if (Convert.ToUInt32(data.Temparature) > 30); var Parameters = new Dictionary <string, string> { { "@time", time.ToString() }, { "@temperature", data.Temparature }, { "@humadity", data.Humadity } }; var DataTable = SQLOperation.ExecuteCommand(Startup.ConnectionString, "InsertTemp", false, Parameters); //DataTable.Merge(SQLOperation.ExecuteCommand(Startup.ConnectionString, "getlastfive", Parameters)); } else { var Parameters = new Dictionary <string, string> { { "@time", time.ToString() }, { "@gasvalue", data.GasValue } }; var DataTable = SQLOperation.ExecuteCommand(Startup.ConnectionString, "InsertAirQual", false, Parameters); } }
} //创建相册按钮--点开之后使与创建有关的输入、按钮等内容可见 protected void btnAddNew_Click(object sender, EventArgs e) //立刻创建相册按钮 { if (divNewAlbum.Visible = true) { btnAddNew.Text = "立刻创建"; string newName = txtNewName.Text; string newDes = txtNewDescipt.Text; SQLOperation sql = new SQLOperation(); //id,userid,albumname,amount,des,null string id = Session["NowUserId"].ToString(); string limit = dplstLimit.SelectedValue.ToString(); if (sql.add(" a_album ", " " + id + ",'" + newName + "',0,'" + newDes + "','" + limit + "'")) { divNewAlbum.Visible = false; btnNewAlbum.Visible = true; Response.Write("<script> alert('添加相册成功!');location= 'AlbumPage.aspx'</script> "); } } else { btnAddNew.Text = "取消创建"; btnNewAlbum.Visible = false; divNewAlbum.Visible = true; } }
protected void rptApplications_ItemCommand(object source, RepeaterCommandEventArgs e) //所有加好友申请显示--按钮判断 { SQLOperation sql = new SQLOperation(); string userID = Session["NowUserId"].ToString(); if (e.CommandName == "btnPass") { string AppID = e.CommandArgument.ToString(); DataTable dt = sql.select(" fromID ", " friendApplication ", " id=" + AppID); string friendID = dt.Rows[0][0].ToString(); if (sql.add(" friends ", " " + userID + "," + friendID)) { sql.delete(" FriendApplication ", " id=" + AppID); //好友申请通过后删除申请 Response.Write("<script> alert('添加好友成功!');</script> "); } } else if (e.CommandName == "btnIgnore") { string AppID = e.CommandArgument.ToString(); if (sql.delete(" FriendApplication ", " id=" + AppID)) { Response.Write("<script> alert('您已删除该申请!');</script> "); } } }
protected void rptAllStatus_ItemDataBound(object sender, RepeaterItemEventArgs e)//评论区RPT的数据绑定---DONE { SQLOperation sql = new SQLOperation(); /*当该页面被访问时,不允许访客删除动态*/ if (Request.QueryString["id"] != null) { int count = rptAllStatus.Items.Count; for (int i = 0; i < count; i++) { Button btn = (Button)rptAllStatus.Items[i].FindControl("btnStatusDel"); btn.Visible = false; } } /*绑定评论的数据*/ if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //找到外层Repeater的数据项 DataRowView rowv = (DataRowView)e.Item.DataItem; //提取外层Repeater的数据项的ID int ID = Convert.ToInt32(rowv["id"]); //找到对应ID下的评论 //string select = "select * from a_comment where commentedid=" + ID.ToString(); //找到内嵌Repeater Repeater rept = (Repeater)e.Item.FindControl("rptInReply"); //数据绑定 rept.DataSource = sql.select(" a_comment.id,a_comment.commentContent, users.nickname ", " users,a_comment ", " a_comment.commentedId= " + ID.ToString() + " and a_comment.kind = 'status' and a_comment.userid = users.id"); rept.DataBind(); } }
// Lookup one Map and return it if is found public List <Page> LoadFromEpisode(int episodeNumber) { var sqlCommand = new SqlCommand("SELECT PAGEID, PATH from PAGES WHERE EPISODENUMBER = @EPISODENUMBER ORDER BY PAGEID ASC"); sqlCommand.Parameters.AddWithValue("EPISODENUMBER", episodeNumber); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } // Getting all pages var PageList = new List <Page>(dt.Tables[0].Rows.Count); var mapRep = new MapRepository(); for (int count = 0; count <= dt.Tables[0].Rows.Count - 1; count++) { var newPage = new Page(); newPage.episodeNumber = episodeNumber; newPage.pageID = Int16.Parse(dt.Tables[0].Rows[count]["PAGEID"].ToString()); newPage.Path = dt.Tables[0].Rows[count]["Path"].ToString(); // Getting the maps of each page newPage.Maps = mapRep.LoadMapsByPageID(newPage.pageID); PageList.Add(newPage); } return(PageList); }
protected void hylkAllFriends_Click(object sender, EventArgs e) //所有好友的显示 { RepeaterOperate rptHelper = new RepeaterOperate(); SQLOperation sql = new SQLOperation(); if (divAllFriends.Visible) { hylkAllFriends.Text = "查看好友"; divAllFriends.Visible = false; } else { string id; id = Session["NowUserId"].ToString(); DataTable dt = sql.select(" friends.friendId,users.nickname,users.loginstatus ", " friends,users ", " friends.userId= " + id + " and friends.friendId = users.id "); if (dt.Rows.Count == 0) { dt = sql.select(" friends.userId,users.nickname,users.loginstatus ", " friends,users ", " friends.friendId= " + id + " and friends.friendId = users.id "); dt.Columns["userId"].ColumnName = "friendId"; } rptHelper.dataBound(ref rptFriends, ref dt, 1, ref lblTotal, 5); lblNow.Text = "1"; hylkAllFriends.Text = "收起"; divAllFriends.Visible = true; } }
protected void btnMessageAdd_Click(object sender, EventArgs e) { if (txtMessageContent == null) { helper.alertHelper(this, "留言不可以为空!"); } else { string message = txtMessageContent.Text; SQLOperation sql = new SQLOperation(); string messagerID = Session["NowUserId"].ToString(); string userId = Request.QueryString["id"].ToString(); string time = DateTime.Now.ToString(); try { //userid,messagerid,messagecontent,time,whocansee sql.add(" a_message ", " " + userId + "," + messagerID + ",'" + txtMessageContent.Text + "','" + time + "','" + dplstLimit.SelectedValue.ToString() + "'"); helper.alertHelper(this, "留言成功!", "MessagePage.aspx?id=" + userId); } catch (Exception exception) { helper.alertHelper(this, "留言失败!"); } } }
// Lookup one Map and return it if is found public List <Map> LoadMapsByPageID(int pageId) { var sqlCommand = new SqlCommand("SELECT mapid, scale, X, y from MAPS WHERE PAGEID = @PAGEID order by mapid asc"); sqlCommand.Parameters.AddWithValue("PAGEID", pageId); var dt = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); if (dt.Tables[0].Rows.Count <= 0) { return(null); } var mapList = new List <Map>(dt.Tables[0].Rows.Count); for (int count = 0; count <= dt.Tables[0].Rows.Count - 1; count++) { var newMap = new Map(); newMap.PageId = pageId; newMap.mapID = Int16.Parse(dt.Tables[0].Rows[count]["mapid"].ToString()); newMap.Scale = Double.Parse(dt.Tables[0].Rows[count]["scale"].ToString()); newMap.X = Int16.Parse(dt.Tables[0].Rows[count]["x"].ToString()); newMap.Y = Int16.Parse(dt.Tables[0].Rows[count]["y"].ToString()); mapList.Add(newMap); } return(mapList); }
protected void btnLike_Click(object sender, EventArgs e) { SQLOperation sql = new SQLOperation(); string diaryId = Request.QueryString["articleId"].ToString(); string id = Session["NowUserId"].ToString(); if (btnLike.Text.StartsWith("取消赞")) { DataTable dt = sql.select(" likeamount ", " a_diary ", " id=" + diaryId); int midAmount = int.Parse(dt.Rows[0][0].ToString()) - 1; string amount = midAmount.ToString(); if (sql.delete(" a_like ", " likedId=" + diaryId + " and userId=" + id + " and likekind='日志'") && sql.update(" a_diary ", " likeamount =" + amount + " ", " id=" + diaryId)) { btnLike.Text = "赞(" + amount + ")"; } } else { string time = DateTime.Now.ToString(); DataTable dt = sql.select(" likeamount ", " a_diary ", " id=" + diaryId); int midAmount = int.Parse(dt.Rows[0][0].ToString()) + 1; string amount = midAmount.ToString(); //userid,likedid,likekind,time if (sql.add(" a_like ", " " + id + "," + diaryId + ",'日志','" + time + "'") && sql.update(" a_diary ", " likeamount =" + amount + " ", " id=" + diaryId)) { btnLike.Text = "取消赞(" + amount + ")"; } } }
protected void Page_Load(object sender, EventArgs e) { if (Session["NowUserId"] != null) { /*权限设置的选项初始化*/ dplstLimit.Items.Add("所有人可见"); dplstLimit.Items.Add("仅好友可见"); dplstLimit.Items.Add("仅自己可见"); dplstLimit.Items.Add("部分好友不可见"); if (Request.QueryString["id"] != null)//说明现在是在被访问状态 { divStatusAdd.Visible = false; } else { string id; id = Session["NowUserId"].ToString(); SQLOperation sql = new SQLOperation(); RepeaterOperate rptOperate = new RepeaterOperate(); DataTable dtt = sql.select(" users.NickName,A_Status.* ", " users,a_status ", " users.id = " + id); //rptOperate.dataBound(ref rptAllStatus, ref dtt); // rptOperate.dataBound(ref rptStatusShow, ref dtt, 1, ref lblTotal, 5); // lblNow.Text = "1"; } } else { helper.alertHelper(this, "请先登录!", "MainPage.aspx"); } }
/* protected void btnAddFriend_Click(object sender, EventArgs e) * { * divAddSearch.Visible = true; * } */ protected void btnSearch_Click(object sender, EventArgs e) //查找按钮 { SQLOperation sql = new SQLOperation(); RepeaterOperate rptHelper = new RepeaterOperate(); string text = txtSearch.Text; if (txtSearch == null) { txtSearch.Text = "请填写内容!"; } else { DataTable dt = sql.select(" nickname,loginstatus,id,number ", " users ", " number= '" + text + "' or nickname='" + text + "'"); //nickname or number to find if (dt == null) { txtSearch.Text = "没有相匹配的用户"; } else { lblNowResult.Text = "1"; rptHelper.dataBound(ref rptSearchResult, ref dt, 1, ref lblTotalResult, 5); } } divSearchResult.Visible = true; divResearchPages.Visible = true; rptSearchResult.Visible = true; }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["NowUserId"] != null) { if (Request.QueryString["id"] == null) { string id; id = Session["NowUserId"].ToString(); SQLOperation sql = new SQLOperation(); RepeaterOperate rptOperate = new RepeaterOperate(); DataTable dtt = sql.select(" distinct users.NickName,A_Status.* ", " Friends,(users join A_Status on users.id = A_Status.UserId) ", " (users.id = " + id + ") or (Friends.UserId =" + id + " and Users.id = Friends.FriendId)"); //rptOperate.dataBound(ref rptAllStatus, ref dtt); rptOperate.dataBound(ref rptAllStatus, ref dtt, 1, ref lblTotal, 5); lblNow.Text = "1"; } else { helperSpecial.alertHelper(this, "您无权访问他人的个人中心!"); } } else { Response.Write("<script> alert('请先登录!');location= 'MainPage.aspx'</script> "); } } }
protected void Page_Load(object sender, EventArgs e) { SQLOperation sql = new SQLOperation(); if (Session["NowUserId"] != null) { string id; /*权限设置的选项初始化*/ dplstLimit.Items.Add("所有人可见"); dplstLimit.Items.Add("仅双方可见"); if (Request.QueryString["id"] != null) //正在被访问 { id = Request.QueryString["id"].ToString(); } else { divAddMessage.Visible = false;//自己不可以给自己留言 id = Session["NowUserId"].ToString(); } DataTable dt = sql.select(" a_message.*,users.nickname ", " a_message,users ", " a_message.userid= " + id + " and users.id=a_message.messagerId"); /*然后是repeater的数据绑定*/ } else { helper.alertHelper(this, "请先登录", "MainPage.aspx"); } }
protected void rptInReply_ItemDataBound(object sender, RepeaterItemEventArgs e) //回复评论的数据绑定 { SQLOperation sql = new SQLOperation(); /*绑定评论的数据*/ if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { //找到外层Repeater的数据项 DataRowView rowv = (DataRowView)e.Item.DataItem; //提取外层Repeater的数据项的ID int ID = Convert.ToInt32(rowv["id"]); //找到对应ID下的Book //string select = "select * from a_comment where commentedid=" + ID.ToString(); //找到内嵌Repeater Repeater rept = (Repeater)e.Item.FindControl("rptInInReply"); //数据绑定 DataTable dt = new DataTable(); dt = sql.select(" a1.*,user1.NickName as name1,user2.NickName as name2 ", " (users as user1 join a_comment as a1 on user1.id = a1.userId ),(users as user2 join A_Comment as a2 on user2.id = a2.userId ) ", " a1.BelongFatherCommentId = " + ID.ToString() + " and user1.id = a1.UserId and a2.id = a1.CommentedId and user2.id = a2.UserId "); rept.DataSource = dt; rept.DataBind(); } }
protected void btnSave_Click(object sender, EventArgs e) { if (calBirthday.SelectedDate != null) { txtBirthday.Text = calBirthday.SelectedDate.ToShortDateString(); } string nickname = txtNickName.Text; string name = txtName.Text; string birthday = txtBirthday.Text; string email = txtEmail.Text; string sex = txtSex.Text; string age = txtAge.Text; if (txtNickName == null || txtSex == null || txtEmail == null) { Response.Write("<script> alert('请填写完整!');</script> "); } else { SQLOperation sql = new SQLOperation(); string id = Session["NowUserId"].ToString(); bool updateResult = sql.update(" users ", " nickname=N'" + nickname + "',name=N'" + name + "',birthday='" + birthday + "',email='" + email + "',sex ='" + sex + "',age=" + age + " ", " id=" + id); if (updateResult) { Response.Write("<script> alert('修改信息成功!');location= 'PersonalInfoPage.aspx'</script> "); } else { Response.Write("<script> alert('修改信息失败!');location= 'PersonalInfoPage.aspx'</script> "); } } }
protected void rptAllAlbum_ItemCommand(object source, RepeaterCommandEventArgs e) { SQLOperation sql = new SQLOperation(); RepeaterOperate rptHelper = new RepeaterOperate(); DataTable dt = new DataTable(); if (e.CommandName == "btnDelAlbum") { string albumId = e.CommandArgument.ToString(); if (sql.delete(" a_album ", " id =" + albumId)) { Response.Write("<script> alert('删除相册成功!');location= 'AlbumPage.aspx'</script> "); } else { Response.Write("<script> alert('删除相册失败!');</script> "); } } else if (e.CommandName == "imgBtnAlbum") { rptAllAlbum.Visible = false; divShowPhotos.Visible = true; divPagesForAll.Visible = false; divPagesForPhoto.Visible = true; /*绑定数据是显示当前相册下的所有照片*/ dt = sql.select(" * ", " a_photo ", " albumID=" + Request.QueryString["albumId"].ToString()); rptHelper.dataBound(ref rptPhotos, ref dt, 1, ref lblTotalPhoto, 30); lblNowPhoto.Text = "1"; } } //所有相册的显示--按钮判断
public User SignIn(User user, string ConnectionString) { var paramDict = new Dictionary <string, string>() { { "Email", user.Email }, { "Password", user.Password } }; var DataOperation = SQLOperation.ExecuteCommand(ConnectionString, "GetUser", paramDict); try { var DataRow = DataOperation.Rows[0]; return(new User { FirstName = DataRow["FirstName"].ToString(), LastName = DataRow["LastName"].ToString(), Email = DataRow["Email"].ToString(), Username = DataRow["Username"].ToString(), Role = DataRow["Role"].ToString(), }); } catch (Exception) { return(new User()); } }
static void LoadHTML() { #region 物件 DateTime theDate = new DateTime(2014, 7, 28); int count = 1; // string dir = System.Environment.CurrentDirectory; // string url = "http://www.nfd.com.tw/lottery/39-year/39-f2017.htm"; // string url = "http://www.nfd.com.tw/lottery/39-year/39-f2016.htm"; // string url = "http://www.nfd.com.tw/lottery/39-year/39-f2015.htm"; // string url = "http://www.nfd.com.tw/lottery/39-year/39-f2014.htm"; string url = "http://www.nfd.com.tw/lottery/39-year/39-f2013.htm"; int year = 2013; HttpClient client; HttpContent content; HttpResponseMessage message; HtmlDocument document = new HtmlDocument(); Models.Number numberData; SQLOperation operation = new SQLOperation(); #endregion using (client = new HttpClient()){ using (message = client.GetAsync(url).Result){ content = message.Content; if (content != null) { document.LoadHtml(content.ReadAsStringAsync().Result); var table = document.DocumentNode.SelectSingleNode("//table"); var trList = table.SelectNodes("//tr");//.Skip(0); foreach (var item in trList) { if (count <= 1) { count++; continue; } numberData = new Models.Number(); numberData.NumberDate = DateTime.Parse( String.Concat(year, "/", RemoveTag(item.SelectSingleNode("td[2]").InnerText))); numberData.num1 = int.Parse(RemoveTag(item.SelectSingleNode("td[4]").InnerText)); numberData.num2 = int.Parse(RemoveTag(item.SelectSingleNode("td[5]").InnerText)); numberData.num3 = int.Parse(RemoveTag(item.SelectSingleNode("td[6]").InnerText)); numberData.num4 = int.Parse(RemoveTag(item.SelectSingleNode("td[7]").InnerText)); numberData.num5 = int.Parse(RemoveTag(item.SelectSingleNode("td[8]").InnerText)); numberData.Periods = PaddingZero( (year - 1911).ToString(), RemoveTag(item.SelectSingleNode("td[3]").InnerText)); Console.WriteLine(numberData.NumberDate.ToShortDateString() + " " + numberData.num1 + " " + numberData.num2 + " " + numberData.num3 + " " + numberData.num4 + " " + numberData.num5 + " " + numberData.Periods); Console.WriteLine(operation.InsertHistory(numberData)); } } } } }
public List <SimpleTranslation> LoadTextRepository() { SqlCommand sqlCommand = null; var translationList = new List <SimpleTranslation>(); try { // Searching all repository sqlCommand = new SqlCommand("SELECT * FROM TEXT_TRANSLATIONS ORDER BY DOM_ELEMENT_ID"); DataSet dataSet = SQLOperation.ExecuteSQLCommandWithResult(sqlCommand); SimpleTranslation simpleTranslation = new SimpleTranslation(); int contRows = 0; do { // Running all content, and build the repository. if (simpleTranslation.DOMElementID != dataSet.Tables[0].Rows[contRows]["DOM_ELEMENT_ID"].ToString()) { if (simpleTranslation.DOMElementID != null) { //Save the last translation repository translationList.Add(simpleTranslation); } simpleTranslation = new SimpleTranslation(); simpleTranslation.DOMElementID = dataSet.Tables[0].Rows[contRows]["DOM_ELEMENT_ID"].ToString(); } // Now, set the translation if (dataSet.Tables[0].Rows[contRows]["IDIOM"].ToString() == "PT") { simpleTranslation.PortugueseContent = dataSet.Tables[0].Rows[contRows]["TRANSLATION"].ToString(); } else { simpleTranslation.EnglishContent = dataSet.Tables[0].Rows[contRows]["TRANSLATION"].ToString(); } contRows++; } while (contRows < dataSet.Tables[0].Rows.Count); //Save the last translation repository translationList.Add(simpleTranslation); // With the translation repository complete, generate the JSON format return(translationList); } catch (Exception e) // Em qualquer caso de erro, retornar nulo. { return(null); } finally { // In all errors, return null sqlCommand.Dispose(); } }
public string GetStockDataByDate(string date) { var Parameters = new Dictionary <string, string> { { "@date", date } }; var DataTable = SQLOperation.ExecuteCommand(Startup.ConnectionString, "getstockbydate", Parameters); return(JsonConvert.SerializeObject(DataTable)); }
public string GetStockDataByName(string stock) { var Parameters = new Dictionary <string, string> { { "@symbol", stock.ToUpper() } }; var DataTable = SQLOperation.ExecuteCommand(Startup.ConnectionString, "getstockbysymbol", Parameters); return(JsonConvert.SerializeObject(DataTable)); }
protected void rptPhotos_ItemCommand(object source, RepeaterCommandEventArgs e) //显示当前相册下所有照片 --- 按钮判断 { SQLOperation sql = new SQLOperation(); string id = Session["NowUserId"].ToString(); DataTable dt = new DataTable(); string rootPath = "E:/enid1/Documents/003IT/程序/QQZoneWebSite"; if (e.CommandName == "btnDelPhoto") //删除图片 { string picID = e.CommandArgument.ToString(); //得到这张图片在数据库中的ID dt = sql.select(" picture ", " a_photo ", " id=" + picID); string path = rootPath + dt.Rows[0][0].ToString().Substring(1); dt = sql.select(" amount ", " a_album ", " id =" + Request.QueryString["albumId"].ToString()); string amount = (int.Parse(dt.Rows[0][0].ToString()) - 1).ToString(); if (File.Exists(path)) { File.Delete(path); if (sql.delete(" a_photo ", " id=" + picID) && sql.update(" a_album ", " amount =" + amount, " id= " + Request.QueryString["albumId"].ToString())) { Response.Write("<script> alert('删除照片成功!');location= 'AlbumPage.aspx'</script> "); } } } if (e.CommandName == "btnLikePhoto") //点赞 { string time = DateTime.Now.ToString(); string picID = e.CommandArgument.ToString(); //得到这张图片在数据库中的ID Button btn = (Button)e.Item.FindControl("btnLikePhoto"); if (Request.QueryString["id"] != null) { id = Request.QueryString["id"].ToString(); } if (btn.Text.StartsWith("赞")) { dt = sql.select(" likeamount ", " a_photo ", " id=" + picID); int midAmount = int.Parse(dt.Rows[0][0].ToString()) + 1; string amount = midAmount.ToString(); //userid,likedid,likekind,time if (sql.add(" a_like ", " " + id + "," + picID + ",'图片','" + time + "'") && sql.update(" a_photo ", " likeamount =" + amount + " ", " id=" + picID)) { btn.Text = "取消赞(" + amount + ")"; } } else { dt = sql.select(" likeamount ", " a_photo ", " id=" + picID); int midAmount = int.Parse(dt.Rows[0][0].ToString()) - 1; string amount = midAmount.ToString(); if (sql.delete(" a_like ", " likedId=" + picID + " and userId=" + id + " and likekind='图片'") && sql.update(" a_photo ", " likeamount =" + amount + " ", " id=" + picID)) { btn.Text = "赞(" + amount + ")"; } } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Session["NowUserId"] != null) { string id; SQLOperation sql = new SQLOperation(); DataTable dt = new DataTable(); divNewAlbum.Visible = false; /*权限设置的选项初始化*/ dplstLimit.Items.Add("所有人可见"); dplstLimit.Items.Add("仅好友可见"); dplstLimit.Items.Add("仅自己可见"); dplstLimit.Items.Add("部分好友不可见"); if (Request.QueryString["id"] != null) //visiting { id = Request.QueryString["id"].ToString(); rptAllAlbum.FindControl("btnDelAlbum").Visible = false; //访问者不可以删除相册 rptPhotos.FindControl("btnDelPhoto").Visible = false; //访问者不可以删除照片 btnNewAlbum.Visible = false; //访问者不可以添加相册 divAddPhoto.Visible = false; //访问者不可以上传照片 /*绑定数据使显示所有相册*/ dt = sql.select(" id,AlbumName ", " a_album ", " userId = " + id); rptAllAlbum.DataSource = dt; rptAllAlbum.DataBind(); } else //not visiting { id = Session["NowUserId"].ToString(); /*给相册分类的下拉框绑定数据并且赋给默认值*/ dt = sql.select(" * ", " a_album ", " userId = " + id); dplstAlbums.DataSource = dt; dplstAlbums.DataBind(); if (Request.QueryString["albumId"] != null) { dplstAlbums.SelectedValue = Request.QueryString["albumId"].ToString(); } /*绑定数据使显示所有相册*/ dt = sql.select(" id,AlbumName ", " a_album ", " userId = " + id); RepeaterOperate rptHelper = new RepeaterOperate(); rptHelper.dataBound(ref rptAllAlbum, ref dt, 1, ref lblTotal, 5); lblNow.Text = "1"; } } else { Response.Write("<script> alert('请先登录!');location= 'MainPage.aspx'</script> "); } } }
protected void rptAllDiaries_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "btnDel") //unfinished,打算在分类跳转那里加一个?传值,通过判断是否传递类的ID判断是在哪里进行删除操作 { SQLOperation sql = new SQLOperation(); string articleId = e.CommandArgument.ToString(); //日志ID DataTable dt = sql.select(" classes.name ", " a_diary,classes ", " a_diary.classid = classes.id "); string className = dt.Rows[0][0].ToString(); } }
protected void btnLogout_Click(object sender, EventArgs e) //注销按钮 { SQLOperation sql = new SQLOperation(); string id = Session["NowUserId"].ToString(); sql.update(" users ", " loginStatus =N'下线'", " id=" + id); Session["NowUserId"] = null; Response.Redirect("~/MainPage.aspx"); }
public string ForceMatch(string SGref, string CLRef) { var parameters = new Dictionary <string, string> { { "@SGRef", SGref }, { "@CLRef", CLRef } }; var DataTable = SQLOperation.ExecuteCommand(Startup.ConnectionString, "forceMatch", parameters); return(JsonConvert.SerializeObject(DataTable)); }