Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Samples / ActiveRecord / BlogSample / UI / LoginForm.cs
blobdf19dca2f3237589b36370bad6bee3c9304e6ac1
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.Windows.Forms;
19 public class LoginForm : Form
21 private GroupBox groupBox1;
22 private Button logInButton;
23 private Button closeButton;
24 private Label label1;
25 private TextBox loginText;
26 private Label label2;
27 private TextBox passwordText;
28 private System.ComponentModel.Container components = null;
30 public LoginForm()
32 InitializeComponent();
35 /// <summary>
36 /// Clean up any resources being used.
37 /// </summary>
38 protected override void Dispose( bool disposing )
40 if( disposing )
42 if(components != null)
44 components.Dispose();
47 base.Dispose( disposing );
50 #region Windows Form Designer generated code
51 /// <summary>
52 /// Required method for Designer support - do not modify
53 /// the contents of this method with the code editor.
54 /// </summary>
55 private void InitializeComponent()
57 this.groupBox1 = new System.Windows.Forms.GroupBox();
58 this.passwordText = new System.Windows.Forms.TextBox();
59 this.label2 = new System.Windows.Forms.Label();
60 this.loginText = new System.Windows.Forms.TextBox();
61 this.label1 = new System.Windows.Forms.Label();
62 this.logInButton = new System.Windows.Forms.Button();
63 this.closeButton = new System.Windows.Forms.Button();
64 this.groupBox1.SuspendLayout();
65 this.SuspendLayout();
66 //
67 // groupBox1
68 //
69 this.groupBox1.Controls.Add(this.passwordText);
70 this.groupBox1.Controls.Add(this.label2);
71 this.groupBox1.Controls.Add(this.loginText);
72 this.groupBox1.Controls.Add(this.label1);
73 this.groupBox1.Location = new System.Drawing.Point(16, 8);
74 this.groupBox1.Name = "groupBox1";
75 this.groupBox1.Size = new System.Drawing.Size(448, 136);
76 this.groupBox1.TabIndex = 0;
77 this.groupBox1.TabStop = false;
78 this.groupBox1.Text = "Login";
79 //
80 // passwordText
81 //
82 this.passwordText.Location = new System.Drawing.Point(200, 80);
83 this.passwordText.Name = "passwordText";
84 this.passwordText.PasswordChar = '*';
85 this.passwordText.Size = new System.Drawing.Size(160, 21);
86 this.passwordText.TabIndex = 3;
87 this.passwordText.Text = "";
88 //
89 // label2
90 //
91 this.label2.Location = new System.Drawing.Point(88, 88);
92 this.label2.Name = "label2";
93 this.label2.Size = new System.Drawing.Size(100, 16);
94 this.label2.TabIndex = 2;
95 this.label2.Text = "Password:";
96 //
97 // loginText
98 //
99 this.loginText.Location = new System.Drawing.Point(200, 40);
100 this.loginText.Name = "loginText";
101 this.loginText.Size = new System.Drawing.Size(160, 21);
102 this.loginText.TabIndex = 1;
103 this.loginText.Text = "";
105 // label1
107 this.label1.Location = new System.Drawing.Point(88, 48);
108 this.label1.Name = "label1";
109 this.label1.Size = new System.Drawing.Size(100, 16);
110 this.label1.TabIndex = 0;
111 this.label1.Text = "Login:";
113 // logInButton
115 this.logInButton.Location = new System.Drawing.Point(122, 160);
116 this.logInButton.Name = "logInButton";
117 this.logInButton.Size = new System.Drawing.Size(112, 24);
118 this.logInButton.TabIndex = 1;
119 this.logInButton.Text = "Log In";
120 this.logInButton.Click += new System.EventHandler(this.logInButton_Click);
122 // closeButton
124 this.closeButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
125 this.closeButton.Location = new System.Drawing.Point(246, 160);
126 this.closeButton.Name = "closeButton";
127 this.closeButton.Size = new System.Drawing.Size(112, 24);
128 this.closeButton.TabIndex = 2;
129 this.closeButton.Text = "Close";
130 this.closeButton.Click += new System.EventHandler(this.closeButton_Click);
132 // LoginForm
134 this.AcceptButton = this.logInButton;
135 this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
136 this.CancelButton = this.closeButton;
137 this.ClientSize = new System.Drawing.Size(480, 204);
138 this.Controls.Add(this.closeButton);
139 this.Controls.Add(this.logInButton);
140 this.Controls.Add(this.groupBox1);
141 this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
142 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
143 this.MaximizeBox = false;
144 this.MinimizeBox = false;
145 this.Name = "LoginForm";
146 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
147 this.Text = "Log in";
148 this.groupBox1.ResumeLayout(false);
149 this.ResumeLayout(false);
152 #endregion
154 private void logInButton_Click(object sender, System.EventArgs e)
156 User user = User.FindByUserName(loginText.Text);
158 if (user == null)
160 MessageBox.Show(this, "User not found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
161 return;
164 if (user.Password != passwordText.Text)
166 MessageBox.Show(this, "Wrong password", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
167 return;
170 DialogResult = DialogResult.OK;
171 Hide();
174 private void closeButton_Click(object sender, System.EventArgs e)
176 DialogResult = DialogResult.Cancel;
177 Hide();