соединяет регистрацию с формой
This commit is contained in:
parent
8b1d8d93b4
commit
ff9e5827b7
@ -22,9 +22,9 @@ namespace AwesomeEmailExtractor
|
||||
try
|
||||
{
|
||||
Globals.currentUser = Authorization.Login(entryLogin.Text, entryPassword.Text);
|
||||
this.Close();
|
||||
|
||||
new MainForm().Show();
|
||||
var mainForm = FormManager.Current.CreateForm<MainForm>();
|
||||
FormManager.Current.Navigate(this, mainForm);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -34,9 +34,8 @@ namespace AwesomeEmailExtractor
|
||||
|
||||
private void registerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
|
||||
new RegistrationForm().Show();
|
||||
var form = FormManager.Current.CreateForm<RegistrationForm>();
|
||||
FormManager.Current.Navigate(this, form);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,6 +84,7 @@
|
||||
<DependentUpon>AuthorizationForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="ExtactEmailsAlgorithm.cs" />
|
||||
<Compile Include="FormManager.cs" />
|
||||
<Compile Include="Globals.cs" />
|
||||
<Compile Include="Logs.cs" />
|
||||
<Compile Include="MainForm.cs">
|
||||
|
46
FormManager.cs
Normal file
46
FormManager.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AwesomeEmailExtractor
|
||||
{
|
||||
public class FormManager : ApplicationContext
|
||||
{
|
||||
private void onFormClosed(object sender, EventArgs e)
|
||||
{
|
||||
if (Application.OpenForms.Count == 0)
|
||||
{
|
||||
if (((Form)sender).Name == currentForm)
|
||||
ExitThread();
|
||||
}
|
||||
}
|
||||
|
||||
public T CreateForm<T>() where T : Form, new()
|
||||
{
|
||||
var ret = new T();
|
||||
ret.FormClosed += onFormClosed;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void Navigate(Form from, Form to)
|
||||
{
|
||||
currentForm = to.Name;
|
||||
from.Close();
|
||||
to.Show();
|
||||
}
|
||||
|
||||
public string currentForm = "AuthorizationForm";
|
||||
|
||||
private static Lazy<FormManager> _current = new Lazy<FormManager>();
|
||||
public static FormManager Current => _current.Value;
|
||||
|
||||
public FormManager()
|
||||
{
|
||||
var authorization = CreateForm<AuthorizationForm>();
|
||||
authorization.Show();
|
||||
}
|
||||
}
|
||||
}
|
@ -20,9 +20,7 @@ namespace AwesomeEmailExtractor
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
new AuthorizationForm().Show();
|
||||
Application.Run();
|
||||
Application.Run(FormManager.Current);
|
||||
|
||||
postMain();
|
||||
}
|
||||
|
8
RegistrationForm.Designer.cs
generated
8
RegistrationForm.Designer.cs
generated
@ -55,6 +55,7 @@
|
||||
this.entryPassword.Name = "entryPassword";
|
||||
this.entryPassword.Size = new System.Drawing.Size(195, 20);
|
||||
this.entryPassword.TabIndex = 10;
|
||||
this.entryPassword.UseSystemPasswordChar = true;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
@ -79,9 +80,10 @@
|
||||
this.registerButton.Location = new System.Drawing.Point(14, 135);
|
||||
this.registerButton.Name = "registerButton";
|
||||
this.registerButton.Size = new System.Drawing.Size(364, 23);
|
||||
this.registerButton.TabIndex = 7;
|
||||
this.registerButton.TabIndex = 6;
|
||||
this.registerButton.Text = "Зарегистрироваться";
|
||||
this.registerButton.UseVisualStyleBackColor = true;
|
||||
this.registerButton.Click += new System.EventHandler(this.registerButton_Click);
|
||||
//
|
||||
// loginButton
|
||||
//
|
||||
@ -89,7 +91,7 @@
|
||||
this.loginButton.Location = new System.Drawing.Point(14, 187);
|
||||
this.loginButton.Name = "loginButton";
|
||||
this.loginButton.Size = new System.Drawing.Size(364, 23);
|
||||
this.loginButton.TabIndex = 6;
|
||||
this.loginButton.TabIndex = 7;
|
||||
this.loginButton.Text = "Авторизоваться";
|
||||
this.loginButton.UseVisualStyleBackColor = true;
|
||||
this.loginButton.Click += new System.EventHandler(this.loginButton_Click);
|
||||
@ -121,7 +123,6 @@
|
||||
this.label4.Size = new System.Drawing.Size(178, 18);
|
||||
this.label4.TabIndex = 14;
|
||||
this.label4.Text = "Уже зарегистрированы?";
|
||||
this.label4.Click += new System.EventHandler(this.label4_Click);
|
||||
//
|
||||
// RegistrationForm
|
||||
//
|
||||
@ -140,6 +141,7 @@
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.Name = "RegistrationForm";
|
||||
this.Text = "Зарегистрироваться";
|
||||
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.RegistrationForm_FormClosed);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
|
@ -17,16 +17,36 @@ namespace AwesomeEmailExtractor
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void label4_Click(object sender, EventArgs e)
|
||||
private void registerButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (!string.Equals(entryPassword.Text, entryRePassword.Text))
|
||||
{
|
||||
MessageBox.Show("Пароли не совпадают!");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
Globals.currentUser = Authorization.Register(entryLogin.Text, entryPassword.Text);
|
||||
|
||||
var form = FormManager.Current.CreateForm<MainForm>();
|
||||
FormManager.Current.Navigate(this, form);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void loginButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Close();
|
||||
AuthorizationForm form = FormManager.Current.CreateForm<AuthorizationForm>();
|
||||
FormManager.Current.Navigate(this, form);
|
||||
}
|
||||
|
||||
new AuthorizationForm().Show();
|
||||
private void RegistrationForm_FormClosed(object sender, FormClosedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user