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.

1069 lines
50 KiB

using BiskLog_Point_Of_Sale.Classes;
using BiskLog_Point_Of_Sale.Properties;
using LiveCharts;
using LiveCharts.Wpf;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Media;
using Color = System.Drawing.Color;
namespace Point_Of_Sale_Managment
{
public partial class Dashboard : Form
{
DatabaseConn dbconn = new DatabaseConn();
SqlConnection cn = new SqlConnection();
SqlCommand cm = new SqlCommand();
SqlDataReader dr;
public static string year, term, listType;
public string CurrentYear, CurrentTerm;
public static string schoolName = "", schoolAddress = "", schoolLocation = "", schoolTelephone1 = "", schoolTelephone2 = "", schoolEmail = "", schoolMotto = "", Logostring;
int initialPanelY;
int initialPanelX;
SortedList<string, decimal> salesAtShop;
SortedList<string, decimal> cancelled;
SortedList<string, decimal> deliverieSort;
List<string> dates = new List<string>();
int total = 0;
public Dashboard()
{
InitializeComponent();
DoubleBuffered = true;
initialPanelY = this.chartContent.Location.Y;
initialPanelX = this.chartContent.Location.X;
cn = new SqlConnection(dbconn.MyConnection());
panel1.Left = (ClientSize.Width - panel1.Width) / 2;
pane.Left = (ClientSize.Width - pane.Width) / 2;
if (chartContent.Width < ClientSize.Width)
{
horizontalSellScroll.Visible = false;
}
else
{
horizontalSellScroll.Visible = true;
}
hold.ForeColor = Color.FromArgb(10, 10, 56);
holding.Left = (ClientSize.Width - holding.Width) / 2;
holding.Top = (ClientSize.Height - holding.Height) / 2;
}
private void HorizontalSellScroll_Scroll(object sender, ScrollEventArgs e)
{
int v = sellScroll.Value;
int hiddenPanelWidth = this.chartContent.Size.Width - this.ClientSize.Width;
float moveX = (float)hiddenPanelWidth * ((float)v / 100);
int newX = initialPanelX + (int)moveX;
this.chartContent.Location = new Point(newX, chartContent.Location.Y);
}
private void SellScroll_Scroll(object sender, ScrollEventArgs e)
{
int v = sellScroll.Value;
int hiddenPanelHeight = this.chartContent.Size.Height - this.ClientSize.Height;
float moveY = (float)hiddenPanelHeight * ((float)v / 100);
int newY = initialPanelY + (int)moveY;
this.chartContent.Location = new Point(this.chartContent.Location.X, newY);
}
private async void SummaryDate_ValueChanged(object sender, EventArgs e)
{
dates.Clear();
Task<int> task = new Task<int>(() =>
{
productsDetails();
salesPeople();
topSellingItems();
LoadShopSales();
CancelledTransaction();
customerNumber();
LoadChart();
soldOut();
invoiceGenerated();
deliveries();
LoadDeliveryTransactions();
return 1;
});
holding.Visible = true;
hold.Value = 0;
var progress = new Progress<int>(percent =>
{
hold.Value = percent;
});
await Task.Run(() => Progression.DoSomething(progress));
task.Start();
await task;
loadCatesian(salesAtShop, dates, cancelled, deliverieSort);
holding.Visible = false;
}
private async void Dashboard_Load(object sender, EventArgs e)
{
dates.Clear();
Task<int> task = new Task<int>(() =>
{
productsDetails();
salesPeople();
topSellingItems();
LoadShopSales();
CancelledTransaction();
customerNumber();
LoadChart();
soldOut();
invoiceGenerated();
deliveries();
LoadDeliveryTransactions();
return 1;
});
holding.Visible = true;
hold.Value = 0;
var progress = new Progress<int>(percent =>
{
hold.Value = percent;
});
await Task.Run(() => Progression.DoSomething(progress));
task.Start();
await task;
loadCatesian(salesAtShop, dates, cancelled, deliverieSort);
holding.Visible = false;
}
public int getValues(string id)
{
try
{
int value = 0;
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Declare @total int = (Select Count(id) from tblCart where Month(date) = @month and " +
"Year(date) = @year and status = 'SOLD' and branchID = @branchID)" +
"Declare @produce int = (Select Count(id) from tblCart where id = @id and Month(date) = @month and " +
"Year(date) = @year and status = 'SOLD' and branchID = @branchID) " +
"Select @produce,@total", cn);
cm.Parameters.AddWithValue("@id", id);
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
value = int.Parse(dr[0].ToString());
total = int.Parse(dr[1].ToString());
}
dr.Close();
}));
cn.Close();
return value;
}
catch
{
cn.Close();
return 0;
}
}
public int topSellingItems()
{
try
{
int i = 1;
string firstitem = "";
string seconditem = "";
string thirditem = "";
string fourthitem = "";
string fifthitem = "";
string sixthitem = "";
item5.Invoke(new Action(() =>
{
cn.Open();
cm = new SqlCommand("Select Top 6 Count(id) as total,tblProduct.product_name,tblProduct.pcode from " +
"tblCart Inner Join tblProduct on tblProduct.pcode = tblCart.id " +
"where YEAR(date) = @year and MONTH(date) = @month and tblCart.branchID = @branchID " +
"and tblCart.status ='SOLD' group by tblProduct.product_name,tblProduct.pcode order by total desc", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (i == 1)
{
item1.Text = dr["product_name"].ToString().ToUpper();
item1Sales.Text = dr[0].ToString() + " SOLD";
firstitem = item1.Text;
firstProduct.Text = dr[2].ToString();
i++;
}
else if (i == 2)
{
item2.Text = dr["product_name"].ToString().ToUpper();
item2Sales.Text = dr[0].ToString() + " SOLD";
i++;
seconditem = item2.Text;
secondProduct.Text = dr[2].ToString();
}
else if (i == 3)
{
item3.Text = dr["product_name"].ToString().ToUpper();
item3Sales.Text = dr[0].ToString() + " SOLD";
i++;
thirditem = item3.Text;
thirdProduct.Text = dr[2].ToString();
}
else if (i == 4)
{
item4.Text = dr["product_name"].ToString().ToUpper();
item4Sales.Text = dr[0].ToString() + " SOLD";
i++;
fourthitem = item4.Text;
fourthProduct.Text = dr[2].ToString();
}
else if (i == 5)
{
item5.Text = dr["product_name"].ToString().ToUpper();
item5Sales.Text = dr[0].ToString() + " SOLD";
i++;
fifthitem = item5.Text;
fifthProduct.Text = dr[2].ToString();
}
else if (i == 6)
{
item6.Text = dr["product_name"].ToString().ToUpper();
item6sales.Text = dr[0].ToString() + " SOLD";
i++;
fifthitem = item5.Text;
sixthProduct.Text = dr[2].ToString();
}
}
dr.Close();
cn.Close();
if (String.IsNullOrEmpty(firstitem))
{
item1.Text = "";
item1Sales.Text = "";
firstProduct.Text = "";
}
if (String.IsNullOrEmpty(seconditem))
{
item2.Text = "";
item2Sales.Text = "";
secondProduct.Text = "";
}
if (String.IsNullOrEmpty(thirditem))
{
item3.Text = "";
item3Sales.Text = "";
thirdProduct.Text = "";
}
if (String.IsNullOrEmpty(fourthitem))
{
item4.Text = "";
item4Sales.Text = "";
fourthProduct.Text = "";
}
if (String.IsNullOrEmpty(fifthitem))
{
item5.Text = "";
item5Sales.Text = "";
fifthProduct.Text = "";
}
if (String.IsNullOrEmpty(sixthitem))
{
item6.Text = "";
item6sales.Text = "";
sixthProduct.Text = "";
}
}));
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int salesPeople()
{
try
{
lblFirstname.Invoke(new Action(() =>
{
int i = 1;
string firstperson = "";
string secondperson = "";
string thirdperson = "";
cn.Open();
cm = new SqlCommand("Select Top 3 SUM(total) as total,tblUsers.firstname, tblUsers.surname from " +
"tblCart Inner Join tblUsers on tblUsers.username = tblCart.cashier " +
"where YEAR(date) = @year and MONTH(date) = @month and tblCart.branchID = @branchID " +
"and status ='SOLD' group by tblUsers.firstname, tblUsers.surname order by total desc", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (i == 1)
{
lblFirstname.Text = dr["firstname"].ToString().ToUpper() + " " + dr["surname"].ToString().ToUpper();
lblFirstTotal.Text = Settings.Default.currrencyCode + " " + dr[0].ToString();
firstperson = lblFirstname.Text;
i++;
}
else if (i == 2)
{
lblSecondName.Text = dr["firstname"].ToString().ToUpper() + " " + dr["surname"].ToString().ToUpper();
lblSecondTotal.Text = Settings.Default.currrencyCode + " " + dr[0].ToString();
secondperson = lblSecondName.Text;
i++;
}
else if (i == 3)
{
lblThirdName.Text = dr["firstname"].ToString().ToUpper() + " " + dr["surname"].ToString().ToUpper();
lblThirdTotal.Text = Settings.Default.currrencyCode + " " + dr[0].ToString();
thirdperson = lblThirdName.Text;
i++;
}
}
dr.Close();
cn.Close();
if (String.IsNullOrEmpty(firstperson))
{
lblFirstname.Text = "";
lblFirstTotal.Text = "";
}
if (String.IsNullOrEmpty(secondperson))
{
lblSecondName.Text = "";
lblSecondTotal.Text = "";
}
if (String.IsNullOrEmpty(thirdperson))
{
lblThirdName.Text = "";
lblThirdTotal.Text = "";
}
}));
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int productsDetails()
{
try
{
lblProducts.Invoke(new Action(() =>
{
cn.Open();
cm = new SqlCommand("Declare @lowCost int = (Select COUNT(t.pcode) from tblInventoryEntries t Inner Join (Select pcode, max(date) " +
"as MaxDate from tblInventoryEntries group by pcode) tm on t.pcode = tm.pcode and t.date = tm.MaxDate where quantity < @treshold " +
"and branchID = @branchID and YEAR(date) = @year and MONTH(date) = @month)" +
"Declare @categories int = (Select COUNT(Distinct tblProduct.cid) from tblInventoryEntries Inner Join tblProduct On tblProduct.pcode = " +
"tblInventoryEntries.pcode where tblInventoryEntries.branchID = @branchID and YEAR(date) = @year and MONTH(date) = @month)" +
"Declare @brands int = (Select COUNT(Distinct tblProduct.bid) from tblInventoryEntries Inner Join tblProduct On tblProduct.pcode = " +
"tblInventoryEntries.pcode where tblInventoryEntries.branchID = @branchID and YEAR(date) = @year and MONTH(date) = @month)" +
"Declare @items int = (Select Count(Distinct pcode) from tblInventoryEntries where branchID = @branchID and Year(date) = @year and " +
"Month(date) = @month) " +
"Declare @totalCancelled int = (Select Count(transno) from tblCancelledTransactions where branchID =@branchID and Year(dateCancelled) = @year and Month(dateCancelled) = @month) " +
"Declare @totalSales int = (Select Count(Distinct transno) from tblCart where status = 'SOLD' and branchID =@branchID and Year(date) = @year and Month(date) = @month) " +
"Declare @salesSum decimal(19,2) = (Select Sum(total) from tblCart where status = 'SOLD' and branchID =@branchID and Year(date) = @year and Month(date) = @month) " +
"Select @lowCost as LowCost,@categories as Category,@brands as Brands,@items as Products, @totalCancelled as Cancelled,@totalSales as numOfSales," +
"@salesSum as SumOfSales", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@treshold", Settings.Default.lowStockTreshold);
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
lblProducts.Text = dr["Products"].ToString();
lblStock.Text = dr["LowCost"].ToString();
lblCategory.Text = dr["Category"].ToString();
lblBrands.Text = dr["Brands"].ToString();
totalSalesSum.Text = Settings.Default.currrencyCode + " " + dr["SumOfSales"].ToString();
totalSales.Text = dr["numOfSales"].ToString();
labelCancelled.Text = dr["Cancelled"].ToString();
}
else
{
lblProducts.Text = "0";
lblStock.Text = "0";
lblCategory.Text = "0";
lblBrands.Text = "0";
totalSalesSum.Text = Settings.Default.currrencyCode + " " + "0.00";
totalSales.Text = "0";
labelCancelled.Text = "0";
}
dr.Close();
cn.Close();
}));
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public void loadCatesian(SortedList<string, decimal> Shop, List<string> Dates, SortedList<string, decimal> cancelled,
SortedList<string, decimal> deliverySystemList)
{
ChartValues<decimal> Shopped = new ChartValues<decimal>();
ChartValues<decimal> Cancelledth = new ChartValues<decimal>();
ChartValues<decimal> DeliverySystem = new ChartValues<decimal>();
Dates.Sort();
foreach (string date in Dates)
{
if (!Shop.ContainsKey(date))
{
Shop.Add(date, decimal.Parse("0"));
}
if (!cancelled.ContainsKey(date))
{
cancelled.Add(date, decimal.Parse("0"));
}
if (!deliverySystemList.ContainsKey(date))
{
deliverySystemList.Add(date, decimal.Parse("0"));
}
}
foreach (var place in Shop)
{
Shopped.Add(place.Value);
}
foreach (var place in cancelled)
{
Cancelledth.Add(place.Value);
}
foreach (var place in deliverySystemList)
{
DeliverySystem.Add(place.Value);
}
salesChart.AxisX.Clear();
salesChart.AxisY.Clear();
salesChart.Series = new SeriesCollection
{
new LineSeries
{
Title = "SHOP SALES",
Values = Shopped,
},
new LineSeries
{
Title = "CANCELLED TRANSACTION",
Values = Cancelledth,
},
new LineSeries
{
Title = "COMPLETED DELIVERIES",
Values = DeliverySystem,
}
};
salesChart.AxisX.Add(new Axis
{
Title = "Day",
Labels = Dates
});
salesChart.AxisY.Add(new Axis
{
Title = "Sales",
LabelFormatter = value => Settings.Default.currrencyCode + " " + value.ToString()
});
//modifying the series collection will animate and update the chart
//cartesianChart1.Series.Add(new LineSeries
//{
// Values = new ChartValues<double> { 5, 3, 2, 4, 5 },
// LineSmoothness = 0, //straight lines, 1 really smooth lines
// PointGeometry = Geometry.Parse("m 25 70.36218 20 -28 -20 22 -8 -6 z"),
// PointGeometrySize = 50,
// PointForeground = System.Windows.Media.Brushes.Gray
//});
//cartesianChart1.Series[2].Values.Add(5d)
}
public void LoadChart()
{
firstProduct.Invoke(new Action(() =>
{
var converter = new BrushConverter();
System.Windows.Media.Brush product = (System.Windows.Media.Brush)converter.ConvertFromString("#970a91");
System.Windows.Media.Brush totalColor = (System.Windows.Media.Brush)converter.ConvertFromString("#0a0a38");
int i = 0;
while (i < 7)
{
i++;
string id = "";
total = 0;
int difference = 0;
int firstValue = 0;
switch (i)
{
case 1:
if (!String.IsNullOrEmpty(firstProduct.Text))
{
id = firstProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item1.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart1.InnerRadius = 25;
chart1.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item1.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart1.InnerRadius = 25;
chart1.Series = pieChart;
}
break;
case 2:
if (!String.IsNullOrEmpty(secondProduct.Text))
{
id = secondProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item2.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart2.InnerRadius = 25;
chart2.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item2.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart2.InnerRadius = 25;
chart2.Series = pieChart;
}
break;
case 3:
if (!String.IsNullOrEmpty(thirdProduct.Text))
{
id = thirdProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item3.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart3.InnerRadius = 25;
chart3.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item3.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart3.InnerRadius = 25;
chart3.Series = pieChart;
}
break;
case 4:
if (!String.IsNullOrEmpty(fourthProduct.Text))
{
id = fourthProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item4.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart4.InnerRadius = 25;
chart4.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item4.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart4.InnerRadius = 25;
chart4.Series = pieChart;
}
break;
case 5:
if (!String.IsNullOrEmpty(fifthProduct.Text))
{
id = fifthProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item5.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart5.InnerRadius = 25;
chart5.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item5.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart5.InnerRadius = 25;
chart5.Series = pieChart;
}
break;
case 6:
if (!String.IsNullOrEmpty(sixthProduct.Text))
{
id = sixthProduct.Text;
firstValue = getValues(id);
difference = total - firstValue;
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item6.Text,
Values = new ChartValues<int> { firstValue },
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { difference },
Fill = totalColor,
});
chart6.InnerRadius = 25;
chart6.Series = pieChart;
}
else
{
Func<ChartPoint, string> labelPoint = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation);
SeriesCollection pieChart = new SeriesCollection();
pieChart.Add(
new PieSeries
{
Title = item6.Text,
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = product,
});
pieChart.Add(
new PieSeries
{
Title = "Other products",
Values = new ChartValues<int> { 0 },
DataLabels = true,
LabelPoint = labelPoint,
Fill = totalColor,
});
chart6.InnerRadius = 25;
chart6.Series = pieChart;
}
break;
}
}
}));
}
public int LoadShopSales()
{
salesAtShop = new SortedList<string, decimal>();
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Select Sum(total),Cast (date as DATE) from tblCart where status = 'SOLD' and MONTH(date) = @date " +
"and Year(date) = @dateYear and branchID = @branchID group by Cast(date as DATE)", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@date", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@dateYear", summaryDate.Value.Year.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (!String.IsNullOrEmpty(dr[0].ToString()) && !String.IsNullOrEmpty(dr[1].ToString()))
{
salesAtShop.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"), decimal.Parse(dr[0].ToString()));
dates.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"));
}
}
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int CancelledTransaction()
{
cancelled = new SortedList<string, decimal>();
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Select Sum(total), date from tblCart where status = 'CANCELLED' and MONTH(date) = @date and Year(date) = " +
"@dateYear and branchID = @branchID group by date", cn);
cm.Parameters.AddWithValue("@date", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@dateYear", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (!String.IsNullOrEmpty(dr[0].ToString()) && !String.IsNullOrEmpty(dr[1].ToString()))
{
if (!dates.Contains(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy")))
{
cancelled.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"), decimal.Parse(dr[0].ToString()));
dates.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"));
}
}
}
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int customerNumber()
{
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Declare @total int = case when (Select count(customerID) from tblCustomers where (Month(dateAdded) <= @dateMonth and YEAR(dateAdded) <= @dateYear) and " +
"(dateExit is Null or (MONTH(dateExit) > @dateMonth and Year(dateExit) > @dateYear)) and branchID = @branchID) is null then 0 else " +
"(Select count(customerID) from tblCustomers where (Month(dateAdded) <= @dateMonth and YEAR(dateAdded) <= @dateYear) and " +
"(dateExit is Null or (MONTH(dateExit) > @dateMonth and Year(dateExit) > @dateYear)) and branchID = @branchID) end Select @total", cn);
cm.Parameters.AddWithValue("@dateMonth", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@dateYear", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
customersNo.Text = dr[0].ToString();
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int soldOut()
{
try
{
summaryDate.Invoke(new Action(() =>
{
SortedList<string, string> counting = new SortedList<string, string>();
List<string> passed = new List<string>();
cn.Open();
cm = new SqlCommand("Select pcode,quantity from tblInventoryEntries where MONTH(date) = @month and " +
"Year(date) = @year and branchID = @branchID order by date desc", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (!passed.Contains(dr[0].ToString()) && !String.IsNullOrEmpty(dr[1].ToString()))
{
passed.Add(dr[0].ToString());
int soldout = int.Parse(dr[1].ToString());
if (soldout < 1)
{
counting.Add(dr[0].ToString(), dr[1].ToString());
}
}
}
dr.Close();
lblSoldOut.Text = counting.Count.ToString();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int invoiceGenerated()
{
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Select count(distinct invoiceid) from tblInvoice where MONTH(dateGenerated) = @month and " +
"Year(dateGenerated) = @year and branchID = @branchID", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
lblInvoice.Text = dr[0].ToString();
}
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int deliveries()
{
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Select count(deliveryID) from tblDeliveryHead where Month(dateInitiated) = @month and Year(dateInitiated) = @year " +
"and branchID = @branchID and status != 'CANCELLED'", cn);
cm.Parameters.AddWithValue("@month", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@year", summaryDate.Value.Year.ToString());
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
lblDeliveries.Text = dr[0].ToString();
}
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
public int LoadDeliveryTransactions()
{
deliverieSort = new SortedList<string, decimal>();
try
{
cn.Open();
summaryDate.Invoke(new Action(() =>
{
cm = new SqlCommand("Select Sum(totalCost), dateCompleted from tblDeliveryHead where status = 'DELIVERED' and " +
"MONTH(dateCompleted) = @date and Year(dateCompleted) = @dateYear and branchID = @branchID group by dateCompleted", cn);
cm.Parameters.AddWithValue("@branchID", Settings.Default.BranchID);
cm.Parameters.AddWithValue("@date", summaryDate.Value.Month.ToString());
cm.Parameters.AddWithValue("@dateYear", summaryDate.Value.Year.ToString());
cm.ExecuteNonQuery();
dr = cm.ExecuteReader();
while (dr.Read())
{
if (!String.IsNullOrEmpty(dr[0].ToString()) && !String.IsNullOrEmpty(dr[1].ToString()))
{
deliverieSort.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"), decimal.Parse(dr[0].ToString()));
if (!dates.Contains(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy")))
{
dates.Add(Convert.ToDateTime(dr[1].ToString()).ToString("dd MMMM,yyyy"));
}
}
}
dr.Close();
}));
cn.Close();
return 1;
}
catch
{
cn.Close();
return 0;
}
}
}
}