当前位置:网站首页>Example of multipoint alarm clock

Example of multipoint alarm clock

2022-06-22 08:10:00 shixch

 Insert picture description here

Save the alarm clock

 private void button4_Click_1(object sender, EventArgs e) // Save alarm clock to text file 
        {
    
            // take listView Save contents of as TXT Format 
            string[] arr = new string[lstList.Items.Count];
            for (int i = 0; i < lstList.Items.Count; i++)
            {
    
                string s = "";
                int len = lstList.Items[0].SubItems.Count;
                for (int j = 1; j < len; j++)
                {
    
                    // Use a comma as a delimiter   If   There are children that contain commas   Something is going wrong 
                    s += lstList.Items[i].SubItems[j].Text + ",";
                }
                if (s.EndsWith(","))
                    s = s.Substring(0, s.Length - 1);
                arr[i] = s;
            }
            // Save to file 
            File.WriteAllLines(conf, arr);
        }

Call in alarm clock

 private void button5_Click(object sender, EventArgs e)
        {
    
            // Read data from text to listView among 
            string[] array = File.ReadAllLines(conf);
            lstList.Items.Clear();
            for (int i = 0; i < array.Length; i++)
            {
    
                if (array[i].Length > 0)// Do not add blank lines 
                {
    
                    ListViewItem listviewItem = new ListViewItem();
                    string s = array[i].ToString();
                    // There is no judgment on whether the format meets the requirements , If the content is changed to another format, an exception will occur 
                    string[] arr = s.Split(',');
                    listviewItem.Text = (i + 1).ToString();
                    // listviewItem.Text = arr[0];
                    listviewItem.SubItems.Add(arr[0]);
                    listviewItem.SubItems.Add(arr[1]);
                    listviewItem.SubItems.Add(arr[2]);
                    lstList.Items.Add(listviewItem);
                }
            }

Add the time

private void Add_Click(object sender, EventArgs e)
        {
    
            if (txtMsg.Text.Trim().Replace(" ", "") == "")
            {
    
                MessageBox.Show(" Note cannot be null ");
                return;
            }
            int i = lstList.Items.Count + 1;
            ListViewItem listItem = lstList.Items.Add(i.ToString());    //((lstList.Items.Count + 1).ToString().Trim());
            listItem.SubItems.Add(dtboxTime.Value.ToString("HH:mm:ss"));                                                                              // listItem.SubItems.Add(dtboxTime.Value.ToString("HH:mm:ss"));
            listItem.SubItems.Add(txtMsg.Text);
            listItem.SubItems.Add("");
            txtMsg.Text = "";
        }

Delete selected time

private void button1_Click_1(object sender, EventArgs e)
        {
    
            for (int i = lstList.SelectedItems.Count - 1; i >= 0; i--)
            {
    
                ListViewItem item = lstList.SelectedItems[i];
                lstList.Items.Remove(item);
            }
        }

Timing judgment

private void timer1_Tick(object sender, EventArgs e)
        {
    
            for (int i = 0; i < lstList.Items.Count; i++)
            {
    
                if (m_TodayDate.ToString("yyyyMMdd") != DateTime.Now.ToString("yyyyMMdd"))
                {
    
                    for (int n = 0; n < lstList.Items.Count; n++)
                    {
    
                        lstList.Items[n].SubItems[3].Text = "";
                    }
                    m_TodayDate = DateTime.Now;
                }
                string timeString = lstList.Items[i].SubItems[1].Text;
                timeString = DateTime.Now.ToString("yyyy/MM/dd") + " " + timeString;
                if (DateTime.Parse(timeString) <= DateTime.Now)
                {
    
                    if (lstList.Items[i].SubItems[3].Text != "Y")
                    {
    
                        lstList.Items[i].SubItems[3].Text = "Y";
                        ts = lstList.Items[i].SubItems[2].Text;
                        speak.Sp_T(ts);
                    }
                }
            }

Reading function

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Speech.Synthesis;
using System.Globalization;

namespace  alarm clock 
{
    
    class Speedch_T
    {
    
        private SpeechSynthesizer speech = new SpeechSynthesizer();
        public void Sp_T(string phrase)
        {
    
            #region  Can only read numbers and English 
            //string text = textBox1.Text;
            //if (text.Trim().Length != 0)
            //{
    
            // speech.Rate = 5;// The speed 
            // speech.SelectVoice("Microsoft Lili");// Set up announcer ( chinese )
            // //speech.SelectVoice("Microsoft Anna"); // english 
            // speech.Volume = 100; // The volume 
            // speech.SpeakAsync(textBox1.Text);// Phonics reading methods 
            //}
            #endregion
            #region  Can read Chinese 
            SpeechSynthesizer speech = new SpeechSynthesizer();
            CultureInfo keyboardCulture = System.Windows.Forms.InputLanguage.CurrentInputLanguage.Culture;
            InstalledVoice neededVoice = speech.GetInstalledVoices(keyboardCulture).FirstOrDefault();
            if (neededVoice == null)
            {
    
                phrase = "Unsupported Language";
            }
            else if (!neededVoice.Enabled)
            {
    
                phrase = "Voice Disabled";
            }
            else
            {
    
                speech.SelectVoice(neededVoice.VoiceInfo.Name);
            }
            speech.Speak(phrase);
            #endregion
        }
    }
}

Form code

 private void Form1_Load(object sender, EventArgs e)
        {
    
            dtboxTime.Value = DateTime.Now;
            timer1.Enabled = true;
            m_TodayDate = DateTime.Now;
        }

Class declaration

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Windows.Forms;
  public System.Media.SoundPlayer music = new SoundPlayer(Directory.GetCurrentDirectory() + "\\ Jiang Zi teeth - alarm clock .wav");
        DateTime m_TodayDate;
        string conf = "test.txt";
        Speedch_T speak = new Speedch_T();
        string ts;```

原网站

版权声明
本文为[shixch]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/173/202206220801373173.html