首页 >> 大全

电梯调度程序的实施 by郭莉莉李亚文

2023-12-22 大全 37 作者:考证青年

一、开门见山,代码粘

using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace lift
{public partial class Form1 : Form{int destion = 0;//目的楼层int number = 0;//所到楼层public Form1(){InitializeComponent();//this.skinEngine1.SkinFile = "Vista2_color5.ssk";
        }private void button21_Click(object sender, EventArgs e){if (destion == 0){lblWarming.Visible = true;}else{tmrSeconds.Start();}}private void lift_click(object sender, EventArgs e){if (destion == 0){destion = Convert.ToInt32(((Button)sender).Tag);((Button)sender).BackColor = Color.Red;if (destion > 21){number = destion / 100 * 100 + number;}}else{MessageBox.Show("你只能选择一个楼层","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);}}private void tmrSeconds_Tick(object sender, EventArgs e){if (number < destion){// FormmoveUp();number++;   foreach (Control item in this.Controls){if (item is Button){if(number<=destion){item.BackColor = Color.LightGray;}int index = Convert.ToInt32(item.Tag);if (index == number){item.BackColor = Color.Green;}}}lblPostion.Text = (number%100).ToString();} else if(number>destion){//  FormmoveDown();number--;foreach (Control item in this.Controls){if (item is Button){//number=destion / 100 * 100 + number;if (number >= destion){item.BackColor = Color.LightGray;}int index = Convert.ToInt32(item.Tag);if (index == number){item.BackColor = Color.Green;}}}lblPostion.Text = (number%100).ToString();}else{tmrSeconds.Stop();foreach(Control item in this.Controls ){if (item is Button){int index = Convert.ToInt32(item.Tag);if (index == destion){item.BackColor = Color.LightGray;}}}MessageBox.Show(destion%100+"层到了", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);destion = 0;number = number % 100;}}private void button21_MouseLeave(object sender, EventArgs e){lblWarming.Visible = false;}private void lblWarming_Click(object sender, EventArgs e){}}
}

二、实现思路

1、首先考虑一部电梯运行的情况,乘客上电梯后,通过按按钮确定目的楼层,因此,按钮的click事件是同一个道理,因此用一个函数实现即;

2、其次考虑按下按钮后,电梯上升和下降,首先比较当前楼层与目的楼层的数值大小,如果目的楼层大于当前楼层,则上升一层则(所到楼层)加一,否则-1,将按钮变成绿色表示到达该楼层;

3、然后思考当到达该楼层时候,给出提示框提示。

4、最后考虑四部电梯的情况。

三、开发日志

3月12日 星期三 14:00-16:30

万事开头难,我们今天讨论了具体思路和编程的策略,并且查找了很多资料,做了个界面:

电梯调度是什么意思_电梯调度流程图_

3月13日星期四 16:30-18:50

一部电梯调度的click事件,界面很简单,做好界面以后开始写函数,完成如下:

private void lift_click(object sender, EventArgs e){if (destion == 0){destion = Convert.ToInt32(((Button)sender).Tag);((Button)sender).BackColor = Color.Red;}else{MessageBox.Show("你只能选择一个楼层","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);}}

3月14日 星期五 18:00-22:00

按下电梯运行按钮,实现了电梯上下楼的功能:

 private void tmrSeconds_Tick(object sender, EventArgs e){if (number < destion){FormmoveUp();number++;   foreach (Control item in this.Controls){if (item is Button){if(number<=destion){item.BackColor = Color.LightGray;}int index = Convert.ToInt32(item.Tag);if (index == number){item.BackColor = Color.Green;}}}lblPostion.Text = number.ToString();} else if(number>destion){FormmoveDown();number--;foreach (Control item in this.Controls){if (item is Button){if (number >= destion){item.BackColor = Color.LightGray;}int index = Convert.ToInt32(item.Tag);if (index == number){item.BackColor = Color.Green;}}}lblPostion.Text = number.ToString();}else{tmrSeconds.Stop();foreach(Control item in this.Controls ){if (item is Button){int index = Convert.ToInt32(item.Tag);if (index == destion){item.BackColor = Color.LightGray;}}}MessageBox.Show(destion+"层到了", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);destion = 0;}}

这样程序已经可以运行了:

运行结果如下

_电梯调度是什么意思_电梯调度流程图

电梯调度是什么意思_电梯调度流程图_

2014年3月16日 14:00-18:00

_电梯调度是什么意思_电梯调度流程图

编写四个电梯的程序,首先修改界面,但是遇到了很大的问题,如果复制粘贴以后的按钮属性全都相同,四个电梯就像一个电梯一样,后来我们看了半天也没找到解决方案,于是放弃了。界面修改如下:

电梯调度是什么意思_电梯调度流程图_

2014年3月17日 星期一 18:00-23:00

提交程序在即,但是我们还是一个电梯,我们本来想就此罢手,但是我们能这么做吗?不能!!!!!!我们于是仔细看了问题的症结,发现只要修改Tag值和值就可以达到效果,于是,将第二个电梯的值加了100,第三个电梯的值加了200,第四个电梯Tag值加了300然后修改了让他变成/100*100+实现利用整型除法的弊端来解决了问题。得到了如下结果:

电梯调度是什么意思__电梯调度流程图

_电梯调度流程图_电梯调度是什么意思

电梯调度流程图_电梯调度是什么意思_

电梯调度流程图_电梯调度是什么意思_

电梯调度是什么意思_电梯调度流程图_

电梯调度流程图__电梯调度是什么意思

还有很多不足之处!

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了