private void btn_save_Click(object sender, EventArgs e) { try { string path = txt_picPath.Text, title = txt_picTitle.Text; if (path.Length == 0) { throw new Exception("You haven't selected any image!"); } if (title.Length == 0) { throw new Exception("Specify a title to the selected image!"); } AccomdationType t = (AccomdationType)cmb_accommodation.SelectedItem; t.AccomndationPictures.Add(new AccomndationPicture { AccomndationTypeID = t.AccomndationTypeID, PicturePath = path, PictureTitle = title }); DataHandler.Save(); DataHandler.showMessage("Picture has been added!", MessageBoxIcon.Information); cmb_accommodation_SelectedIndexChanged(null, EventArgs.Empty); } catch (Exception x) { DataHandler.showMessage(x.Message, MessageBoxIcon.Warning); } }
void cmb_accommodation_SelectedIndexChanged(object sender, EventArgs e) { AccomdationType t = (AccomdationType)cmb_accommodation.SelectedItem; lbl_price.Text = "Current price is " + t.AccomndationPricePerNight; loadPictures(t); }
private void loadPictures(AccomdationType t) { try { dataGridView1.Rows.Clear(); foreach (AccomndationPicture p in t.AccomndationPictures) { if (File.Exists(p.PicturePath)) { dataGridView1.Rows.Add(Image.FromFile(p.PicturePath), p.PictureTitle); } } } catch (Exception) {} }
private void btn_search_Click(object sender, EventArgs e) { string fullName = txt_fullName.Text; AccomdationType type = (AccomdationType)cmb_type.SelectedItem; List <AccomdationData> data = accomdations.ToList(); if (!cb_allUsers.Checked) { data = accomdations.Where(i => i.User.FullName.Contains(fullName)).ToList(); } if (!cb_allTypes.Checked) { data = data.Where(i => i.AccomdationTypeID.Equals(type.AccomndationTypeID)).ToList(); } loadAccomdations(data); }