narsil/Tanshu.Accounts.PointOfSale/Sales/PaymentForm.cs

85 lines
2.7 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.BI;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Helpers;
namespace Tanshu.Accounts.PointOfSale
{
public partial class PaymentForm : Form
{
List<PaymentDisplayBO> paymentList = new List<PaymentDisplayBO>();
public PaymentForm()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
UserBO user = CurrentUser.user;
if (txtAmount.Text == "0" || cmbType.Text == "")
{
System.Windows.Forms.MessageBox.Show("Amount can't be blank", "Blank not Allowed");
}
else
{
PaymentBO paymentEntry = new PaymentBO();
paymentEntry.Date = DateTime.Now;
paymentEntry.Type = cmbType.Text;
paymentEntry.CashierID = user.UserID;
paymentEntry.Amount = Convert.ToDecimal(txtAmount.Text);
paymentEntry.Narration = txtNarration.Text;
new PaymentBI().Insert(paymentEntry);
}
GridBind();
}
private void PaymentForm_Load(object sender, EventArgs e)
{
UserBO user = CurrentUser.user;
dtpFrom.Value = DateTime.Today;
dtpTo.Value = DateTime.Today;
GridBind();
txtCashier.Text = user.Name;
txtCashier.Tag = user.UserID;
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (!Thread.CurrentPrincipal.IsInRole("Payment/Delete"))
MessageBox.Show("You are not authorized to access");
else
{
UserBO user = CurrentUser.user;
if (dgvPayments.SelectedRows.Count <= 0)
return;
Guid paymentID = ((PaymentDisplayBO)bindingSource.Current).PaymentID;
new PaymentBI().Delete(paymentID);
GridBind();
}
}
private void GridBind()
{
Guid? userID;
if (!Thread.CurrentPrincipal.IsInRole("Payment/SeeAll"))
userID = null;
else
{
userID = CurrentUser.user.UserID;
}
paymentList = new PaymentBI().GetPayments(userID, dtpFrom.Value, dtpTo.Value);
bindingSource.DataSource = paymentList;
}
private void dtpFrom_ValueChanged(object sender, EventArgs e)
{
GridBind();
}
private void dtpTo_ValueChanged(object sender, EventArgs e)
{
GridBind();
}
}
}