예제 #1
0
        public void CreateNote()
        {
            this.State = TypeControl.Create;

            NoteGroup ng = NotesGroups.FirstOrDefault(x => x.ShowNotes);

            using (DBContext context = new DBContext(false)) {
                if (ng == null)
                {
                    if (NotesGroups.Count > 0)
                    {
                        ng = NotesGroups.First();
                    }
                    else
                    {
                        ng = NoteGroup.New();
                        Color cr = Colors.LightBlue;
                        ng.IDUser  = App.CurrentUser.ID;
                        ng.IDColor = BitConverter.ToInt32(new byte[] { cr.B, cr.G, cr.R, cr.A }, 0);
                        context.NoteGroups.AddObject(ng);

                        NotesGroups.Add(ng);

                        context.SaveChanges();
                    }
                }

                if (ng != null)
                {
                    Note         newN = new Note();
                    FlowDocument fd   = new FlowDocument {
                        AllowDrop = true, PageWidth = 130, PageHeight = 130
                    };
                    fd.Blocks.Add(new Paragraph(new Run("Note")));
                    newN.Text       = XamlWriter.Save(fd);
                    newN.Owner      = App.CurrentUser.ID;
                    newN.Group      = ng.ID;
                    newN.CreateDate = DateTime.Now;
                    newN.Width      = 130;
                    newN.Height     = 130;
                    newN.PosX       = (int)(SystemParameters.PrimaryScreenWidth - 130) / 2;
                    newN.PosY       = (int)(SystemParameters.PrimaryScreenHeight - 130) / 2;
                    newN.IDColor    = ng.IDColor;
                    newN.IsShowin   = true;
                    newN.IsTop      = true;

                    context.Notes.AddObject(newN);

                    context.SaveChanges();
                    //ng.AddNewNote(newN);

                    ItemNoteWindow w = new ItemNoteWindow();
                    w.DataContext = newN;
                    WindowVisibilityBehaviour.SetCloseByHidden(w, true);
                    WindowVisibilityBehaviour.SetIsVisible(w, true);
                }
            }

            this.State = TypeControl.Normal;
        }
예제 #2
0
 public static void ShowTopWindow()
 {
     System.Threading.Tasks.Task.Factory.StartNew(() =>
     {
         using (DBContext context = new DBContext(false))
         {
             foreach (var item in context.Notes.Where(x => x.Owner == App.CurrentUser.ID && x.IsShowin && x.IsTop))
             {
                 App.BeginInvoke(() =>
                 {
                     ItemNoteWindow w = new ItemNoteWindow();
                     w.DataContext    = item;
                     WindowVisibilityBehaviour.SetCloseByHidden(w, true);
                     WindowVisibilityBehaviour.SetIsVisible(w, true);
                 });
             }
         }
     });
 }