在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → 教室/会议室预定系统源码

教室/会议室预定系统源码

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:0.43M
  • 下载次数:40
  • 浏览次数:580
  • 发布时间:2020-07-14
  • 实例类别:Windows系统编程
  • 发 布 人:guomin0801
  • 文件格式:.zip
  • 所需积分:2
 相关标签: 会议

实例介绍

【实例简介】

  用c#实现的教室/会议室预定系统, 数据存在本地txt文件

【实例截图】

from clipboard

【核心代码】

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;

using System.IO;
using System.Data.SqlClient;
using System.Security.AccessControl;

namespace chooseRoom
{
    public partial class Form_index : Form
    {
        bool exits = false;
        string userid = "";
        string filename = "";

        public Form_index()
        {
            InitializeComponent();
        }

        private void Form_index_Load(object sender, EventArgs e)
        {
            readAllFile();

            List<string> initTimeList = new List<string>();
            initTimeList.Add("...");
            initTimeList.Add("08:00-10:00");
            initTimeList.Add("10:00-12:00");
            initTimeList.Add("12:00-14:00");
            initTimeList.Add("14:00-16:00");
            initTimeList.Add("16:00-18:00");
            initTimeList.Add("18:00-20:00");
            initTimeList.Add("20:00-22:00");
            comboBox_time.DataSource = initTimeList;

            string logname = "";
            logname = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) "\\教室及会议室预约系统";
            if (Directory.Exists(logname) == false)//如果不存在就创建file文件夹
            {
                Directory.CreateDirectory(logname);
            }
            logname = "\\roomItem.txt";
            if (File.Exists(@logname) == false)
            {
                MessageBox.Show("感谢您使用 教室/会议室 预约系统!", "欢迎!");
                File.Copy("roomItem.txt", logname);
            }

            List<string> initItemList = new List<string>();
            try
            {
                FileStream fs = File.Open(logname, FileMode.Open, FileAccess.Read);
                StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                String line;
                while ((line = sr.ReadLine()) != null)
                {
                    initItemList.Add(line.ToString());
                }
                fs.Close();
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
                //Message返回异常对象中包含的错误信息 
            }
            comboBox_item.DataSource = initItemList;
        }

        private void userClear()
        {
            textBox_username.Text = null;
            textBox_usertel.Text = null;
            textBox_userid.Text = null;
        }

