private void btnNoteDelete_Click(object sender, EventArgs e) { if (lstNotesOfPeople.SelectedItems.Count <= 0) { return; } txtNoteText.Text = ""; btnNoteSave.Enabled = false; if (MyPeople.OpenDetailsForAdd || MyPeople.OpenForPersonalAdd) { NotesOfPeople n = MyPeople.Note.Find(p => p.NoteId == int.Parse(lstNotesOfPeople.SelectedItems[0].SubItems[3].Text)); MyPeople.Note.Remove(n); lstNotesOfPeople.Items.Remove(lstNotesOfPeople.SelectedItems[0]); } else { int id = int.Parse(lstNotesOfPeople.SelectedItems[0].SubItems[3].Text); DBFunction.Execute("delete from NotesOfPeople where NoteId=" + id); HistoryChangeDetails h = new HistoryChangeDetails( GLOBALVARS.MyUser.ID, MyPeople.ID, GLOBALVARS.MyUser.Name, "הערה - מחיקה", lstNotesOfPeople.SelectedItems[0].SubItems[2].Text, ""); h.InserHistory(); loadNotes(); } }
private void btnNoteSave_Click(object sender, EventArgs e) { if (MyPeople.OpenDetailsForAdd || MyPeople.OpenForPersonalAdd) { if (isnew)//הערה חדשה { if (txtNoteText.Text.Length < 1000) { MyPeople.Note.Add(new NotesOfPeople() { NoteText = txtNoteText.Text, NoteId = tempId }); tempId++; ListViewItem item; lstNotesOfPeople.BeginUpdate(); item = new ListViewItem(new string[] { DateTime.Now.ToShortDateString(), GLOBALVARS.MyUser.Name, txtNoteText.Text, tempId.ToString() }); item.Tag = tempId.ToString(); lstNotesOfPeople.Items.Add(item); lstNotesOfPeople.EndUpdate(); } else { MessageBox.Show("אורך הערה מקסימלי הוא עד 1000 תווים." + Environment.NewLine + "נא פצלו ל2 הערות"); } } else//הערה ששינו אותה { lstNotesOfPeople.SelectedItems[0].SubItems[2].Text = txtNoteText.Text; MyPeople.Note.ToArray()[lstNotesOfPeople.SelectedItems[0].Index].NoteText = txtNoteText.Text; } } else//הערה שמשנים אותה נשמרת מייד { if (isnew) { if (txtNoteText.Text.Length < 1000) { HistoryChangeDetails h = new HistoryChangeDetails( GLOBALVARS.MyUser.ID, MyPeople.ID, GLOBALVARS.MyUser.Name, "הערה חדשה", "", txtNoteText.Text); h.InserHistory(); People.InsertNewNotes(new NotesOfPeople() { NoteText = txtNoteText.Text, PeopleId = MyPeople.ID }); loadNotes(); } else { MessageBox.Show("אורך הערה מקסימלי הוא עד 1000 תווים." + Environment.NewLine + "נא פצלו ל2 הערות"); } } else { NotesOfPeople n = new NotesOfPeople() { NoteId = int.Parse(lstNotesOfPeople.SelectedItems[0].SubItems[3].Text), UserId = int.Parse(lstNotesOfPeople.SelectedItems[0].Tag.ToString()), UserName = lstNotesOfPeople.SelectedItems[0].SubItems[1].Text, NoteText = txtNoteText.Text, PeopleId = MyPeople.ID, NoteDate = DateTime.Parse(lstNotesOfPeople.SelectedItems[0].SubItems[0].Text) }; if (txtNoteText.Text.Length < 1000) { HistoryChangeDetails h = new HistoryChangeDetails( GLOBALVARS.MyUser.ID, MyPeople.ID, GLOBALVARS.MyUser.Name, "הערה - עדכון", lstNotesOfPeople.SelectedItems[0].SubItems[2].Text, txtNoteText.Text); h.InserHistory(); People.UpdateNotes(n); loadNotes(); } else { MessageBox.Show("אורך הערה מקסימלי הוא עד 1000 תווים." + Environment.NewLine + "נא פצלו ל2 הערות"); } } } }