private void danhsachvasuaspbtn_Click(object sender, EventArgs e) { HidePanels(); menuStrip1.Visible = true; danhsachsanphampn.Visible = true; vatphambus vpbus = new vatphambus(); danhsachsanphamdgv.DataSource = vpbus.listvatpham(); DataGridViewImageColumn ic = new DataGridViewImageColumn(); ic.HeaderText = "Hình ảnh"; ic.Image = null; ic.Name = "cImg"; ic.Width = 100; danhsachsanphamdgv.Columns.Insert(0, ic); danhsachsanphamdgv.Columns[2].Visible = false; foreach (DataGridViewRow row in danhsachsanphamdgv.Rows) { DataGridViewImageCell cell = row.Cells[0] as DataGridViewImageCell; string path = row.Cells[2].Value.ToString(); path = appPath + path; Console.WriteLine(path); cell.Value = Bitmap.FromFile(path); row.Height = 100; } }
private void luusanpham_Click(object sender, EventArgs e) { string tenanh = tensanphamtxt.Text.Replace(" ", "") + DateTime.Now.ToString("ddmmyyyyhhmmss") + ".jpeg"; if (Directory.Exists(appPath) == false) { Directory.CreateDirectory(appPath); } if (pictureBox1 == null || pictureBox1.Image == null) { MessageBox.Show("khong co hinh"); tenanh = "default-product-image.jpg"; } else { pictureBox1.Image.Save(appPath + tenanh, ImageFormat.Jpeg); } vatphamdto vpdto = new vatphamdto(); vpdto.Tenvatpham = tensanphamtxt.Text; vpdto.Loaivatpham = loaisptxt.Text; vpdto.Hinhanh = tenanh; vpdto.Tukhoa = mieutatxt.Text; vpdto.Gia = Convert.ToDecimal(giatxt.Text); vatphambus vpbus = new vatphambus(); vpbus.add(vpdto); danhsachsanphamnhapdgv.DataSource = vpbus.listvatpham(vpdto.Tenvatpham); DataGridViewImageColumn ic = new DataGridViewImageColumn(); ic.HeaderText = "Hình ảnh"; ic.Image = null; ic.Name = "cImg"; ic.Width = 100; danhsachsanphamnhapdgv.Columns.Insert(0, ic); danhsachsanphamnhapdgv.Columns[2].Visible = false; foreach (DataGridViewRow row in danhsachsanphamnhapdgv.Rows) { DataGridViewImageCell cell = row.Cells[0] as DataGridViewImageCell; string path = "default-product-image.jpg"; try { path = row.Cells[2].Value.ToString(); } catch (Exception) { } path = appPath + path; Console.WriteLine(path); cell.Value = Bitmap.FromFile(path); row.Height = 100; } }
private void taodonnhapluu_Click(object sender, EventArgs e) { nhaphangdto nhdto = new nhaphangdto(); nhdto.Manhaphang = manhapkhotxt.Text; nhdto.Ngaynhaphang = ngaynhapkho.Value.Date.ToShortDateString(); nhdto.Machinhanh = machinhanh; nhaphangbus nhb = new nhaphangbus(); nhb.add(nhdto); madonnhap = nhdto.Manhaphang; madonnhaplbl.Text = madonnhap; nhapdon.Visible = false; nhapchitietdon.Visible = true; vatphambus vpbus = new vatphambus(); danhsachsanpham1dgv.DataSource = vpbus.listvatpham(); DataGridViewImageColumn ic = new DataGridViewImageColumn(); ic.HeaderText = "Hình ảnh"; ic.Image = null; ic.Name = "cImg"; ic.Width = 100; danhsachsanpham1dgv.Columns.Insert(0, ic); danhsachsanpham1dgv.Columns[2].Visible = false; foreach (DataGridViewRow row in danhsachsanpham1dgv.Rows) { DataGridViewImageCell cell = row.Cells[0] as DataGridViewImageCell; string path = row.Cells[2].Value.ToString(); path = appPath + path; Console.WriteLine(path); cell.Value = Bitmap.FromFile(path); row.Height = 100; } }