private void btn_loadChart_Click(object sender, EventArgs e) { //Clear Biểu đồ foreach (var series in chart1.Series) { series.Points.Clear(); } //Xử lý đọc doanh số từ NSX if (radiobtn_producer.Checked) { if (radiobtn_time.Checked) { if (dropdown_type.selectedValue == "Day") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBYDAY(bunifuDatepicker1.Value.Date).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } else if (dropdown_type.selectedValue == "Month") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString()).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString()).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBY2DAYS(bunifuDatepicker3.Value.Date, bunifuDatepicker2.Value.Date).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } } //Xử lý đọc sản phẩm từ NSX else { if (radiobtn_time.Checked) { if (dropdown_type.selectedValue == "Day") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCTBYDAY(bunifuDatepicker1.Value.Date, dropdown_producer.selectedValue).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total); } } } else if (dropdown_type.selectedValue == "Month") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCTBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString(), dropdown_producer.selectedValue).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total); } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCTBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString(), dropdown_producer.selectedValue).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total); } } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCTBY2DAYS(bunifuDatepicker3.Value.Date, bunifuDatepicker2.Value.Date, dropdown_producer.selectedValue).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.NAME_PRODUCT, i.Total); } } } } }
private void bunifuImageButton1_Click(object sender, EventArgs e) { foreach (var series in chart2.Series) { series.Points.Clear(); } if (radiobtn_time2.Checked) { if (dropdown_type2.selectedValue == "Day") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { int total = db.BILLs.Where(x => x.DATE_TIME == bunifuDatepicker6.Value.Date).Sum(x => x.PRICE); var temp = db.GETREVENUEBYDAY(bunifuDatepicker6.Value.Date).ToList(); int purchase = 0; foreach (var i in temp) { purchase = purchase + (i.PURCHASE_PRICE * (int)i.Amount); } lstSoBanNgay.Add(new KeyValuePair <DateTime, int>(bunifuDatepicker6.Value.Date, purchase)); chart2.Series["SELL"].Points.AddXY(lstSoBanNgay[0].Key.ToString("dd - MM - yy"), total); chart2.Series["PURCHASE"].Points.AddXY(lstSoBanNgay[0].Key.ToString("dd - MM - yy"), lstSoBanNgay[0].Value); } } else if (dropdown_type.selectedValue == "Month") { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBYMONTH(bunifuDatepicker1.Value.Date.Month.ToString(), bunifuDatepicker1.Value.Date.Year.ToString()).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETPRODUCERBYYEAR(bunifuDatepicker1.Value.Date.Year.ToString()).ToList(); foreach (var i in temp) { chart1.Series["Value"].Points.AddXY(i.PRODUCER, i.Total); } } } } else { using (DataStoreManagementDataContext db = new DataStoreManagementDataContext()) { var temp = db.GETREVENUEBY2DAY(bunifuDatepicker4.Value.Date, bunifuDatepicker5.Value.Date).ToList(); int total = 0; int purchase = 0; for (var day2 = bunifuDatepicker4.Value.Date; day2 <= bunifuDatepicker5.Value.Date; day2 = day2.AddDays(1)) { if (db.BILLs.Where(x => x.DATE_TIME == day2.Date).ToList().Count() == 0) { total = 0; } else { total = db.BILLs.Where(x => x.DATE_TIME == day2.Date).Sum(x => x.PRICE); var temp2 = db.GETREVENUEBYDAY(day2.Date).ToList(); purchase = 0; foreach (var i in temp2) { purchase = purchase + (i.PURCHASE_PRICE * (int)i.Amount); } } chart2.Series["SELL"].Points.AddXY(day2.Date.ToString("dd - MM - yy"), total); chart2.Series["PURCHASE"].Points.AddXY(day2.Date.ToString("dd - MM - yy"), purchase); } } } }