SUBD_LAB/SUBD_LABA/View/FormLocation.cs

62 lines
1.2 KiB
C#

using Commentbase;
using Microsoft.VisualBasic.ApplicationServices;
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 FormLocation : Form
{
public int? LocationId { get; set; }
private Abstracts db;
public FormLocation(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void FormLocation_Load(object sender, EventArgs e)
{
if (LocationId.HasValue)
{
var location = db.GetLocation(LocationId.Value);
textBox1.Text = location.Name;
textBox2.Text = location.ShortName;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (LocationId.HasValue)
{
db.UpdateLocation(new()
{
Id = LocationId.Value,
Name = textBox1.Text,
ShortName = textBox2.Text
});
}
else
{
db.CreateLocation(new()
{
Name = textBox1.Text,
ShortName = textBox2.Text
});
}
DialogResult = DialogResult.OK;
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}