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();
            }
        }
示例#2
0
        public NotesOfPeople ReaderToNotes(ref SqlDataReader reader)
        {
            NotesOfPeople n = new NotesOfPeople();

            n.NoteId   = int.Parse(reader["NoteId"].ToString());
            n.UserId   = int.Parse(reader["UserId"].ToString());
            n.UserName = (string)reader["UserName"];
            n.PeopleId = int.Parse(reader["PeopleId"].ToString());
            n.NoteText = (string)reader["NoteText"];
            n.NoteDate = DateTime.Parse(reader["NoteDate"].ToString());

            return(n);
        }
示例#3
0
        public static bool UpdateNotes(NotesOfPeople note)
        {
            SqlParameter[] prms = new SqlParameter[10];
            string         sqlnotes, sql;

            sql = "BEGIN TRANSACTION ";

            sql += "update NotesOfPeople SET " +
                   BuildSql.UpdateSql(out prms[0], note.UserId, "UserId") +
                   BuildSql.UpdateSql(out prms[1], note.UserName, "UserName") +
                   BuildSql.UpdateSql(out prms[2], note.PeopleId, "PeopleId") +
                   BuildSql.UpdateSql(out prms[3], note.NoteText, "NoteText") +
                   BuildSql.UpdateSql(out prms[4], note.NoteDate, "NoteDate", true)
                   + " where NoteId=" + note.NoteId + "; COMMIT";
            return(DBFunction.Execute(sql, prms));
        }
示例#4
0
        public static bool InsertNewNotes(NotesOfPeople note)
        {
            SqlParameter[] prms = new SqlParameter[10];
            string         sqlnotes, sql;

            sqlnotes = "INSERT INTO NotesOfPeople VALUES(" +
                       BuildSql.InsertSql(out prms[0], GLOBALVARS.MyUser.ID) +
                       BuildSql.InsertSql(out prms[1], GLOBALVARS.MyUser.Name) +
                       BuildSql.InsertSql(out prms[2], note.PeopleId) +
                       BuildSql.InsertSql(out prms[3], note.NoteText) +
                       BuildSql.InsertSql(out prms[4], DateTime.Now, true)
                       + ");";
            sql = "BEGIN TRANSACTION " +
                  sqlnotes +
                  "COMMIT";
            return(DBFunction.Execute(sql, prms));
        }
        private void loadNotes(ListView lstvw = null)
        {
            lstNotesOfPeople.Items.Clear();
            txtNoteText.Text    = "";
            btnNoteSave.Enabled = false;
            SqlDataReader reader = null;

            if (lstvw == null)
            {
                lstvw = lstNotesOfPeople;
            }

            ListViewItem item;

            //  ||GLOBALVARS.MyUser.CanEdit
            if (GLOBALVARS.MyUser.Control == User.TypeControl.Manger || GLOBALVARS.MyUser.Control == User.TypeControl.Admin)
            {
                reader = DBFunction.ExecuteReader("select * from NotesOfPeople n where n.PeopleId=" + MyPeople.ID);
            }
            else
            {
                reader = DBFunction.ExecuteReader("select * from NotesOfPeople n where n.UserId=" + GLOBALVARS.MyUser.ID + "and n.PeopleId=" + MyPeople.ID);
            }
            lstNotesOfPeople.BeginUpdate();
            MyPeople.Note = new List <NotesOfPeople>();
            NotesOfPeople n = new NotesOfPeople();

            while (reader.Read())
            {
                MyPeople.Note.Add(n.ReaderToNotes(ref reader));
                item = new ListViewItem(new string[] {
                    DateTime.Parse(reader["NoteDate"].ToString()).ToShortDateString(),
                    (string)reader["UserName"],
                    (string)reader["NoteText"],
                    reader["NoteId"].ToString()
                });
                item.Tag = reader["UserId"].ToString();
                lstvw.Items.Add(item);
            }
            lstNotesOfPeople.EndUpdate();
            reader.Close();
        }
        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 הערות");
                    }
                }
            }
        }