Beispiel #1
0
        private void IncreaseQuantity_ContextMenu_Click(object sender, EventArgs e)
        {
            try
            {
                int ProductID = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductID"].Value.ToString());

                int Quantity = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value.ToString());

                // get được số lượng còn lại của sản phẩm này trong kho
                BUS_SanPham bus_Products = new BUS_SanPham();
                DataTable   dtProduct    = bus_Products.BUS_GetBasicInfo_Products(ProductID);

                if (dtProduct == null)
                {
                    return;
                }
                if (dtProduct.Rows.Count > 0)
                {
                    Quantity++;
                    int MaxProductQuantity = (int)dtProduct.Rows[0]["SoLuong"];
                    if (Quantity > MaxProductQuantity)
                    {
                        MessageBox.Show("Số lượng sản phẩm chọn lớn hơn số lượng còn lại trong kho!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        // cập nhật trong cart
                        Cart.IncreaseProductQuantityChosen(ProductID);

                        // update số lượng
                        dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value = Quantity;

                        // lấy giá 1 sản phẩm
                        int productPriceAfterSale = (int)dtgvShowProduct.SelectedRows[0].Cells["ProductPriceSale"].Value;

                        // update giá tiền
                        int TotalPrice = Quantity * productPriceAfterSale;

                        dtgvShowProduct.SelectedRows[0].Cells["ProductTotalCost"].Value = TotalPrice;

                        // update tổng tiền
                        txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency((MySupportMethods.StrCurrencyToInt(txbTotalCost.Text) + productPriceAfterSale).ToString());
                    }
                }
                else
                {
                    MessageBox.Show($"Sản phẩm có mã số {ProductID} không tồn tại!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            catch (Exception ex) { }
        }
        private void BtnAddImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlgOpen = new OpenFileDialog();

            dlgOpen.Filter = "Images(.jpg,.png)|*.png;*.jpg";

            if (dlgOpen.ShowDialog() == DialogResult.OK)
            {
                string filePath = dlgOpen.FileName;

                Image img = new Bitmap(filePath);

                Picimage.Image = MySupportMethods.ResizeImage(img, img.Width * 280 / img.Height, 280);
            }
        }
Beispiel #3
0
        private void RemoveProduct_ContextMenu_Click(object sender, EventArgs e)
        {
            // remove dòng hiện tại trong datagridview
            int index = dtgvShowProduct.SelectedRows[0].Index;

            int ProductID = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductID"].Value.ToString());

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

            int productPrice = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductPriceSale"].Value.ToString());

            int productQuantity = int.Parse(dtgvShowProduct.Rows[index].Cells["ProductQuantity"].Value.ToString());

            txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency((TotalCost - productPrice * productQuantity).ToString());

            dtgvShowProduct.Rows.RemoveAt(index);

            // xóa sản phẩm trong cart
            Cart.RemoveProduct(ProductID);
        }
Beispiel #4
0
        private void DecreaseQuantity_ContextMenu_Click(object sender, EventArgs e)
        {
            try
            {
                int ProductID = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductID"].Value.ToString());

                int Quantity = int.Parse(dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value.ToString());
                if (Quantity > 1)
                {
                    Quantity--;

                    // cập nhật trong cart
                    Cart.DecreaseProductQuantityChosen(ProductID);

                    // update số lượng
                    dtgvShowProduct.SelectedRows[0].Cells["ProductQuantity"].Value = Quantity;

                    // lấy giá 1 sản phẩm được giảm giá
                    int productPriceAfterSale = (int)dtgvShowProduct.SelectedRows[0].Cells["ProductPriceSale"].Value;

                    // update giá tiền
                    int TotalPrice = Quantity * productPriceAfterSale;

                    dtgvShowProduct.SelectedRows[0].Cells["ProductTotalCost"].Value = TotalPrice;

                    // update tổng tiền
                    txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency((MySupportMethods.StrCurrencyToInt(txbTotalCost.Text) - productPriceAfterSale).ToString());
                }
                else
                {
                    MessageBox.Show("Sản phẩm chỉ còn 1 cái!", "Thông báo",
                                    MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex) { }
        }
Beispiel #5
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;
            }
        }
Beispiel #6
0
        public UC_ViewProduct(int ID, string Name, int Price, Byte[] arrByteImage)
        {
            InitializeComponent();

            picImageProduct.SizeMode = PictureBoxSizeMode.CenterImage;

            _ProductID   = ID;
            _ProductName = Name;
            _Price       = Price;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(arrByteImage))
            {
                _Img = Image.FromStream(ms);
            }

            lbProductName.Text  = _ProductName;
            lbProductPrice.Text = MySupportMethods.StrMoneyToStrCurrency(_Price.ToString());
            //lbProductPrice.Text = _Price.ToString();
            picImageProduct.Image = MySupportMethods.ResizeImage(_Img, _Img.Width * 150 / _Img.Height, 150);

            // tìm khuyến mãi hiện tại có phần trăm lớn nhất
            // update giá
            BUS_KhuyenMai bus_Promotion = new BUS_KhuyenMai();

            DataTable dtPromotions = bus_Promotion.BUS_GetAllPromotionNow(DateTime.Now);

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

            if (dtPromotions.Rows.Count == 0)
            {
                // không có giảm giá
                lbProductPriceDiscount.Text    = lbProductPrice.Text;
                lbProductPriceDiscount.Visible = false;

                lbProductPrice.Font = new Font(lbProductPrice.Font, FontStyle.Regular);
            }
            else
            {
                //  nếu có khuyến mãi
                DTO_Promotion promotion = new DTO_Promotion()
                {
                    PromotionID          = (int)dtPromotions.Rows[0]["ID_KHUYENMAI"],
                    PromotionName        = dtPromotions.Rows[0]["TENKHUYENMAI"].ToString(),
                    PromotionPercent     = (int)dtPromotions.Rows[0]["PHANTRAM"],
                    PromotionMaxDiscount = (int)dtPromotions.Rows[0]["TIENTOIDA"],
                    PromotionBeginDate   = (DateTime)dtPromotions.Rows[0]["NGAYBATDAU"],
                    PromotionEndDate     = (DateTime)dtPromotions.Rows[0]["NGAYKETTHUC"],
                };

                if (DateTime.Now >= promotion.PromotionBeginDate && DateTime.Now <= promotion.PromotionEndDate)
                {
                    lbProductPriceDiscount.Visible = true;

                    lbProductPrice.Font = new Font(lbProductPrice.Font, FontStyle.Strikeout);

                    // remove tất cả các dấu chấm phân cách
                    int productPrice = MySupportMethods.StrCurrencyToInt(lbProductPrice.Text);

                    lbProductPriceDiscount.Text = MySupportMethods.StrMoneyToStrCurrency(promotion.CalcDiscount(productPrice).ToString());
                }
            }
        }
Beispiel #7
0
        public void ReloadForm()
        {
            //dtpkDateSell.Value = DateTime.Now;

            if (IsSelling == true)
            {
                // xóa dữ liệu trong datagridview
                dtgvShowProduct.Rows.Clear();

                // load du lieu tu Cart vao datagridview

                Dictionary <int, int> listProductID = Cart.GetListProductID();

                BUS_SanPham bus_Product = new BUS_SanPham();

                try
                {
                    int TotalCostForAll = 0;
                    foreach (var key in listProductID.Keys)
                    {
                        DataTable dtProductInfo = bus_Product.BUS_GetBasicInfo_Products(key);

                        if (dtProductInfo == null)
                        {
                            return;
                        }

                        if (dtProductInfo.Rows.Count > 0)
                        {
                            // lấy ảnh
                            Image img;
                            using (System.IO.MemoryStream ms = new System.IO.MemoryStream((Byte[])dtProductInfo.Rows[0]["HinhAnh"]))
                            {
                                img = Image.FromStream(ms);
                            }

                            Image ImgResize = MySupportMethods.ResizeImage(img, img.Width * 100 / img.Height, 100);

                            // lấy tên
                            string ProductName = dtProductInfo.Rows[0]["TenSP"].ToString();
                            // lấy đơn giá
                            int ProductPrice = int.Parse(dtProductInfo.Rows[0]["DonGia"].ToString());
                            // lấy số lượng
                            int ProductQuantityChosen = listProductID[key];



                            // đơn giá khuyến mãi
                            int ProductPriceSale = ProductPrice;
                            // lấy giá sau khuyến mãi
                            foreach (var promo in listPromotion)
                            {
                                ProductPriceSale = promo.CalcDiscount(ProductPriceSale);
                            }

                            // tổng tiền
                            int TotalCost = ProductPriceSale * ProductQuantityChosen;


                            // thêm row vào datagridview
                            dtgvShowProduct.Rows.Add(ImgResize, key, ProductName, ProductQuantityChosen, ProductPrice, ProductPriceSale, TotalCost);

                            TotalCostForAll += TotalCost;

                            // cập nhật tổng tiền
                            txbTotalCost.Text = MySupportMethods.StrMoneyToStrCurrency(TotalCostForAll.ToString());
                        }
                        else
                        {
                            MessageBox.Show($"Sản phẩm có mã số {key} không tồn tại!", "Thông báo",
                                            MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }
            else
            {
                //dtpkDateSell.Value = DateTime.Now;
            }
        }
Beispiel #8
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();
        }
        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 #10
0
        private void UC_KhuyenMai_Load(object sender, EventArgs e)
        {
            dtgvPromotion.Rows.Clear();

            // bật tắt các button
            BtnAddPromotion.Enabled    = true;
            BtnDeletePromotion.Enabled = false;
            BtnEditPromotion.Enabled   = false;

            // load danh sách các khuyến mãi chưa bị xóa vào datagridview

            DataTable dtPromotion = bus_Promotion.BUS_GetAllPromotionNotDeleted();

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

            foreach (DataRow row in dtPromotion.Rows)
            {
                dtgvPromotion.Rows.Add();
                int Index = dtgvPromotion.Rows.Count - 1;
                dtgvPromotion.Rows[Index].Cells["PromotionID"].Value = (int)row["ID_KHUYENMAI"];

                dtgvPromotion.Rows[Index].Cells["PromotionName"].Value = $"{row["TENKHUYENMAI"]} "
                                                                         + $"giảm giá {row["PHANTRAM"]}% tối đa {MySupportMethods.StrMoneyToStrCurrency(row["TIENTOIDA"].ToString())} đồng";

                dtgvPromotion.Rows[Index].Cells["PromotionPercent"].Value = (int)row["PHANTRAM"];

                dtgvPromotion.Rows[Index].Cells["PromotionMaxDiscount"].Value = (int)row["TIENTOIDA"];

                dtgvPromotion.Rows[Index].Cells["StartDay"].Value = (DateTime)row["NGAYBATDAU"];

                dtgvPromotion.Rows[Index].Cells["EndDay"].Value = (DateTime)row["NGAYKETTHUC"];
                // tính toán ngày còn lại

                DateTime now = DateTime.Now;
                if ((DateTime)dtgvPromotion.Rows[Index].Cells["EndDay"].Value < now)
                {
                    dtgvPromotion.Rows[Index].Cells["RemainDay"].Value = (int)0;
                }
                else
                {
                    dtgvPromotion.Rows[Index].Cells["RemainDay"].Value = (int)((DateTime)row["NGAYKETTHUC"] - now).TotalDays;
                }
            }

            // resize columns
            //dtgvPromotion.Columns["RemainDay"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCellsExceptHeader;
        }
Beispiel #11
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();
            }
        }