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

📄 ownerform.cs

📁 C#通过读取.txt文档进行运行的小系统
💻 CS
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;

namespace BikeRentSystem
{
    public partial class OwnerForm : Form
    {
        //用于读取文件
        private BinaryFormatter reader = new BinaryFormatter();
        private FileStream input;

        //存储管理员的基本数据
        private OwnerInforClass ownerInfor;


        public OwnerForm()
        {
            InitializeComponent();
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            //价格栏清空
            priceCollapseTextBox.Text = "";
            priceDoubleTextBox.Text = "";
            priceLieTextBox.Text = "";
            priceMOUTextBox.Text = "";
            priceRunTextBox.Text = "";

            //押金栏清空
            depCollapseTextBox.Text = "";
            depDoubleTextBox.Text = "";
            depLieTextBox.Text = "";
            depMOUTextBox.Text = "";
            depRunTextBox.Text = "";

            //车辆总数栏清空
            totNUMCollapseTextBox1.Text = "";
            totNUMDoubleTextBox1.Text = "";
            totNumLieTextBox1.Text = "";
            totNumMOUTextBox.Text = "";
            totNUMRunTextBox1.Text = "";

            //折扣栏清空
            studentTextBox1.Text = "";
            normalTextBox1.Text="";
            groupTextBox1.Text="";
            clintMenberTextBox1.Text="";
        }

        

        private void button2_Click(object sender, EventArgs e)
        {
            OwnerInforClass ownerInfor = new OwnerInforClass();

            try
            {

                //存储价格信息
                ownerInfor.priceCollapse = Double.Parse(priceCollapseTextBox.Text);
                ownerInfor.priceDouble = Double.Parse(priceDoubleTextBox.Text);
                ownerInfor.priceMOU = Double.Parse(priceMOUTextBox.Text);
                ownerInfor.priceRun = Double.Parse(priceRunTextBox.Text);
                ownerInfor.pricrLie = Double.Parse(priceLieTextBox.Text);

                //存储押金信息
                ownerInfor.depCollapse = Double.Parse(depCollapseTextBox.Text);
                ownerInfor.depDouble = Double.Parse(depDoubleTextBox.Text);
                ownerInfor.depLie = Double.Parse(depLieTextBox.Text);
                ownerInfor.depMOU = Double.Parse(depMOUTextBox.Text);
                ownerInfor.depRun = Double.Parse(depRunTextBox.Text);

                //存储车辆总数信息
                ownerInfor.totNUMCollapse = Double.Parse(totNUMCollapseTextBox1.Text);
                ownerInfor.totNUMDouble = Double.Parse(totNUMDoubleTextBox1.Text);
                ownerInfor.totNUMLie = Double.Parse(totNumLieTextBox1.Text);
                ownerInfor.totNUMMON = Double.Parse(totNumMOUTextBox.Text);
                ownerInfor.totNUMRun = Double.Parse(totNUMRunTextBox1.Text);

                //存储折扣信息
                ownerInfor.discountClientMen = Double.Parse(clintMenberTextBox1.Text);
                ownerInfor.discountGroup = Double.Parse(groupTextBox1.Text);
                ownerInfor.discountStudent = Double.Parse(studentTextBox1.Text);
                ownerInfor.discountTeacher = Double.Parse(normalTextBox1.Text);

                //团体界限
                ownerInfor.groupLine =Int32.Parse(groupLineTextBox.Text);

                //学生和会员应交押金
                ownerInfor.SCExcepton = Double.Parse(SCExceptTextBox.Text);

           
                //存储相关信息
                BinaryFormatter formatter = new BinaryFormatter();
                FileStream output;

                output = new FileStream("OwnerInfor.txt", FileMode.Open, FileAccess.Write);


                formatter.Serialize(output, ownerInfor);

                //关闭文件
                output.Close();
                MessageBox.Show("存储成功", "成功", MessageBoxButtons.OK,
                     MessageBoxIcon.Information);    
            }

            catch (ArgumentNullException)
            {
                MessageBox.Show("请填满所有数据再按\"确定按钮\"", "输入信息不全", MessageBoxButtons.OK,
                    MessageBoxIcon.Information);
            }

            catch (FormatException)
            {
                MessageBox.Show("请输入有效的数据格式再按\"确定\"按钮", "数据格式有误", MessageBoxButtons.OK,
                 MessageBoxIcon.Information);
            }

            catch (OverflowException)
            {
                MessageBox.Show("数据过大或过小", "数据有误", MessageBoxButtons.OK,
                 MessageBoxIcon.Information);

            }

            catch (IOException)
            {
                MessageBox.Show("点击一次\"确定\"按钮即可","点击次数过多",MessageBoxButtons.OK,
                MessageBoxIcon.Information);
            }

                  
        }

        public OwnerInforClass ReadOwnerInfor()
        {

            input = new FileStream("OwnerInfor.txt", FileMode.Open, FileAccess.Read);

            ownerInfor = (OwnerInforClass)reader.Deserialize(input);

            input.Close();

            return ownerInfor;
        }

        private void OwnerForm_Load(object sender, EventArgs e)
        {
            ownerInfor = ReadOwnerInfor();

            depLieTextBox.Text = ownerInfor.depLie+"";
            depRunTextBox.Text = ownerInfor.depRun + "";
            depMOUTextBox.Text = ownerInfor.depMOU + "";
            depCollapseTextBox.Text = ownerInfor.depCollapse + "";
            depDoubleTextBox.Text = ownerInfor.depDouble + "";

            totNumLieTextBox1.Text = ownerInfor.totNUMLie + "";
            totNumMOUTextBox.Text = ownerInfor.totNUMMON + "";
            totNUMRunTextBox1.Text = ownerInfor.totNUMRun + "";
            totNUMCollapseTextBox1.Text = ownerInfor.totNUMCollapse + "";
            totNUMDoubleTextBox1.Text = ownerInfor.totNUMDouble + "";

            priceLieTextBox.Text = ownerInfor.pricrLie + "";
            priceMOUTextBox.Text = ownerInfor.priceMOU + "";
            priceRunTextBox.Text = ownerInfor.priceRun + "";
            priceCollapseTextBox.Text = ownerInfor.priceCollapse + "";
            priceDoubleTextBox.Text = ownerInfor.priceDouble + "";

            studentTextBox1.Text = ownerInfor.discountStudent + "";
            normalTextBox1.Text = ownerInfor.discountTeacher + "";
            clintMenberTextBox1.Text = ownerInfor.discountClientMen + "";
            groupTextBox1.Text = ownerInfor.discountGroup + "";

            groupLineTextBox.Text = ownerInfor.groupLine + "";
            SCExceptTextBox.Text = ownerInfor.SCExcepton + "";

        }

        

     
    }
}

⌨️ 快捷键说明

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