private void Accept(object sender, EventArgs e) { EditButton.Enabled = true; AcceptButton.Enabled = false; CancelButton.Enabled = false; CommentBox.ReadOnly = true; CommentBox.Cursor = Cursors.Default; if (MyCommentIndex == -1) // add new comment { // add comment to record MyCommentIndex = Record.AddComment(Doctor, CommentBox.Text); // add comment label to CommentLabelList Point Point = new Point(10, MyCommentIndex * 110); if (Point.Y > CommentListBox.Height) CommentListBox.Height = Point.Y + 100; CommentLabel newCommentLabel = new CommentLabel(Doctor, Record.Comment[MyCommentIndex], MyCommentIndex, Point); newCommentLabel.Select += this.Select; this.CommentListBox.Controls.Add(newCommentLabel); // select new comment label newCommentLabel.MouseClick(null, null); } else // edit comment { Record.EditComment(Doctor, CommentBox.Text); } }
private void Select(object sender, CommentEventArgs e) { CommentDoctorNameLabel.Text = Record.Comment[e.Index].DoctorName; CommentDateLabel.Text = Record.Comment[e.Index].DateTime.ToShortDateString() + " " + Record.Comment[e.Index].DateTime.ToShortTimeString(); CommentBox.Text = Record.Comment[e.Index].Data; EditButton.Enabled = Record.Comment[e.Index].DoctorID == Doctor.ID; if (LastSelectLabel != null) LastSelectLabel.Selected = false; LastSelectLabel = (CommentLabel) sender; }
private void LoadComment() { Record.LoadComment(); if (Record.Comment.Count > 0) { int count = Record.Comment.Count(); for (int i = 0; i < count; i++) { Point Point = new Point(10, i * 110); if (Point.Y > CommentListBox.Height) CommentListBox.Height = Point.Y + 100; CommentLabel newCommentLabel = new CommentLabel(Doctor, Record.Comment[i], i, Point); //newCommentLabel.Select += new System.EventHandler(this.Select); newCommentLabel.Select += this.Select; this.CommentListBox.Controls.Add( newCommentLabel); // default select first comment if (i == 0) newCommentLabel.MouseClick(null, null); } // find My comment for (int i = 0; i < count && MyCommentIndex == -1; i++) if (Record.Comment[i].DoctorID == Doctor.ID) MyCommentIndex = i; AddButton.Enabled = MyCommentIndex == -1; } }