narsil/Tanshu.Accounts.PointOfSale/Products/TableForm.cs

83 lines
2.4 KiB
C#
Raw Normal View History

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;
2018-08-24 10:41:33 +00:00
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())
{
2018-08-24 10:41:33 +00:00
FoodTable foodTable;
if (_tableID.HasValue)
{
2018-08-24 10:41:33 +00:00
foodTable = FoodTableBI.Get(_tableID.Value);
if (foodTable.IsActive && chkIsActive.Checked == false && (foodTable.Status != null || foodTable.VoucherID.HasValue))
{
2018-08-24 10:41:33 +00:00
MessageBox.Show("Cannot deactivate a table with running bill");
return;
}
}
2018-08-24 10:41:33 +00:00
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;
}
}
}