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;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
int i = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
shud.Items.Add("模式一");
shud.Items.Add("模式二");
groupBox1.Enabled = false;
groupBox2.Enabled = false;
for (int i = 0; i < 60; i++)
{
ok.Items.Add(i.ToString());
}
for (int i = 0; i <= 24; i++)
{
c1.Items.Add(i.ToString());
}
for (int i = 0; i <= 60; i++)
{
c2.Items.Add(i.ToString());
c3.Items.Add(i.ToString());
c6.Items.Add(i.ToString());
c5.Items.Add(i.ToString());
}
for (int i = System.DateTime.Now.Hour; i <= 24; i++)
{
c4.Items.Add(i.ToString());
}
}
private void button2_Click(object sender, EventArgs e)
{
int h = 0, m = 0;
string dingshi="";
timer1.Enabled = true;
timer1.Interval = 1000;
if (groupBox2.Enabled)
{
int ss = 0;
int mm = 0;
int hh = 0;
try
{
ss = Convert.ToInt16(c3.Text) + System.DateTime.Now.Second;
mm = Convert.ToInt16(c2.Text) + System.DateTime.Now.Minute;
hh = Convert.ToInt16(c1.Text) + System.DateTime.Now.Hour;
}
catch (Exception)
{
MessageBox.Show("请输入时间");
}
dingshi = "";
if (ss >=59)
{
m = ss / 60;
}
string dingshi1 = (ss - 60 * m).ToString() + "秒";
if (mm>=59)
{
h = mm / 60;
}
string dingshi2 = ((mm + m) - (h * 60)).ToString() + "分";
string dingshi3 = (hh + h).ToString() + "时";
if (hh + h >= 24)
dingshi3 = ((hh + h) - 24).ToString()+"时";
dingshi = dingshi3 + dingshi2 + dingshi1;
}
else if (groupBox1.Enabled)
{
dingshi = "";
dingshi = c4.Text + "时" + c5.Text + "分" + c6.Text + "秒";
}
else
MessageBox.Show("请选择模式!");
label13.Text = dingshi;
}
private void timer1_Tick(object sender, EventArgs e)
{
i++;
label3.Text = System.DateTime.Now.Hour.ToString() + "时" + System.DateTime.Now.Minute.ToString() + "分" + System.DateTime.Now.Second.ToString() + "秒";
if (label3.Text == label13.Text)
{
playmusic();
timer2.Enabled = true;
timer2.Interval =1000;
}
}
void shutdown()
{
System.Diagnostics.Process.Start("shutdown", "-s -t 0"); //调用windows的shutdown来关机
}
private void shud_SelectedIndexChanged(object sender, EventArgs e)
{
if(shud.Text=="模式一")
{
close();
groupBox2.Enabled=true;
}
else if(shud.Text=="模式二")
{
close();
groupBox1.Enabled=true;
}
}
void close()
{
groupBox1.Enabled = false;
groupBox2.Enabled = false;
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("xxxx"); //进入网站
//System.Diagnostics.Process.Start("xxxxx");
}
private void playmusic() //关机前的音乐
{
string path = Application.StartupPath;
path = path.Replace("bin\\Debug", "Resources\\midi\\");
if (chose_music.Text != "")
path = path + chose_music.Text + ".mid";
this.axWindowsMediaPlayer1.URL = path;
this.axWindowsMediaPlayer1.Ctlcontrols.play();
axWindowsMediaPlayer1.settings.setMode("loop", true); //循环播放
}
private void button1_Click_1(object sender, EventArgs e)
{
Button b=(Button)sender;
if(b.Text=="试听")
{
playmusic();
button1.Text="停止";
}
else
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
button1.Text="试听";
}
}
private void timer2_Tick(object sender, EventArgs e) //开始计时
{
i++;
if(i>=Convert.ToInt16(ok.Text)) //时间到
{
shutdown(); //调用自己定义的函数进行关机
Close();
Application.Exit();
}
}
private void button3_Click(object sender, EventArgs e)
{
Close();
Application.Exit();
}
private void button4_Click(object sender, EventArgs e)
{
MessageBox.Show("xxxxx,与我联系,2011,6,5","说明");
}
private void label18_Click(object sender, EventArgs e)
{
Hide();
}
private void label19_Click(object sender, EventArgs e)
{
//Form2 f2 = new Form2();
//f2.Show();
}
}