예제 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            var isYes = MessageBox.Show(
                "Bạn có muốn xóa Loại Này Không?"
                , "Thông Báo"
                , MessageBoxButtons.YesNo,
                MessageBoxIcon.Warning
                );

            if (isYes != DialogResult.Yes)
            {
                // không dồng ý
                return;
            }
            // đồng ý
            Loai loaiXoa = _dataBase.Loais
                           .FirstOrDefault(
                item => item.MaLoai.ToString() == txtMaLoai.Text);

            _dataBase.Loais.DeleteOnSubmit(loaiXoa);
            _dataBase.SubmitChanges();
            //cap nhat danh sách
            dgvDanhSachLoai.DataSource =
                _dataBase.Loais.ToList();
            SetInputForm(new Loai());
        }
예제 #2
0
 private void SetInputForm(Loai loai)
 {
     txtMaLoai.Text  = loai.MaLoai.ToString();
     txtTenLoai.Text = loai.TenLoai;
     txtMoTa.Text    = loai.MoTa;
     txtHinhAnh.Text = loai.Hinh;
 }
        private void dgvDanhSachLoai_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int  maLoai  = int.Parse(dgvDanhSachLoai.Rows[e.RowIndex].Cells["MaLoai"].Value.ToString());
            Loai loaiSua = _dataBase.Loais.FirstOrDefault(item => item.MaLoai == maLoai);

            SetInputForm(loaiSua);
        }
예제 #4
0
        private void cbbLoai_SelectedIndexChanged(object sender, EventArgs e)
        {
            Loai loaiChon = (Loai)cbbLoai.SelectedItem;

            dgvDanhSachHangHoa.DataSource =
                _dataBase.HangHoas.Where(
                    item => item.MaLoai == loaiChon.MaLoai
                    ).Select(
                    hh => new
            {
                MaHH      = hh.MaHH,
                TenHH     = hh.TenHH,
                MoTaDonVi = hh.MoTaDonVi,
                MaNCC     = hh.MaNCC,
                TenCongTy = hh.NhaCungCap.TenCongTy,
                DonGia    = hh.DonGia,
                Hinh      = hh.Hinh,
                SoLanXem  = hh.SoLanXem,
                MaLoai    = hh.MaLoai,
                TenLoai   = hh.Loai.TenLoai,
                NgaySX    = hh.NgaySX,
                MoTa      = hh.MoTa,
            }
                    ).ToList();
        }
예제 #5
0
        private void dgvDanhSachLoai_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            // lấy ma loại của dòngclick
            int maLoai = int.Parse(dgvDanhSachLoai.Rows[e.RowIndex].Cells["MaLoai"].Value.ToString());
            // tim loai theo
            Loai loaiSua = _dataBase.Loais.FirstOrDefault(item => item.MaLoai == maLoai);

            // set input form
            SetInputForm(loaiSua);
        }
예제 #6
0
        private void LoadDanhSachLoai()
        {
            List <Loai> dsLoai   = _dataBase.Loais.ToList();
            Loai        loaiChon = new Loai()
            {
                MaLoai  = 0,
                TenLoai = "Chọn loại hàng hóa"
            };

            dsLoai.Insert(0, loaiChon);
            cbbLoai.DataSource    = dsLoai;
            cbbLoai.DisplayMember = "TenLoai";
            cbbLoai.ValueMember   = "MaLoai";
        }
예제 #7
0
        private HangHoa GetInputForm()
        {
            if (txtTenHH.Text == "")
            {
                throw new Exception("Tên Hàng Hóa Không Để Trống");
            }
            if (txtDonGia.Text == "")
            {
                throw new Exception("Đơn Giá Không Để Trống");
            }
            string hinhAnh = "";

            if (openFileDialog1.FileName != null)
            {
                string fileName
                    = string.Format("{0}/{1}", Application.StartupPath
                                    , txtTenHH.Text + ".jpg");
                Bitmap hinhBitMap = new Bitmap(pictureBox1.Image);
                pictureBox1.Image.Dispose();
                File.Delete(fileName);
                hinhBitMap.Save(fileName);
                hinhAnh = fileName;
            }

            double donGia;

            double.TryParse(txtDonGia.Text, out donGia);
            double giamGia;

            double.TryParse(txtDonGia.Text, out giamGia);
            Loai       loaiHH = (Loai)cbbLoai.SelectedItem;
            NhaCungCap nccHH  = (NhaCungCap)cbbNCC.SelectedItem;
            DateTime   ngaySX = dtpNgaySanXuat.Value;

            return(new HangHoa()
            {
                MaHH = this.maHangHoa,
                TenHH = txtTenHH.Text,
                DonGia = donGia,
                GiamGia = giamGia,
                NgaySX = ngaySX,
                MoTaDonVi = txtMoTaDonVi.Text,
                MoTa = txtMoTa.Text,
                MaLoai = loaiHH.MaLoai,
                MaNCC = nccHH.MaNCC,
                Hinh = hinhAnh,
                SoLanXem = 0,
            });
        }
예제 #8
0
 private void btnThemLoai_Click(object sender, EventArgs e)
 {
     try
     {
         Loai loaiThem = GetInputForm();
         _dataBase.Loais.InsertOnSubmit(loaiThem);
         _dataBase.SubmitChanges();
         dgvDanhSachLoai.DataSource = _dataBase.Loais.ToList();
         SetInputForm(new Loai());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void btnSua_Click(object sender, EventArgs e)
 {
     try
     {
         Loai loaiSua = GetInputForm();
         Loai loaiTim = _dataBase.Loais.FirstOrDefault(item => item.MaLoai == loaiSua.MaLoai);
         loaiTim.TenLoai = loaiSua.TenLoai;
         loaiTim.MoTa    = loaiSua.MoTa;
         loaiTim.Hinh    = loaiSua.Hinh;
         _dataBase.SubmitChanges();
         dgvDanhSachLoai.DataSource = _dataBase.Loais.ToList();
         SetInputForm(new Loai());
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #10
0
        private HangHoa GetInputForm()
        {
            if (txtTenHangHoa.Text == "")
            {
                throw new Exception("Tên hàng hóa không được để trống");
            }
            if (txtDonGia.Text == "")
            {
                throw new Exception("Đơn giá không được để trống");
            }
            string hinhAnh = "";

            if (pictureBox1.Image != null)
            {
                string fileName = string.Format("{0}/{1}", Application.StartupPath, txtTenHangHoa.Text + ".jpg");
                pictureBox1.Image.Save("fileName");
                hinhAnh = fileName;
            }
            double donGia;

            double.TryParse(txtDonGia.Text, out donGia);
            double giamGia;

            double.TryParse(txtGiamGia.Text, out giamGia);
            Loai       loaiHH = (Loai)cbbLoaiHangHoa.SelectedItem;
            NhaCungCap nccHH  = (NhaCungCap)cbbNhaCungCap.SelectedItem;
            DateTime   ngaySX = dtpNgaySanXuat.Value;

            return(new HangHoa()
            {
                TenHH = txtTenHangHoa.Text,
                DonGia = donGia,
                GiamGia = giamGia,
                MoTaDonVi = txtMoTaDonVi.Text,
                MoTa = txtMoTa.Text,
                MaLoai = loaiHH.MaLoai,
                MaNCC = nccHH.MaNCC,
                Hinh = hinhAnh,
                SoLanXem = 0,
                NgaySX = ngaySX
            });
        }
예제 #11
0
 partial void DeleteLoai(Loai instance);
예제 #12
0
 partial void UpdateLoai(Loai instance);
예제 #13
0
 partial void InsertLoai(Loai instance);