Exemplo n.º 1
0
        void addNote_AddClicked(object sender, EventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(addNote._header) && !string.IsNullOrEmpty(addNote._note))
                {
                    int maxId = stickyNoteList.Max(c => c.Id) + 1;

                    StickyNoteMaster master = new StickyNoteMaster();
                    master.Id              = maxId;
                    master.Header          = addNote._header;
                    master.Note            = addNote._note;
                    master.Height          = 250;
                    master.Width           = 250;
                    master.XLocation       = 0;
                    master.YLocation       = 0;
                    master.BackgroundColor = "#FFFFFF";

                    User user = new User();
                    user.UserId         = UserId;
                    user.StickyNoteList = new List <StickyNoteMaster>();
                    user.StickyNoteList.Add(master);

                    if (FileUtils.ProcessStickyNote(user, FileOperation.AddNote))
                    {
                        stickyNoteList.Add(new StickyNoteMaster {
                            Header = addNote._header, Height = 250, Id = maxId, Note = addNote._note, Width = 250, XLocation = 0, YLocation = 0, BackgroundColor = "#FFFFFF"
                        });
                        stickyNote = new StickyNote(UserId, addNote._header, addNote._note, new Thickness(0, 0, 0, 0), maxId.ToString(), 250, 250, "#FFFFFF");
                        stickyNote.ShowDialog();
                        stickyNote.AddNewClicked += new EventHandler(stickyNote_AddNewClicked);
                        LayoutRoot.Children.Add(stickyNote);
                    }
                }
                else
                {
                    MessageBox.Show("*Header and Note are required.", "Error", MessageBoxButton.OK);
                    addNote             = new AddNotes();
                    addNote.AddClicked += new EventHandler(addNote_AddClicked);
                    addNote.Show();
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    XDocument doc;
                    IsolatedStorageFileStream isoStream;

                    if (!isoStore.DirectoryExists("StickyNotes"))
                    {
                        isoStore.CreateDirectory("StickyNotes");
                    }

                    if (isoStore.FileExists(@"\StickyNotes\credentials.txt"))
                    {
                        chkAuthenticate.Visibility        = Visibility.Collapsed;
                        chkDisableAuthenticate.Visibility = Visibility.Visible;
                        stackPassword.Visibility          = Visibility.Collapsed;
                    }
                    if (isoStore.FileExists(@"\StickyNotes\Config.txt"))
                    {
                        isoStream = new IsolatedStorageFileStream(@"\StickyNotes\Config.txt", FileMode.Open, FileAccess.Read, isoStore);
                        TextReader reader   = new StreamReader(isoStream);
                        string     sLine    = reader.ReadToEnd();
                        string[]   strArray = sLine.Split('~');
                        isoStream.Close();
                        if (Convert.ToBoolean(strArray[1]))
                        {
                            ImageBrush imgBrush = new ImageBrush();
                            imgBrush.ImageSource = new BitmapImage(new Uri(strArray[0], UriKind.Relative));
                            MainGrid.Background  = imgBrush;
                        }
                        else
                        {
                            ImageBrush  imgBrush    = new ImageBrush();
                            BitmapImage imageSource = new BitmapImage();
                            imgBrush.ImageSource = imageSource;

                            isoStream = new IsolatedStorageFileStream(strArray[0], FileMode.Open, isoStore);
                            imageSource.SetSource(isoStream);
                            isoStream.Close();
                            MainGrid.Background = imgBrush;
                        }
                    }
                    else
                    {
                        ImageBrush imgBrush = new ImageBrush();
                        imgBrush.ImageSource = new BitmapImage(new Uri(@"/LastestStickyNote;component/Images/HD Image 1.jpg", UriKind.Relative));
                        MainGrid.Background  = imgBrush;
                    }

                    if (!isoStore.FileExists(@"\StickyNotes\StickyNotes.xml"))
                    {
                        isoStream = new IsolatedStorageFileStream(@"\StickyNotes\StickyNotes.xml", FileMode.Create, isoStore);

                        UserId = Guid.NewGuid().ToString();
                        doc    = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
                                               new XElement("stickynote",
                                                            new XElement("user",
                                                                         new XAttribute("id", UserId),
                                                                         new XAttribute("enabledEncryption", false),
                                                                         new XElement("note",
                                                                                      new XAttribute("id", 1),
                                                                                      new XAttribute("header", "Default Note !!!"),
                                                                                      new XAttribute("xLocation", 0),
                                                                                      new XAttribute("yLocation", 0),
                                                                                      new XAttribute("height", 250),
                                                                                      new XAttribute("width", 250),
                                                                                      new XAttribute("backgroundColor", "#FFFFFF"),
                                                                                      new XCData("This is default note and can be deleted....")))));

                        doc.Save(isoStream);
                        isoStream.Close();

                        stickyNoteList = new List <StickyNoteMaster>();
                        stickyNoteList.Add(new StickyNoteMaster {
                            Header = "Default Note !!!", Height = 250, Id = 1, Note = "This is default note and can be deleted....", Width = 250, XLocation = 0, YLocation = 0, BackgroundColor = "#FFFFFF"
                        });

                        stickyNote = new StickyNote(UserId, "Default Note !!!", "This is default note and can be deleted....", new Thickness(0, 0, 0, 0), "1", 250, 250, "#FFFFFF");
                        stickyNote.ShowDialog();
                        stickyNote.AddNewClicked += new EventHandler(stickyNote_AddNewClicked);
                        LayoutRoot.Children.Add(stickyNote);
                    }
                    else
                    {
                        isoStream = new IsolatedStorageFileStream(@"\StickyNotes\StickyNotes.xml", FileMode.Open, isoStore);
                        doc       = XDocument.Load(isoStream);

                        isoStream.Close();
                        User user = FileUtils.GetNotes(doc.Element("stickynote"));
                        UserId         = user.UserId;
                        stickyNoteList = new List <StickyNoteMaster>();
                        //user.StickyNoteList.ToList().Reverse();
                        stickyNoteList = user.StickyNoteList.ToList();
                        foreach (StickyNoteMaster stickyNotes in user.StickyNoteList)
                        {
                            stickyNote = new StickyNote(UserId, stickyNotes.Header, stickyNotes.Note, new Thickness(stickyNotes.XLocation, stickyNotes.YLocation, 0, 0), stickyNotes.Id.ToString(), stickyNotes.Width, stickyNotes.Height, stickyNotes.BackgroundColor);
                            stickyNote.ShowDialog();
                            stickyNote.AddNewClicked += new EventHandler(stickyNote_AddNewClicked);
                            LayoutRoot.Children.Add(stickyNote);
                        }
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error while loading sticky note application.", "Error", MessageBoxButton.OK);
            }
        }