




已阅读5页,还剩9页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
专业:计算机科学与技术指导老师:李伟班级:计092学号:099074054姓名:陶嘉莉 实验五异常处理实验目的1. 理解异常的产生过程和异常处理的概念2. 掌握C#异常处理的方法实验内容异常的产生是由于代码执行过程中满足了异常的条件而使程序无法正常运行下去,捕获异常实验try-catch语句。还可以通过throw语句无条件抛出异常。 输入1365之间的数字,判断它是一年中的几月几日。增加的代码 Console.Write(Please input the year:); string st = Console.ReadLine(); int yearNum = int.Parse(st); bool isleapyear = yearNum % 4 = 0 & yearNum % 100 != 0 | yearNum % 400 = 0; int maxDayNum = isleapyear ? 366 : 365; Console.Write(Please input a day number between 1 and 0:, maxDayNum);运行结果 实验四-界面设计与文件存取1实验目的(1)练习界面功能的设计方法。(2)练习文本文件的存取方法。(3)练习对话框的使用方法。(4)练习菜单的设计方法。(5)练习工具条和状态条的设计方法。(6)练习一个窗体调用另外一个窗体以及窗体间参数传递的方法。2实验内容重新设计和处理与个人存取款相关的业务,假定处理业务仅有活期存款一种,而且业务处理规定与实验三的活期存款业务相同。要求功能界面中包括菜单条、工具条和状态条。3.实验步骤(1)创建一个名为MenuBankCustoms 的Windows 应用程序项目。重命名Form1.cs 为FormMain.cs,然后在此窗体上设计个人存款业务处理的功能界面。(2)向项目中添加一个类文件Account.cs,提供以下属性。AccountName:存款人姓名AccountNumber:存款人帐号AccountBalance:帐户余额。同时在该类中提供下面的方法。Deposit方法:负责实现存款功能。Withdraw方法:负责实现取款功能。(3)向项目中添加一个类文件Customers.cs,用于处理所有帐户的信息。类中提供下面的方法。Load 方法:负责从文件bankdata.txt 中将所有存款人的信息读入到Account 类型的数组中,并返回该数组。Save 方法:负责将所有存款人的信息保存到bankdata.txt 文件中。该方法返回一个布尔型的值,表明保存是否成功。CreateAccount 方法:负责创建新帐户,该方法返回新建的帐户。(4)向项目中添加一个Windows 窗体文件FormShowAccountMessage.cs,在该窗体中显示所有帐户信息using lab4b1;using lab4b2;namespace lab4b public partial class Form1 : Form public Form1() InitializeComponent(); private void toolStripLabel3_MouseEnter(object sender, EventArgs e) label3.Text = 将内存中所有用户的信息显示出来; private void toolStripLabel3_MouseLeave(object sender, EventArgs e) label3.Text = ; private void toolStripLabel1_MouseEnter(object sender, EventArgs e) label3.Text = 打开内存中所有用户的信息; private void toolStripLabel1_MouseLeave(object sender, EventArgs e) label3.Text = ; private void toolStripLabel2_MouseEnter(object sender, EventArgs e) label3.Text = 保存所有用户信息; private void toolStripLabel2_MouseLeave(object sender, EventArgs e) label3.Text = ; private void button1_MouseEnter(object sender, EventArgs e) label3.Text = 在已有用户上存款或者新开户并存款; private void button1_MouseLeave(object sender, EventArgs e) label3.Text = ; private void button2_MouseEnter(object sender, EventArgs e) label3.Text = 在已有用户上进行利息结算并取款; private void button2_MouseLeave(object sender, EventArgs e) label3.Text = ; private void listBox1_MouseEnter(object sender, EventArgs e) label3.Text = 所有用户的信息记录; private void listBox1_MouseLeave(object sender, EventArgs e) label3.Text = ; private void toolStripButton1_Click(object sender, EventArgs e) Form1_Load(sender, e); Customs cs = new Customs(); Account at0 = new Account50; at0 = cs.Load(); for (int i = 0; string.Compare(at0i.AccountName, ) != 0; i+) listBox1.Items.Insert(0, at0i.AccountName + t + at0i.AccountNumber + t + at0i.AccountBalance.ToString(); int j; for (j = 0; j at.Length; j+) if (string.Compare(atj.AccountName, ) = 0) break; for (int i = 0; i at0.Length; i+) ati + j = at0i; private void button1_Click(object sender, EventArgs e) int i, items = -1; double dollars = double.Parse(textBox2.Text); string Name = textBox1.Text; for (i = 0; i at.Length; i+) if (string.Compare(ati.AccountName, ) = 0) break; else if (string.Compare(ati.AccountName, Name) = 0) items = i; break; if (items = -1) int j; do int Num = int.Parse(Account.newAccountNum); Num+; if (Num / 10 = 0) Account.newAccountNum = 000 + Num.ToString(); else if (Num / 100 = 0) Account.newAccountNum = 00 + Num.ToString(); else if (Num / 1000 = 0) Account.newAccountNum = 0 + Num.ToString(); else Account.newAccountNum = Num.ToString(); for (j = 0; string.Compare(atj.AccountNumber, Account.newAccountNum) != 0 & string.Compare(atj.AccountName, ) != 0; j+) ; while (string.Compare(atj.AccountName, ) != 0); ati.AccountName = Name; ati.AccountNumber = Account.newAccountNum; ati.Deposit(dollars); listBox1.Items.Insert(0, 开户: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); else listBox1.Items.Insert(0, 存款前: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); ati.Deposit(dollars); listBox1.Items.Insert(0, 存款后: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); private void Form1_Load(object sender, EventArgs e) for (int i = 0; i at.Length; i+) ati = new lab4b1.Account(); textBox2.Text = 0; private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) toolStripButton1_Click(sender, e); private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) toolStripButton2_Click(sender, e); private void button2_Click(object sender, EventArgs e) string Name = textBox1.Text; double dollars = double.Parse(textBox2.Text); int items = -1; int i; for (i = 0; i at.Length; i+) if (string.Compare(ati.AccountName, ) = 0) break; else if (string.Compare(ati.AccountName, Name) = 0) items = i; break; if (items = -1) listBox1.Items.Insert(0, Error: + Name + 不存在:如果要开户请选择存款按钮); else if (ati.IsWithdraw(dollars) = 0) listBox1.Items.Insert(0, Error: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString() + t余额不足); else listBox1.Items.Insert(0, 存款前: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); ati.Withdraw(dollars); listBox1.Items.Insert(0, 存款后: + ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); private void toolStripButton2_Click(object sender, EventArgs e) if (MessageBox.Show(是否将所有用户信息保存在/bankdata.txt中, 保存, MessageBoxButtons.YesNo) = DialogResult.Yes) Customs ct = new Customs(); ct.Save(at0, false); for (int i = 1; string.Compare(ati.AccountName, ) != 0; i+) ct.Save(ati); private void toolStripButton3_Click(object sender, EventArgs e) f2.Show(); for (int i = 0; string.Compare(ati.AccountName, ) != 0; i+) f2.listBox1.Items.Insert(0, ati.AccountName + t + ati.AccountNumber + t + ati.AccountBalance.ToString(); private void 显示所有账户信息ToolStripMenuItem_Click(object sender, EventArgs e) toolStripButton3_Click(sender, e); private void listBox1_SelectedIndexChanged(object sender, EventArgs e) string str = listBox1.SelectedItem.ToString(); str = str.Substring(0, 3); str = str.Trim(); textBox1.Text = str; class Account public static string newAccountNum = 0000; private string accountName = ; private string accountNumber = ; private double accountBalance = 0; public double rate1 = 0.003; public double rate2 = 0.006; public Account() accountName = ; accountNumber = ; accountBalance = 0; public Account(string Name, double Balance) accountName = Name; accountNumber = newAccountNum; int Num = int.Parse(newAccountNum); Num+; if (Num / 10 = 0) newAccountNum = 000 + Num.ToString(); else if (Num / 100 = 0) newAccountNum = 00 + Num.ToString(); else if (Num / 1000 = 0) newAccountNum = 0 + Num.ToString(); else newAccountNum = Num.ToString(); accountBalance = Balance; public void Deposit(double dollars) accountBalance += dollars; public int IsWithdraw(double dollars) if (accountBalance = dollars) return 1; else return 0; else if (accountBalance * (1 + rate2) = dollars) return 1; else return 0; public void Withdraw(double dollars) if (accountBalance = 500) accountBalance -= -accountBalance * rate1 + dollars; else accountBalance -= -accountBalance * rate2 + dollars; public string AccountName set accountName = value; get return accountName; public string AccountNumber set accountNumber = value; get return accountNumber; public double AccountBalance set accountBalance = value; get return accountBalance; class Customs public Account Load() int i; Account At = new Account30; for (i = 0; i At.Length; i+) Ati = new Account(); string str; i = 0; StreamReader reader = new StreamReader(F:bankdata.txt, System.Text.Encoding.Default); while (str = reader.ReadLine() != null) string strline = new string3; strline = str.Split( ); Ati.AccountName = strline0; Ati.AccountNumber = strline1; Ati.AccountBalance = double.Parse(strline2); i+; reader.Close(); return At; public bool Save(Account at0, bool append) StreamWriter writer = new StreamWriter(F:bankdata.txt, append, System.Text.Encoding.Default); writer.WriteLine(at0.AccountName + + at0.AccountNumber + + at0.AccountBalance.ToString(); writer.Close(); return true; public bool Save(Account at0) StreamWriter writer = new StreamWriter(F:bankdata.txt, true, System.Text.Encoding.Default); writer.WriteLine(at0.AccountName + + at0.AccountNumber + + at0.AccountBalance.ToString(); writer.Close(); return true; 运行结果 ADO.NET 与数据操作1实验目的(1)练习SQL Server 数据库的创建与使用方法。(2)练习存储过程的创建与调用方法。(3)练习简单的统计查询方法。(4)练习绑定DataGridView到数据源的方法。(5)练习绑定其他控件到数据源的方法。(6)练习数据库中图片的显示和存取方法。2实验内容设计一个Windows应用程序项目,实现简单的银行工作人员基本信息管理,以及利用存储过程实现统计和查询功能。具体要求如下。(1)程序开始运行出现图4-4 所示的主功能以及登录界面,系统功能仅有两种,一种是基本信息管理,另一种是统计男女人数。已知所有操作员和对应的密码已经保存在数据库中的某个表中,只有操作员密码正确时才允许使用系统功能。(2)当操作员选中【基本信息管理】功能时,弹出如图4-5 所示的窗体,可以对基本信息进行记录导航、添加、删除、修改、保存,以及对照片的导入和移除处理。(3)当操作员选中【统计男女人数】功能时,直接弹出一个对话框显示统计结果。3实验步骤(1)创建一个名为BankEmployee 的Windows 应用程序项目。重命名Form1.cs 为FormMain.cs,然后在此窗体上设计如图4-4所示的设计界面。(2)在项目中创建一个名为Employee.mdf的数据库,新建两个表和3 个存储过程。BasicTable:该表用于保存职员基本信息。Operator:该表用于保存操作员名称及密码。SelectAllUserNameFromOperator:该存储过程用于填充下拉列表框。SelectOperator:该存储过程用于判断选择的操作员及密码。SimpleQuery:该存储过程用于统计男女人数。(3)完成FormMain.cs 窗体的【进入】、【退出】以及【统计男女人数】功能。(4)向项目中添加一个新窗体FormEmployee.cs,通过简单的拖放操作设计图4-5所示的设计界面,同时将各控件与数据库的对应字段绑定,然后在导航条的下面,添加一个居中显示的Label 控件,用于提示异常以及操作提示等信息,最后修改Program.cs 让其直接运行该窗体,以便快速调试该窗体提供的功能。(5)将FormEmployee.cs 窗体导航条中的【第一个记录】、【上一个记录】、【下一个记录】、【最后一个记录】、【新添】和【删除】按钮的对应属性全部改为“(无)”,例如【第一个记录】对应【MoveFirstItem】属性,【下一个记录】对应【MoveNextItem】属性等,以便自己用代码实现对应功能。(6)实现导航条上对应按钮的功能。(7)实现照片的【导入】和【移除】功能。(8)完成从FormMain.cs 调用FormEmployee.cs 的功能,并修改Program.cs 中的代码让其首先调用FormMain窗体。4.代码实现public partial class FormMain : Form public FormMain() InitializeComponent(); private void FormMain_Load(object sender, EventArgs e) this.selectAllUserNameFromOperatorTableAdapter.Fill(this.employeeDataSet1.SelectAllUserNameFromOperator); comboBoxOperator.DataSource = employeeDataSet1.SelectAllUserNameFromOperator; comboBoxOperator.DisplayMember = employeeDataSet1.SelectAllUserNameFromOperator.usernameColumn.ColumnName; private void buttonLogin_Click(object sender, EventArgs e) selectOperatorTableAdapter1.Fill(employeeDataSet1.SelectOperator, comboBoxOperator.Text, textBoxPassword.Text); if (textBoxPassword .Text != 123456) MessageBox.Show(操作员或密码不正确, , MessageBoxButtons.OK, MessageBoxIcon.Error); groupBox1.Enabled = false; else groupBox1.Enabled = true; private void buttonExit_Click(object sender, EventArgs e) this.Close(); private void radioButtonManage_CheckedChanged(object sender, EventArgs e) if (radioButtonManage.Checked = true) this.Hide(); FormEmployee fm = new FormEmployee(); fm.ShowDialog(); this.Show(); private void radioButtonQuery_CheckedChanged(object sender, EventArgs e) if (radioButtonQuery.Checked = true) int? maleNumber = 0; int? femaleNumber = 0; simpleQueryTableAdapter1.GetData(ref maleNumber , ref femaleNumber); MessageBox.Show(string.Format(男:0,女:1, maleNumber, femaleNumber); public partial class FormEmployee : Form public FormEmployee() InitializeComponent(); groupBox1.Text = ; private void basicTableBindingNavigatorSaveItem_Click(object sender, EventArgs e) try this.Validate(); this.basicTableBindingSource.EndEdit(); this.basicTableTableAdapter.Update(this.employeeDataSet.BasicTable); labelTip.Text = 保存成功; catch(Exception err) labelTip.Text = 保存失败: + err.Message; private void Form1_Load(object sender, EventArgs e) this.basicTableTableAdapter.Fill(this.employeeDataSet.BasicTable); ChangeCurrentPosition(CurrentOperator.当前记录); private void buttonImport_Click(object sender, EventArgs e) OpenFileDialog openFileDialog1 = new OpenFileDialog(); if (openFileDialog1.ShowDialog() = DialogResult.OK) Bitmap image = new Bitmap(openFileDialog1.FileName); pictureBoxPhoto.Image = image; private void buttonClear_Click(object sender, EventArgs e) pictureBoxPhoto.Image = null; private void basicTableBindingNavigator_RefreshItems(object sender, EventArgs e) private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e) try basicTableBindingSource.AddNew(); ChangeCurrentPosition(CurrentOperator.当前记录); textBoxName.Focus(); catch(Exception err) labelTip.Text = 当前记录有错:+err.Message; enum CurrentOperator 第一个记录, 前一个记录, 下一个记录, 最后一个记录, 当前记录 ; private void ChangeCurrentPosition(CurrentOperator cp) labelTip.Text = 温馨提示:操作一段时间后别忘了保存一下; try switch (cp) case CurrentOperator.第一个记录: basicTableBindingSource.M
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024年辽宁装备制造职业技术学院辅导员考试真题
- 信用行业管理制度
- 信访重点管理制度
- 修改单据管理制度
- 公司商务舱管理制度
- 加气站消防管理制度
- 售楼部设计管理制度
- 实验室养护管理制度
- 小公司报账管理制度
- 已耗品采购管理制度
- 北京市顺义区2023-2024学年五年级下学期数学期末试卷(含答案)
- 2025公基题库(附答案解析)
- 2025年宁夏银川灵武市选聘市属国有企业管理人员招聘笔试冲刺题(带答案解析)
- 机关内部制度管理制度
- 两办意见宣贯考试题及答案
- 2025年高纯硫酸锶项目市场调查研究报告
- 2025年汽车驾照考试科目一考试题库及参考答案
- 广东省广州市天河区2023-2024学年七年级下学期期末考试英语试题(含答案)
- 净水机服务合同协议书
- 古城煤矿压风系统远程监控改造技术协议
- 2025年上海市公务员录用考试《行测》真题及答案解析(B类)
评论
0/150
提交评论