コード例 #1
0
        private void timerRemind_Tick(object sender, EventArgs e)
        {
            RemindList remindlist = new RemindList();

            //  string x = "";
            SoundPlayer sp = new SoundPlayer(Application.StartupPath + "\\" + "Music" + "\\" + "two.WAV");

            for (int i = 0; i < remindlist.Filename.Length; i++)
            {
                string[] NameAndContent = FileNameToText.NameToText(remindlist.Filename[i]);
                string   NowTime        = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();
                //    x = NowTime;
                if (NowTime == NameAndContent[2])
                {
                    sp.PlayLooping();
                    timerRemind.Enabled = false;
                    if (MessageBox.Show(NameAndContent[3], "Time's up", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        File.Delete(remindlist.Filename[i]);
                        sp.Stop();
                        timerRemind.Enabled = true;
                    }
                    else
                    {
                        File.Delete(remindlist.Filename[i]);
                        sp.Stop();
                        timerRemind.Enabled = true;
                    }
                }
                //MessageBox.Show(x);
            }
        }
コード例 #2
0
ファイル: MainWindow.cs プロジェクト: Snsaiu/-
        private void MainWindow_Load(object sender, EventArgs e)
        {
            //创建xml文档
            XmlDocument xmldoc = new XmlDocument();


            if (!File.Exists("data.xml"))
            {
                XmlDeclaration dec = xmldoc.CreateXmlDeclaration("1.0", "utf-8", null);
                xmldoc.AppendChild(dec);
                XmlElement root1 = xmldoc.CreateElement("dataCol");
                xmldoc.AppendChild(root1);
                xmldoc.Save("data.xml");
                labInfo.Text = "xml created successful!";
            }



            xmldoc.Load("data.xml");
            //应用帮助提示
            if (xmldoc.SelectSingleNode("dataCol/MainWindow").Attributes["help"].Value == "true")
            {
                this.cbHelp.Checked      = true;
                this.ttMainWindow.Active = true;
            }
            else
            {
                this.cbHelp.Checked      = false;
                this.ttMainWindow.Active = false;
            }

            GetTomWeather = xmldoc.SelectSingleNode("dataCol/TomCityWeather").Attributes["weather"].Value;
            //
            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T1"].Value == "true")
            {
                this.cbT1.Checked = true;
            }
            else
            {
                this.cbT1.Checked = false;
            }

            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T2"].Value == "true")
            {
                this.cbT2.Checked = true;
            }
            else
            {
                this.cbT2.Checked = false;
            }

            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T3"].Value == "true")
            {
                this.cbT3.Checked = true;
            }
            else
            {
                this.cbT3.Checked = false;
            }

            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T4"].Value == "true")
            {
                this.cbT4.Checked = true;
            }
            else
            {
                this.cbT4.Checked = false;
            }

            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T5"].Value == "true")
            {
                this.cbT5.Checked = true;
            }
            else
            {
                this.cbT5.Checked = false;
            }

            if (xmldoc.SelectSingleNode("dataCol/IsAppRemind").Attributes["T6"].Value == "true")
            {
                this.cbT6.Checked = true;
            }
            else
            {
                this.cbT6.Checked = false;
            }


            XmlElement  root = xmldoc.DocumentElement;
            XmlNodeList list = root.ChildNodes;

            foreach (XmlNode node in list)
            {
                if (node.Name == "CityWeather")
                {
                    XmlNode repleaseWeather = xmldoc.SelectSingleNode("dataCol/CityWeather");
                    //获得cityweather节点下的所有属性
                    //判断是否需要更新天气
                    //1个小时更新一次,判断方法当前时间减去上次更新时间,如果时间差大于1个小时进行更新
                    int latestTime  = int.Parse(repleaseWeather.Attributes["latestTime"].Value);//获得后更新时间
                    int currentHour = DateTime.UtcNow.Hour;
                    //如果当前时间-最后更新时间大于等于1,那么进行天气更新
                    if (Math.Abs(currentHour - latestTime) >= 1)
                    {
                        GetWeather getweather = new GetWeather();
                        getweather.getWeather(repleaseWeather.Attributes["cityname"].Value);
                        repleaseWeather.Attributes["weather"].Value    = getweather.Getclound;
                        repleaseWeather.Attributes["temp"].Value       = getweather.Gettemperature;
                        repleaseWeather.Attributes["latestTime"].Value = DateTime.Now.Hour.ToString();

                        xmldoc.Save("data.xml");

                        lbWeather.Text = repleaseWeather.Attributes["cityname"].Value + repleaseWeather.Attributes["weather"].Value + repleaseWeather.Attributes["temp"].Value;
                    }
                    else
                    {
                        lbWeather.Text = repleaseWeather.Attributes["cityname"].Value + repleaseWeather.Attributes["weather"].Value + repleaseWeather.Attributes["temp"].Value;
                    }
                    break;
                }
                else
                {
                    XmlElement CityInfo = xmldoc.CreateElement("CityWeather");
                    CityInfo.SetAttribute("cityname", "南京");
                    CityInfo.SetAttribute("weather", "good");
                    CityInfo.SetAttribute("temp", "20");
                    CityInfo.SetAttribute("latestTime", "1");
                    root.AppendChild(CityInfo);
                    xmldoc.Save("data.xml");
                    break;
                    // labInfo.Text = "create CityInfo!";
                    //  xmldoc.Load("data.xml");
                    //  lbWeather.Text = xmldoc.SelectSingleNode("dataCol/CityWeather").Attributes["weather"].Value.ToString();
                }
            }

            //判断下滑
            isdroped = false;
            string sourcePath = Application.StartupPath;
            string shortcut   = Path.GetFileName(Application.ExecutablePath) + " - Shortcut.lnk";
            string targetPath = @"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp" + "\\" + shortcut;

            if (File.Exists(targetPath))
            {
                cbAutoSetup.Checked = true;
            }
            else
            {
                cbAutoSetup.Checked = false;
            }



            //读取时间提醒
            RemindList remindlist = new RemindList();

            for (int i = 0; i < remindlist.Filename.Length; i++)
            {
                string[]     NameAndContent = FileNameToText.NameToText(remindlist.Filename[i]);
                ListViewItem lv             = new ListViewItem(new string[] { NameAndContent[0], NameAndContent[1] });
                lvRemind.Items.Add(lv);
            }



            //string SaveWeatherCity = Application.StartupPath + "\\" + "cityOfWeather";
            //if (!Directory.Exists(SaveWeatherCity))
            //{
            //    Directory.CreateDirectory(SaveWeatherCity);
            //}
            //string saceWeatherCityFile = SaveWeatherCity + "\\" + "City.txt";
            //if (!File.Exists(saceWeatherCityFile))
            //{
            //    lbWeather.Text = "双击添加天气";
            //}
            //else
            //{
            //    string cityName;
            //    using (StreamReader sr = new StreamReader(saceWeatherCityFile))
            //    {
            //        cityName = sr.ReadToEnd();
            //    }
            //    programmingQuickSetup.GetWeather getweather = new programmingQuickSetup.GetWeather();
            //    getweather.getWeather(cityName);
            //    lbWeather.Text = cityName + ":" + getweather.Getclound + ";温度:" + getweather.Gettemperature;
            //}



            #region windowLocation
            RemindInfo.IsHidder = true;
            //Screen x = Screen.PrimaryScreen;
            //Rectangle r = x.Bounds;

            //Point p = new Point(r.Width-300, r.Y);
            this.Location = new Point(Control.MousePosition.X - 100, Control.MousePosition.Y - 20);



            #endregion



            //废弃初始化应用方法
            #region

            /*
             *
             #region app1 init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp1.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp1.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp1.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp1.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *
             *          }
             #endregion
             #region  app2 init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp2.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp2.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp2.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp2.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *              else
             *              {
             *                  this.btnApp2.Text = "右击添加快捷应用";
             *              }
             *          }
             #endregion
             #region app3init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp3.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp3.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp3.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp3.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *
             *          }
             #endregion
             #region app4init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp4.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp4.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp4.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp4.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *
             *          }
             *
             #endregion
             #region app5init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp5.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp5.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp5.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp5.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *
             *          }
             #endregion
             *
             #region app6init
             *          {
             *              if (File.Exists(fullpath + "\\" + "btnApp6.txt") == false)
             *              {
             *
             *                  return;
             *              }
             *              string appfilename;
             *              using (StreamReader sr = new StreamReader(fullpath + "\\" + "btnApp6.txt"))
             *              {
             *
             *                  appfilename = sr.ReadToEnd();
             *
             *              }
             *
             *              if (appfilename != "")
             *              {
             *                 // btnApp6.Text = Path.GetFileNameWithoutExtension(appfilename);
             *                  btnApp6.Image = (GetExeIcon.GetIcon(appfilename, true)).ToBitmap();
             *              }
             *
             *          }
             #endregion
             *
             */

            #endregion
            Button[]    btnlists = new Button[] { btnApp1, btnApp2, btnApp3, btnApp4, btnApp5, btnApp6 };
            SetQuickApp initApp  = SetQuickApp.GetInstace();
            initApp.SetIcomn(btnlists);


            //天气显示



            if (GetTomWeather.Contains("雨") || GetTomWeather.Contains("雪"))
            {
                Timer timerWeatherWarn = new Timer();
                timerWeatherWarn.Interval = 1500;
                timerWeatherWarn.Enabled  = true;
                timerWeatherWarn.Tick    += TimerWeatherWarn_Tick;
            }
        }