Exemple #1
0
        public void SetLaptop(Laptop laptop)
        {
            txtNameLaptop.Text = laptop.Name;
            ID = laptop.IDLaptop;
            for (int i = 0; i < cmbHangSX.Items.Count; i++)
            {
                if (laptop.Brand.Equals(cmbHangSX.GetItemText(cmbHangSX.Items[i])))
                {
                    cmbHangSX.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cmbMucDichSD.Items.Count; i++)
            {
                if (laptop.Funtion.Equals(cmbMucDichSD.GetItemText(cmbMucDichSD.Items[i])))
                {
                    cmbMucDichSD.SelectedIndex = i;
                }
            }

            txtGia.Text = laptop.Cost.ToString();

            for (int i = 0; i < cbmLoaiOCung.Items.Count; i++)
            {
                if (laptop.Hard.Equals(cbmLoaiOCung.GetItemText(cbmLoaiOCung.Items[i])))
                {
                    cbmLoaiOCung.SelectedIndex = i;
                }
            }
            txtRAM.Text              = laptop.Ram.ToString();
            txtDungLuong.Text        = laptop.Memory.ToString();
            txtKichThuocManHinh.Text = laptop.Desktop.ToString();
            txtCardManHinh.Text      = laptop.Card;
            if (laptop.Species == rdoOnBoard.Text)
            {
                rdoOnBoard.Checked = true;
            }

            if (laptop.Species == rdoRoi.Text)
            {
                rdoRoi.Checked = true;
            }

            if (laptop.Species == rdoRoiOn.Text)
            {
                rdoRoiOn.Checked = true;
            }

            for (int i = 0; i < cmbDoPhanGiai.Items.Count; i++)
            {
                if (laptop.Resolution.Equals(cmbDoPhanGiai.GetItemText(cmbDoPhanGiai.Items[i])))
                {
                    cmbDoPhanGiai.SelectedIndex = i;
                }
            }

            for (int i = 0; i < cmbCPU.Items.Count; i++)
            {
                if (laptop.CPU.Equals(cmbCPU.GetItemText(cmbCPU.Items[i])))
                {
                    cmbCPU.SelectedIndex = i;
                }
            }

            txtKhoiLuong.Text = laptop.Weight.ToString();
            txtSoLuong.Text   = laptop.Number.ToString();
            if (laptop.ImagePath != "")
            {
                picImage.Image = Image.FromFile(laptop.ImagePath);
            }
            ImagePath = laptop.ImagePath;
            chkNgungKinhDoanh.Checked = laptop.Status;
        }
Exemple #2
0
        private void Loaddata(string SQL)
        {
            //Tạo combobox chọn hãng sản xuất
            Db.Connection_Open();
            string           SQLBrand = "SELECT NameBrand FROM TbCategory";
            OleDbDataAdapter da       = new OleDbDataAdapter(SQLBrand, Db.Connec);
            DataTable        dt       = new DataTable();

            da.Fill(dt);
            Db.Connection_Close();
            cmbBrand.DataSource    = dt;
            cmbBrand.DisplayMember = "NameBrand";
            cmbBrand.ValueMember   = "NameBrand";

            //Hiển thị hình ảnh

            Db.Connection_Open();
            OleDbCommand    cmd = new OleDbCommand(SQL, Db.Connec);
            OleDbDataReader dr  = cmd.ExecuteReader();

            while (dr.Read())
            {
                ToolTip Tol    = new ToolTip();
                Laptop  laptop = new Laptop();
                laptop.ImagePath  = "";
                laptop.IDLaptop   = Convert.ToInt32(dr["ID"]);
                laptop.Name       = dr["Name"].ToString();
                laptop.Brand      = dr["Brand"].ToString();
                laptop.Funtion    = dr["Funt"].ToString();
                laptop.Cost       = Convert.ToInt32(dr["Cost"]);
                laptop.CPU        = dr["CPU"].ToString();
                laptop.Ram        = Convert.ToInt32(dr["RAM"]);
                laptop.Hard       = dr["Hard"].ToString();
                laptop.Memory     = Convert.ToInt32(dr["Memory"]);
                laptop.Desktop    = Convert.ToDouble(dr["Desktop"]);
                laptop.Species    = dr["Species"].ToString();
                laptop.Card       = dr["Card"].ToString();
                laptop.Resolution = dr["Resolution"].ToString();
                laptop.Weight     = Convert.ToDouble(dr["Weight"]);
                laptop.Number     = Convert.ToInt32(dr["Num"]);
                laptop.ImagePath  = dr["Img"].ToString();
                laptop.Status     = Convert.ToBoolean(dr["Status"]);
                //Tạo danh sách sản phẩm
                Panel panel = new Panel();
                panel.Size      = new Size(400, 400);
                panel.BackColor = Color.White;

                Label lblName = new Label();
                lblName.Text      = laptop.Name;
                lblName.Size      = new Size(400, 40);
                lblName.Location  = new Point(0, 220);
                lblName.TextAlign = ContentAlignment.MiddleCenter;
                lblName.Font      = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
                lblName.ForeColor = Color.BlueViolet;

                Label lblCost = new Label();
                if (laptop.Status)
                {
                    lblCost.Text = "Ngừng kinh doanh";
                }
                else
                {
                    lblCost.Text = String.Format("{0:0,0 VNĐ}", laptop.Cost);
                }

                lblCost.Size      = new Size(400, 40);
                lblCost.Location  = new Point(0, 260);
                lblCost.TextAlign = ContentAlignment.MiddleCenter;
                lblCost.Font      = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
                lblCost.ForeColor = Color.Blue;


                PictureBox pic = new PictureBox();
                pic.Size     = new Size(400, 200);
                pic.Location = new Point(0, 10);
                pic.SizeMode = PictureBoxSizeMode.Zoom;
                if (laptop.ImagePath != "")
                {
                    pic.Image = Image.FromFile(laptop.ImagePath);
                }
                pic.MouseLeave  += Pic_MouseLeave;
                pic.MouseMove   += Pic_MouseMove;
                Tol.ToolTipTitle = "Thông tin sản phẩm";
                Tol.ToolTipIcon  = ToolTipIcon.Info;
                Tol.SetToolTip(pic, laptop.ToString());


                //Tạo button bán
                var btnSell = new btnEditLaptop();
                btnSell.laptop    = laptop;
                btnSell.Text      = "Bán";
                btnSell.Location  = new Point(50, 350);
                btnSell.AutoSize  = true;
                btnSell.Font      = new Font("Microsoft Sans Serif", 20, FontStyle.Bold);
                btnSell.ForeColor = Color.Red;
                btnSell.Click    += BtnSell_Click;

                //Tạo button sửa thông tin
                var btnEdit = new btnEditLaptop();
                btnEdit.laptop    = laptop;
                btnEdit.Text      = "Sửa thông tin";
                btnEdit.Location  = new Point(190, 349);
                btnEdit.AutoSize  = true;
                btnEdit.Click    += BtnEdit_Click;
                btnEdit.Font      = new Font("Microsoft Sans Serif", 20, FontStyle.Bold);
                btnEdit.ForeColor = Color.Red;

                //Tạo label số lương lap top
                Label lblNumbe = new Label();
                lblNumbe.Text      = "Số lượng: ";
                lblNumbe.Font      = lblCost.Font = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
                lblNumbe.Location  = new Point(221, 310);
                lblNumbe.ForeColor = Color.Black;

                Label lblNumber = new Label();
                if (laptop.Number == 0)
                {
                    lblNumber.Text   = "Hết hàng";
                    lblNumbe.Visible = false;
                }

                else
                {
                    lblNumber.Text = laptop.Number + " chiếc";
                }

                lblNumber.Location  = new Point(318, 310);
                lblNumber.Font      = new Font("Microsoft Sans Serif", 12, FontStyle.Bold);
                lblNumber.ForeColor = Color.Cyan;

                panel.Controls.Add(pic);
                panel.Controls.Add(lblCost);
                panel.Controls.Add(lblName);
                panel.Controls.Add(btnEdit);
                panel.Controls.Add(btnSell);
                panel.Controls.Add(lblNumbe);
                panel.Controls.Add(lblNumber);

                flwHome.Controls.Add(panel);
            }

            Db.Connection_Close();
        }