码迷,mamicode.com
首页 > 其他好文 > 详细

第七次作业+梦飞扬

时间:2015-12-14 22:47:10      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

 

在第六次的基础上:

增加:

1、用代码实现对数据库的增删改查操作,以此来实现用户的注册。

2、新建一个报修表,名字为repair_info,列有用户名、报修类型、报修地点、报修内容,报修日期和时间、用户报修次数等,列名自己起。

3、在报修界面中,当用户点击“报修”按钮时,软件会把用户报修的信息写入数据库中,更新报修次数,同时会清空相应的文本框,软件还要

检查所有文本框是否为空,空的话提示报修失败。

代码实现:

from1:

 

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Data.SqlClient;
10 
11 namespace 登录
12 {
13     public partial class Form1 : Form
14     {
15         public Form1()
16         {
17             InitializeComponent();
18         }
19         string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
20         SqlConnection conn = new SqlConnection();
21         public static string name;
22         private void button1_Click(object sender, EventArgs e)
23         {
24            
25             if (textBox1.Text != "" && textBox2.Text != "")
26             {
27                 kailu();
28 
29                 name = textBox1.Text;
30                 string com = "select count(*) from user_info where userName=‘" + name + "";
31                 SqlCommand comm = new SqlCommand(com, conn);
32                 int a = (int)comm.ExecuteScalar();
33                 if (a == 0)
34                 {
35                     label3.Text = "用户名不存在!";
36                     textBox1.Clear();
37                     textBox2.Clear();
38 
39                 }
40                 else
41                 {
42 
43                     string corrStr = "select count(*)  from user_info where userName=‘" + textBox1.Text + "‘ and  passWord=‘" + textBox2.Text + "";
44                     SqlCommand con = new SqlCommand(corrStr, conn);
45                     int tt = (int)con.ExecuteScalar();
46                     if (tt == 0)
47                     {
48                         label3.Text = "您输入的密码有错误,请重新输入!";                       
49                         textBox2.Clear();
50                     }
51                     else
52                     {
53 
54                         label3.Text="恭喜你,登录成功了!";
55                         Form2 foa = new Form2();
56                         foa.ShowDialog();
57                     }
58                 }
59 
60 
61 
62             }
63             else
64             {
65                 MessageBox.Show("请输入用户名和密码!");
66             }
67             
68             
69         }
70         private void kailu()
71         {
72            
73 
74             try
75             {
76                 conn = new SqlConnection(ConnStr);
77                 conn.Open();
78             }
79             catch (Exception ex)
80             {
81 
82                label3.Text="数据库连接失败" + ex.ToString();
83             }
84  
85         }
86 
87         private void button2_Click(object sender, EventArgs e)
88         {
89             Form3 form = new Form3();
90             form.ShowDialog();
91         }
92         }
93     }

 

from2:

  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using System.Data.SqlClient;
 10 
 11 namespace 登录
 12 {
 13     public partial class Form2 : Form
 14     {
 15         public Form2()
 16         {
 17             InitializeComponent();
 18         }
 19         string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
 20         SqlConnection conn = new SqlConnection();
 21         private void Form2_Load(object sender, EventArgs e)
 22         {
 23             label1.Text = "欢迎你" + Form1.name;
 24         }
 25 
 26         private void button1_Click(object sender, EventArgs e)
 27         {
 28             conn = new SqlConnection(ConnStr);
 29             string updarta = "Update user_info set passWord=‘" + textBox3.Text.Trim() + "‘ where userName=‘" + textBox1.Text.Trim() + "";
 30             SqlCommand comm = new SqlCommand(updarta, conn);
 31             conn.Open();
 32             int a = comm.ExecuteNonQuery();
 33             if (a > 0)
 34             {
 35                 MessageBox.Show("修改成功!");
 36             }
 37             else
 38             {
 39                 MessageBox.Show("修改失败!");
 40             }
 41             conn.Close();
 42         }
 43 
 44         private void button2_Click(object sender, EventArgs e)
 45         {
 46             conn = new SqlConnection(ConnStr);
 47             string comstr = "insert into repair_info(usernaem,class1,addss,nierong,nowdate,cishu) values(‘"+textBox2.Text+"‘,‘"+textBox4.Text+"‘,‘"+textBox5.Text+"‘,‘"+textBox6.Text+"‘,‘"+textBox7.Text+"‘,‘"+textBox8.Text+"‘)";
 48             SqlCommand comm = new SqlCommand(comstr, conn);
 49             conn.Open();
 50             if (textBox2.Text != "")
 51             {
 52                 int a = comm.ExecuteNonQuery();
 53                 if (a > 0)
 54                 {
 55                     MessageBox.Show("报修成功!");
 56                 }
 57                 else
 58                 {
 59                     MessageBox.Show("报修失败!");
 60                 }
 61             }
 62             string commstr = "select usernaem,class1,addss,nierong,nowdate,cishu from repair_info";
 63             SqlDataAdapter das = new SqlDataAdapter(commstr, conn);
 64             DataSet ds = new DataSet();
 65             DataTable td = new DataTable();
 66             das.Fill(ds);
 67             dataGridView1.DataSource = ds.Tables[0];
 68             conn.Close();
 69         }
 70 
 71         private void button3_Click(object sender, EventArgs e)
 72         {
 73             conn = new SqlConnection(ConnStr);
 74             string updarta = "Update repair_info set cishu=‘" + textBox8.Text.Trim() + "‘ where usernaem=‘" + textBox2.Text.Trim() + "";
 75             SqlCommand comm = new SqlCommand(updarta, conn);
 76             conn.Open();
 77             int a = comm.ExecuteNonQuery();
 78             if (a > 0)
 79             {
 80                 MessageBox.Show("再次报修成功!");
 81             }
 82             else
 83             {
 84                 MessageBox.Show("再次报修失败!");
 85             }
 86             conn.Close();
 87         }
 88 
 89         private void button4_Click(object sender, EventArgs e)
 90         {
 91             conn = new SqlConnection(ConnStr);
 92             string updarta = "delete form repair_info where usernaem=‘" + textBox2.Text.Trim() + "";
 93             SqlCommand comm = new SqlCommand(updarta, conn);
 94             conn.Open();
 95             int a = comm.ExecuteNonQuery();
 96             if (a > 0)
 97             {
 98                 MessageBox.Show("完成保修成功!");
 99             }
100             else
101             {
102                 MessageBox.Show("完成报修失败!");
103             }
104             conn.Close();
105         }
106 
107 
108     }
109 }