        private void save_log()
        {
            if (textBox_username.Text.Length < 1 || textBox_usertel.Text.Length < 1 || textBox_userid.Text.Length < 1)
            {
                MessageBox.Show("申请人、申请人电话及申请人证件号不允许为空!", "警告!");
                return;
            }
            else {
                int time = 0;
                if ("..." == comboBox_time.Text)
                {
                    MessageBox.Show("请选择申请的时间段!", "警告!");
                    return;
                }
                else if ("08:00-10:00" == comboBox_time.Text) { time = 1; }
                else if ("10:00-12:00" == comboBox_time.Text) { time = 2; }
                else if ("12:00-14:00" == comboBox_time.Text) { time = 3; }
                else if ("14:00-16:00" == comboBox_time.Text) { time = 4; }
                else if ("16:00-18:00" == comboBox_time.Text) { time = 5; }
                else if ("18:00-20:00" == comboBox_time.Text) { time = 6; }
                else if ("20:00-22:00" == comboBox_time.Text) { time = 7; }
                FileStream fs = null;
                
                filename = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) "\\教室及会议室预约系统\\"
                    dateTimePicker_date.Value.ToString("yyyyMMdd") time.ToString() comboBox_item.Text ".smr";
                Encoding encoder = Encoding.UTF8;
                string content = "";
                content = textBox_username.Text Environment.NewLine;
                content = textBox_usertel.Text Environment.NewLine;
                content = textBox_userid.Text Environment.NewLine;
                byte[] bytes = encoder.GetBytes(content);
                try
                {
                    fs = File.OpenWrite(filename);
                    //设定书写的开始位置为文件的末尾  
                    fs.Position = fs.Length;
                    //将待写入内容追加到文件末尾  
                    fs.Write(bytes, 0, bytes.Length);
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.Message);
                    //Message返回异常对象中包含的错误信息 
                }
                fs.Close();
                MessageBox.Show("申请 教室/会议室 成功!", "申请完成!");
                comboBox_time.SelectedIndex = 0;
                userClear();
                return;
            }
        }

        private void button_fun_Click(object sender, EventArgs e)
        {
            if (exits)
            {
                if (textBox_userid.Text == userid)
                {
                    try
                    {
                        File.Delete(@filename);
                        MessageBox.Show("已经成功撤销所选申请!", "撤销成功!");
                        comboBox_time.SelectedIndex = 0;
                        userClear();
                    }
                    catch (Exception error)
                    {
                        Console.WriteLine(error.Message);
                        //Message返回异常对象中包含的错误信息 
                    }
                }
                else
                {
                    MessageBox.Show("证件号不一致!", "撤销失败!");
                }
            }
            else
            {
                save_log();
            }
            readAllFile();
            return;
        }
        
        private void find_exist()
        {
            int time = 0;
            if ("08:00-10:00" == comboBox_time.Text) { time = 1; }
            else if ("10:00-12:00" == comboBox_time.Text) { time = 2; }
            else if ("12:00-14:00" == comboBox_time.Text) { time = 3; }
            else if ("14:00-16:00" == comboBox_time.Text) { time = 4; }
            else if ("16:00-18:00" == comboBox_time.Text) { time = 5; }
            else if ("18:00-20:00" == comboBox_time.Text) { time = 6; }
            else if ("20:00-22:00" == comboBox_time.Text) { time = 7; }

            filename = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) "\\教室及会议室预约系统\\"
                dateTimePicker_date.Value.ToString("yyyyMMdd") time.ToString() comboBox_item.Text ".smr";
            if (File.Exists(@filename))
            {
                exits = true;
                textBox_username.Enabled = false;
                textBox_usertel.Enabled = false;
                //存在
                button_fun.Text = "撤销申请";
            }
            else
            {
                exits = false;
                textBox_username.Enabled = true;
                textBox_usertel.Enabled = true;
                //不存在
                button_fun.Text = "申请";
            }

            if (exits)
            {
                try
                {
                    FileStream fs = File.Open(filename, FileMode.Open, FileAccess.Read);
                    StreamReader sr = new StreamReader(fs, Encoding.UTF8);
                    String line;
                    int i = 0;
                    while ((line = sr.ReadLine()) != null)
                    {
                        switch (i)
                        {
                            case 0: textBox_username.Text = line.ToString(); break;
                            case 1: textBox_usertel.Text = line.ToString(); break;
                            case 2: userid = line.ToString(); break;
                            default: break;
                        }
                        i ;
                    }
                    fs.Close();
                }
                catch (Exception error)
                {
                    Console.WriteLine(error.Message);
                    //Message返回异常对象中包含的错误信息 
                }
            }
            else
            {
                userClear();
            }
            return;
        }

        private void dateTimePicker_date_ValueChanged(object sender, EventArgs e)
        {
            find_exist();
        }

        private void comboBox_time_SelectedIndexChanged(object sender, EventArgs e)
        {
            find_exist();
        }

        private void comboBox_item_SelectedIndexChanged(object sender, EventArgs e)
        {
            find_exist();
        }
        
        private void readAllFile()
        {
            try
            {
                String path = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) "\\教室及会议室预约系统";
                String thisFileName = "";
                String msg = "";
                var files = Directory.GetFiles(path, "*.smr");
                int time = 0;
                int i = path.Length-1;
                foreach (var file in files)
                {
                    thisFileName = file.ToString();
                    msg = thisFileName.Substring(i 2, 4)
                        "年" thisFileName.Substring(i 6, 2)
                        "月" thisFileName.Substring(i 8, 2) "日 ";
                    try
                    {
                        time = Convert.ToInt32(thisFileName.Substring(i 10, 1));
                    }
                    catch
                    {
                        break;
                    }
                    switch (time)
                    {
                        case 1: msg = "08:00-10:00 "; break;
                        case 2: msg = "10:00-12:00 "; break;
                        case 3: msg = "12:00-14:00 "; break;
                        case 4: msg = "14:00-16:00 "; break;
                        case 5: msg = "16:00-18:00 "; break;
                        case 6: msg = "18:00-20:00 "; break;
                        case 7: msg = "20:00-22:00 "; break;
                        default: break;
                    }
                    if (time > 0) { msg = thisFileName.Substring(i 11, thisFileName.Length - (i 11) - 4) Environment.NewLine; }
                }
                textBox_log.Text = "已借用教室:" Environment.NewLine msg;
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
                //Message返回异常对象中包含的错误信息 
            }
        }
    }
}



标签: 会议

实例下载地址

教室/会议室预定系统源码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警