narsil/Tanshu.Accounts.PointOfSale/Products/TableForm.cs
tanshu da929ad036 Breaking Change: Changed Kot/Voucher Table Name to Guid Foreign key
Breaking Change: Renamed Discontinued to IsActive and added NA field to products.
Cleanup: Removed not used attributes
Change: RoleConstants changed to simple string
Feature: Table Create/Edit/Reorder and Modifier Create/Edit Form
Feature: Bills now show the Tax name from the database and not a hack
2014-10-16 16:41:55 +05:30

88 lines
2.6 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;
using (var bi = new FoodTableBI())
foodTable = bi.Get(x => x.FoodTableID == _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())
{
using (var bi = new FoodTableBI())
{
FoodTable foodTable;
if (_tableID.HasValue)
{
foodTable = bi.Get(x => x.FoodTableID == _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)
bi.Update(foodTable);
else
bi.Insert(foodTable);
bi.SaveChanges();
}
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;
}
}
}