using System; using System.Windows.Forms; using Tanshu.Accounts.Repository; using Tanshu.Accounts.Entities; using System.Linq; using System.Collections.Generic; using System.Text.RegularExpressions; namespace Tanshu.Accounts.PointOfSale { public partial class TaxEditForm : Form { private Guid? _taxID; public TaxEditForm(Guid taxID) : this() { _taxID = taxID; } public TaxEditForm() { InitializeComponent(); } private void TaxEditForm_Load(object sender, EventArgs e) { Tax tax; if (_taxID.HasValue) { tax = TaxBI.Get(_taxID.Value); txtName.Text = tax.Name; txtRate.Text = (tax.Rate * 100).ToString(); } txtName.Focus(); } private void btnCancel_Click(object sender, EventArgs e) { this.Close(); } private void btnOk_Click(object sender, EventArgs e) { Tax tax; if (_taxID.HasValue) tax = TaxBI.Get(_taxID.Value); else tax = new Tax(); if (string.IsNullOrEmpty(txtName.Text.Trim())) return; tax.Name = txtName.Text.Trim(); if (string.IsNullOrEmpty(txtRate.Text.Trim())) txtRate.Text = "0"; decimal rate; if (!decimal.TryParse(txtRate.Text, out rate) || (rate < 0 || rate > 100)) { MessageBox.Show("Tax Rate is not valid, it must be between 0 to 100 percent."); txtRate.Focus(); return; } else tax.Rate = rate / 100; if (_taxID.HasValue) TaxBI.Update(tax); else TaxBI.Insert(tax); MessageBox.Show("Update / Save Successful"); this.Close(); } } }