SUBD/View/UserForm.cs

66 lines
1.2 KiB
C#

using Database;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace View
{
public partial class UserForm : Form
{
public int? UserId { get; set; }
private Abstracts db;
public UserForm(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void button1_Click(object sender, EventArgs e)
{
if (UserId.HasValue)
{
db.UpdateUser(new()
{
Id = UserId.Value,
name = textBox1.Text,
email = textBox2.Text,
birthday = dateTimePicker1.Value
});
}
else
{
db.CreateUser(new()
{
name = textBox1.Text,
email = textBox2.Text,
birthday = dateTimePicker1.Value
});
}
DialogResult = DialogResult.OK;
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void UserForm_Load(object sender, EventArgs e)
{
if (UserId.HasValue)
{
var user = db.GetUser(UserId.Value);
textBox1.Text = user.name;
textBox2.Text = user.email;
dateTimePicker1.Value = user.birthday;
}
}
}
}