First commit
This commit is contained in:
85
Feladat1/UI/MainWindow/MainWindow.cs
Normal file
85
Feladat1/UI/MainWindow/MainWindow.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
using Adw;
|
||||
using Logic;
|
||||
|
||||
namespace Feladat1.UI.MainWindow;
|
||||
|
||||
public class MainWindow
|
||||
{
|
||||
private IUserService userService;
|
||||
private const string windowId = "main_window";
|
||||
|
||||
public Window Window;
|
||||
|
||||
private Gtk.Button saveBtn;
|
||||
private const string saveBtnId = "save_btn";
|
||||
|
||||
private EntryRow emailField;
|
||||
private const string emailFieldId = "email";
|
||||
|
||||
private EntryRow userNameField;
|
||||
private const string userNameFieldId = "username";
|
||||
|
||||
private PasswordEntryRow passwordField;
|
||||
private const string passwordFieldId = "password";
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
var builder = new Gtk.Builder("Feladat1.UI.MainWindow.MainWindow.ui.xml");
|
||||
|
||||
Window = builder.GetObject(windowId) as Window;
|
||||
if (Window == null)
|
||||
{
|
||||
throw new Exception("Failed to load embedded resource MainWindow.ui.xml");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
saveBtn = builder.GetObject(saveBtnId) as Gtk.Button;
|
||||
if (saveBtn == null)
|
||||
{
|
||||
throw new NullReferenceException(saveBtnId);
|
||||
}
|
||||
saveBtn.OnClicked += (sender, args) => Save();
|
||||
|
||||
emailField = builder.GetObject(emailFieldId) as EntryRow;
|
||||
if (emailField == null)
|
||||
{
|
||||
throw new NullReferenceException(emailFieldId);
|
||||
}
|
||||
|
||||
userNameField = builder.GetObject(userNameFieldId) as EntryRow;
|
||||
if (userNameField == null)
|
||||
{
|
||||
throw new NullReferenceException(userNameFieldId);
|
||||
}
|
||||
|
||||
passwordField = builder.GetObject(passwordFieldId) as PasswordEntryRow;
|
||||
if (passwordField == null)
|
||||
{
|
||||
throw new NullReferenceException(passwordFieldId);
|
||||
}
|
||||
}
|
||||
catch (NullReferenceException e)
|
||||
{
|
||||
Console.WriteLine($"Failed to load UI element with ID: {e.Message}");
|
||||
Window.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private bool ValidateFields()
|
||||
{
|
||||
if (userNameField.Text_ != null && emailField.Text_ != null && passwordField.Text_ != null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void Save()
|
||||
{
|
||||
if (ValidateFields())
|
||||
{
|
||||
userService.Create(userNameField.GetText(), emailField.GetText(), passwordField.GetText());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user