83 lines
2.4 KiB
C#
83 lines
2.4 KiB
C#
using System;
|
|
using System.Windows.Forms;
|
|
using Tanshu.Accounts.Repository;
|
|
using Tanshu.Accounts.Entities;
|
|
using System.Linq;
|
|
|
|
namespace Tanshu.Accounts.PointOfSale
|
|
{
|
|
public partial class TableForm : Form
|
|
{
|
|
private Guid? _tableID;
|
|
public TableForm()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public TableForm(Guid tableID)
|
|
: this()
|
|
{
|
|
_tableID = tableID;
|
|
}
|
|
|
|
private void TableForm_Load(object sender, EventArgs e)
|
|
{
|
|
if (_tableID.HasValue)
|
|
{
|
|
FoodTable foodTable;
|
|
foodTable = FoodTableBI.Get(_tableID.Value);
|
|
|
|
txtName.Text = foodTable.Name;
|
|
txtLocation.Text = foodTable.Location;
|
|
chkIsActive.Checked = foodTable.IsActive;
|
|
}
|
|
else
|
|
{
|
|
txtName.Focus();
|
|
}
|
|
}
|
|
|
|
private void btnCancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void btnOk_Click(object sender, EventArgs e)
|
|
{
|
|
if (IsFormValid())
|
|
{
|
|
FoodTable foodTable;
|
|
if (_tableID.HasValue)
|
|
{
|
|
foodTable = FoodTableBI.Get(_tableID.Value);
|
|
if (foodTable.IsActive && chkIsActive.Checked == false && (foodTable.Status != null || foodTable.VoucherID.HasValue))
|
|
{
|
|
MessageBox.Show("Cannot deactivate a table with running bill");
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
foodTable = new FoodTable();
|
|
foodTable.Name = txtName.Text.Trim();
|
|
foodTable.IsActive = chkIsActive.Checked;
|
|
foodTable.Location = txtLocation.Text.Trim();
|
|
|
|
if (_tableID.HasValue)
|
|
FoodTableBI.Update(foodTable);
|
|
else
|
|
FoodTableBI.Insert(foodTable);
|
|
MessageBox.Show("Update / Save Successful");
|
|
this.Close();
|
|
}
|
|
else
|
|
MessageBox.Show("The form is not valid");
|
|
}
|
|
private bool IsFormValid()
|
|
{
|
|
if (string.IsNullOrEmpty(txtName.Text.Trim()))
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
}
|