void DrawSalesChart() { //CLEARS ALL EXISTING SERIES while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); } Double cumulativeSalesFigure; Double cumulativePotential; int workingDaysInMonth; int workingDaysRemaining; int workingDayCounter; int daysToTenDayCutOff; Double currentPotential; SqlStatements sqlst = new SqlStatements(); var tuple = sqlst.GetSalesTarget(cmbMonth.Text, cmbYear.Text); int monthlyTarget = tuple.Item1; double dailyTarget = monthlyTarget / 20; string dailyTargetWording = Math.Round((dailyTarget / 1000), 2).ToString() + "k"; int monthlyTargetWithAdditionalDays = monthlyTarget; string dateWeekendCheck; DateTime weekendCheck; //ADDS SALES FIGURE SERIES var series = new Series("Traditional Sales"); var seriesTarget = new Series("Traditional Target"); var potentialSales = new Series(dailyTargetWording + " Per Day Target Line"); var currentPotentialSeries = new Series(dailyTargetWording + " Per Day from today onwards"); var tenDayCutOff = new Series("10 Day Cut Off"); var fifteenDayCutOff = new Series("15 Day Cut Off"); SqlConnection SqlCon = new SqlConnection(SqlStatements.ConnectionString); SqlCommand getSalesData = new SqlCommand(); getSalesData.Connection = SqlCon; getSalesData.CommandType = CommandType.Text; getSalesData.CommandText = "Select * from c_view_daily_output where date_completion >= @firstDate and date_completion <= @lastDate order by date_completion"; getSalesData.Parameters.AddWithValue("@firstDate", firstDayOfMonth); getSalesData.Parameters.AddWithValue("@lastDate", lastDayOfMonth); DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(getSalesData); adapter.Fill(dt); cumulativeSalesFigure = 0; cumulativePotential = 0; currentPotential = 0; workingDaysInMonth = 0; workingDaysRemaining = 0; progressBar1.Maximum = dt.Rows.Count * 2; foreach (DataRow row in dt.Rows) { progressBar1.Value = progressBar1.Value + 1; progressBar1.Update(); dateWeekendCheck = row["date_completion"].ToString(); weekendCheck = Convert.ToDateTime(dateWeekendCheck); //Totals up the sales figure cumulativeSalesFigure = cumulativeSalesFigure + Convert.ToDouble(row["door_value"].ToString()); if (Convert.ToDateTime(row["date_completion"]) <= DateTime.Today) { currentPotential = currentPotential + Convert.ToDouble(row["door_value"].ToString()); } else { if (DateSystem.IsPublicHoliday(weekendCheck, CountryCode.GB) || weekendCheck.DayOfWeek == DayOfWeek.Saturday || weekendCheck.DayOfWeek == DayOfWeek.Sunday) { currentPotential = currentPotential + 0; } else { currentPotential = currentPotential + dailyTarget; workingDaysRemaining += 1; } } //ONLY ADD THE CUMULATIVE POTENTIAL IF WEEKDAY ISNT WEEKEND if (DateSystem.IsPublicHoliday(weekendCheck, CountryCode.GB) || weekendCheck.DayOfWeek == DayOfWeek.Saturday || weekendCheck.DayOfWeek == DayOfWeek.Sunday) { cumulativePotential = cumulativePotential + 0; } else { cumulativePotential = cumulativePotential + dailyTarget; workingDaysInMonth += 1; } potentialSales.Points.AddXY(row["date_completion"], cumulativePotential); series.Points.AddXY(row["date_completion"], cumulativeSalesFigure); currentPotentialSeries.Points.AddXY(row["date_completion"], currentPotential); //NEED DYNAMIC GOALS seriesTarget.Points.AddXY(row["date_completion"], monthlyTarget); } //FILL TRADITIONAL TEXTBOXES _traditionalPotential = cumulativePotential; _traditionalSales = cumulativeSalesFigure; txtTraditionalSales.Text = "£" + cumulativeSalesFigure.ToString(); txtDailyTargetHit.Text = "£" + cumulativePotential.ToString(); txtDailyTargetHitFromNow.Text = "£" + currentPotential.ToString(); txtWorkingDays.Text = workingDaysInMonth.ToString(); //txtRemainingWorkingDays.Text = workingDaysRemaining.ToString(); //PLOTS THE 10 AND 15 DAY BOOKING IN CUT OFF POINTS. DataTable dt2 = new DataTable(); SqlDataAdapter adapter2 = new SqlDataAdapter(getSalesData); adapter.Fill(dt2); workingDayCounter = Convert.ToInt32(txtWorkingDays.Text.ToString()); //IF THE MONTH BEING VIEWED ISNT THE SAME AS THE CURRENT MONTH THEN TOTAL UP THE AMOUNT OF WORKING DAYS BETWEEN THE CURRENT DATE AND THE START OF THE MONTH BEING VIEWED daysToTenDayCutOff = 0; for (DateTime date = DateTime.Today; date.Date < firstDayOfMonth.Date; date = date.AddDays(1)) { if (DateSystem.IsPublicHoliday(date, CountryCode.GB) || date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday) { } else { daysToTenDayCutOff += 1; } } foreach (DataRow row in dt2.Rows) { dateWeekendCheck = row["date_completion"].ToString(); weekendCheck = Convert.ToDateTime(dateWeekendCheck); if (DateSystem.IsPublicHoliday(weekendCheck, CountryCode.GB) || weekendCheck.DayOfWeek == DayOfWeek.Saturday || weekendCheck.DayOfWeek == DayOfWeek.Sunday) { } else { if (DateTime.Today <= weekendCheck) { daysToTenDayCutOff += 1; } workingDayCounter = workingDayCounter - 1; switch (workingDayCounter) { case 10: tenDayCutOff.Points.AddXY(row["date_completion"], monthlyTarget); //SETS THE AMOUNT OF DAYS REMAINING UNTIL THE 10 DAY CUT OFF txtRemainingWorkingDays.Text = daysToTenDayCutOff.ToString(); break; case 15: fifteenDayCutOff.Points.AddXY(row["date_completion"], monthlyTarget); break; } } } //SETS THE BIG GOAL --- EVERYTHING WE CURRENTLY HAVE BOOKED IN + DAILY GOAL * BY THE AMOUNT OF DAYS TO THE TEN DAY CUT OFF txtBigGoal.Text = "£" + (cumulativeSalesFigure + (27500 * daysToTenDayCutOff)); //SETS THE INTERVAL TYPE chart1.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days; //Adds the series to the chart chart1.Series.Add(series); chart1.Series["Traditional Sales"].ChartType = SeriesChartType.Line; chart1.Series.Add(seriesTarget); chart1.Series["Traditional Target"].ChartType = SeriesChartType.Spline; chart1.Series.Add(potentialSales); chart1.Series[dailyTargetWording + " Per Day Target Line"].ChartType = SeriesChartType.Line; chart1.Series.Add(currentPotentialSeries); chart1.Series[dailyTargetWording + " Per Day from today onwards"].ChartType = SeriesChartType.Line; chart1.Series.Add(tenDayCutOff); chart1.Series["10 Day Cut Off"].ChartType = SeriesChartType.Stock; chart1.Series.Add(fifteenDayCutOff); chart1.Series["15 Day Cut Off"].ChartType = SeriesChartType.Stock; //Adds the series thicknesses and the axis intervals chart1.Series["Traditional Sales"].BorderWidth = 2; chart1.Series["Traditional Target"].BorderWidth = 2; chart1.Series[dailyTargetWording + " Per Day Target Line"].BorderWidth = 2; chart1.Series[dailyTargetWording + " Per Day from today onwards"].BorderWidth = 2; chart1.Series["10 Day Cut Off"].BorderWidth = 2; chart1.Series["10 Day Cut Off"].Color = Color.Black; chart1.Series["15 Day Cut Off"].BorderWidth = 2; chart1.Series["15 Day Cut Off"].Color = Color.Black; chart1.ChartAreas["ChartArea1"].AxisX.Interval = 1; chart1.ChartAreas["ChartArea1"].AxisY.Interval = 50000; chart1.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0; }
private void richTextBox1_TextChanged(object sender, EventArgs e) { SqlStatements sqlst = new SqlStatements(); sqlst.UpdateRecord(this.richTextBox1.Text, firstDayOfMonth); }
void SlimlineDrawSalesChart() { //CLEARS ALL EXISTING SERIES while (chrtSlimline.Series.Count > 0) { chrtSlimline.Series.RemoveAt(0); } Double cumulativeSalesFigure; Double cumulativePotential; Double currentPotential; string dateWeekendCheck; DateTime weekendCheck; SqlStatements sqlst = new SqlStatements(); var tuple = sqlst.GetSalesTarget(cmbMonth.Text, cmbYear.Text); int monthlyTarget = tuple.Item2; double dailyTarget = monthlyTarget / 20; string dailyTargetWording = Math.Round((dailyTarget / 1000), 2).ToString() + "k"; //ADDS SALES FIGURE SERIES var series = new Series("Slimline Sales"); var seriesTarget = new Series("Slimline Target"); var potentialSales = new Series(dailyTargetWording + " Per Day Target Line"); var currentPotentialSeries = new Series(dailyTargetWording + " Per Day from today onwards"); SqlConnection SqlCon = new SqlConnection(SqlStatements.ConnectionString); SqlCommand getSalesData = new SqlCommand(); getSalesData.Connection = SqlCon; getSalesData.CommandType = CommandType.Text; getSalesData.CommandText = "Select * from c_view_daily_output_slimline where date_completion >= @firstDate and date_completion <= @lastDate order by date_completion"; getSalesData.Parameters.AddWithValue("@firstDate", firstDayOfMonth); getSalesData.Parameters.AddWithValue("@lastDate", lastDayOfMonth); DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter(getSalesData); adapter.Fill(dt); cumulativeSalesFigure = 0; cumulativePotential = 0; currentPotential = 0; foreach (DataRow row in dt.Rows) { progressBar1.Value = progressBar1.Value + 1; progressBar1.Update(); cumulativeSalesFigure = cumulativeSalesFigure + Convert.ToDouble(row["door_value"].ToString()); dateWeekendCheck = row["date_completion"].ToString(); weekendCheck = Convert.ToDateTime(dateWeekendCheck); if (Convert.ToDateTime(row["date_completion"]) <= DateTime.Today) { currentPotential = currentPotential + Convert.ToDouble(row["door_value"].ToString()); } else { if (DateSystem.IsPublicHoliday(weekendCheck, CountryCode.GB) || weekendCheck.DayOfWeek == DayOfWeek.Saturday || weekendCheck.DayOfWeek == DayOfWeek.Sunday) { currentPotential = currentPotential + 0; } else { currentPotential = currentPotential + dailyTarget; } } //ONLY ADD THE CUMULATIVE POTENTIAL IF WEEKDAY ISNT WEEKEND if (DateSystem.IsPublicHoliday(weekendCheck, CountryCode.GB) || weekendCheck.DayOfWeek == DayOfWeek.Saturday || weekendCheck.DayOfWeek == DayOfWeek.Sunday) { cumulativePotential = cumulativePotential + 0; } else { cumulativePotential = cumulativePotential + dailyTarget; } potentialSales.Points.AddXY(row["date_completion"], cumulativePotential); series.Points.AddXY(row["date_completion"], cumulativeSalesFigure); currentPotentialSeries.Points.AddXY(row["date_completion"], currentPotential); //NEED DYNAMIC GOALS seriesTarget.Points.AddXY(row["date_completion"], monthlyTarget); } _slimlinePotential = cumulativePotential; _slimlineSales = cumulativeSalesFigure; txtSlimlineSales.Text = "£" + cumulativeSalesFigure.ToString(); txtDailyTargetHitSlimline.Text = "£" + cumulativePotential.ToString(); txtDailyTargetHitFromNowSlimline.Text = "£" + currentPotential.ToString(); chrtSlimline.ChartAreas[0].AxisX.IntervalType = DateTimeIntervalType.Days; chrtSlimline.Series.Add(series); chrtSlimline.Series["Slimline Sales"].ChartType = SeriesChartType.Line; chrtSlimline.Series.Add(seriesTarget); chrtSlimline.Series["Slimline Target"].ChartType = SeriesChartType.Line; chrtSlimline.Series.Add(potentialSales); chrtSlimline.Series[dailyTargetWording + " Per Day Target Line"].ChartType = SeriesChartType.Line; chrtSlimline.Series.Add(currentPotentialSeries); chrtSlimline.Series[dailyTargetWording + " Per Day from today onwards"].ChartType = SeriesChartType.Line; chrtSlimline.Series["Slimline Target"].BorderWidth = 2; chrtSlimline.Series["Slimline Sales"].BorderWidth = 2; chrtSlimline.Series[dailyTargetWording + " Per Day from today onwards"].BorderWidth = 2; chrtSlimline.Series[dailyTargetWording + " Per Day Target Line"].BorderWidth = 2; chrtSlimline.ChartAreas["ChartArea1"].AxisX.Interval = 1; chrtSlimline.ChartAreas["ChartArea1"].AxisY.Interval = 50000; chrtSlimline.ChartAreas[0].AxisX.MajorGrid.LineWidth = 0; }