写一个定时提醒小软件,到点有音乐,或语音朗读提醒

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Collections;

namespace @lock
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int formheight = 310;                      //这个是窗体原来的样式

        int formwidth = 400;

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                this.Height += 30;
            }
            else
            {

                this.Height = formheight;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;
            if (btn.Text == "写个")
            {
                btn.Text = "写完";
                this.Width += 400;
                sign = false;
            }
            else
            {
                string s = "";
                if (radioButton1.Checked)
                {
                    s = radioButton1.Text;
                }
                else
                {
                    s = radioButton2.Text;
                }
                btn.Text = "写个";
                this.Width = formwidth;
                string str = textBox2.Text + ";" + label7.Text + "," + dateTimePicker1.Text + " " + comboBox1.Text + ":" + comboBox2.Text + "," +textBox1.Text+","+ s;
                inputtxt(str);                                                                        //写入txt

                ListViewItem lvi = listView1.Items.Add(textBox2.Text);                                 //名称 
                lvi.SubItems.Add(label7.Text);                                                         //开始时间       
                lvi.SubItems.Add(dateTimePicker1.Text + " " + comboBox1.Text + ":" + comboBox2.Text);  //结束时间
                lvi.SubItems.Add(s);                                                                    //详情
                lvi.SubItems.Add(textBox1.Text); 
                sign = true;

            }

        }

        private static void inputtxt(string str)    //写文档
        {
            FileStream fs = new FileStream(@"d:/123.txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            sw.Close();
            fs.Close();
        }

        private static void allinput(string str)
        {
            FileStream fs = new FileStream(@"d:/123.txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fs);
            sw.WriteLine(str);
            sw.Close();
            fs.Close();

        }   //修改文件

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            for (int i = 10; i < 60; i++)
            {
                comboBox1.Items.Add(i.ToString());
                comboBox2.Items.Add(i.ToString());
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Selected)
                {
                    MessageBox.Show(item.SubItems[4].Text);
                }    

            }


        }

        bool sign = false;

        ArrayList list = new ArrayList();   //列表

        int add = 0;  //累加器 
        private void timer1_Tick(object sender, EventArgs e)
        {
            label7.Text = System.DateTime.Now.ToString();
            add++;
            if (add > 59)
            {
                sign = true;
                add = 0;
            }
            if (sign)
            {
           //   if (label7.Text.Substring(0, label7.Text.LastIndexOf(':')) == dateTimePicker1.Text + " " + comboBox1.Text + ":" + comboBox2.Text)
                  if ("yes" == deleterecord(label7.Text.Substring(0, label7.Text.LastIndexOf(':'))))
                  {
                    sign = false;
                    // MessageBox.Show(dateTimePicker1.Text + comboBox1.Text + comboBox2.Text);  
                    if (music.Text != "" && radioButton1.Checked)
                    {
                        playmusic(); //播放音乐
                        //MessageBox.Show(msg);
                    }
                    else
                    {
                        //this.axWindowsMediaPlayer1.URL = "D:\\21.wav";
                        //this.axWindowsMediaPlayer1.Ctlcontrols.play();
                        //axWindowsMediaPlayer1.settings.setMode("loop", true);  //循环播放

                    }
                    //这里是写调用铃声
                }

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            string input = "";                         //串加器
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Selected)
                {
                    listView1.Items.Remove(item);
                    using (StreamReader sr = File.OpenText(@"d:/123.txt"))
                    {
                        string s = "";
                        while ((s = sr.ReadLine()) != null)
                        {
                            if (s != "")
                            {
                                if (s.Substring(0, s.LastIndexOf(';')) != item.Text)
                                {
                                    input += "\r\n" + s;
                                }
                            }
                        }
                    }
                    allinput(input);
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            listView1.Items.Clear();
            string str = "";
            using (StreamReader sr = File.OpenText(@"d:/123.txt"))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    if (s!="")
                    {
                        ListViewItem lvi = listView1.Items.Add(s.Substring(0,s.LastIndexOf(';')));     //取名称  
                        str=s.Substring(s.LastIndexOf(';')+1);
                        string[] m=str.Split(',');                  //数组
                        lvi.SubItems.Add(m[0]);     //                                                      //开始时间       
                        lvi.SubItems.Add(m[1]);  //结束时间
                        lvi.SubItems.Add(m[3]);
                        lvi.SubItems.Add(m[2]); 
 
                    }
                }
            }
           // button1.Enabled = false;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.Selected)
                {
                   read(item.SubItems[4].Text);     
                }
              
            }
          
        }

        private static void read(string str)
        {
            string readstring = "Const SSFMCreateForWrite = 3\n";
            //readstring+="strText =" +"\""姓名:郭占慧,签到时间:8点10分12秒,状态为:迟到;姓名:吴超,签到时间:8点10分12秒,状态为:迟到;这两个人是两口子"\""+"\n";
            readstring += "strText=" + "\"" + str + "\"" + "\n";
            readstring += "Set objVoice = CreateObject(" + "\"SAPI.SpVoice\"" + ")\n";
            readstring += "objvoice.Speak strText\n";
            //readstring += "Set objFile = CreateObject(" + "\"SAPI.SpFileStream.1\"" + ")\n";
            //readstring += "objFile.Open " + "\"D:\\Test.wav\"" + "," + "SSFMCreateForWrite\n";
            //readstring += "Set objVoice.AudioOutputStream = objFile\n";
            //readstring += "objVoice.Speak strText\n";

            string path = @"D:";
            StreamWriter sw = new StreamWriter(path + "\\" + "1.vbs", false, Encoding.Unicode);//GetEncoding("gb2312 "));
            sw.WriteLine(readstring);
            sw.Close();
            sw.Dispose();
            System.Diagnostics.Process.Start(@"d:\1.vbs");
        }
        bool mn = true;
        private void music_SelectedIndexChanged(object sender, EventArgs e)
        {
            playmusic();   //调用播放音乐
                                                                                                                                                                                                                                                                                 
        }

        private void playmusic()   //这里是播放音乐
        {
            string path = Application.StartupPath;
            path = path.Replace("bin\\Debug", "Resources\\midi\\");
            if (music.Text != "")
                path = path + music.Text + ".mid";
            this.axWindowsMediaPlayer1.URL = path;
            this.axWindowsMediaPlayer1.Ctlcontrols.play();
            axWindowsMediaPlayer1.settings.setMode("loop", true);  //循环播放

        }

        private void button6_Click(object sender, EventArgs e)
        {
            mn = false;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            string str = "";
            deleterecord(str);                //清除当前激活的这条记录
            
        }
        string msg = "";
        private string deleterecord(string str)
        {
            string b = "no";
            ListViewItem lv = new ListViewItem(str);
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.SubItems[2].Text == str)
                {
                     b = "yes";
                     msg = item.SubItems[4].Text;
                     if (ip)
                     {
                         read0(msg);
                     }
                     else {
                         System.Diagnostics.Process.Start(@"d:\1.vbs");
                     
                     }

                }
            }
            return b;
        }
        bool ip = true;
        private void read0(string str)
        {
            string readstring = "Const SSFMCreateForWrite = 3\n";
            //readstring+="strText =" +"\""姓名:郭占慧,签到时间:8点10分12秒,状态为:迟到;姓名:吴超,签到时间:8点10分12秒,状态为:迟到;这两个人是两口子"\""+"\n";
            readstring += "strText=" + "\"" + str + "\"" + "\n";
            readstring += "Set objVoice = CreateObject(" + "\"SAPI.SpVoice\"" + ")\n";
            readstring += "objvoice.Speak strText\n";
            readstring += "Set objFile = CreateObject(" + "\"SAPI.SpFileStream.1\"" + ")\n";
            readstring += "objFile.Open " + "\"D:\\21.wav\"" + "," + "SSFMCreateForWrite\n";
            readstring += "Set objVoice.AudioOutputStream = objFile\n";
            readstring += "objVoice.Speak strText\n";

            string path = @"D:";
            StreamWriter sw = new StreamWriter(path + "\\" + "1.vbs", false, Encoding.Unicode);//GetEncoding("gb2312 "));
            sw.WriteLine(readstring);
            sw.Close();
            sw.Dispose();
            ip = false;
        }
        

    }
}

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值