|
|
|
|
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 AppointmentsUi.Views
|
|
|
|
|
{
|
|
|
|
|
public partial class PostalsList : Form
|
|
|
|
|
{
|
|
|
|
|
public PostalsList()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
var postals = AppointmentsLib.Models.Postal.GetPostals();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < postals.Count(); i++)
|
|
|
|
|
{
|
|
|
|
|
var postal = postals.ElementAt(i);
|
|
|
|
|
|
|
|
|
|
var labelPostalId = new Label() { Text = postal.PostalId.ToString(), AutoSize = true, TextAlign = ContentAlignment.MiddleCenter };
|
|
|
|
|
var textboxPostalLabel = new TextBox() { Text = postal.Label, AutoSize = true };
|
|
|
|
|
var buttonApplyChanges = new Button() { Text = "Apply" };
|
|
|
|
|
var buttonDelete = new Button() { Text = "Delete" };
|
|
|
|
|
|
|
|
|
|
buttonApplyChanges.Click += new EventHandler(delegate (object sender, EventArgs e) {
|
|
|
|
|
postal.Save();
|
|
|
|
|
Program.mainForm.EmbedForm<PostalsList>();
|
|
|
|
|
});
|
|
|
|
|
buttonDelete.Click += new EventHandler(delegate (object sender, EventArgs e) {
|
|
|
|
|
var res = MessageBox.Show($"Are you sure to delete the postal\n{postal.Label}\n?", "Delete postal?", MessageBoxButtons.YesNo);
|
|
|
|
|
if (res == DialogResult.Yes)
|
|
|
|
|
{
|
|
|
|
|
postal.Delete();
|
|
|
|
|
Program.mainForm.EmbedForm<PostalsList>();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
textboxPostalLabel.TextChanged += new EventHandler(delegate (object sender, EventArgs e) {
|
|
|
|
|
postal.Label = textboxPostalLabel.Text;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
tableLayoutPanelPostals.Controls.Add(labelPostalId, 0, 1 + i);
|
|
|
|
|
tableLayoutPanelPostals.Controls.Add(textboxPostalLabel, 1, 1 + i);
|
|
|
|
|
tableLayoutPanelPostals.Controls.Add(buttonApplyChanges, 2, 1 + i);
|
|
|
|
|
tableLayoutPanelPostals.Controls.Add(buttonDelete, 3, 1 + i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal void addPostal()
|
|
|
|
|
{
|
|
|
|
|
AppointmentsLib.Models.Postal.Create("New postal");
|
|
|
|
|
Program.mainForm.EmbedForm<PostalsList>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void buttonAddNewPostals_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
addPostal();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|