from3:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Linq;
 7 using System.Text;
 8 using System.Windows.Forms;
 9 using System.Data.SqlClient;
10 
11 namespace 登录
12 {
13     public partial class Form3 : Form
14     {
15         public Form3()
16         {
17             InitializeComponent();
18         }
19         string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
20         SqlConnection conn = new SqlConnection();
21 
22         private void button1_Click(object sender, EventArgs e)
23         {
24 
25             if (textBox1.Text != "" && textBox2.Text != "")
26             {
27                 conn = new SqlConnection(ConnStr);
28                 string comstr = @"insert into user_info(userName,passWord) values(‘" + textBox1.Text + "‘,‘" + textBox2.Text + "‘)";
29                 SqlCommand comm = new SqlCommand(comstr, conn);
30                 conn.Open();
31                     int a = comm.ExecuteNonQuery();
32                     if (a > 0)
33                     {
34                         MessageBox.Show("注册成功!");
35                     }
36                     else
37                     {
38                         MessageBox.Show("注册失败!");
39                     }                          
40  
41             }
42             else
43             {
44                 if (textBox1.Text != "")
45                 {
46                     MessageBox.Show("密码不能为空!");
47                 }
48                 else
49                 {
50                     MessageBox.Show("用户名不能为空!");
51                 }
52             }
53             conn.Close();
54         }
55 
56         private void button2_Click(object sender, EventArgs e)
57         {
58             conn = new SqlConnection(ConnStr);
59             string delstr = "delete from user_info where userName=‘"+textBox1.Text.Trim()+"";
60             SqlCommand comm = new SqlCommand(delstr,conn);
61             conn.Open();
62             int a = comm.ExecuteNonQuery();
63             if (a > 0)
64             {
65                 MessageBox.Show("注销成功!");
66             }
67             else
68             {
69                 MessageBox.Show("注销失败哦!");
70             }
71             conn.Close();
72         }
73 
74     }
75 }

 数据库:

技术分享技术分享

代码实现:

技术分享技术分享技术分享技术分享

 PSP消耗:

psp Personal Software Process Stages Time(h)
planning .计划 5
.Estimate .估计这个任务需要多长时间 4
Development .开发 40
.Analysis .需求分析 3
.Design Spec .生成设计文档 2
.Design Review .设计复审 4
• Coding Standard .代码规范 2
 • Design .具体设计 15
 • Coding .具体编码 4
• Code Review .代码复审 3
 • Text .测试 3
Reporting .报告 4
• Test Report .测试报告 3
• Size Measurement .计算工作量 0.5
 • Postmortem&Process Improvement Plan .事后总结并提出改进计划 4

团队总结:

本次团队在上一次的作业中,做了增量,通过团队合作,需要的是交流,只有交流多了,才能进步的多,多动手,在出错中改进,多做,才知道问题所在,在团队里,学会学习,我记得老师说,大学要学会学习的能力,学会查资料;我们团队需要多学习!希望跟上大家的步伐!

工作分配

    队长:赵文涛

    杨栗:查资料      1分;

    娄豪:PSP消耗统计 1分;

    李宁:总结        1分;

    姚震:测试        1分;

    肖雪峰:代码复审  1分;

    赵文涛:代码、复查、数据库、思路、界面设计  5分;

 

第七次作业+梦飞扬

标签:

原文地址:http://www.cnblogs.com/zwt0626/p/5046515.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!