RetrieveAddress helper method
This commit is contained in:
parent
b1609b1b1b
commit
6c6de5e505
@ -1,14 +1,18 @@
|
|||||||
|
using C969Project.Data.Models;
|
||||||
|
|
||||||
namespace C969Project;
|
namespace C969Project;
|
||||||
|
|
||||||
public partial class AddUpdateCustomerForm : Form
|
public partial class AddUpdateCustomerForm : Form
|
||||||
{
|
{
|
||||||
public enum OperationType { Add, Update }
|
public enum OperationType { Add, Update }
|
||||||
public AddUpdateCustomerForm(OperationType operationType)
|
public AddUpdateCustomerForm(OperationType operationType, Customer? customer = null)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
if (operationType == OperationType.Add) InitAdd();
|
if (operationType == OperationType.Add) InitAdd();
|
||||||
else if (operationType == OperationType.Update) InitUpdate();
|
else if (operationType == OperationType.Update && customer is not null) InitUpdate(customer);
|
||||||
|
else Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitAdd()
|
private void InitAdd()
|
||||||
@ -17,10 +21,12 @@ public partial class AddUpdateCustomerForm : Form
|
|||||||
label1.Text = "Add Customer";
|
label1.Text = "Add Customer";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitUpdate()
|
private void InitUpdate(Customer customer)
|
||||||
{
|
{
|
||||||
Text = "Update Customer";
|
Text = "Update Customer";
|
||||||
label1.Text = "Update Customer";
|
label1.Text = "Update Customer";
|
||||||
|
|
||||||
|
nameTextBox.Text = customer.CustomerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
// name, {address, phone}
|
// name, {address, phone}
|
||||||
|
@ -115,4 +115,43 @@ public static class DatabaseHelper
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Address? RetrieveAddress(int addressId)
|
||||||
|
{
|
||||||
|
using MySqlConnection connection = new MySqlConnection(AppSettings.GetSetting("ConnectionStrings", "DefaultConnection"));
|
||||||
|
try
|
||||||
|
{
|
||||||
|
connection.Open();
|
||||||
|
}
|
||||||
|
catch (MySqlException e)
|
||||||
|
{
|
||||||
|
Console.WriteLine(e);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
|
string query = $"SELECT * FROM client_schedule.address WHERE addressId = {addressId}";
|
||||||
|
using MySqlCommand command = new MySqlCommand(query, connection);
|
||||||
|
using MySqlDataReader reader = command.ExecuteReader();
|
||||||
|
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
var addr = new Address()
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32("addressId"),
|
||||||
|
Address1 = reader.GetString("address1"),
|
||||||
|
Address2 = reader.GetString("address2"),
|
||||||
|
CityId = reader.GetInt32("cityId"),
|
||||||
|
PostalCode = reader.GetString("postalCode"),
|
||||||
|
Phone = reader.GetString("phone"),
|
||||||
|
CreateDate = reader.GetDateTime("createDate"),
|
||||||
|
CreatedBy = reader.GetString("createdBy"),
|
||||||
|
LastUpdate = reader.GetDateTime("lastUpdate"),
|
||||||
|
LastUpdateBy = reader.GetString("lastUpdateBy"),
|
||||||
|
};
|
||||||
|
|
||||||
|
return addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ public partial class RecordsForm : Form
|
|||||||
UpdateCustomersList();
|
UpdateCustomersList();
|
||||||
|
|
||||||
AddButton.Click += (sender, args) => { ShowDialog(new AddUpdateCustomerForm(AddUpdateCustomerForm.OperationType.Add)); };
|
AddButton.Click += (sender, args) => { ShowDialog(new AddUpdateCustomerForm(AddUpdateCustomerForm.OperationType.Add)); };
|
||||||
|
ModifyButton.Click += (sender, args) => { ShowDialog(new AddUpdateCustomerForm(AddUpdateCustomerForm.OperationType.Update)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateCustomersList()
|
public void UpdateCustomersList()
|
||||||
|
Loading…
Reference in New Issue
Block a user