活动页面添加参赛作品瀑布流
[PumpkinHouse.git] / PumpkinHouseWeb / Admin / PictureManagement.aspx.cs
blob9522906d5e38d664899920e6af3cfcf31b42aa42
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5 using System.Web.UI;
6 using System.Web.UI.WebControls;
7 using PumpkinHouseDatabase;
8 using PumpkinHouse.Utils;
9 using System.Data;
11 namespace PumpkinHouse.Admin
13 public partial class PictureManagement : System.Web.UI.Page
16 protected void Page_Load(object sender, EventArgs e)
18 if (!IsPostBack)
20 DateTime start = DateTime.Parse("2012/1/1");
21 DateTime today = DateTime.Now;
23 CalendarStart.SelectedDate = start;
25 CalendarEnd.SelectedDate = today;
27 BindDataSource();
31 protected void BindDataSource()
33 // SqlDataSource1.SelectCommand =
34 // @"SELECT [Id], [Description], [Upload_Time], [Tags], u.[Username], [Image_Filename], [Image_File_Ext], [Nick_Name], [On_Top]
35 // FROM [DB_Picture] d, [DB_User] u
36 // where d.Username = u.Username ";
37 // SqlDataSource1.UpdateCommandType = SqlDataSourceCommandType.Text;
38 // SqlDataSource1.UpdateCommand = "Update DB_Picture set Description = @Description, Tags = @Tags, On_Top = @On_Top where Id = @Id";
40 // if (!string.IsNullOrEmpty(textNickName.Text))
41 // {
42 // string name = textNickName.Text.Trim();
43 // SqlDataSource1.SelectCommand += " and u.Nick_Name = '" + name + "'";
44 // }
45 // if (!string.IsNullOrEmpty(textPictureId.Text))
46 // {
47 // long id = 0;
48 // bool success = long.TryParse(textPictureId.Text, out id);
49 // if (success)
50 // {
51 // SqlDataSource1.SelectCommand += " and d.Id = " + id;
52 // }
53 // }
55 SqlDataSource1.FilterExpression = string.Format("(Nick_Name LIKE '{0}' AND Collect_Time >= '{1}' and Collect_Time <= '{2}') ",
56 textNickName.Text, CalendarStart.SelectedDate.ToString("yyyy-MM-dd"), CalendarEnd.SelectedDate.AddDays(1).ToString("yyyy-MM-dd"));
58 if (!string.IsNullOrWhiteSpace(textPictureId.Text))
60 SqlDataSource1.FilterExpression += "and Id = " + textPictureId.Text;
63 GridView1.DataBind();
68 protected void btnFilter_Click(object sender, EventArgs e)
70 if (string.IsNullOrEmpty(textNickName.Text))
72 textNickName.Text = "%";
74 BindDataSource();
77 protected void OnUpdating(object sender, GridViewUpdateEventArgs e)
79 using (DataUtils utils = new DataUtils())
81 long id = (long)e.Keys[0];
82 DB_Collection2 pic = utils.FindCollection2(id);
83 if (pic != null)
85 pic.Tags = e.NewValues["Tags"] as string;
86 pic.Description = e.NewValues["Description"] as string;
87 if (e.NewValues["On_Top"].Equals("1") && (e.OldValues["On_Top"] == null || e.OldValues["On_Top"].Equals("0")))
89 pic.On_Top = 1;
90 pic.On_Top_Update_Time = DateTime.Now;
92 if (e.NewValues["On_Top"].Equals("0") && e.OldValues["On_Top"].Equals("1"))
94 pic.On_Top = 0;
95 pic.On_Top_Update_Time = null;
97 utils.Commit();
100 BindDataSource();
103 protected void OnDelete(object sender, GridViewDeleteEventArgs e)
105 e.Cancel = true;
107 long id = (long)e.Keys[0];
108 using (DataUtils utils = new DataUtils())
110 DB_Collection2 col = utils.FindCollection2(id);
111 if (col != null)
113 Operation.DeleteCollection(utils, col);
117 BindDataSource();
120 protected void OnDateChanged(object sender, EventArgs e)
122 BindDataSource();
125 protected void PageIndexChanged(object sender, EventArgs e)
127 BindDataSource();
130 protected void Sorted(object sender, EventArgs e)
132 BindDataSource();
135 protected void OnEditing(object sender, GridViewEditEventArgs e)
137 BindDataSource();
140 protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
142 lblCount.Text = e.AffectedRows.ToString();
145 protected void deleteSelected_Click(object sender, EventArgs e)
147 using (DataUtils utils = new DataUtils())
149 for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
151 CheckBox CheckBox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox");
152 if (CheckBox.Checked)
154 long id = long.Parse(GridView1.Rows[i].Cells[2].Text);
155 DB_Collection2 col2 = utils.FindCollection2(id);
156 Operation.DeleteCollection(utils, col2);
160 BindDataSource();
164 protected void selectAll_CheckedChanged(object sender, EventArgs e)
166 for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
168 CheckBox CheckBox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox");
169 if (this.selectAll.Checked == true)
171 CheckBox.Checked = true;
173 else
175 CheckBox.Checked = false;