Changed to use Authenticate asp.net event instead of Authorize
[castle.git] / Samples / InversionOfControl / ExtendingSample / Components / MainForm.cs
blob92e1702f65fb40dbb21e929d9a5e6bbf15acd3f6
2 namespace ExtendingSample.Components
4 using System;
5 using System.Drawing;
6 using System.Collections;
7 using System.ComponentModel;
8 using System.Windows.Forms;
10 using ExtendingSample.Dao;
12 /// <summary>
13 /// Summary description for MainForm.
14 /// </summary>
15 public class MainForm : Form
17 /// <summary>
18 /// Required designer variable.
19 /// </summary>
20 private System.ComponentModel.Container components = null;
22 private INewsletterService _newsletterService;
23 private System.Windows.Forms.Panel panel1;
24 private System.Windows.Forms.TabControl tabControl1;
25 private System.Windows.Forms.TabPage tabPage1;
26 private System.Windows.Forms.TabPage tabPage2;
27 private System.Windows.Forms.Label label1;
28 private System.Windows.Forms.ListView listView1;
29 private System.Windows.Forms.ColumnHeader columnHeader1;
30 private System.Windows.Forms.ColumnHeader columnHeader2;
31 private System.Windows.Forms.ComboBox templateName;
32 private System.Windows.Forms.Label label2;
33 private System.Windows.Forms.Button button1;
34 private System.Windows.Forms.Button button2;
35 private FriendsDao _friendsDao;
37 public MainForm(INewsletterService newsletterService, FriendsDao friendsDao)
39 InitializeComponent();
41 _newsletterService = newsletterService;
42 _friendsDao = friendsDao;
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 protected override void OnClosed(EventArgs e)
62 base.OnClosed(e);
64 Application.Exit();
67 #region Windows Form Designer generated code
68 /// <summary>
69 /// Required method for Designer support - do not modify
70 /// the contents of this method with the code editor.
71 /// </summary>
72 private void InitializeComponent()
74 this.panel1 = new System.Windows.Forms.Panel();
75 this.tabControl1 = new System.Windows.Forms.TabControl();
76 this.tabPage1 = new System.Windows.Forms.TabPage();
77 this.listView1 = new System.Windows.Forms.ListView();
78 this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
79 this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
80 this.label1 = new System.Windows.Forms.Label();
81 this.tabPage2 = new System.Windows.Forms.TabPage();
82 this.templateName = new System.Windows.Forms.ComboBox();
83 this.label2 = new System.Windows.Forms.Label();
84 this.button1 = new System.Windows.Forms.Button();
85 this.button2 = new System.Windows.Forms.Button();
86 this.tabControl1.SuspendLayout();
87 this.tabPage1.SuspendLayout();
88 this.tabPage2.SuspendLayout();
89 this.SuspendLayout();
90 //
91 // panel1
92 //
93 this.panel1.Location = new System.Drawing.Point(16, 236);
94 this.panel1.Name = "panel1";
95 this.panel1.Size = new System.Drawing.Size(528, 2);
96 this.panel1.TabIndex = 2;
97 //
98 // tabControl1
99 //
100 this.tabControl1.Controls.Add(this.tabPage1);
101 this.tabControl1.Controls.Add(this.tabPage2);
102 this.tabControl1.Location = new System.Drawing.Point(12, 8);
103 this.tabControl1.Name = "tabControl1";
104 this.tabControl1.SelectedIndex = 0;
105 this.tabControl1.Size = new System.Drawing.Size(544, 220);
106 this.tabControl1.TabIndex = 5;
108 // tabPage1
110 this.tabPage1.Controls.Add(this.listView1);
111 this.tabPage1.Controls.Add(this.label1);
112 this.tabPage1.Location = new System.Drawing.Point(4, 23);
113 this.tabPage1.Name = "tabPage1";
114 this.tabPage1.Size = new System.Drawing.Size(536, 193);
115 this.tabPage1.TabIndex = 0;
116 this.tabPage1.Text = "Targets";
118 // listView1
120 this.listView1.CheckBoxes = true;
121 this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
122 this.columnHeader1,
123 this.columnHeader2});
124 this.listView1.FullRowSelect = true;
125 this.listView1.GridLines = true;
126 this.listView1.Location = new System.Drawing.Point(8, 24);
127 this.listView1.Name = "listView1";
128 this.listView1.Size = new System.Drawing.Size(520, 152);
129 this.listView1.TabIndex = 3;
130 this.listView1.View = System.Windows.Forms.View.Details;
132 // columnHeader1
134 this.columnHeader1.Text = "Name";
135 this.columnHeader1.Width = 190;
137 // columnHeader2
139 this.columnHeader2.Text = "E-Mail";
140 this.columnHeader2.Width = 240;
142 // label1
144 this.label1.Location = new System.Drawing.Point(8, 8);
145 this.label1.Name = "label1";
146 this.label1.Size = new System.Drawing.Size(184, 16);
147 this.label1.TabIndex = 2;
148 this.label1.Text = "List of friends:";
150 // tabPage2
152 this.tabPage2.Controls.Add(this.templateName);
153 this.tabPage2.Controls.Add(this.label2);
154 this.tabPage2.Location = new System.Drawing.Point(4, 22);
155 this.tabPage2.Name = "tabPage2";
156 this.tabPage2.Size = new System.Drawing.Size(536, 194);
157 this.tabPage2.TabIndex = 1;
158 this.tabPage2.Text = "Template";
160 // templateName
162 this.templateName.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
163 this.templateName.Location = new System.Drawing.Point(166, 85);
164 this.templateName.Name = "templateName";
165 this.templateName.Size = new System.Drawing.Size(204, 22);
166 this.templateName.TabIndex = 6;
168 // label2
170 this.label2.Location = new System.Drawing.Point(166, 65);
171 this.label2.Name = "label2";
172 this.label2.Size = new System.Drawing.Size(200, 23);
173 this.label2.TabIndex = 5;
174 this.label2.Text = "Message template:";
176 // button1
178 this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
179 this.button1.Location = new System.Drawing.Point(384, 248);
180 this.button1.Name = "button1";
181 this.button1.TabIndex = 6;
182 this.button1.Text = "Close";
184 // button2
186 this.button2.Location = new System.Drawing.Point(468, 248);
187 this.button2.Name = "button2";
188 this.button2.Size = new System.Drawing.Size(84, 23);
189 this.button2.TabIndex = 7;
190 this.button2.Text = "Dispatch";
191 this.button2.Click += new System.EventHandler(this.button2_Click);
193 // MainForm
195 this.AutoScaleBaseSize = new System.Drawing.Size(7, 15);
196 this.CancelButton = this.button1;
197 this.ClientSize = new System.Drawing.Size(568, 283);
198 this.Controls.Add(this.button2);
199 this.Controls.Add(this.button1);
200 this.Controls.Add(this.tabControl1);
201 this.Controls.Add(this.panel1);
202 this.Font = new System.Drawing.Font("Verdana", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
203 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
204 this.MaximizeBox = false;
205 this.Name = "MainForm";
206 this.Text = "MainForm";
207 this.Load += new System.EventHandler(this.OnLoad);
208 this.tabControl1.ResumeLayout(false);
209 this.tabPage1.ResumeLayout(false);
210 this.tabPage2.ResumeLayout(false);
211 this.ResumeLayout(false);
214 #endregion
216 private void OnCancel(object sender, System.EventArgs e)
218 this.Close();
221 private void OnLoad(object sender, System.EventArgs e)
223 Friend[] friends = _friendsDao.Find();
225 foreach(Friend friend in friends)
227 listView1.Items.Add( friend.Name ).SubItems.Add(friend.Email);
230 templateName.Items.Add( "Independency day" );
231 templateName.Items.Add( "Happy b-day" );
234 private void button2_Click(object sender, System.EventArgs e)
236 ArrayList friends = new ArrayList();
238 foreach(ListViewItem item in listView1.Items)
240 if (!item.Checked) continue;
241 friends.Add(item.Text);
244 _newsletterService.Dispatch(
245 "me@myhost.com",
246 (String[]) friends.ToArray( typeof(String) ),
247 templateName.SelectedText );
249 MessageBox.Show("Message(s) sent!", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);