Biskilog POS desktop appilcation
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
4.7 KiB

using BiskLog_Point_Of_Sale.Cashier_Module;
using BiskLog_Point_Of_Sale.Classes;
using BiskLog_Point_Of_Sale.Company_Setup;
using BiskLog_Point_Of_Sale.Multiple_Login;
using BiskLog_Point_Of_Sale.Properties;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Point_Of_Sale_Managment.CashierModule
{
public partial class DailySales : Form
{
DatabaseConn conn = new DatabaseConn();
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
public DailySales()
{
InitializeComponent();
cn = new SqlConnection(conn.MyConnection());
holding.Left = (ClientSize.Width - holding.Width) / 2;
holding.Top = (ClientSize.Height - holding.Height) / 2;
}
private void DailySales_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
{
this.Close();
}
}
public int getForDay(DateTime date, string cashier)
{
try
{
dataGridView1.Invoke(new Action(() =>
{
dataGridView1.Rows.Clear();
int i = 1;
cn.Open();
cm = new SqlCommand("Select p.product_name,tc.price,tc.quantity,tc.total from tblCart tc Inner Join tblProduct p On p.pcode = tc.id where " +
"Year(tc.date) = @dateYear and MONTH(tc.date) = @dateMonth and DAY(tc.date) = @dateDay and tc.cashier = @cashier and tc.status = 'SOLD' and tc.branchID = @branchID group by p.product_name, tc.price, tc.quantity, tc.total " +
"Select Count(Distinct tc.transno), sum(total) from tblCart tc where Year(tc.date) = @dateYear and MONTH(tc.date) = @dateMonth and DAY(tc.date) = @dateDay and tc.cashier = @cashier and tc.status = 'SOLD' and tc.branchID = @branchID", cn);
cm.Parameters.AddWithValue("@dateYear", date.Year);
cm.Parameters.AddWithValue("@dateMonth", date.Month);
cm.Parameters.AddWithValue("@dateDay", date.Day);
cm.Parameters.AddWithValue("@cashier", cashier);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
dataGridView1.Rows.Add(i, dr[0].ToString(), Settings.Default.currrencyCode + " " + dr[1].ToString(), dr[2].ToString(), Settings.Default.currrencyCode + " " + dr[3].ToString());
i++;
}
dr.NextResult();
dr.Read();
if (dr.HasRows)
{
numberCustomers.Text = dr[0].ToString();
dailyIncome.Text = Settings.Default.currrencyCode + " " + dr[1].ToString();
}
else
{
numberCustomers.Text = "";
dailyIncome.Text = "";
}
dr.Close();
cn.Close();
}));
return 1;
}
catch (Exception ex)
{
cn.Close();
MessageBox.Show(ex.ToString());
ErrorLogging.WriteToFile(ex.ToString());
return 0;
}
}
private async void DateTimePicker1_ValueChanged(object sender, EventArgs e)
{
Task<int> task = new Task<int>(() => getForDay(dateTimePicker1.Value, MainLogin.login_user));
holding.Visible = true;
task.Start();
int result = await task;
if (result == 0)
{
string title = "Error Occurred";
string message = "Sorry an error occurred while looking up sales on this date";
NoAction noAction = new NoAction(title, message);
noAction.BringToFront();
noAction.ShowDialog();
}
holding.Visible = false;
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Exit_MouseEnter(object sender, EventArgs e)
{
exit.BackColor = Color.Crimson;
}
private void Exit_MouseLeave(object sender, EventArgs e)
{
exit.BackColor = Color.Transparent;
}
}
}