Beispiel #1
0
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            ChartImportAndExport.Series.Clear();
            ChartImport.Series.Clear();
            ChartExport.Series.Clear();

            switch (CurrentSelected)
            {
            case 0:     // load theo năm
            {
                // kiểm tra điều kiện
                if (txbYear.Text == "")
                {
                    MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MySupportMethods.isNumberic(txbYear.Text) == false)
                {
                    MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbYear.Text) < 0)
                {
                    MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                // thống kê theo năm. giới hạn là 10 năm so với năm hiện tại
                int year = DateTime.Now.Year;

                if (year - int.Parse(txbYear.Text) > 10)
                {
                    MessageBox.Show("Chương trình chỉ lưu dữ liệu trong vòng 10 năm so với hiện tại!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // get giá trị nhập điên thoại
                DataTable dtPhoneImport = bus_Statistics.BUS_GetListProductImportByYear(int.Parse(txbYear.Text), 1);

                // get giá trị nhập laptop
                DataTable dtLaptopImport = bus_Statistics.BUS_GetListProductImportByYear(int.Parse(txbYear.Text), 2);

                // get giá trị xuất điện thoại
                DataTable dtPhoneExport = bus_Statistics.BUS_GetListProductExportByYear(int.Parse(txbYear.Text), 1);

                // get giá trị xuất laptop
                DataTable dtLaptopExport = bus_Statistics.BUS_GetListProductExportByYear(int.Parse(txbYear.Text), 2);

                // tính tổng tiền nhập điện thoại
                int TotalPhoneImportPrice = 0;
                foreach (DataRow row in dtPhoneImport.Rows)
                {
                    TotalPhoneImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền nhập laptop
                int TotalLaptopImportPrice = 0;
                foreach (DataRow row in dtLaptopImport.Rows)
                {
                    TotalLaptopImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền bán điện thoại
                int TotalPhoneExportPrice = 0;
                foreach (DataRow row in dtPhoneExport.Rows)
                {
                    TotalPhoneExportPrice += (int)row["TONGTIEN"];
                }

                // tính tổng tiền bán laptop
                int TotalLaptopExportPrice = 0;
                foreach (DataRow row in dtLaptopExport.Rows)
                {
                    TotalLaptopExportPrice += (int)row["TONGTIEN"];
                }

                int TotalImport = TotalPhoneImportPrice + TotalLaptopImportPrice;

                int TotalExport = TotalPhoneExportPrice + TotalLaptopExportPrice;

                // dựng biểu đồ cột
                string SeriesImport = "Tổng tiền nhập";
                ChartImportAndExport.Series.Add(SeriesImport);

                ChartImportAndExport.Series[SeriesImport].Points.AddXY(SeriesImport, TotalImport);
                ChartImportAndExport.Series[SeriesImport]["PointWidth"] = "0.5";

                string SeriesExport = "Tổng tiền bán";
                ChartImportAndExport.Series.Add(SeriesExport);

                ChartImportAndExport.Series[SeriesExport].Points.AddXY(SeriesExport, TotalExport);
                ChartImportAndExport.Series[SeriesExport]["PointWidth"] = "0.5";

                ChartImportAndExport.AlignDataPointsByAxisLabel();

                // dựng biểu đồ tròn:
                // biểu đồ tròn Nhập sản phẩm

                string SeriesImport_Pie = "Tiền nhập";
                ChartImport.Series.Add(SeriesImport_Pie);

                ChartImport.Series[SeriesImport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập điện thoại", TotalPhoneImportPrice);
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập laptop", TotalLaptopImportPrice);
                ChartImport.Series[SeriesImport_Pie].IsValueShownAsLabel = true;
                ChartImport.Series[SeriesImport_Pie].Label = "#PERCENT\n#VALX";

                // biểu đồ tròn Bán sản phẩm
                string SeriesExport_Pie = "Tiền nhập";
                ChartExport.Series.Add(SeriesExport_Pie);

                ChartExport.Series[SeriesExport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán điện thoại", TotalPhoneExportPrice);
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán laptop", TotalLaptopExportPrice);
                ChartExport.Series[SeriesExport_Pie].IsValueShownAsLabel = true;
                ChartExport.Series[SeriesExport_Pie].Label = "#PERCENT\n#VALX";
            }
            break;

            case 1:     // tháng
            {
                // kiểm tra điều kiện
                if (txbYear.Text == "" || txbMonth.Text == "")
                {
                    MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbMonth.Text) == false)
                {
                    MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbYear.Text) < 0 || int.Parse(txbMonth.Text) < 0)
                {
                    MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbMonth.Text) > 12)
                {
                    MessageBox.Show("Tháng chỉ từ 1 -> 12!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                // get giá trị nhập điên thoại
                DataTable dtPhoneImport = bus_Statistics.BUS_GetListProductImportByMonth(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), 1);

                // get giá trị nhập laptop
                DataTable dtLaptopImport = bus_Statistics.BUS_GetListProductImportByMonth(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), 2);

                // get giá trị xuất điện thoại
                DataTable dtPhoneExport = bus_Statistics.BUS_GetListProductExportByMonth(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), 1);

                // get giá trị xuất laptop
                DataTable dtLaptopExport = bus_Statistics.BUS_GetListProductExportByMonth(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), 2);

                // tính tổng tiền nhập điện thoại
                int TotalPhoneImportPrice = 0;
                foreach (DataRow row in dtPhoneImport.Rows)
                {
                    TotalPhoneImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền nhập laptop
                int TotalLaptopImportPrice = 0;
                foreach (DataRow row in dtLaptopImport.Rows)
                {
                    TotalLaptopImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền bán điện thoại
                int TotalPhoneExportPrice = 0;
                foreach (DataRow row in dtPhoneExport.Rows)
                {
                    TotalPhoneExportPrice += (int)row["TONGTIEN"];
                }

                // tính tổng tiền bán laptop
                int TotalLaptopExportPrice = 0;
                foreach (DataRow row in dtLaptopExport.Rows)
                {
                    TotalLaptopExportPrice += (int)row["TONGTIEN"];
                }

                int TotalImport = TotalPhoneImportPrice + TotalLaptopImportPrice;

                int TotalExport = TotalPhoneExportPrice + TotalLaptopExportPrice;

                // dựng biểu đồ cột
                string SeriesImport = "Tổng tiền nhập";
                ChartImportAndExport.Series.Add(SeriesImport);

                ChartImportAndExport.Series[SeriesImport].Points.AddXY(SeriesImport, TotalImport);
                ChartImportAndExport.Series[SeriesImport]["PointWidth"] = "0.5";

                string SeriesExport = "Tổng tiền bán";
                ChartImportAndExport.Series.Add(SeriesExport);

                ChartImportAndExport.Series[SeriesExport].Points.AddXY(SeriesExport, TotalExport);
                ChartImportAndExport.Series[SeriesExport]["PointWidth"] = "0.5";

                ChartImportAndExport.AlignDataPointsByAxisLabel();

                // dựng biểu đồ tròn:
                // biểu đồ tròn Nhập sản phẩm

                string SeriesImport_Pie = "Tiền nhập";
                ChartImport.Series.Add(SeriesImport_Pie);

                ChartImport.Series[SeriesImport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập điện thoại", TotalPhoneImportPrice);
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập laptop", TotalLaptopImportPrice);
                ChartImport.Series[SeriesImport_Pie].IsValueShownAsLabel = true;
                ChartImport.Series[SeriesImport_Pie].Label = "#PERCENT\n#VALX";

                // biểu đồ tròn Bán sản phẩm
                string SeriesExport_Pie = "Tiền nhập";
                ChartExport.Series.Add(SeriesExport_Pie);

                ChartExport.Series[SeriesExport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán điện thoại", TotalPhoneExportPrice);
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán laptop", TotalLaptopExportPrice);
                ChartExport.Series[SeriesExport_Pie].IsValueShownAsLabel = true;
                ChartExport.Series[SeriesExport_Pie].Label = "#PERCENT\n#VALX";
            }

            break;

            case 2:
            {
                // kiểm tra điều kiện
                if (txbYear.Text == "" || txbWeek.Text == "")
                {
                    MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbWeek.Text) == false)
                {
                    MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbYear.Text) < 0 || int.Parse(txbWeek.Text) < 0)
                {
                    MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbWeek.Text) > 52)
                {
                    MessageBox.Show("Tuần chỉ từ 1 -> 52!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                // get giá trị nhập điên thoại
                DataTable dtPhoneImport = bus_Statistics.BUS_GetListProductImportByWeek(int.Parse(txbYear.Text), int.Parse(txbWeek.Text), 1);

                // get giá trị nhập laptop
                DataTable dtLaptopImport = bus_Statistics.BUS_GetListProductImportByWeek(int.Parse(txbYear.Text), int.Parse(txbWeek.Text), 2);

                // get giá trị xuất điện thoại
                DataTable dtPhoneExport = bus_Statistics.BUS_GetListProductExportByWeek(int.Parse(txbYear.Text), int.Parse(txbWeek.Text), 1);

                // get giá trị xuất laptop
                DataTable dtLaptopExport = bus_Statistics.BUS_GetListProductExportByWeek(int.Parse(txbYear.Text), int.Parse(txbWeek.Text), 2);

                // tính tổng tiền nhập điện thoại
                int TotalPhoneImportPrice = 0;
                foreach (DataRow row in dtPhoneImport.Rows)
                {
                    TotalPhoneImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền nhập laptop
                int TotalLaptopImportPrice = 0;
                foreach (DataRow row in dtLaptopImport.Rows)
                {
                    TotalLaptopImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền bán điện thoại
                int TotalPhoneExportPrice = 0;
                foreach (DataRow row in dtPhoneExport.Rows)
                {
                    TotalPhoneExportPrice += (int)row["TONGTIEN"];
                }

                // tính tổng tiền bán laptop
                int TotalLaptopExportPrice = 0;
                foreach (DataRow row in dtLaptopExport.Rows)
                {
                    TotalLaptopExportPrice += (int)row["TONGTIEN"];
                }

                int TotalImport = TotalPhoneImportPrice + TotalLaptopImportPrice;

                int TotalExport = TotalPhoneExportPrice + TotalLaptopExportPrice;

                // dựng biểu đồ cột
                string SeriesImport = "Tổng tiền nhập";
                ChartImportAndExport.Series.Add(SeriesImport);

                ChartImportAndExport.Series[SeriesImport].Points.AddXY(SeriesImport, TotalImport);
                ChartImportAndExport.Series[SeriesImport]["PointWidth"] = "0.5";

                string SeriesExport = "Tổng tiền bán";
                ChartImportAndExport.Series.Add(SeriesExport);

                ChartImportAndExport.Series[SeriesExport].Points.AddXY(SeriesExport, TotalExport);
                ChartImportAndExport.Series[SeriesExport]["PointWidth"] = "0.5";

                ChartImportAndExport.AlignDataPointsByAxisLabel();

                // dựng biểu đồ tròn:
                // biểu đồ tròn Nhập sản phẩm

                string SeriesImport_Pie = "Tiền nhập";
                ChartImport.Series.Add(SeriesImport_Pie);

                ChartImport.Series[SeriesImport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập điện thoại", TotalPhoneImportPrice);
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập laptop", TotalLaptopImportPrice);
                ChartImport.Series[SeriesImport_Pie].IsValueShownAsLabel = true;
                ChartImport.Series[SeriesImport_Pie].Label = "#PERCENT\n#VALX";

                // biểu đồ tròn Bán sản phẩm
                string SeriesExport_Pie = "Tiền nhập";
                ChartExport.Series.Add(SeriesExport_Pie);

                ChartExport.Series[SeriesExport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán điện thoại", TotalPhoneExportPrice);
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán laptop", TotalLaptopExportPrice);
                ChartExport.Series[SeriesExport_Pie].IsValueShownAsLabel = true;
                ChartExport.Series[SeriesExport_Pie].Label = "#PERCENT\n#VALX";
            }
            break;

            case 3:
            {
                // kiểm tra điều kiện
                if (txbYear.Text == "" || txbMonth.Text == "" || txbDay.Text == "")
                {
                    MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbMonth.Text) == false ||
                    MySupportMethods.isNumberic(txbDay.Text) == false)
                {
                    MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbYear.Text) < 0 || int.Parse(txbMonth.Text) < 0 || int.Parse(txbDay.Text) < 0)
                {
                    MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                if (int.Parse(txbMonth.Text) > 12)
                {
                    MessageBox.Show("Tháng chỉ từ 1 -> 12!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                int[] arr = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

                int Day = int.Parse(txbDay.Text), Month = int.Parse(txbMonth.Text), Year = int.Parse(txbYear.Text);

                if ((Month != 2 && (Day > arr[Month] || Day < 0)) ||
                    (Year / 4 == 0 && Year / 100 != 0 && Month == 2 && (Day > 29 || Day < 0)) ||
                    (!(Year / 4 == 0 && Year / 100 != 0) && Month == 2 && (Day > 28 || Day < 0)))
                {
                    MessageBox.Show("Ngày nhập không đúng!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }


                // get giá trị nhập điên thoại
                DataTable dtPhoneImport    = bus_Statistics.BUS_GetListProductImportByDate(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), int.Parse(txbDay.Text), 1);

                // get giá trị nhập laptop
                DataTable dtLaptopImport   = bus_Statistics.BUS_GetListProductImportByDate(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), int.Parse(txbDay.Text), 2);

                // get giá trị xuất điện thoại
                DataTable dtPhoneExport    = bus_Statistics.BUS_GetListProductExportByDate(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), int.Parse(txbDay.Text), 1);

                // get giá trị xuất laptop
                DataTable dtLaptopExport   = bus_Statistics.BUS_GetListProductExportByDate(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), int.Parse(txbDay.Text), 2);

                // tính tổng tiền nhập điện thoại
                int TotalPhoneImportPrice  = 0;
                foreach (DataRow row in dtPhoneImport.Rows)
                {
                    TotalPhoneImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền nhập laptop
                int TotalLaptopImportPrice = 0;
                foreach (DataRow row in dtLaptopImport.Rows)
                {
                    TotalLaptopImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền bán điện thoại
                int TotalPhoneExportPrice  = 0;
                foreach (DataRow row in dtPhoneExport.Rows)
                {
                    TotalPhoneExportPrice += (int)row["TONGTIEN"];
                }

                // tính tổng tiền bán laptop
                int TotalLaptopExportPrice = 0;
                foreach (DataRow row in dtLaptopExport.Rows)
                {
                    TotalLaptopExportPrice += (int)row["TONGTIEN"];
                }

                int TotalImport            = TotalPhoneImportPrice + TotalLaptopImportPrice;

                int TotalExport = TotalPhoneExportPrice + TotalLaptopExportPrice;

                // dựng biểu đồ cột
                string SeriesImport = "Tổng tiền nhập";
                ChartImportAndExport.Series.Add(SeriesImport);

                ChartImportAndExport.Series[SeriesImport].Points.AddXY(SeriesImport, TotalImport);
                ChartImportAndExport.Series[SeriesImport]["PointWidth"] = "0.5";

                string SeriesExport = "Tổng tiền bán";
                ChartImportAndExport.Series.Add(SeriesExport);

                ChartImportAndExport.Series[SeriesExport].Points.AddXY(SeriesExport, TotalExport);
                ChartImportAndExport.Series[SeriesExport]["PointWidth"] = "0.5";

                ChartImportAndExport.AlignDataPointsByAxisLabel();

                // dựng biểu đồ tròn:
                // biểu đồ tròn Nhập sản phẩm

                string SeriesImport_Pie = "Tiền nhập";
                ChartImport.Series.Add(SeriesImport_Pie);

                ChartImport.Series[SeriesImport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập điện thoại", TotalPhoneImportPrice);
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập laptop", TotalLaptopImportPrice);
                ChartImport.Series[SeriesImport_Pie].IsValueShownAsLabel = true;
                ChartImport.Series[SeriesImport_Pie].Label = "#PERCENT\n#VALX";

                // biểu đồ tròn Bán sản phẩm
                string SeriesExport_Pie = "Tiền nhập";
                ChartExport.Series.Add(SeriesExport_Pie);

                ChartExport.Series[SeriesExport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán điện thoại", TotalPhoneExportPrice);
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán laptop", TotalLaptopExportPrice);
                ChartExport.Series[SeriesExport_Pie].IsValueShownAsLabel = true;
                ChartExport.Series[SeriesExport_Pie].Label = "#PERCENT\n#VALX";
            }
            break;

            case 4:
            {
                if (dtpkFrom.Value >= dtpkTo.Value)
                {
                    MessageBox.Show("Ngày bắt đầu và ngày kết thúc không trùng nhau!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // get giá trị nhập điên thoại
                DataTable dtPhoneImport = bus_Statistics.BUS_GetListProductImportByOption(dtpkFrom.Value, dtpkTo.Value, 1);

                // get giá trị nhập laptop
                DataTable dtLaptopImport = bus_Statistics.BUS_GetListProductImportByOption(dtpkFrom.Value, dtpkTo.Value, 2);

                // get giá trị xuất điện thoại
                DataTable dtPhoneExport = bus_Statistics.BUS_GetListProductExportByOption(dtpkFrom.Value, dtpkTo.Value, 1);

                // get giá trị xuất laptop
                DataTable dtLaptopExport = bus_Statistics.BUS_GetListProductExportByOption(dtpkFrom.Value, dtpkTo.Value, 2);

                // tính tổng tiền nhập điện thoại
                int TotalPhoneImportPrice = 0;
                foreach (DataRow row in dtPhoneImport.Rows)
                {
                    TotalPhoneImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền nhập laptop
                int TotalLaptopImportPrice = 0;
                foreach (DataRow row in dtLaptopImport.Rows)
                {
                    TotalLaptopImportPrice += (int)row["SOLUONG"] * (int)row["DONGIA"];
                }

                // tính tổng tiền bán điện thoại
                int TotalPhoneExportPrice = 0;
                foreach (DataRow row in dtPhoneExport.Rows)
                {
                    TotalPhoneExportPrice += (int)row["TONGTIEN"];
                }

                // tính tổng tiền bán laptop
                int TotalLaptopExportPrice = 0;
                foreach (DataRow row in dtLaptopExport.Rows)
                {
                    TotalLaptopExportPrice += (int)row["TONGTIEN"];
                }

                int TotalImport = TotalPhoneImportPrice + TotalLaptopImportPrice;

                int TotalExport = TotalPhoneExportPrice + TotalLaptopExportPrice;

                // dựng biểu đồ cột
                string SeriesImport = "Tổng tiền nhập";
                ChartImportAndExport.Series.Add(SeriesImport);

                ChartImportAndExport.Series[SeriesImport].Points.AddXY(SeriesImport, TotalImport);
                ChartImportAndExport.Series[SeriesImport]["PointWidth"] = "0.5";

                string SeriesExport = "Tổng tiền bán";
                ChartImportAndExport.Series.Add(SeriesExport);

                ChartImportAndExport.Series[SeriesExport].Points.AddXY(SeriesExport, TotalExport);
                ChartImportAndExport.Series[SeriesExport]["PointWidth"] = "0.5";

                ChartImportAndExport.AlignDataPointsByAxisLabel();

                // dựng biểu đồ tròn:
                // biểu đồ tròn Nhập sản phẩm

                string SeriesImport_Pie = "Tiền nhập";
                ChartImport.Series.Add(SeriesImport_Pie);

                ChartImport.Series[SeriesImport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập điện thoại", TotalPhoneImportPrice);
                ChartImport.Series[SeriesImport_Pie].Points.AddXY("Tiền nhập laptop", TotalLaptopImportPrice);
                ChartImport.Series[SeriesImport_Pie].IsValueShownAsLabel = true;
                ChartImport.Series[SeriesImport_Pie].Label = "#PERCENT\n#VALX";

                // biểu đồ tròn Bán sản phẩm
                string SeriesExport_Pie = "Tiền nhập";
                ChartExport.Series.Add(SeriesExport_Pie);

                ChartExport.Series[SeriesExport_Pie].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Pie;
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán điện thoại", TotalPhoneExportPrice);
                ChartExport.Series[SeriesExport_Pie].Points.AddXY("Tiền bán laptop", TotalLaptopExportPrice);
                ChartExport.Series[SeriesExport_Pie].IsValueShownAsLabel = true;
                ChartExport.Series[SeriesExport_Pie].Label = "#PERCENT\n#VALX";
            }

            break;
            }
        }
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            if (IsLoaded == true)
            {
                dtgvProducts.DataSource = null;
                LoadListProductExpire();

                ChartBestSellingProducts.Series.Clear();

                switch (CurrentSelected)
                {
                case 0:     // năm
                    // kiểm tra điều kiện
                    if (txbYear.Text == "")
                    {
                        MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (MySupportMethods.isNumberic(txbYear.Text) == false)
                    {
                        MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbYear.Text) < 0)
                    {
                        MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }


                    // load dữ liệu theo năm:
                    DataTable dtProduct_Year = bus_Statistics.BUS_GetProductsSoldByYear(int.Parse(txbYear.Text), (int)cmbCategories.SelectedValue);

                    if (dtProduct_Year == null)
                    {
                        MessageBox.Show("Có lỗi khi load dữ liệu!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    foreach (DataRow row in dtProduct_Year.Rows)
                    {
                        string SeriesName = row["TENSP"].ToString();
                        ChartBestSellingProducts.Series.Add(SeriesName);

                        ChartBestSellingProducts.Series[SeriesName]["PointWidth"] = "0.5";

                        int Quantity = (int)row["SOLUONG"];
                        ChartBestSellingProducts.Series[SeriesName].Points.AddXY(SeriesName, Quantity);
                    }

                    ChartBestSellingProducts.AlignDataPointsByAxisLabel();

                    ShowInfo_RightPanel();

                    break;

                case 1:     // tháng
                    // kiểm tra điều kiện
                    if (txbYear.Text == "" || txbMonth.Text == "")
                    {
                        MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbMonth.Text) == false)
                    {
                        MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbYear.Text) < 0 || int.Parse(txbMonth.Text) < 0)
                    {
                        MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbMonth.Text) > 12)
                    {
                        MessageBox.Show("Tháng chỉ từ 1 -> 12!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    // load dữ liệu theo tháng:
                    DataTable dtProduct_Month = bus_Statistics.BUS_GetProductsSoldByMonth(int.Parse(txbYear.Text), int.Parse(txbMonth.Text), (int)cmbCategories.SelectedValue);

                    if (dtProduct_Month == null)
                    {
                        MessageBox.Show("Có lỗi khi load dữ liệu!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    foreach (DataRow row in dtProduct_Month.Rows)
                    {
                        string SeriesName = row["TENSP"].ToString();
                        ChartBestSellingProducts.Series.Add(SeriesName);

                        ChartBestSellingProducts.Series[SeriesName]["PointWidth"] = "0.5";

                        int Quantity = (int)row["SOLUONG"];
                        ChartBestSellingProducts.Series[SeriesName].Points.AddXY(SeriesName, Quantity);
                    }

                    ChartBestSellingProducts.AlignDataPointsByAxisLabel();

                    ShowInfo_RightPanel();

                    break;

                case 2:     // tuần
                    // kiểm tra điều kiện
                    if (txbYear.Text == "" || txbWeek.Text == "")
                    {
                        MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbWeek.Text) == false)
                    {
                        MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbYear.Text) < 0 || int.Parse(txbWeek.Text) < 0)
                    {
                        MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbWeek.Text) > 52)
                    {
                        MessageBox.Show("Tuần chỉ từ 1 -> 52!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    // load dữ liệu theo tháng:
                    DataTable dtProduct_Week = bus_Statistics.BUS_GetProductsSoldByWeek(int.Parse(txbYear.Text), int.Parse(txbWeek.Text), (int)cmbCategories.SelectedValue);

                    if (dtProduct_Week == null)
                    {
                        MessageBox.Show("Có lỗi khi load dữ liệu!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    foreach (DataRow row in dtProduct_Week.Rows)
                    {
                        string SeriesName = row["TENSP"].ToString();
                        ChartBestSellingProducts.Series.Add(SeriesName);

                        ChartBestSellingProducts.Series[SeriesName]["PointWidth"] = "0.5";

                        int Quantity = (int)row["SOLUONG"];
                        ChartBestSellingProducts.Series[SeriesName].Points.AddXY(SeriesName, Quantity);
                    }

                    ChartBestSellingProducts.AlignDataPointsByAxisLabel();


                    ShowInfo_RightPanel();

                    break;

                case 3:     // ngày
                    // kiểm tra điều kiện
                    if (txbYear.Text == "" || txbMonth.Text == "" || txbDay.Text == "")
                    {
                        MessageBox.Show("Không được để trống các trường!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (MySupportMethods.isNumberic(txbYear.Text) == false || MySupportMethods.isNumberic(txbMonth.Text) == false ||
                        MySupportMethods.isNumberic(txbDay.Text) == false)
                    {
                        MessageBox.Show("Các trường chỉ được phép là số!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbYear.Text) < 0 || int.Parse(txbMonth.Text) < 0 || int.Parse(txbDay.Text) < 0)
                    {
                        MessageBox.Show("Các trường là số không âm!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (int.Parse(txbMonth.Text) > 12)
                    {
                        MessageBox.Show("Tháng chỉ từ 1 -> 12!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    int[] arr = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };

                    int Day = int.Parse(txbDay.Text), Month = int.Parse(txbMonth.Text), Year = int.Parse(txbYear.Text);

                    if ((Month != 2 && (Day > arr[Month] || Day < 0)) ||
                        (Year / 4 == 0 && Year / 100 != 0 && Month == 2 && (Day > 29 || Day < 0)) ||
                        (!(Year / 4 == 0 && Year / 100 != 0) && Month == 2 && (Day > 28 || Day < 0)))
                    {
                        MessageBox.Show("Ngày nhập không đúng!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }


                    // load dữ liệu theo tháng:
                    DataTable dtProduct_Day = bus_Statistics.BUS_GetProductsSoldByDay(Year, Month, Day, (int)cmbCategories.SelectedValue);

                    if (dtProduct_Day == null)
                    {
                        MessageBox.Show("Có lỗi khi load dữ liệu!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    foreach (DataRow row in dtProduct_Day.Rows)
                    {
                        string SeriesName = row["TENSP"].ToString();
                        ChartBestSellingProducts.Series.Add(SeriesName);

                        ChartBestSellingProducts.Series[SeriesName]["PointWidth"] = "0.5";

                        int Quantity = (int)row["SOLUONG"];
                        ChartBestSellingProducts.Series[SeriesName].Points.AddXY(SeriesName, Quantity);
                    }

                    ChartBestSellingProducts.AlignDataPointsByAxisLabel();

                    ShowInfo_RightPanel();

                    break;

                case 4:     // tùy chọn
                    if (dtpkFrom.Value >= dtpkTo.Value)
                    {
                        MessageBox.Show("Ngày bắt đầu và ngày kết thúc không trùng nhau!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    DataTable dtProduct_Option = bus_Statistics.BUS_GetProductSoldByOption(dtpkFrom.Value, dtpkTo.Value, (int)cmbCategories.SelectedValue);

                    if (dtProduct_Option == null)
                    {
                        MessageBox.Show("Có lỗi khi load dữ liệu!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    foreach (DataRow row in dtProduct_Option.Rows)
                    {
                        string SeriesName = row["TENSP"].ToString();
                        ChartBestSellingProducts.Series.Add(SeriesName);

                        ChartBestSellingProducts.Series[SeriesName]["PointWidth"] = "0.5";

                        int Quantity = (int)row["SOLUONG"];
                        ChartBestSellingProducts.Series[SeriesName].Points.AddXY(SeriesName, Quantity);
                    }

                    ChartBestSellingProducts.AlignDataPointsByAxisLabel();

                    ShowInfo_RightPanel();

                    break;
                }
            }
        }
Beispiel #3
0
        private void BtnPayment_Click(object sender, EventArgs e)
        {
            // thanh toán
            // kiểm tra các trường dữ liệu có bị rỗng hay không
            if (txbCustomerName.Text == "" || txbCustomerID.Text == "" || txbCustomerPhone.Text == "" || txbCustomerAddr.Text == "")
            {
                MessageBox.Show("Các trường dữ liệu không được để rỗng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra gridview có sản phẩm nào chưa
            if (dtgvShowProduct.Rows.Count == 0)
            {
                MessageBox.Show("Không có sản phẩm nào trong giỏ hàng!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // kiểm tra CMND và số điện thoại có kí tự "lạ" hay không
            if (MySupportMethods.isNumberic(txbCustomerID.Text) == false)
            {
                MessageBox.Show("Chứng minh nhân dân phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (MySupportMethods.isNumberic(txbCustomerPhone.Text) == false)
            {
                MessageBox.Show("Số điện thoại phải là chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult dlgRes = MessageBox.Show("Bạn có muốn thanh toán?", "Thông báo",
                                                  MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

            if (dlgRes == DialogResult.Cancel)
            {
                return;
            }

            // đóng gói thông tin khách hàng
            DTO_Customer customer = new DTO_Customer()
            {
                CustomerName    = txbCustomerName.Text,
                CustomerID      = txbCustomerID.Text,
                CustomerPhone   = txbCustomerPhone.Text,
                CustomerAddress = txbCustomerAddr.Text
            };

            // đóng gói lại các sản phẩm được chọn
            List <DTO_ProductChosen> listProductChosen = new List <DTO_ProductChosen>();

            foreach (DataGridViewRow row in dtgvShowProduct.Rows)
            {
                DTO_ProductChosen temp = new DTO_ProductChosen()
                {
                    ProductID       = (int)row.Cells["ProductID"].Value,
                    ProductPrice    = (int)row.Cells["ProductPrice"].Value,
                    ProductQuantity = (int)row.Cells["ProductQuantity"].Value
                };

                listProductChosen.Add(temp);
            }

            BUS_BanHang bus_SellProducts = new BUS_BanHang();

            int TotalPrice = MySupportMethods.StrCurrencyToInt(txbTotalCost.Text);

            // lưu dữ liệu vào database.
            bool res = bus_SellProducts.BUS_InsertNewOrder(customer, listProductChosen, dtpkDateSell.Value, TotalPrice, listPromotion);

            if (res == false)
            {
                MessageBox.Show("Lập phiếu thanh toán thất bại!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Lập phiếu thanh toán thành công!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            this.IsSelling = false;

            EmptyAllFields();

            TurnOnOffFieldsAnhButtons();
        }
Beispiel #4
0
        private void BtnEditPromotion_Click(object sender, EventArgs e)
        {
            // kiểm tra các trường có bị rỗng hay không
            if (txbPromotionName.Text.Length == 0 || txbPromotionPercent.Text.Length == 0 || txbPromotionMaxDiscount.Text.Length == 0)
            {
                MessageBox.Show("Không được để trống các trường dữ liệu!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra trong text box có toàn chữ số hay không
            if (MySupportMethods.isNumberic(txbPromotionPercent.Text) == false)
            {
                MessageBox.Show("Phần trăm khuyến mãi chỉ bao gồm các chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra trong text box có toàn chữ số hay không
            if (MySupportMethods.isNumberic(txbPromotionMaxDiscount.Text) == false)
            {
                MessageBox.Show("Số tiền khuyến mãi tối đa chỉ bao gồm các chữ số!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // kiểm tra xem phần trăm có nằm trong khoảng từ 0 đến 100 hay không?
            if (int.Parse(txbPromotionPercent.Text) < 0 || int.Parse(txbPromotionPercent.Text) > 100)
            {
                MessageBox.Show("Phần trăm khuyến mãi phải nằm trong đoạn [0, 100]", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // đóng gói thông tin từ text box
            DTO_Promotion promotion = new DTO_Promotion()
            {
                PromotionID          = (int)dtgvPromotion.SelectedRows[0].Cells["PromotionID"].Value,
                PromotionName        = txbPromotionName.Text,
                PromotionMaxDiscount = int.Parse(txbPromotionMaxDiscount.Text),
                PromotionPercent     = int.Parse(txbPromotionPercent.Text),
                PromotionBeginDate   = dtpkStartDay.Value,
                PromotionEndDate     = dtpkEndDay.Value
            };

            // lưu thông tin xuống db

            bool res = bus_Promotion.BUS_EditPromotion(promotion);

            if (res == false)
            {
                MessageBox.Show("Sửa khuyến mãi thất bại!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                MessageBox.Show("Sửa khuyến mãi thành công!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.XoaDuLieu();
                this.ReloadForm();
            }
        }