Beispiel #1
0
        private void themsanpham()
        {
            TrangSuc ts = new TrangSuc();

            ts.MaTS    = txtMaTS.Text;
            ts.TenTS   = txtTenTS.Text;
            ts.SoLuong = Int32.Parse(txtSoLuong.Text);
            ts.DonGia  = float.Parse(txtDonGia.Text);
            ts.DonVi   = txtDonVi.Text;
            ts.MaLoai  = txtMaLoai.Text;
            //Byte[] img = ts.HinhAnh;
            //if (img != null)
            //{
            //    using(MemoryStream stream = new MemoryStream(img))
            //    {
            //        Image returnImage = Image.FromStream(stream);
            //        hinhanh.Image = returnImage;
            //    }
            //}

            trangsuc.TrangSucs.Add(ts);
            trangsuc.SaveChanges();
            MessageBox.Show("Thêm thành công.");
            dataGridView1.DataSource = trangsuc.TrangSucs.ToList();
        }
Beispiel #2
0
        private void chonhinhanh(object sender, EventArgs e)
        {
            BunifuImageButton img = sender as BunifuImageButton;

            mats = img.Name.ToString();
            TrangSuc ts = trangsuc.TrangSucs.FirstOrDefault(p => p.MaTS == mats);

            cbLoaiTS.SelectedValue = ts.MaLoai;
            txtTenTS.Text          = ts.TenTS;
            txtDonGia.Text         = ts.DonGia.ToString();
        }
Beispiel #3
0
        private void btsua_Click(object sender, EventArgs e)
        {
            TrangSuc ts = trangsuc.TrangSucs.FirstOrDefault(p => p.MaTS == txtMaTS.Text);

            ts.TenTS   = txtTenTS.Text;
            ts.SoLuong = Int32.Parse(txtSoLuong.Text);
            ts.DonGia  = float.Parse(txtDonGia.Text);
            ts.DonVi   = txtDonVi.Text;
            ts.MaLoai  = txtMaLoai.Text;
            trangsuc.SaveChanges();
            MessageBox.Show("Sửa thành công.");
            dataGridView1.DataSource = trangsuc.TrangSucs.ToList();
        }
Beispiel #4
0
        private void btxoa_Click(object sender, EventArgs e)
        {
            TrangSuc ts = trangsuc.TrangSucs.FirstOrDefault(p => p.MaTS == txtMaTS.Text);

            trangsuc.TrangSucs.Remove(ts);
            trangsuc.SaveChanges();
            using (Stream stream = new MemoryStream(a))
            {
                hinhanh.Image = Image.FromStream(stream);
                stream.Dispose();
            }
            MessageBox.Show("Xóa Thành công");
            dataGridView1.DataSource = trangsuc.TrangSucs.ToList();
        }
Beispiel #5
0
        private void updateTrangSuc(string MaTS)
        {
            TrangSuc     ts = trangsuc.TrangSucs.FirstOrDefault(p => p.MaTS == MaTS);
            MemoryStream me = new MemoryStream();

            byte[]       images = null;
            FileStream   stream = new FileStream(img, FileMode.Open, FileAccess.Read);
            BinaryReader brs    = new BinaryReader(stream);

            images     = brs.ReadBytes((int)stream.Length);
            ts.HinhAnh = images;
            trangsuc.SaveChanges();
            dataGridView1.DataSource = trangsuc.TrangSucs.ToList();
            MessageBox.Show("Update thành công");
        }