narsil/Tanshu.Accounts.PointOfSale/Updates/ReplaceForm.cs

79 lines
3.7 KiB
C#
Raw Normal View History

2010-03-02 17:56:21 +00:00
using System;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using Tanshu.Accounts.Helpers;
using System.Collections.Generic;
using Tanshu.Accounts.BI;
using Tanshu.Accounts.Contracts;
using System.Data.SqlClient;
using System.Configuration;
namespace Tanshu.Accounts.PointOfSale
{
public partial class ReplaceForm : Form
{
public ReplaceForm()
{
InitializeComponent();
}
private void btnGo_Click(object sender, EventArgs e)
{
if (!Thread.CurrentPrincipal.IsInRole("Security/CreateUser"))
return;
dtpFrom.Value = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 00:00:00", dtpFrom.Value));
dtpTo.Value = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} 23:59:59", dtpTo.Value));
string query = string.Empty;
if (txtStatus.Text == "")
{
txtZero1.Text = GetBalance(0M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtFour1.Text = GetBalance(.04M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtTwelve1.Text = GetBalance(0.125M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
2011-12-05 09:23:02 +00:00
txtFive1.Text = GetBalance(0.05M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtFiveTwoFive1.Text = GetBalance(0.0525M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtThirteenOneTwoFive1.Text = GetBalance(0.13125M, txtOne.Text, dtpFrom.Value, dtpTo.Value).ToString();
2010-03-02 17:56:21 +00:00
txtZero2.Text = GetBalance(0M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtFour2.Text = GetBalance(.04M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtTwelve2.Text = GetBalance(0.125M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
2011-12-05 09:23:02 +00:00
txtFive2.Text = GetBalance(0.05M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtFiveTwoFive2.Text = GetBalance(0.0525M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
txtThirteenOneTwoFive2.Text = GetBalance(0.13125M, txtTwo.Text, dtpFrom.Value, dtpTo.Value).ToString();
2010-03-02 17:56:21 +00:00
txtStatus.Text = "Initial Values Loaded";
}
else
{
Update(txtOne.Text, txtTwo.Text, dtpFrom.Value, dtpTo.Value);
MessageBox.Show("Data Merged");
}
}
private decimal GetBalance(decimal tax, string database, DateTime startDate, DateTime finishDate)
{
string query = @"
SELECT ISNULL(SUM(i.Amount), 0) FROM {0}.dbo.Vouchers t INNER JOIN {0}.dbo.SaleVoucher s ON t.VoucherID = s.VoucherID
INNER JOIN {0}.dbo.Inventory i ON t.VoucherID = i.VoucherID
WHERE t.Date BETWEEN @StartDate AND @FinishDate AND s.Void = 0 AND s.Paid = 1
2010-03-02 17:56:21 +00:00
AND i.Tax = @Tax
";
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString))
{
con.Open();
using (SqlCommand cmd = new SqlCommand(string.Format(query, database), con))
{
2011-12-05 09:23:02 +00:00
cmd.CommandTimeout = int.MaxValue;
2010-03-02 17:56:21 +00:00
cmd.Parameters.AddWithValue("@StartDate", startDate);
cmd.Parameters.AddWithValue("@FinishDate", finishDate);
cmd.Parameters.AddWithValue("@Tax", tax);
return (decimal)cmd.ExecuteScalar();
}
}
}
private bool Update(string sourceDB, string targetDB, DateTime startDate, DateTime finishDate)
{
return new ManagementBI().MergeData(startDate, finishDate, sourceDB, targetDB);
}
}
}