You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.9 KiB

8 months ago
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 db_lab
{
public partial class EditFormBuilding : Form
{
private BuildingRepository buildingRepository;
private int? recordId;
public EditFormBuilding(BuildingRepository buildingRepository, int? recordId = null)
{
this.buildingRepository = buildingRepository;
this.recordId = recordId;
InitializeComponent();
if (recordId.HasValue)
{
LoadRecordData(recordId.Value);
}
}
private void LoadRecordData(int id)
{
DataRow row = buildingRepository.GetBuildingById(id);
if (row != null)
{
textBoxFloorCount.Text = row["floor_count"].ToString();
textBoxAddress.Text = row["address"].ToString();
textBoxCreatingUserId.Text = row["creating_user_id"].ToString();
textBoxBuildingType.Text = row["building_type"].ToString();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
int floorCount = int.Parse(textBoxFloorCount.Text);
string address = textBoxAddress.Text;
int creatingUserId = int.Parse(textBoxCreatingUserId.Text);
string buildingType = textBoxBuildingType.Text;
if (recordId.HasValue)
{
buildingRepository.UpdateBuilding(recordId.Value, floorCount, address, creatingUserId, buildingType);
}
else
{
buildingRepository.AddBuilding(floorCount, address, creatingUserId, buildingType);
}
this.Close();
}
}
}