📄 rentform.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 RentForm : Form
{
//存储器客户输入内容
private RecordClass rentInfor = new RecordClass();
//折扣
private double discount;
//用于读取文件
private BinaryFormatter reader = new BinaryFormatter();
private FileStream input;
//存储管理员的基本数据
private OwnerInforClass ownerInfor;
//已用车辆信息
UsedClass used = new UsedClass();
//计算出编号
public string GetNO()
{
//获取当前时间
string time = System.DateTime.Now + "";
timeBuilder.Insert(0, time);
//年份去后两位
timeBuilder.Remove(0, 2);
//用0补充空位
if (timeBuilder[4] == '-')
timeBuilder.Insert(3, "0");
if (timeBuilder[7] == ' ')
timeBuilder.Insert(6, "0");
if (timeBuilder[10] == ':')
timeBuilder.Insert(9, "0");
//删除多余的字符
timeBuilder.Replace("-", "");
timeBuilder.Replace(" ", "");
timeBuilder.Replace(":", "");
timeBuilder.Remove(10, 2);
//输出编号
return timeBuilder.ToString();
}
public RentForm()
{
InitializeComponent();
}
private void returnButtom_Click(object sender, EventArgs e)
{
this.Close();
}
public OwnerInforClass ReadOwnerInfor()
{
input = new FileStream("OwnerInfor.txt", FileMode.Open, FileAccess.Read);
ownerInfor = (OwnerInforClass)reader.Deserialize(input);
input.Close();
return ownerInfor;
}
public StringBuilder timeBuilder = new StringBuilder();
//显示剩余车辆数目
public void ShowUsedNum()
{
int[] temp ={ 0, 0, 0, 0, 0 };
temp = used.GetUsedNum();
//读取车辆总数
ownerInfor=ReadOwnerInfor();
//显示剩余车辆数目
int i = -1;
reLieLabel.Text = "辆 剩余 " +(ownerInfor.totNUMLie- temp[++i]);
reMountainLabel.Text = "辆 剩余 " +(ownerInfor.totNUMMON -temp[++i]);
reRunLabel.Text = "辆 剩余 " +(ownerInfor.totNUMRun- temp[++i]);
reCollapeLabel.Text = "辆 剩余 " +(ownerInfor.totNUMCollapse- temp[++i]);
reDoubleLabel.Text = "辆 剩余 " + (ownerInfor.totNUMDouble -temp[++i]);
}
//处理剩余车辆信息
public void SetNewUsedNum()
{
int[] newUsed ={ 0, 0, 0, 0, 0 };
int[] haveUsed = { 0, 0, 0, 0, 0 };
int i = -1;
haveUsed = used.GetUsedNum();
newUsed[++i] = haveUsed[i] + rentInfor.lieNum;
newUsed[++i] = haveUsed[i] + rentInfor.mounNum;
newUsed[++i] = haveUsed[i] + rentInfor.runNum;
newUsed[++i] = haveUsed[i] + rentInfor.collapseNum;
newUsed[++i] = haveUsed[i] + rentInfor.doubleNum;
used.SetUsedNum(newUsed);
}
private void RentForm_Load(object sender, EventArgs e)
{
//显示剩余车辆数目
ShowUsedNum();
//获取编号
numberLabel.Text = null;
numberLabel.Text = GetNO();
//读取数据
ownerInfor=ReadOwnerInfor();
//价格栏信息
lieLabel.Text = "每辆每小时"+ownerInfor.pricrLie+"元 租";
runLabel.Text = "每辆每小时" + ownerInfor.pricrLie + "元 租";
collaprLabel.Text = "每辆每小时" + ownerInfor.priceCollapse + "元 租";
doubleLabel.Text = "每辆每小时" + ownerInfor.priceDouble + "元 租";
mountainLabel.Text = "每辆每小时" + ownerInfor.priceMOU + "元 租";
//信用方式栏信息
studentRadioButton.Text = "学生(打" + (10*ownerInfor.discountStudent) + "折)";
CMenberRadioButton.Text = "会员(打" + (10*ownerInfor.discountClientMen) + "折)";
normalRadioButton.Text = "普通(打" + (10*ownerInfor.discountTeacher) + "折)";
//存储租车时间
rentInfor.time = System.DateTime.Now;
}
//存储客户信息并检验
private bool SaveAndCheckClintInfor()
{
//客户信息
try
{
rentInfor.NO = timeBuilder.ToString();
int length = renterPhoneTextBox.Text.Length;
if (length != 11 && length != 12)
throw new ArgumentException();
if (renterPhoneTextBox.Text == null)
{
throw new ArgumentNullException();
}
else
rentInfor.phone = renterPhoneTextBox.Text;
if (renterIDTextBox.Text.Length != 18)
throw new ArithmeticException();
if (renterNameTextBox.Text == null)
{
throw new ArgumentNullException();
}
else
rentInfor.ID = renterIDTextBox.Text;
rentInfor.name = renterNameTextBox.Text;
return true;
}
catch (ArgumentNullException)
{
MessageBox.Show("姓名,电话,身份证号码都要填写", "信息错误",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
catch (ArgumentException)
{
MessageBox.Show("电话号码长度不对,请更正", "电话号码错误",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
catch (ArithmeticException)
{
MessageBox.Show("身份证号的位数不对,请更正", "身份证信息错误",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
private bool SaveAndChekBikeShape()
{
//车型信息
try
{
if (lieTextBox.Text != null)
{
rentInfor.lieNum = Int32.Parse(lieTextBox.Text);
}
if (MOUTextBox.Text != null)
{
rentInfor.mounNum = Int32.Parse(MOUTextBox.Text);
}
if (runTextBox.Text != null)
{
rentInfor.runNum = Int32.Parse(runTextBox.Text);
}
if (collapseTextBox.Text != null)
{
rentInfor.collapseNum = Int32.Parse(collapseTextBox.Text);
}
if (doubleTextBox.Text != null)
{
rentInfor.doubleNum = Int32.Parse(doubleTextBox.Text);
}
return true;
}
catch (ArgumentNullException)
{
MessageBox.Show("车型的数目不能为空,请更正", "车型信息错误",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
catch (FormatException)
{
MessageBox.Show("每种车型的数目都应该填写而且由数字构成,请更正", "车型数目错误",
MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
//租用形式
private bool SaveAndCheckRentWay()
{
try
{
if (studentRadioButton.Checked == true)
{
discount = ownerInfor.discountStudent;
rentInfor.student = "checked";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -