private void AddDiaryToXml(diary d) { //add the diary node XmlElement diaryElement = myXml.CreateElement("Diary"); myXml.FirstChild.AppendChild(diaryElement); XmlElement Date = myXml.CreateElement("Date"); Date.InnerText = d.DATE.ToShortDateString(); diaryElement.AppendChild(Date); XmlElement Weather = myXml.CreateElement("Weather"); Weather.InnerText = d.WEATHER.ToString(); diaryElement.AppendChild(Weather); XmlElement Mood = myXml.CreateElement("Mood"); Mood.InnerText = d.MOOD.ToString(); diaryElement.AppendChild(Mood); XmlElement TitleList = myXml.CreateElement("TitleList"); diaryElement.AppendChild(TitleList); for (int i = 0; i < 8; i++) { XmlElement Title = myXml.CreateElement("Title" + i.ToString()); Title.InnerText = d.TITLE[i]; TitleList.AppendChild(Title); } XmlElement ContentList = myXml.CreateElement("ContentList"); diaryElement.AppendChild(ContentList); for (int i = 0; i < 8; i++) { XmlElement Content = myXml.CreateElement("Content" + i.ToString()); Content.InnerText = d.CONTENT[i]; ContentList.AppendChild(Content); } XmlElement CheckList = myXml.CreateElement("CheckList"); diaryElement.AppendChild(CheckList); for (int i = 0; i < 5; i++) { XmlElement CheckPoint = myXml.CreateElement("CheckList" + i.ToString()); CheckPoint.InnerText = d.checkPoint[i].checkContent; CheckList.AppendChild(CheckPoint); } XmlElement IsCheckedList = myXml.CreateElement("IsCheckedList"); diaryElement.AppendChild(IsCheckedList); for (int i = 0; i < 5; i++) { XmlElement IsChecked = myXml.CreateElement("IsCheckedList" + i.ToString()); IsChecked.InnerText = d.checkPoint[i].isChecked.ToString(); IsCheckedList.AppendChild(IsChecked); } }
//Read one node to MyDiary private void ReadXmlNodeToDiary(XmlElement xe) { //get the element list in one node XmlNodeList elementList = xe.ChildNodes; //if the date is OK DateTime nodeDate; if (DateTime.TryParse(elementList[0].InnerText, out nodeDate)) { diary nodeDiary = new diary(nodeDate); if(elementList.Count>1) nodeDiary.SetWeather(elementList[1].InnerText); if (elementList.Count > 2) nodeDiary.SetMood(elementList[2].InnerText); if (elementList.Count > 3) for (int i = 0; i < 8; i++) { nodeDiary.SetTitle(elementList[3].ChildNodes[i].InnerText, i); } if (elementList.Count > 4) for (int i = 0; i < 8; i++) { nodeDiary.SetContent(elementList[4].ChildNodes[i].InnerText, i); } if (elementList.Count > 6) for (int i = 0; i < 5; i++) { nodeDiary.checkPoint[i].Set(elementList[5].ChildNodes[i].InnerText, elementList[6].ChildNodes[i].InnerText); } myDiary.Add(nodeDiary); } }
//refresh oneday status private void ShowOneday(diary d) { CurrentDateBlock.Text = d.DATE.ToShortDateString(); TitleBox1.Text = d.TITLE[0]; TitleBox2.Text = d.TITLE[1]; TitleBox3.Text = d.TITLE[2]; TitleBox4.Text = d.TITLE[3]; TitleBox5.Text = d.TITLE[4]; TitleBox6.Text = d.TITLE[5]; TitleBox7.Text = d.TITLE[6]; TitleBox8.Text = d.TITLE[7]; DiaryBox1.Text = d.CONTENT[0]; DiaryBox2.Text = d.CONTENT[1]; DiaryBox3.Text = d.CONTENT[2]; DiaryBox4.Text = d.CONTENT[3]; DiaryBox5.Text = d.CONTENT[4]; DiaryBox6.Text = d.CONTENT[5]; DiaryBox7.Text = d.CONTENT[6]; DiaryBox8.Text = d.CONTENT[7]; ImageBrush b = new ImageBrush(); b.Stretch = Stretch.Uniform; switch (d.WEATHER) { case 1: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Blizzard.png")); break; case 2: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Freezing.png")); break; case 3: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/HeavyRain.png")); break; case 4: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/LightCloud.png")); break; case 5: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/LightRain.png")); break; case 6: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/MuchCloud.png")); break; case 7: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Rainbow.png")); break; case 8: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Snow.png")); break; case 9: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Sun.png")); break; case 10: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/SunBath.png")); break; case 11: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/ThunderRain.png")); break; default: b.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/Sun.png")); break; } WeatherBox.Fill = b; ImageBrush m = new ImageBrush(); m.Stretch = Stretch.Uniform; switch (d.MOOD) { case 1: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/白日梦.png")); break; case 2: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/暴怒.png")); break; case 3: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/愁.png")); break; case 4: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/大喜.png")); break; case 5: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/发病.png")); break; case 6: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/发呆.png")); break; case 7: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/烦着呢别理我.png")); break; case 8: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/奋斗.png")); break; case 9: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/觉皇.png")); break; case 10: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/漏油.png")); break; case 11: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/美美.png")); break; case 12: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/迷糊.png")); break; case 13: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/迷茫.png")); break; case 14: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/内牛满面.png")); break; case 15: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/死了.png")); break; case 16: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/窝火.png")); break; default: m.ImageSource = new BitmapImage(new Uri("pack://application:,,,/Images/美美.png")); break; } FaceBox.Fill = m; checkListBox1.IsChecked = d.checkPoint[0].isChecked; checkListBox2.IsChecked = d.checkPoint[1].isChecked; checkListBox3.IsChecked = d.checkPoint[2].isChecked; checkListBox4.IsChecked = d.checkPoint[3].isChecked; checkListBox5.IsChecked = d.checkPoint[4].isChecked; CheckListTextBox1.Text = d.checkPoint[0].checkContent; CheckListTextBox2.Text = d.checkPoint[1].checkContent; CheckListTextBox3.Text = d.checkPoint[2].checkContent; CheckListTextBox4.Text = d.checkPoint[3].checkContent; CheckListTextBox5.Text = d.checkPoint[4].checkContent; }