Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Samples / ActiveRecord / BlogSample / UI / BlogManagement.cs
blobb9e7dd15cf469c2ba27977f291ef8e7611d9a882
1 // Copyright 2004-2008 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 BlogManagement : Form
22 private GroupBox groupBox2;
23 private ColumnHeader columnHeader1;
24 private ColumnHeader columnHeader2;
25 private ColumnHeader columnHeader3;
26 private System.Windows.Forms.ListView blogsList;
27 private System.Windows.Forms.Button viewPostsButton;
28 private System.Windows.Forms.Button deleteButton;
29 private System.Windows.Forms.Button closeButton;
30 private System.Windows.Forms.Button addButton;
31 private System.ComponentModel.Container components = null;
33 public BlogManagement()
35 InitializeComponent();
38 protected override void OnLoad(EventArgs e)
40 base.OnLoad(e);
42 PopulateBlogList();
45 /// <summary>
46 /// Clean up any resources being used.
47 /// </summary>
48 protected override void Dispose(bool disposing)
50 if (disposing)
52 if (components != null)
54 components.Dispose();
57 base.Dispose(disposing);
60 #region Windows Form Designer generated code
62 /// <summary>
63 /// Required method for Designer support - do not modify
64 /// the contents of this method with the code editor.
65 /// </summary>
66 private void InitializeComponent()
68 this.groupBox2 = new System.Windows.Forms.GroupBox();
69 this.addButton = new System.Windows.Forms.Button();
70 this.viewPostsButton = new System.Windows.Forms.Button();
71 this.deleteButton = new System.Windows.Forms.Button();
72 this.blogsList = new System.Windows.Forms.ListView();
73 this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
74 this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
75 this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
76 this.closeButton = new System.Windows.Forms.Button();
77 this.groupBox2.SuspendLayout();
78 this.SuspendLayout();
79 //
80 // groupBox2
81 //
82 this.groupBox2.Controls.Add(this.addButton);
83 this.groupBox2.Controls.Add(this.viewPostsButton);
84 this.groupBox2.Controls.Add(this.deleteButton);
85 this.groupBox2.Controls.Add(this.blogsList);
86 this.groupBox2.Location = new System.Drawing.Point(8, 8);
87 this.groupBox2.Name = "groupBox2";
88 this.groupBox2.Size = new System.Drawing.Size(568, 216);
89 this.groupBox2.TabIndex = 1;
90 this.groupBox2.TabStop = false;
91 this.groupBox2.Text = "Blog management";
92 //
93 // addButton
94 //
95 this.addButton.Location = new System.Drawing.Point(440, 32);
96 this.addButton.Name = "addButton";
97 this.addButton.Size = new System.Drawing.Size(112, 23);
98 this.addButton.TabIndex = 3;
99 this.addButton.Text = "Add...";
100 this.addButton.Click += new System.EventHandler(this.addButton_Click);
102 // viewPostsButton
104 this.viewPostsButton.Location = new System.Drawing.Point(440, 96);
105 this.viewPostsButton.Name = "viewPostsButton";
106 this.viewPostsButton.Size = new System.Drawing.Size(112, 23);
107 this.viewPostsButton.TabIndex = 2;
108 this.viewPostsButton.Text = "View Posts";
109 this.viewPostsButton.Click += new System.EventHandler(this.viewPostsButton_Click);
111 // deleteButton
113 this.deleteButton.Location = new System.Drawing.Point(440, 64);
114 this.deleteButton.Name = "deleteButton";
115 this.deleteButton.Size = new System.Drawing.Size(112, 23);
116 this.deleteButton.TabIndex = 1;
117 this.deleteButton.Text = "Delete";
118 this.deleteButton.Click += new System.EventHandler(this.deleteButton_Click);
120 // blogsList
122 this.blogsList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
123 this.columnHeader1,
124 this.columnHeader2,
125 this.columnHeader3});
126 this.blogsList.FullRowSelect = true;
127 this.blogsList.GridLines = true;
128 this.blogsList.Location = new System.Drawing.Point(16, 32);
129 this.blogsList.MultiSelect = false;
130 this.blogsList.Name = "blogsList";
131 this.blogsList.Size = new System.Drawing.Size(408, 168);
132 this.blogsList.TabIndex = 0;
133 this.blogsList.View = System.Windows.Forms.View.Details;
134 this.blogsList.SelectedIndexChanged += new System.EventHandler(this.blogsList_SelectedIndexChanged);
136 // columnHeader1
138 this.columnHeader1.Text = "Id";
139 this.columnHeader1.Width = 50;
141 // columnHeader2
143 this.columnHeader2.Text = "Name";
144 this.columnHeader2.Width = 170;
146 // columnHeader3
148 this.columnHeader3.Text = "Author";
149 this.columnHeader3.Width = 170;
151 // closeButton
153 this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
154 this.closeButton.Location = new System.Drawing.Point(464, 240);
155 this.closeButton.Name = "closeButton";
156 this.closeButton.Size = new System.Drawing.Size(104, 23);
157 this.closeButton.TabIndex = 5;
158 this.closeButton.Text = "Close";
159 this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
161 // BlogManagement
163 this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
164 this.CancelButton = this.closeButton;
165 this.ClientSize = new System.Drawing.Size(584, 280);
166 this.Controls.Add(this.closeButton);
167 this.Controls.Add(this.groupBox2);
168 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
169 this.MaximizeBox = false;
170 this.MinimizeBox = false;
171 this.Name = "BlogManagement";
172 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
173 this.Text = "BlogManagement";
174 this.groupBox2.ResumeLayout(false);
175 this.ResumeLayout(false);
179 #endregion
181 private void PopulateBlogList()
183 blogsList.Items.Clear();
185 foreach(Blog blog in Blog.FindAll())
187 ListViewItem item = blogsList.Items.Add(blog.Id.ToString());
189 item.Tag = blog;
191 item.SubItems.Add(blog.Name);
192 item.SubItems.Add(blog.Author);
196 private void closeButton_Click(object sender, System.EventArgs e)
198 Hide();
201 private void addButton_Click(object sender, System.EventArgs e)
203 using(BlogForm newBlog = new BlogForm())
205 if (newBlog.ShowDialog(this) == DialogResult.OK)
207 PopulateBlogList();
212 private void deleteButton_Click(object sender, System.EventArgs e)
214 if (blogsList.SelectedItems.Count == 0)
216 MessageBox.Show(this, "Select a blog to delete first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
217 return;
220 foreach(ListViewItem item in blogsList.SelectedItems)
222 Blog blog = (Blog) item.Tag;
224 blog.Delete();
227 PopulateBlogList();
230 private void viewPostsButton_Click(object sender, System.EventArgs e)
232 if (blogsList.SelectedItems.Count == 0)
234 MessageBox.Show(this, "Select a blog first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
235 return;
238 Blog selected = (Blog) blogsList.SelectedItems[0].Tag;
240 using(PostManagement form = new PostManagement(selected))
242 form.ShowDialog(this);
246 private void blogsList_SelectedIndexChanged(object sender, System.EventArgs e)
248 if (blogsList.SelectedItems.Count == 1)
250 Blog blog = (Blog) blogsList.SelectedItems[0].Tag;
252 using(BlogForm newBlog = new BlogForm(blog))
254 if (newBlog.ShowDialog(this) == DialogResult.OK)
256 PopulateBlogList();