narsil/Tanshu.Accounts.PointOfSale/Masters/TaxEditForm.cs

75 lines
1.9 KiB
C#
Raw Permalink Normal View History

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)
{
2018-08-24 10:41:33 +00:00
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;
2018-08-24 10:41:33 +00:00
if (_taxID.HasValue)
tax = TaxBI.Get(_taxID.Value);
else
tax = new Tax();
2018-08-24 10:41:33 +00:00
if (string.IsNullOrEmpty(txtName.Text.Trim()))
return;
tax.Name = txtName.Text.Trim();
2018-08-24 10:41:33 +00:00
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;
}
2018-08-24 10:41:33 +00:00
else
tax.Rate = rate / 100;
if (_taxID.HasValue)
TaxBI.Update(tax);
else
TaxBI.Insert(tax);
MessageBox.Show("Update / Save Successful");
this.Close();
}
}
}