Exemplo n.º 1
0
        //public NoteBLL()
        //{
        //    try
        //    {
        //    }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.InnerException.ToString());
        //    }
        //}
        public List<NoteView> GetUserNotes(int ID)
        {
            List<NoteView>  noteList = new List<NoteView>();

            try
            {
                using (ClassRoomEntities entities = new ClassRoomEntities())
                {
                    var notes = from m in entities.Notes
                                where m.NUserID == ID
                                select m;
                    List<Note> list = notes.ToList();

                    list.ForEach(m =>
                    {
                        NoteView view = new NoteView ();
                        Note entityInfo = view.Clone(m);

                        view.Clone(m);
                        noteList.Add(view);
                    });
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.ToString());
            }

            return noteList;
        }
        private void CreateNote(NoteView note)
        {
            ContentControl noteControl = new ContentControl();
            noteControl.Name = "Note" + newNoteCount++;
            noteControl.Tag = note;
            Style template = this.TryFindResource("DesignerItemStyle") as Style;
            noteControl.Style = template;
            noteControl.ApplyTemplate();
            SolidColorBrush brush = new SolidColorBrush();
            brush.Color = ColorHelpers.GetColorByName(note.Color);
            noteControl.Background = brush;
            noteControl.Width = note.Width;
            noteControl.Height = note.Height;
            Canvas.SetTop(noteControl, note.Y);
            Canvas.SetLeft(noteControl, note.X);
            Transform rotate = new RotateTransform(note.RotateAngle, note.RotateCenterX, note.RotateCenterY);
            noteControl.RenderTransform = rotate;

            Button btnClose = noteControl.Template.FindName("btnClose", noteControl) as Button;
            Button btnChangeColor = noteControl.Template.FindName("btnChangeColor", noteControl) as Button;
            RichTextBox rtbBody = noteControl.Template.FindName("rtbNoteBody", noteControl) as RichTextBox;

            rtbBody.LoadFromRTF(note.Body);
            //SetValueToRichTextBox(note, rtbBody);

            MoveThumb moveThumb = noteControl.Template.FindName("moveThumb", noteControl) as MoveThumb;
            moveThumb.ApplyTemplate();
            TextBlock txtTitle = moveThumb.Template.FindName("txtTitle", moveThumb) as TextBlock;

            txtTitle.Text = note.User == null ? "新建" : note.User.Realname + note.AddTime.ToShortDateString();
            btnClose.Click += new RoutedEventHandler(btnClose_Click);
            btnChangeColor.Click += new RoutedEventHandler(btnChangeColor_Click);

            rtbBody.TextChanged += new TextChangedEventHandler(rtbBody_TextChanged);

            this.NoteCanvas.Children.Add(noteControl);
        }
        private void MenuItem_NewNote(object sender, RoutedEventArgs e)
        {
            NoteView note = new NoteView();
            note.Color = "LightBlue";
            note.NoteID = 0;
            note.Width = 200;
            note.Height = 200;
            //note.User = Common.CommonClass.UserTicket.UserInfo;
            note.NUserID = 4;
            note.AddTime = DateTime.Now;
            Point position = Mouse.GetPosition(NoteCanvas);
            position.Offset(-35, -15);
            note.Y = position.Y;
            note.X = position.X;
            note.Body = "";
            note.DataStatus = DataStatusEnum.Added;
            noteList.Add(note);

            CreateNote(note);
        }