private void lvNotification_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { try { var item = e.Item; if (item != null) { tblPetDiary noti = (tblPetDiary)item.Tag; tbDate.Text = noti.createDate.ToString(); txtName.Text = noti.tblPet.name; txtAdopter.Text = noti.adopter; txtPetDiaryDetail.Text = noti.diaryDetail; imgPath = FileDAO.Folder + "/" + noti.diaryImages; if (!noti.isRead && !isForAdopter) { NotificationDAO.Instance.MakeRead(noti.id); } item.ForeColor = Color.Black; } } catch (Exception) { MessageBox.Show("Connection Error"); this.Close(); } }
private void btnSave_Click(object sender, System.EventArgs e) { string error = Validation(); if (!string.IsNullOrEmpty(error)) { MessageBox.Show(error, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } DialogResult r = MessageBox.Show("Do you want to save?", "Confirmation", MessageBoxButtons.YesNo); if (r == DialogResult.Yes) { string fileName = DateTime.Now.Ticks.ToString() + "_" + openFileDialog.SafeFileName; tblPetDiary diary = new tblPetDiary { adopter = adopter.username, petId = (int)cboPetName.SelectedValue, diaryDetail = txtPetDiaryDetail.Text.Trim(), diaryImages = fileName, createDate = DateTime.Now, isRead = false }; bool result = TblPetDiaryDAO.Instance.CreatePetDiary(diary); if (result) { FileDAO.CopyImage(openFileDialog.FileName, fileName); MessageBox.Show("Saved successfully!", "Notification"); RefreshScreen(); } } }
//this function will insert pet diary into TblPetDiary table public bool CreatePetDiary(tblPetDiary diary) { tblPetDiary result = DBProvider.Instance.Db.tblPetDiary.Add(diary); if (result != null) { DBProvider.Instance.Db.SaveChanges(); return(true); } return(false); }