📄 form1.cs
字号:
//保存午餐
if(this.i002.Checked)
DBConn.SaveSelected("","002",Public.currentUserID,nowTime.ToString(),Public.configXml.Rows[0]["LastUserIP"].ToString());
//记录更改日志
//string _sr= DBConn.SaveEditLog(DBConn.GetServerTime().ToString(),_results,Public.currentUserID,Public.currentUserID);
//if(_sr != "OK"){
// MessageBox.Show(_sr.ToString());
// return;
//}
Public.AlertTime = nowTime.ToString();
Public.todayIsAlert = true;
this.Visible = false;
this.submit.Enabled = true;
}
/// <summary>
/// 提交按钮的状态
/// </summary>
private void SetSubmitState(){
if(i001.Checked || i002.Checked || i003.Checked){
this.submit.Enabled = true;
}else{
this.submit.Enabled = false;
}
}
/// <summary>
/// 变更事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void i002_CheckedChanged(object sender, System.EventArgs e) {
//this.SetSubmitState();
}
private void i003_CheckedChanged(object sender, System.EventArgs e) {
//this.SetSubmitState();
}
private void i001_CheckedChanged(object sender, System.EventArgs e) {
//this.SetSubmitState();
}
/// <summary>
/// 检查是否是提醒期
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e) {
if(DBConn.DbIsAvailable()){
this.ChangeNotIcon(true);
try{
DataTable alertTimes = DBConn.GetAlertTime();
string today = DBConn.GetServerTime().Date.ToString().Replace("0:00:00","");
DateTime _startTime = Convert.ToDateTime(today + alertTimes.Rows[0]["StartTime"].ToString());
DateTime _endTime = Convert.ToDateTime(today + alertTimes.Rows[0]["EndTime"].ToString());
if(_startTime != Public.startTime || _endTime != Public.endTime){
Public.todayIsAlert = false;
Public.startTime = _startTime;
Public.endTime = _endTime;
}
if(alertTimes.Rows[0]["isMod"].ToString() == "1"){
Public.alertingIsMod = true;
}else{
Public.alertingIsMod = false;
}
this.SetDate();
}catch{}
try{
DateTime nowTime = DBConn.GetServerTime();
string _dodate = nowTime.Year.ToString() + "-" + nowTime.Month.ToString() + "-" + nowTime.Day.ToString();
if(!Public.todayIsAlert){
if(Public.startTime < nowTime && Public.endTime > nowTime && !this.Visible){
System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(this.CheckUpdate));
thread.IsBackground = true;
thread.Start();
this.Visible = true;
this.submit.Visible = true;
this.submit.Enabled = true;
}else if(Public.startTime < nowTime && Public.endTime > nowTime && this.Visible){
//
}else{
this.Visible = false;
//Public.todayIsAlert = true;
}
}else{
if(nowTime.Date.ToString().Replace(" 0:00:00","") != Convert.ToDateTime(Public.AlertTime).Date.ToString().Replace(" 0:00:00","")){
Public.todayIsAlert = false;
this.i001.Checked = false;
this.i002.Checked = false;
this.i003.Checked = false;
}
}
int selectNum = 0;
if(this.i001.Checked) selectNum ++;
if(this.i002.Checked) selectNum ++;
if(this.i003.Checked) selectNum ++;
//比较数据,检查是否被管理员修改过
try{
DataTable selected = DBConn.GetTodaySelected(Public.currentUserID);
string[] elog = DBConn.GetLastEditLog(Public.currentUserID,nowTime.Year.ToString() + "-" + nowTime.Month.ToString() + "-" + nowTime.Day.ToString());
if(elog != null && selected.Rows.Count != selectNum && nowTime > Convert.ToDateTime(nowTime.Date.ToString() + " 0:05:00")){
if(!this.Visible) this.Visible = true;
else this.LoadSelectedFormDB();
string _editLog = "";
_editLog = " " + elog[0].ToString() + " ";
MessageBox.Show("您的就餐数据已被管理员"+ _editLog +"修改!","通知");
}
}catch(Exception ex){
//MessageBox.Show(ex.Message.ToString());
//if(this.falseNum <= 100){
// this.falseNum ++;
// }else{
// if(MessageBox.Show("连接不到服务器,请重新启动!\n\n系统异常信息:" + ex.Message.ToString(),"服务器连接故障") == DialogResult.OK){
// Process process = new Process();
// process.StartInfo.FileName = "XFMAS.exe";
// process.Start();
// Application.Exit();
// }
//}
}
}catch{}
try{
this.SetDate();
}catch{}
}else{
this.ChangeNotIcon(false);
if(this.isff <= 20){
this.isff ++;
}else{
//检查软件版本
System.Threading.Thread u = new System.Threading.Thread(new System.Threading.ThreadStart(this.CheckUpdate));
u.IsBackground = true;
u.Start();
this.isff = 0;
}
}
}
/// <summary>
/// 界面显示时重新载入已选结果
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Form1_VisibleChanged(object sender, System.EventArgs e) {
if(this.Visible){
//从数据库载入已选的信息并反映到界面中,如果超出提醒时间段则不能修改
this.LoadSelectedFormDB();
}
}
private void menuItem1_Click(object sender, System.EventArgs e) {
AboutUs au = new AboutUs();
au.ShowDialog();
}
/// <summary>
/// 打开并查询历史数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e) {
if(!DBConn.DbIsAvailable()){
MessageBox.Show("连系不到服务器,无法获取历史记录!");
return;
}
XFMAS.Admin.MainForm mf = new XFMAS.Admin.MainForm();
mf.RemoveMenu();
mf.SetUserID(Public.currentUserID);
mf.Show();
}
private void submit_EnabledChanged(object sender, System.EventArgs e) {
if(this.submit.Enabled == true){
//this.label4.Visible = false;
}else{
//this.submit.Visible = false;
this.label4.Visible = true;
}
}
/// <summary>
/// 重启软件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click_1(object sender, System.EventArgs e) {
if(MessageBox.Show("确定重启软件?","确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes){
Process process = new Process();
process.StartInfo.FileName = "XFMAS.exe";
process.Start();
this.notifyIcon1.Icon = null;
Application.Exit();
}
}
/// <summary>
/// 是否新版本
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckUpdate(){
String temp = "";
try{
WebRequest Wrequest = WebRequest.Create("http://10.227.64.92/AMS/ClientUpdate.htm");
WebResponse Wresponse = Wrequest.GetResponse();
Stream Sm = Wresponse.GetResponseStream();
StreamReader Sr = new StreamReader(Sm,Encoding.GetEncoding("GB2312"));
temp = Sr.ReadToEnd().ToString();
Sr.Close();
}catch(Exception ex){
return;
}
int oneI = temp.IndexOf("]");
string softVer = temp.Substring(1,oneI-1).ToString();
try{
//if(Public.configXml.Rows[0]["SoftVer"].ToString() != softVer && MessageBox.Show("系统检查到有升级文件可供更新,确定升级吗?","升级确认",MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK){
if(Public.configXml.Rows[0]["SoftVer"].ToString() != softVer){
Public.configXml.Rows[0]["SoftVer"] = softVer;
//保存到XML
SRXML.SaveDataTableToXML(Public.configXml,Public.configFile);
System.Diagnostics.Process p = new Process();
p.StartInfo.FileName = Application.StartupPath + "\\Update.exe";
p.Start();
this.notifyIcon1.Icon = null;
Application.Exit();
}
}catch{
//MessageBox.Show("开始升级时出错:" + ex.Message.ToString());
}
}
/// <summary>
/// 是否有重复进程
/// </summary>
/// <returns></returns>
private static bool IsExistProcess() {
bool result = false;
System.Diagnostics.Process[] p = System.Diagnostics.Process.GetProcessesByName(Path.GetFileNameWithoutExtension(Application.ExecutablePath));
if ( p!=null && p.Length >1) {
result = true;
}
return result;
}
/// <summary>
/// 退出系统
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuItem2_Click(object sender, System.EventArgs e) {
if(MessageBox.Show("如果退出系统,您可能会错过就餐提醒。\r\n\r\n确定退出吗?","退出确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes){
this.notifyIcon1.Icon = null;
Application.Exit();
}
}
private void Form1_Closed(object sender, System.EventArgs e) {
this.notifyIcon1.Icon = null;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -