基本信息
源码名称:教室/会议室预定系统源码
源码大小:0.43M
文件格式:.zip
开发语言:C#
更新时间:2020-07-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

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

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返回异常对象中包含的错误信息 
            }
        }
    }
}