narsil/Tanshu.Accounts.PointOfSale/Advances/frmRecieveAdvance.cs
unknown 59909a5ee7 Updated NH, Code Refactoring, made all DB transactions atomic.
Must use the Repositories with Using or else bad things will happen.
2011-06-30 01:57:07 +05:30

86 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using Tanshu.Accounts.Print;
using Tanshu.Accounts.Contracts;
using Tanshu.Accounts.Repository;
using Tanshu.Accounts.Entities;
namespace Tanshu.Accounts.PointOfSale
{
public partial class frmRecieveAdvance : Form
{
bool loading = true;
public frmRecieveAdvance()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
if (Convert.ToDecimal(txtAmount.Text) == 0)
return;
Advance adv = new Advance();
adv.Narration = txtNarration.Text;
adv.Amount = Convert.ToDecimal(txtAmount.Text.Trim());
using (var bi = new UserBI())
adv.CashierIn = bi.Get(x => x.UserID == (int)txtCashier.Tag);
adv.DateIn = DateTime.Now;
using (var bi = new AdvanceBI())
bi.Insert(adv);
GridBind();
PrintAdvances();
}
private void frmRecieveAdvance_Load(object sender, EventArgs e)
{
dtpFrom.Format = DateTimePickerFormat.Custom;
dtpFrom.CustomFormat = "dd-MMM-yyyy";
dtpFrom.Value = DateTime.Now;
dtpTo.Format = DateTimePickerFormat.Custom;
dtpTo.CustomFormat = "dd-MMM-yyyy";
dtpTo.Value = DateTime.Now;
txtCashier.Text = Session.User.Name;
txtCashier.Tag = Session.User.UserID;
loading = false;
GridBind();
}
private void GridBind()
{
using (var bi = new AdvanceBI(false))
dgExpenses.DataSource = bi.GetAdvances(dtpFrom.Value, dtpTo.Value, true);
}
private void dtpFrom_ValueChanged(object sender, EventArgs e)
{
if (!loading)
GridBind();
}
private void PrintAdvances()
{
Thermal.PrintAdvance(Session.User.Name, txtAmount.Text.Trim(), txtNarration.Text.Trim());
}
private string AddDate(string SqlStringP, DateTime FromDate, DateTime ToDate)
{
return SqlStringP.Replace("$From$", string.Format(FromDate.ToString(), "dd-MMM-yyyy" + " 05:00:00")).Replace("$To$", string.Format(ToDate.ToString(), "dd-MMM-yyyy" + " 23:59:59"));
}
private void txtAmount_TextChanged(object sender, EventArgs e)
{
}
private void txtAmount_Leave(object sender, EventArgs e)
{
if (txtAmount.Text.Trim() == "")
{
txtAmount.Focus();
}
}
}
}