void homestayown() { HomestayEntities db = new HomestayEntities(); cbxHomestayown.DataSource = db.Homestayown.ToList(); cbxHomestayown.DisplayMember = "Name"; cbxHomestayown.ValueMember = "ID"; }
void room(int ID) { HomestayEntities db = new HomestayEntities(); grdListview.DataSource = db.Room.Where(b => b.Homestayown_ID == ID).ToList(); grdListview.Columns["ID"].Visible = false; grdListview.Columns["Homestayown"].Visible = false; grdListview.Columns["Homestayown_ID"].Visible = false; }
private void btnSave_Click(object sender, EventArgs e) { if (roomID == 0) { try { HomestayEntities db = new HomestayEntities(); Room bk = new Room(); bk.Room_Name = txtRoom.Text; bk.Status = txtStatus.Text; bk.Price = txtPrice.Text; bk.Space = txtSpace.Text; bk.Homestayown_ID = (int)cbxHomestayown.SelectedValue; ImageConverter converter = new ImageConverter(); byte[] image = (byte[])converter.ConvertTo(pictureBox.Image, typeof(byte[])); Room upload = new Room(); upload.Image = image; bk.Image = image; db.Room.Add(bk); db.SaveChanges(); MessageBox.Show("Add new product success"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { try { HomestayEntities db = new HomestayEntities(); bkedit = db.Room.Find(bkedit.ID); bkedit.Room_Name = txtRoom.Text; bkedit.Status = txtStatus.Text; bkedit.Price = txtPrice.Text; bkedit.Space = txtSpace.Text; bkedit.Homestayown_ID = (int)cbxHomestayown.SelectedValue; ImageConverter converter = new ImageConverter(); byte[] image = (byte[])converter.ConvertTo(pictureBox.Image, typeof(byte[])); Room upload = new Room(); upload.Image = image; bkedit.Image = image; db.Entry(bkedit).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); MessageBox.Show("Edit product success"); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnDelete_Click(object sender, EventArgs e) { if (grdListview.SelectedRows.Count == 1) { if (MessageBox.Show("Do you want to delete this?", "Confirm", MessageBoxButtons.YesNo) == DialogResult.Yes) { var row = grdListview.SelectedRows[0]; var cell = row.Cells["ID"]; int ID = (int)cell.Value; HomestayEntities db = new HomestayEntities(); Room bk = db.Room.Single(b => b.ID == ID); db.Room.Remove(bk); db.SaveChanges(); room((int)cbxHomestayown.SelectedValue); ShowList(); } } }