public bool DAL_UpdateProductInfoAndProfile(DTO_Product product, DTO_ProductProfile productProfile)
        {
            try
            {
                _conn.Open();

                using (SqlCommand cmd = new SqlCommand("UpdateThongTinVaCauHinhSanPham", _conn)
                {
                    CommandType = CommandType.StoredProcedure,
                })
                {
                    // product
                    cmd.Parameters.AddWithValue("@MaSP", product.ID);
                    cmd.Parameters.AddWithValue("@MaLoai", product.CategoryID);
                    cmd.Parameters.AddWithValue("@MaHangSX", product.ManufacturerID);
                    cmd.Parameters.AddWithValue("@TenSP", product.ProductName);
                    cmd.Parameters.AddWithValue("@DonGia", product.ProductPrice);
                    cmd.Parameters.AddWithValue("@HinhAnh", product.ProductImage);

                    // product profile
                    cmd.Parameters.AddWithValue("@Id_ChiTietCauHinh", productProfile.IDProductProfile);
                    cmd.Parameters.AddWithValue("@CPU", productProfile.CPU);
                    cmd.Parameters.AddWithValue("@GPU", productProfile.GPU);
                    cmd.Parameters.AddWithValue("@RAM", productProfile.RAM);
                    cmd.Parameters.AddWithValue("@BoNho", productProfile.Storage);
                    cmd.Parameters.AddWithValue("@ManHinh", productProfile.Screen);
                    cmd.Parameters.AddWithValue("@Camera", productProfile.Camera);
                    cmd.Parameters.AddWithValue("@Pin", productProfile.PIN);
                    cmd.Parameters.AddWithValue("@HeDieuHanh", productProfile.OS);
                    cmd.Parameters.AddWithValue("@Khac", productProfile.More);

                    if (cmd.ExecuteNonQuery() <= 0)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                _conn.Close();
            }
            return(true);
        }
        public bool DAL_AddProductProfile(DTO_ProductProfile productProfile)
        {
            try
            {
                using (SqlCommand cmd = new SqlCommand("ThemChiTietCauHinhSanPham", _conn)
                {
                    CommandType = CommandType.StoredProcedure,
                })
                {
                    _conn.Open();

                    cmd.Parameters.AddWithValue("@MaSP", productProfile.ProductID);
                    cmd.Parameters.AddWithValue("@CPU", productProfile.CPU);
                    cmd.Parameters.AddWithValue("@GPU", productProfile.GPU);
                    cmd.Parameters.AddWithValue("@RAM", productProfile.RAM);
                    cmd.Parameters.AddWithValue("@BoNho", productProfile.Storage);
                    cmd.Parameters.AddWithValue("@ManHinh", productProfile.Screen);
                    cmd.Parameters.AddWithValue("@Camera", productProfile.Camera);
                    cmd.Parameters.AddWithValue("@Pin", productProfile.PIN);
                    cmd.Parameters.AddWithValue("@HeDieuHanh", productProfile.OS);
                    cmd.Parameters.AddWithValue("@Khac", productProfile.More);

                    if (cmd.ExecuteNonQuery() <= 0)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                _conn.Close();
            }
            return(true);
        }
示例#3
0
        private void BtnApplyEdit_Click(object sender, EventArgs e)
        {
            // kiểm tra các trường thông tin cơ bản có bị trống hay không
            if (txbProductName.Text == "" || txbProductPrice.Text == "" || txbProductQuantity.Text == "")
            {
                MessageBox.Show("Không được để trống các trường dữ liệu cơ bản!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            // kiểm tra ở các ô chỉ toàn số có kí tự lạ hay không
            if (isNumberic(txbProductPrice.Text) == false)
            {
                MessageBox.Show("Đơn giá chỉ bao gồm các chữ số!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }

            if (isNumberic(txbProductQuantity.Text) == false)
            {
                MessageBox.Show("Số lượng chỉ bao gồm các chữ số!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }


            if (txbCamera.Text == "" || txbCPU.Text == "" || txbGPU.Text == "" || txbMore.Text == "" ||
                txbOS.Text == "" || txbPin.Text == "" || txbRAM.Text == "" || txbScreen.Text == "" || txbStorage.Text == "")
            {
                DialogResult dlgResult = MessageBox.Show("Có một số thông tin về Thông số kĩ thuật còn trống!\n Bạn có muốn tiếp tục?",
                                                         "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                if (dlgResult == DialogResult.Cancel)   // nếu người dùng khong muốn tiếp tục
                {
                    return;
                }
            }

            // get được ID_MASP, get ID_CHITIETCAUHINH
            // ghi đè thông tin dựa vào 2 ID này
            Byte[] arrImage;
            Bitmap BitImg = new Bitmap(Picimage.Image);

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                Image img = BitImg;
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                arrImage = ms.ToArray();
            }

            DTO_Product product = new DTO_Product()
            {
                ID             = this._ProductID,
                CategoryID     = (int)cmbCategories.SelectedValue,
                ManufacturerID = (int)cmbManufacturer.SelectedValue,
                ProductName    = txbProductName.Text,
                ProductPrice   = int.Parse(txbProductPrice.Text),
                ProductImage   = arrImage
            };

            DTO_ProductProfile productProfile = new DTO_ProductProfile()
            {
                IDProductProfile = this._ID_ProductProfile,
                CPU     = txbCPU.Text,
                GPU     = txbGPU.Text,
                RAM     = txbRAM.Text,
                Storage = txbStorage.Text,
                Screen  = txbScreen.Text,
                Camera  = txbCamera.Text,
                PIN     = txbPin.Text,
                OS      = txbOS.Text,
                More    = txbMore.Text
            };

            bool result = bus_Product.BUS_UpdateProductInfoAndProfile(product, productProfile);

            if (result == false)
            {
                MessageBox.Show("Không thể sửa thông tin sản phẩm!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            MessageBox.Show("Sửa thông tin sản phẩm thành công!", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#4
0
 public bool BUS_UpdateProductInfoAndProfile(DTO_Product product, DTO_ProductProfile productProfile)
 {
     return(dal_Products.DAL_UpdateProductInfoAndProfile(product, productProfile));
 }
示例#5
0
 public bool BUS_AddProductProfile(DTO_ProductProfile productProfile)
 {
     return(dal_Products.DAL_AddProductProfile(productProfile));
 }
        private void BtnAddProduct_Click(object sender, EventArgs e)
        {
            // kiểm tra các trường thông tin cơ bản có bị trống hay không
            if (txbProductName.Text == "" || txbProductPrice.Text == "" || txbProductQuantity.Text == "")
            {
                MessageBox.Show("Không được để trống các trường dữ liệu cơ bản!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }
            // kiểm tra ở các ô chỉ toàn số có kí tự lạ hay không
            if (isNumberic(txbProductPrice.Text) == false)
            {
                MessageBox.Show("Đơn giá chỉ bao gồm các chữ số!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }

            if (isNumberic(txbProductQuantity.Text) == false)
            {
                MessageBox.Show("Số lượng chỉ bao gồm các chữ số!",
                                "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                return;
            }


            if (txbCamera.Text == "" || txbCPU.Text == "" || txbGPU.Text == "" || txbMore.Text == "" ||
                txbOS.Text == "" || txbPin.Text == "" || txbRAM.Text == "" || txbScreen.Text == "" || txbStorage.Text == "")
            {
                DialogResult dlgResult = MessageBox.Show("Có một số thông tin về Thông số kĩ thuật còn trống!\n Bạn có muốn tiếp tục?",
                                                         "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

                if (dlgResult == DialogResult.Cancel)   // nếu người dùng khong muốn tiếp tục
                {
                    return;
                }
            }

            // thực hiện việc thêm 1 sản phẩm mới vào database

            // chuyển từ image sang byte []

            Byte[] arrImage;
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                Image img = Picimage.Image;
                img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                arrImage = ms.ToArray();
            }

            // lưu thông tin cơ bản vào DTO

            DTO_Product product = new DTO_Product()
            {
                CategoryID      = (int)cmbCategories.SelectedValue,
                ManufacturerID  = (int)cmbManufacturer.SelectedValue,
                ProductImage    = arrImage,
                ProductName     = txbProductName.Text,
                ProductPrice    = int.Parse(txbProductPrice.Text.ToString()),
                ProductQuantity = int.Parse(txbProductQuantity.Text.ToString())
            };

            // lưu DTO product xuống database
            bool resultAdd = bus_Product.BUS_AddNewProduct(product);

            if (resultAdd == false)
            {
                MessageBox.Show("Thêm không thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // get được ID của product vừa được lưu vào bảng SANPHAM dựa vào tên và ID

            DataTable dtProductInfo = bus_Product.BUS_GetProductInfoByIDAndName(txbProductName.Text, (int)cmbCategories.SelectedValue);

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

            if (dtProductInfo.Rows.Count > 0)
            {
                try
                {
                    // lưu thông số cấu hình vào DTO
                    DTO_ProductProfile productProfile = new DTO_ProductProfile()
                    {
                        ProductID = int.Parse(dtProductInfo.Rows[0]["ID_MASP"].ToString()),
                        CPU       = txbCPU.Text,
                        GPU       = txbGPU.Text,
                        RAM       = txbRAM.Text,
                        Storage   = txbStorage.Text,
                        Screen    = txbScreen.Text,
                        Camera    = txbCamera.Text,
                        PIN       = txbPin.Text,
                        OS        = txbOS.Text,
                        More      = txbMore.Text
                    };

                    // lưu DTO xuống database
                    bool resultAddProductProfile = bus_Product.BUS_AddProductProfile(productProfile);

                    if (resultAddProductProfile == false)
                    {
                        MessageBox.Show("Thêm không thành công!", "Thông báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                catch (Exception ex) { }
            }
            else
            {
                MessageBox.Show("Không thể thêm thông số kĩ thuật!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            // thêm dữ liệu vào lịch sử nhập kho
            // TẠI ĐÂY PRODUCT.QUANTITY = 0 VÌ SỐ LƯỢNG SẢN PHẨM THÊM VÀO TRƯỚC ĐÓ ĐÃ CÓ TRONG SANPHAM.
            // SAU KHI THỰC HIỆN LỆNH NÀY SẼ LẤY TRONG SẢN PHẨM + SỐ TRUYỀN VÀO.
            // VÌ VẬY THAM SỐ PRODUCT.QUANTITY = 0 SẼ KHÔNG BỊ CỘNG DỒN LÊN.
            bool result = bus_Product.BUS_AddProduct_History(int.Parse(dtProductInfo.Rows[0]["ID_MASP"].ToString()), product.ProductPrice, 0, DateTime.Now);

            if (result == false)
            {
                MessageBox.Show("Không thể thêm lịch sử nhập kho!", "Thông báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }


            MessageBox.Show("Thêm sản phẩm thành công!", "Thông báo",
                            MessageBoxButtons.OK, MessageBoxIcon.Information);

            // khi thêm sp thành công thì gửi 1 sự kiện reload lại tại form cha
            ReloadData?.Invoke(this, EventArgs.Empty);

            this.Close();
        }