您的位置:首页 > 其它

第七次作业+梦飞扬

2015-12-14 20:51 381 查看
在第六次的基础上:

增加:

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

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

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

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

[b]代码实现:[/b]

[b]from1:[/b]

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();
}
string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
SqlConnection conn = new SqlConnection();
public static string name;
private void button1_Click(object sender, EventArgs e)
{

if (textBox1.Text != "" && textBox2.Text != "")
{
kailu();

name = textBox1.Text;
string com = "select count(*) from user_info where userName='" + name + "' ";
SqlCommand comm = new SqlCommand(com, conn);
int a = (int)comm.ExecuteScalar();
if (a == 0)
{
label3.Text = "用户名不存在!";
textBox1.Clear();
textBox2.Clear();

}
else
{

string corrStr = "select count(*)  from user_info where userName='" + textBox1.Text + "' and  passWord='" + textBox2.Text + "'";
SqlCommand con = new SqlCommand(corrStr, conn);
int tt = (int)con.ExecuteScalar();
if (tt == 0)
{
label3.Text = "您输入的密码有错误,请重新输入!";
textBox2.Clear();
}
else
{

label3.Text="恭喜你,登录成功了!";
Form2 foa = new Form2();
foa.ShowDialog();
}
}

}
else
{
MessageBox.Show("请输入用户名和密码!");
}

}
private void kailu()
{

try
{
conn = new SqlConnection(ConnStr);
conn.Open();
}
catch (Exception ex)
{

label3.Text="数据库连接失败" + ex.ToString();
}

}

private void button2_Click(object sender, EventArgs e)
{
Form3 form = new Form3();
form.ShowDialog();
}
}
}


from2:

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();
}
string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
SqlConnection conn = new SqlConnection();
private void Form2_Load(object sender, EventArgs e)
{
label1.Text = "欢迎你" + Form1.name;
}

private void button1_Click(object sender, EventArgs e)
{
conn = new SqlConnection(ConnStr);
string updarta = "Update user_info set passWord='" + textBox3.Text.Trim() + "' where userName='" + textBox1.Text.Trim() + "'";
SqlCommand comm = new SqlCommand(updarta, conn);
conn.Open();
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("修改成功!");
}
else
{
MessageBox.Show("修改失败!");
}
conn.Close();
}

private void button2_Click(object sender, EventArgs e)
{
conn = new SqlConnection(ConnStr);
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+"')";
SqlCommand comm = new SqlCommand(comstr, conn);
conn.Open();
if (textBox2.Text != "")
{
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("报修成功!");
}
else
{
MessageBox.Show("报修失败!");
}
}
string commstr = "select usernaem,class1,addss,nierong,nowdate,cishu from repair_info";
SqlDataAdapter das = new SqlDataAdapter(commstr, conn);
DataSet ds = new DataSet();
DataTable td = new DataTable();
das.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}

private void button3_Click(object sender, EventArgs e)
{
conn = new SqlConnection(ConnStr);
string updarta = "Update repair_info set cishu='" + textBox8.Text.Trim() + "' where usernaem='" + textBox2.Text.Trim() + "'";
SqlCommand comm = new SqlCommand(updarta, conn);
conn.Open();
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("再次报修成功!");
}
else
{
MessageBox.Show("再次报修失败!");
}
conn.Close();
}

private void button4_Click(object sender, EventArgs e)
{
conn = new SqlConnection(ConnStr);
string updarta = "delete form repair_info where usernaem='" + textBox2.Text.Trim() + "'";
SqlCommand comm = new SqlCommand(updarta, conn);
conn.Open();
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("完成保修成功!");
}
else
{
MessageBox.Show("完成报修失败!");
}
conn.Close();
}

}
}


from3:

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 Form3 : Form
{
public Form3()
{
InitializeComponent();
}
string ConnStr = "Data Source=.;Initial Catalog=repair;Integrated Security=True";
SqlConnection conn = new SqlConnection();

private void button1_Click(object sender, EventArgs e)
{

if (textBox1.Text != "" && textBox2.Text != "")
{
conn = new SqlConnection(ConnStr);
string comstr = @"insert into user_info(userName,passWord) values('" + textBox1.Text + "','" + textBox2.Text + "')";
SqlCommand comm = new SqlCommand(comstr, conn);
conn.Open();
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("注册成功!");
}
else
{
MessageBox.Show("注册失败!");
}

}
else
{
if (textBox1.Text != "")
{
MessageBox.Show("密码不能为空!");
}
else
{
MessageBox.Show("用户名不能为空!");
}
}
conn.Close();
}

private void button2_Click(object sender, EventArgs e)
{
conn = new SqlConnection(ConnStr);
string delstr = "delete from user_info where userName='"+textBox1.Text.Trim()+"'";
SqlCommand comm = new SqlCommand(delstr,conn);
conn.Open();
int a = comm.ExecuteNonQuery();
if (a > 0)
{
MessageBox.Show("注销成功!");
}
else
{
MessageBox.Show("注销失败哦!");
}
conn.Close();
}

}
}


数据库:







代码实现:











PSP消耗:

pspPersonal Software Process StagesTime(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分;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: