Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Samples / ActiveRecord / BlogSample / UI / PostManagement.cs
blob00e69fc59cd7a2ac368e497116d41848464301ef
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace BlogSample.UI
17 using System;
18 using System.Windows.Forms;
20 public class PostManagement : Form
22 private readonly Blog parentBlog;
23 private Button closeButton;
24 private GroupBox groupBox2;
25 private Button addButton;
26 private Button deleteButton;
27 private ColumnHeader columnHeader1;
28 private ColumnHeader columnHeader2;
29 private ColumnHeader columnHeader3;
30 private ColumnHeader columnHeader4;
31 private ListView postsList;
32 private System.ComponentModel.Container components = null;
34 public PostManagement()
36 InitializeComponent();
39 public PostManagement(Blog parentBlog) : this()
41 this.parentBlog = parentBlog;
44 protected override void OnLoad(EventArgs e)
46 base.OnLoad(e);
48 PopulatePostList();
51 private void PopulatePostList()
53 parentBlog.Refresh();
55 postsList.Items.Clear();
57 foreach(Post post in parentBlog.Posts)
59 ListViewItem item = postsList.Items.Add(post.Id.ToString());
61 item.Tag = post;
63 item.SubItems.Add(post.Title);
64 item.SubItems.Add(post.Category);
65 item.SubItems.Add(post.Created.ToShortDateString());
69 /// <summary>
70 /// Clean up any resources being used.
71 /// </summary>
72 protected override void Dispose( bool disposing )
74 if( disposing )
76 if(components != null)
78 components.Dispose();
81 base.Dispose( disposing );
84 #region Windows Form Designer generated code
85 /// <summary>
86 /// Required method for Designer support - do not modify
87 /// the contents of this method with the code editor.
88 /// </summary>
89 private void InitializeComponent()
91 this.closeButton = new System.Windows.Forms.Button();
92 this.groupBox2 = new System.Windows.Forms.GroupBox();
93 this.addButton = new System.Windows.Forms.Button();
94 this.deleteButton = new System.Windows.Forms.Button();
95 this.postsList = new System.Windows.Forms.ListView();
96 this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
97 this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
98 this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
99 this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
100 this.groupBox2.SuspendLayout();
101 this.SuspendLayout();
103 // closeButton
105 this.closeButton.Location = new System.Drawing.Point(464, 240);
106 this.closeButton.Name = "closeButton";
107 this.closeButton.Size = new System.Drawing.Size(104, 23);
108 this.closeButton.TabIndex = 7;
109 this.closeButton.Text = "Close";
110 this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
112 // groupBox2
114 this.groupBox2.Controls.Add(this.addButton);
115 this.groupBox2.Controls.Add(this.deleteButton);
116 this.groupBox2.Controls.Add(this.postsList);
117 this.groupBox2.Location = new System.Drawing.Point(8, 8);
118 this.groupBox2.Name = "groupBox2";
119 this.groupBox2.Size = new System.Drawing.Size(568, 216);
120 this.groupBox2.TabIndex = 6;
121 this.groupBox2.TabStop = false;
122 this.groupBox2.Text = "Post management";
124 // addButton
126 this.addButton.Location = new System.Drawing.Point(440, 32);
127 this.addButton.Name = "addButton";
128 this.addButton.Size = new System.Drawing.Size(112, 23);
129 this.addButton.TabIndex = 3;
130 this.addButton.Text = "Add...";
131 this.addButton.Click += new System.EventHandler(this.addButton_Click);
133 // deleteButton
135 this.deleteButton.Location = new System.Drawing.Point(440, 64);
136 this.deleteButton.Name = "deleteButton";
137 this.deleteButton.Size = new System.Drawing.Size(112, 23);
138 this.deleteButton.TabIndex = 1;
139 this.deleteButton.Text = "Delete";
140 this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click);
142 // postsList
144 this.postsList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
145 this.columnHeader1,
146 this.columnHeader2,
147 this.columnHeader3,
148 this.columnHeader4});
149 this.postsList.FullRowSelect = true;
150 this.postsList.GridLines = true;
151 this.postsList.Location = new System.Drawing.Point(16, 32);
152 this.postsList.MultiSelect = false;
153 this.postsList.Name = "postsList";
154 this.postsList.Size = new System.Drawing.Size(408, 168);
155 this.postsList.TabIndex = 0;
156 this.postsList.View = System.Windows.Forms.View.Details;
157 this.postsList.SelectedIndexChanged += new System.EventHandler(this.postsList_SelectedIndexChanged);
159 // columnHeader1
161 this.columnHeader1.Text = "Id";
162 this.columnHeader1.Width = 50;
164 // columnHeader2
166 this.columnHeader2.Text = "Title";
167 this.columnHeader2.Width = 170;
169 // columnHeader3
171 this.columnHeader3.Text = "Category";
172 this.columnHeader3.Width = 90;
174 // columnHeader4
176 this.columnHeader4.Text = "Created";
177 this.columnHeader4.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
178 this.columnHeader4.Width = 85;
180 // PostManagement
182 this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
183 this.ClientSize = new System.Drawing.Size(586, 280);
184 this.Controls.Add(this.closeButton);
185 this.Controls.Add(this.groupBox2);
186 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
187 this.MaximizeBox = false;
188 this.MinimizeBox = false;
189 this.Name = "PostManagement";
190 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
191 this.Text = "PostManagement";
192 this.groupBox2.ResumeLayout(false);
193 this.ResumeLayout(false);
196 #endregion
198 private void deleteButton_Click(object sender, System.EventArgs e)
200 if (postsList.SelectedItems.Count == 0)
202 MessageBox.Show(this, "Select a post to delete first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
203 return;
206 foreach(ListViewItem item in postsList.SelectedItems)
208 Post post = (Post) item.Tag;
210 post.Delete();
213 PopulatePostList();
216 private void addButton_Click(object sender, System.EventArgs e)
218 using(PostForm form = new PostForm(parentBlog))
220 if (form.ShowDialog(this) == DialogResult.OK)
222 PopulatePostList();
227 private void postsList_SelectedIndexChanged(object sender, System.EventArgs e)
229 if (postsList.SelectedItems.Count == 1)
231 Post post = (Post) postsList.SelectedItems[0].Tag;
233 using(PostForm form = new PostForm(parentBlog, post))
235 if (form.ShowDialog(this) == DialogResult.OK)
237 PopulatePostList();
243 private void closeButton_Click(object sender, System.EventArgs e)
245 DialogResult = DialogResult.Cancel;
247 Hide();