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

88 lines
2.8 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Windows.Forms;
using Tanshu.Accounts.BI;
using Tanshu.Accounts.Contracts;
namespace Tanshu.Accounts.PointOfSale
{
public partial class AdjustAdvanceForm : Form
{
2011-12-05 09:23:02 +00:00
bool _loading = true;
private readonly bool _fromSaleForm;
private Guid? _advanceID;
public AdjustAdvanceForm(bool fromSaleForm)
2010-03-02 17:56:21 +00:00
{
2011-12-05 09:23:02 +00:00
_fromSaleForm = fromSaleForm;
2010-03-02 17:56:21 +00:00
InitializeComponent();
}
private void AdjustAdvancesForm_Load(object sender, EventArgs e)
{
2011-12-05 09:23:02 +00:00
btnAdjust.Enabled = _fromSaleForm;
2010-03-02 17:56:21 +00:00
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;
2011-12-05 09:23:02 +00:00
_loading = false;
2010-03-02 17:56:21 +00:00
FillDataGrid();
}
private void FillDataGrid()
{
var fromDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 00:00:00", dtpFrom.Value));
var toDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 23:59:59", dtpTo.Value));
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.AdvanceDAO(connection))
{
dgExpenses.DataSource = dao.GetAdvances(fromDate, toDate, false);
}
}
2010-03-02 17:56:21 +00:00
}
private void dtpFrom_ValueChanged(object sender, EventArgs e)
{
2011-12-05 09:23:02 +00:00
if (!_loading)
2010-03-02 17:56:21 +00:00
FillDataGrid();
}
private void btnSelect_Click(object sender, EventArgs e)
{
try
{
2011-12-05 09:23:02 +00:00
var item = dgExpenses.SelectedRows[0].DataBoundItem as AdvanceDisplayBO;
if (item == null)
return;
2010-03-02 17:56:21 +00:00
txtCashier.Text = item.Cashier;
txtNarration.Tag = item.AdvanceID;
txtNarration.Text = item.Narration;
txtAmount.Text = item.Amount.ToString();
}
catch { }
}
private void btnAdjust_Click(object sender, EventArgs e)
{
2011-12-05 09:23:02 +00:00
if (_fromSaleForm)
{
_advanceID = (Guid)txtNarration.Tag;
this.Close();
}
else
{
using (var connection = new SqlDAO.SqlConnectionDAO())
{
using (var dao = new SqlDAO.AdvanceDAO(connection))
{
dao.Adjust((Guid)txtNarration.Tag, CurrentUser.user.UserID);
}
}
2011-12-05 09:23:02 +00:00
FillDataGrid();
}
}
public Guid? AdvanceID
{
get { return _advanceID; }
2010-03-02 17:56:21 +00:00
}
}
}