C#报修系统Ⅱ
用户需求:
1、用户可以注册,可以登录。
2、需要一个报修界面,当点击“报修”按钮时,软件会把用户报修的信息保存起来,更新报修次数,同时会清空相应的文本框,软件还要要检查所有文本框是否为空,空的话给出提示!
具体设计思路:
第一步:数据库》添加一个名为repair_info的表,此步由侯贺琦负责!
第二步:为实现用户注册,在登录界面做出改变,把之前的取消按钮改为了注册按钮,新增一个注册窗体,两个label,两个文本框,两个按钮。点击注册按钮,可以实现用户的注册。后台代码即为实现用户注册增加的一个SQL语句,以此往user_info表插入新用户记录。此步由康贺、张玉冕负责!
第三步:新增一个报修窗体,一个labUsn,用来存放登录的用户名,这个也叫做高度抽象的效果是吧,两个文本框来存放报修地点以及报修内容,一个ReportDate(DateTimePicker)控件用了存报修日期及时间,一个comboxType,用来存放报修类型。一个按钮来实现数据的插入。此步丁志愿、李锦城负责!
第四步:为了实现用户报修次数的更新,首先要看这个用户是否是第一次报修,如果是第一次报修,那么SQL语句不需要写插入次数的字段,因为数据库设置为默认为1,所以在插入数据之前做个判断就行了。如果不是第一次报修,那么就看这个用户之前共有多少条报修记录,在原来的基础上+1。此步张宇负责!
--》界面设计:找张背景图,添加文字。在线PS就行,很简单!张宇负责!
团队成员及分工
团队: Blue 团队共有六人
姓名: 学号后四位: 贡献分:
张 宇(队长) 1152 1+2=3分
侯贺琦 1027 1+1.5=2.5分
丁志愿 1011 1+0.5=1.5分
李锦城 1040 1+0.5=1.5分
张玉冕 1153 0.7分
康 贺 1169 0.8分
第五步:请看代码实现↓↓↓
DBConn.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data.SqlClient; using System.Data; namespace sixth { class DBConn { //连接字符串 public static string connStr = "Data Source=ZHANGYU;Initial Catalog=repair;Integrated Security=True;Pooling=False"; public static SqlConnection conn = new SqlConnection(connStr); //读取数据 public static DataSet getData(string sqlStr) { conn.Open(); SqlDataAdapter ada = new SqlDataAdapter(sqlStr, conn); DataSet ds = new DataSet(); ds.Clear(); ada.Fill(ds); conn.Close(); return ds; } //更新数据 public static DataSet upData(string sqlStr) { try { conn.Open(); SqlCommand comm = new SqlCommand(sqlStr, conn); comm.CommandType = CommandType.Text; comm.ExecuteNonQuery();//执行sql语句 conn.Close(); } catch { conn.Close(); } return null; } //判断是否更新记录 public static bool PDData(string sqlStr) { try { conn.Open(); SqlCommand comm = new SqlCommand(sqlStr, conn); comm.CommandType = CommandType.Text; comm.ExecuteNonQuery();//执行sql语句 conn.Close(); return true; } catch { conn.Close(); return false; } } } }
FormLogin.cs
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 sixth { public partial class FormLogin : Form { public FormLogin() { InitializeComponent(); } private void btnLogin_Click(object sender, EventArgs e) { try { if (txtUsn.Text.Trim() == "") { labMessage.Text ="用户名不能为空!"; txtUsn.Focus();//获取焦点 return; } else if (txtPwd.Text.Trim() == "") { labMessage.Text ="密码不能为空!"; txtPwd.Focus(); return; } string sqlStr = "select userName,passWord from user_info where userName='"+txtUsn.Text+"'"; DataSet ds = DBConn.getData(sqlStr); ].Rows.Count==) { labMessage.Text = "用户名不存在!请重新输入"; txtUsn.Text = "";//文本框置空 txtPwd.Text = ""; txtUsn.Focus(); } ].Rows[][].ToString() == txtPwd.Text.Trim()) { FormReport frmReport = new FormReport(); frmReport.labUsn.Text = txtUsn.Text.Trim(); labMessage.Text = "恭喜您已成功登录!"; this.Hide(); frmReport.Show(); } else { labMessage.Text = "密码错误!请重新输入!"; txtPwd.Text = ""; txtPwd.Focus(); } } catch (Exception ex) { labMessage.Text = "登录异常:" + ex.Message; txtUsn.Text = ""; txtPwd.Text = ""; txtUsn.Focus(); } finally { DBConn.conn.Close();//最重要的是要关闭数据库! } } private void txtPwd_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { btnLogin_Click(sender, e); } } private void btnRegist_Click(object sender, EventArgs e) { FormRegist frmRegist = new FormRegist(); frmRegist.Show(); } } }
FormRegist.cs
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 sixth { public partial class FormRegist : Form { public FormRegist() { InitializeComponent(); } void ClearAll() { txtUsn.Text = ""; txtPwd.Text = ""; } bool userName(string userName) { string sqlStr = "select userName from user_info where userName='" + txtUsn.Text.Trim() + "'"; DataSet ds = DBConn.getData(sqlStr); ].Rows.Count == ) { return false; } return true; } private void btnCancel_Click(object sender, EventArgs e) { if (MessageBox.Show("确认取消注册?", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { this.Close(); } } private void txtPwd_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { btnRegist_Click(sender, e); } } private void btnRegist_Click(object sender, EventArgs e) { try { if (txtUsn.Text.Trim() == "") { MessageBox.Show("用户名不能为空!", "提示"); txtUsn.Focus(); } else if (txtPwd.Text.Trim() == "") { MessageBox.Show("密码不能为空!", "提示"); txtPwd.Focus(); } else if (userName(txtUsn.Text.Trim())) { MessageBox.Show("用户名已存在!", "提示"); ClearAll(); } else { string sqlStr = "insert into user_info values('" + txtUsn.Text.Trim() + "','" + txtPwd.Text.Trim() + "')"; if (DBConn.PDData(sqlStr)) { MessageBox.Show("用户名为:" + txtUsn.Text + "注册成功!"); } this.Close(); } } catch (Exception ex) { DBConn.conn.Close(); MessageBox.Show(ex.Message); ClearAll(); } } } }
FormReport.cs
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 sixth { public partial class FormReport : Form { public FormReport() { InitializeComponent(); } void ClearAll() { txtAddress.Text = ""; txtContent.Text = ""; ReportDate.Value = DateTime.Now; comboxType.SelectedIndex = -; } private void btnReport_Click(object sender, EventArgs e) { try { if (txtAddress.Text.Trim() == "") { MessageBox.Show("报修地点不能为空", "提示"); txtAddress.Focus(); return; } else if (txtContent.Text.Trim() == "") { MessageBox.Show("报修内容不能为空", "提示"); txtContent.Focus(); return; } ) { MessageBox.Show("请选择报修类型", "提示"); comboxType.Focus(); return; } string sqlStr1 = "select userName,repairCount from repair_info where userName='"+labUsn.Text+"'"; DataSet ds = DBConn.getData(sqlStr1); ].Rows.Count==)//如果ds里面不存在数据,说明这个用户第一次报修,直接插入新的记录 { string sqlStr; sqlStr = "insert into repair_info(userName,repairType,repairAddress,repairContent,repairDate) values('" + labUsn.Text + "','" + comboxType.SelectedItem.ToString() + "','" + txtAddress.Text.Trim() + "','" + txtContent.Text.Trim() + "','" + ReportDate.Value.ToString() + "')"; DBConn.upData(sqlStr); MessageBox.Show("报修成功!"); ClearAll(); } else//否则的话就是repair_info表里已经有了labUsn里的这个用户。目的就是更新这个用户的报修次数,并插入新的记录 { string sqlStr; ].Rows[ds.Tables[].Rows.Count - ][].ToString(); sqlStr = ) + "')"; //更新语句:sqlStr = "update repair_info set repairType ='" + comboxType.SelectedItem.ToString() + "',repairAddress='" + txtAddress.Text.Trim() + "',repairContent='" + txtContent.Text.Trim() + "',repairDate='" + ReportDate.Value + "',repairCount='" + (int.Parse(ds.Tables[0].Rows[0][1].ToString()) + 1) + "'where userName='" + labUsn.Text + "'"; DBConn.upData(sqlStr); MessageBox.Show("报修成功!"); ClearAll(); } } catch (Exception ex) { DBConn.conn.Close(); MessageBox.Show(ex.Message); } } private void FormReport_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("您确认要退出吗?", "退出系统", MessageBoxButtons.OKCancel) == DialogResult.OK) { this.Dispose(); Application.Exit(); } else e.Cancel = true; } } }
运行:
1.当用户名不存在时,注册一个新用户。
2.报修登记,提示报修成功。并且labUsn显示用户名。
3.因为登陆窗体为主窗体,之前Hide了,所以在最后窗体关闭的时候,终止应用程序。
PSP耗时分析:
团队编程总结:
这是这个项目的第二次完善,因为上次封装的时候,只是把连接字符串封装了,而没有把数据的读取封装,所以这次对数据库的访问和操作都封装到了DBConn类里,以便于调用!之前我们基本上没有注重界面这一块,看别人做的项目界面都设计的挺有个性哈,不知道这个重不重要,但这次我们也试着美化了一下界面。
个人总结:
张宇:个人认为--》其实次数的更新才是这次作业最麻烦的地方,本来呢我是直接用update语句来进行更新的,但是更新的话就不能插入新纪录了。并且,SQL语句特别容易写错。我原本以为要求的是要把次数放到repair_info表里的,所以还是用了insert语句。没关系,这样的话一次一次进行改进,不是更好吗,而且我们学到的东西也会更多。毕竟对待事物的方法不止一种,有的只是内容不同罢了!
侯贺琦:
队长仍分配给我们任务。我负责数据库连接这方面,仍然是我薄弱的一方面。队长说一个团队,要做好一个项目,要有十分全面的考虑以及分析。牛老师说作为一个学计算机的,不会写代码就像学音乐的不懂五线谱一样,还是要多努力敲代码的。代码是我们让计算机创造生产力的必须工具。我对他的话很信服,觉得他说的很对,所以我下面也会认真的敲代码,会多看书上的例题,多练习。接下来也会配合队长完善这个程序。还是要感谢队长,感谢他相信我让我负责数据库这一块。我相信我们的团队会完成得很出色。we are a team。we are 伐木累。
C#报修系统Ⅱ的更多相关文章
- PHP实现单人多人聊天源码免费分享 | 电脑报修系统
源码清单 1. 简易版登陆式聊天源码. 2. 电脑报修轻系统源码. 3. 关注下面公众号回复“聊天”,免费获取. 聊天系统 虽然微信,QQ是即时通讯的元老.但是他们限制很多,所以很多人都想做一个自己的 ...
- easyUI 如何不跳转页面,只是加载替换center部分内容
以前做的一个故障报修系统,前端框架使用easyUI框架,layout布局,center使用datagrid .点击左边树形菜单时时页面跳转,想要知道如何点击菜单时不进行页面跳转,而是只对center模 ...
- IText 生成简单表格(报表)doc文档 单元居中
IText生成doc文档需要三个包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar 亲测无误,代码如下所示: import com.lowagie ...
- VMware 虚拟机(linux)增加根目录磁盘空间 转自
转自 http://wenku.baidu.com/link?url=WZDgESO0oXqYfhPYOWFalZsMglS0HKtLw7t6ICRs_sJ_sfPc85RpxsqKMwqSniis0 ...
- 基于j2ee的程序代写MVC架构
人力资源管理系统 完成系统静态页面设计,页面数量不少于10个,页面需用CSS进行美化,并为需要验证的信息利用JavaScript提供客户端验证.要求至少包含部门信息及部门内员工信息的添加.修改.删除和 ...
- VMware 虚拟机(linux)增加根目录磁盘空间
今天查看学校的监控报修系统,不能访问了!!!系统运行很慢,用top命令查看发现内存使用率90%,用"df -h ”查看“/”目录使用率已达到80%,导致系统运行很慢.我用以下方法扩大根目录磁 ...
- asp.net C# 题目大全
net001在线饰品销售系统 net002鲜花商城 net003商品销售管理系统 net004在线辅导答疑 net005土地税务管理系统 net006旅游管理 net007房产中介 net008房产信 ...
- 安卓 Android题目大全
安卓001个人事务管理系统(单端) 安卓002手机订餐系统 安卓003无线点菜 安卓004酒店房间预定系统 安卓005个人相册管理系统(单端) 安卓006计算器(单端) 安卓007英语学习(单端) ...
- 个人作业3——个人总结(Alpha阶段)。
一:个人总结: 陆续几周以及加上上上一周的Alpha冲刺阶段,完成了实验室故障报修系统的基础框架以及内容.这个过程苦中有乐,或许苦中寻乐更加恰当,以一个小组团队的形式来完成这个项目,我们大家就变成了一 ...
随机推荐
- Android课程---关于ListView列表视图的学习
activity_ui3.xml <?xml version="1.0" encoding="utf-8"?> <ListView xmlns ...
- 24 个你应该了解的 PHP 库
24 个你应该了解的 PHP 库 2015-09-08 分类:WEB开发.编程开发.首页精华暂无人评论 来源:伯乐在线 分享到:更多3 二十万年薪PHP工程师培养计划 成为被疯抢的And ...
- Yii源码阅读笔记(二十二)
Module类,属性的注释和构造函数的注释: <?php /** * @link http://www.yiiframework.com/ * @copyright Copyright (c) ...
- 【转】发布一个基于NGUI编写的UI框架
发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...
- bootstrap加深
1.安装: bootstrap中文网:http://www.bootcss.com/ bootstrap.css样式:http://v3.bootcss.com/css/#tables class=' ...
- 启动Hive报错
Exception in thread "main" java.lang.RuntimeException: Hive metastore database is not init ...
- Sublime Text 3 3126 注册码
转载自:https://fatesinger.com/78252 Sublime Text 3 3126 注册码 第一个测试通过 -– BEGIN LICENSE -– Michael Barnes ...
- jQuery源代码学习之四——jQuery.callbacks
自己实现的callbacks模块相较于jquery源代码中的callbacks模块有所简化,表面上看没有考虑firing这个参数,没有对之进行任何处理,即没有考虑在函数执行过程中,再次调用add,re ...
- node 的express 如何接受以一个网站的url作为参数的路由
获取get参数127.0.0.1:3000/index?id=12 ,这种情况下,这种方式是获取客户端get方式传递过来的值,通过使用req.query.id就可以获得,类似于PHP的get方req. ...
- DuiLib学习笔记2——写一个简单的程序
我们要独立出来自己创建一个项目,在我们自己的项目上加皮肤这才是初衷.我的新建项目名为:duilibTest 在duilib根目录下面有个 Duilib入门文档.doc 我们就按这个教程开始入门 首先新 ...