⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setalerttime.cs

📁 食堂就餐提醒系统(含源码) 为一个单位开发的
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

using System.Data;

namespace XFMAS.Admin
{
	/// <summary>
	/// SetAlertTime 的摘要说明。
	/// </summary>
	public class SetAlertTime : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.CheckBox isMod;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TextBox startTime;
		private System.Windows.Forms.TextBox endTime;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public SetAlertTime()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//载入已有时间提醒配置
			this.LoadAlertTimeConfig();
		}

		/// <summary>
		/// 获取已有配置
		/// </summary>
		private void LoadAlertTimeConfig(){
			
			try{
				
				DataTable config = XFMAS.DBConn.GetAlertTime();

				this.startTime.Text = config.Rows[0]["StartTime"].ToString();
				this.endTime.Text   = config.Rows[0]["EndTime"].ToString();

				if(config.Rows[0]["isMod"].ToString() == "1"){
					this.isMod.Checked = true;
				}else{
					this.isMod.Checked = false;
				}

			}catch(Exception ex){
				MessageBox.Show("获取已有时间段配置时出错:" + ex.Message.ToString());
				return;
			}
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.endTime = new System.Windows.Forms.TextBox();
			this.startTime = new System.Windows.Forms.TextBox();
			this.isMod = new System.Windows.Forms.CheckBox();
			this.label2 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "起始时间";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.endTime);
			this.groupBox1.Controls.Add(this.startTime);
			this.groupBox1.Controls.Add(this.isMod);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(296, 112);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(160, 56);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(120, 16);
			this.label5.TabIndex = 8;
			this.label5.Text = "格式:时:分:秒";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(160, 24);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(120, 16);
			this.label4.TabIndex = 7;
			this.label4.Text = "格式:时:分:秒";
			// 
			// endTime
			// 
			this.endTime.Location = new System.Drawing.Point(80, 46);
			this.endTime.Name = "endTime";
			this.endTime.Size = new System.Drawing.Size(72, 21);
			this.endTime.TabIndex = 5;
			this.endTime.Text = "9:00:00";
			// 
			// startTime
			// 
			this.startTime.Location = new System.Drawing.Point(80, 16);
			this.startTime.Name = "startTime";
			this.startTime.Size = new System.Drawing.Size(72, 21);
			this.startTime.TabIndex = 4;
			this.startTime.Text = "8:00:00";
			// 
			// isMod
			// 
			this.isMod.Location = new System.Drawing.Point(80, 80);
			this.isMod.Name = "isMod";
			this.isMod.Size = new System.Drawing.Size(200, 24);
			this.isMod.TabIndex = 3;
			this.isMod.Text = "提醒时间段内是否允许重新选择";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 1;
			this.label2.Text = "终止时间";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(176, 128);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(64, 23);
			this.button1.TabIndex = 2;
			this.button1.Text = "确 定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(240, 128);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(64, 23);
			this.button2.TabIndex = 3;
			this.button2.Text = "取 消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(8, 136);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(152, 16);
			this.label3.TabIndex = 6;
			this.label3.Text = "注:时间格式必须正确。";
			// 
			// SetAlertTime
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(314, 159);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.label3);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "SetAlertTime";
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "设置提醒时间段";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 保存时间提醒
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void button1_Click(object sender, System.EventArgs e) {
			
			try{

				this.button1.Enabled = false;
				this.button2.Enabled = false;

				DateTime _st = Convert.ToDateTime(this.startTime.Text.Trim());
				DateTime _et = Convert.ToDateTime(this.endTime.Text.Trim());

				if(_st >= _et){
					throw new Exception("起始时间必须小于终止时间!");
				}

				string   _im = "1";

				if(this.isMod.Checked == false) _im = "0";

				string updateResult = XFMAS.DBConn.UpdateAlertTime(this.startTime.Text.Trim(),this.endTime.Text.Trim(),_im);

				if(updateResult != "OK"){
					throw new Exception(updateResult);
				}

				this.Close();

			}catch(Exception ex){

				this.button1.Enabled = true;
				this.button2.Enabled = true;

				MessageBox.Show(ex.Message.ToString());
				return;
			}
		}

		private void button2_Click(object sender, System.EventArgs e) {
			this.Close();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -