第七次作业
具体设计思路:
第一步:在上一次的数据库中建表repair_info;
第二步:编写代码。
代码实现:
Form1窗体
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.Data.SqlClient; namespace 登陆 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static string name; private void button1_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("Data Source=LENOVO-PC\\DATA;Initial Catalog=I:\\REPAIR.MDF;Integrated Security=True"); string sql = "select passWord from user_info where userName='"+txtuser.Text+"'"; SqlCommand comm = new SqlCommand(sql, conn); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); if (!reader.Read()) { label3.Visible = true; label3.Text = "用户名不存在!"; } else { if (reader["passWord"].ToString().Trim() == txtpwd.Text.Trim()) { label3.Visible = true; label3.Text = "祝贺你登录成功!"; } else { label3.Visible = true; label3.Text = "密码错误,请重新输入。"; } } name = txtuser.Text.Trim(); reader.Close(); conn.Close(); new Form2().Show(); } } }
Form2窗体
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.Data.SqlClient; namespace 登陆 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } SqlConnection conn; string sql; SqlCommand comm; int n; private void button1_Click(object sender, EventArgs e) { conn = new SqlConnection("Data Source=LENOVO-PC\\DATA;Initial Catalog=I:\\REPAIR.MDF;Integrated Security=True"); sql = "select count(*) from repair_info where userName='" + Form1.name + "'"; comm = new SqlCommand(sql, conn); conn.Open(); int i =(int) comm.ExecuteScalar(); conn.Close(); //当该用户存在是更新 if (n > 0) { sql = "update repair_info set rep_category=@category,rep_address=@address,rep_content=@content," + "rep_date=@date,rep_number=@number where userName='" + Form1.name + "'"; comm = new SqlCommand(sql, conn); comm.Parameters.Add(new SqlParameter("@category", SqlDbType.VarChar)); comm.Parameters["@category"].Value = cbbcategory.SelectedItem.ToString(); comm.Parameters.Add(new SqlParameter("@address", SqlDbType.VarChar)); comm.Parameters["@address"].Value = txtaddress.Text.Trim(); comm.Parameters.Add(new SqlParameter("@content", SqlDbType.NChar)); comm.Parameters["@content"].Value = rtbcontent.Text.Trim(); DateTime dt = new DateTime(); comm.Parameters.Add(new SqlParameter("@date", SqlDbType.DateTime)); comm.Parameters["@date"].Value = dt.Year + "-" + dt.Month + "-" + dt.Day; //+ " " + dt.Hour + ":" + dt.Minute + ":" + dt.Second; comm.Parameters.Add(new SqlParameter("@number", SqlDbType.Int)); comm.Parameters["@number"].Value = n + 1; } //当该用户不存在是插入 else { sql = "insert into repair_info(userName,rep_category,rep_address,rep_content,rep_date," + "rep_number) values(@username,@category,@address,@content,@date,@number)"; comm = new SqlCommand(sql, conn); comm.Parameters.Add("@username", SqlDbType.Char).Value = Form1.name; comm.Parameters.Add("@category", SqlDbType.VarChar).Value = cbbcategory.SelectedItem.ToString(); comm.Parameters.Add("@address", SqlDbType.VarChar).Value = txtaddress.Text.Trim(); comm.Parameters.Add("@content", SqlDbType.NChar).Value = rtbcontent.Text.Trim(); DateTime dt = new DateTime(); comm.Parameters.Add("@date", SqlDbType.DateTime).Value = dt.Year + "-" + dt.Month + "-" + dt.Day; comm.Parameters.Add("@number", SqlDbType.Int).Value = n + 1; } conn.Open(); int m=(int)comm.ExecuteNonQuery(); conn.Close(); if (m > 0) { MessageBox.Show("报修成功!"); } else { MessageBox.Show("请重新报修!"); } } //加载时取出当前报修次数 private void Form2_Load(object sender, EventArgs e) { conn = new SqlConnection("Data Source=LENOVO-PC\\DATA;Initial Catalog=I:\\REPAIR.MDF;Integrated Security=True"); sql = "select rep_number from repair_info where userName='" + Form1.name + "'"; comm = new SqlCommand(sql, conn); conn.Open(); SqlDataReader reader = comm.ExecuteReader(); if (!reader.Read()) { n = 0; } else { n =(int) reader["rep_number"]; } } //退出程序 private void button2_Click(object sender, EventArgs e) { Application.Exit(); } } }
测试:
PSP耗时分析:
PSP | Personal Software Process Stages | Time(min) |
Planning | 计划 | 20 |
·Estimate | ·估计这个任务需要多少时间 | 160 |
Development | 开发 | 120 |
·Analysis | ·需求分析 | 20 |
·Design Spec | ·生成设计档案 | 20 |
·Design Review | ·设计复审 | 30 |
·Coding Standard | ·代码规范 | 40 |
·Design | ·具体设计 | 30 |
·Coding | ·具体编码 | 120 |
·Code Review | ·代码复审 | 20 |
·Test | ·测试 | 20 |
Reporting | 报告 | 40 |
·Test Report | ·测试报告 | 10 |
·Size Measurement | ·计算工作量 | 20 |
·Postmortem & Process Improvement Plan | ·事后总结,并提出过程改进计划 | 10 |
团队成员:
成员姓名 | 学号后四位 | 贡献分 |
张雪(队长)(设计/编写代码) | 1150 | 5 |
穆思羽(复审) | 1172 | 2 |
毛蕊蕊(复审) | 6015 | 1.5 |
赵瑞玲(数据库建表) | 1156 | 1.5 |
团队总结:
张雪:在做这次的作业过程中我又把之前上课学习的有复习了下,感觉编写代码挺有趣的,我会继续努力的。
代码规范。