zoukankan      html  css  js  c++  java
  • 第七次作业

    设计思路:

    我们团队根据作业要求,我们用了一个类做了封装。在这个类定义了对数据库的增删改查方法,还有数据库的连接方法。用户成功登入进入报修界面便是from2。在from2里面调用封装的类,通过报修界面里面的操作然后更新到数据库里面。

    代码实现:

    用户登入

        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
           
    
            private void button1_Click(object sender, EventArgs e)
            {
                string strCon = @"data source=.;initial catalog=wode;integrated security=true";
                SqlConnection sqlCon = new SqlConnection(strCon);//执行连接
                try
                {
                    sqlCon.Open();//打开连接
                    string sqlStr = @"select count(*) from 用户表 where 用户名='"+this.textBox1.Text+"'and 用户密码='"+this.textBox2.Text+"'";//查询数据
                    SqlCommand sqlCmd = new SqlCommand(sqlStr, sqlCon);//执行命令
                    //返回的记录数目强制转换成整型
                    int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
                    if (count != 0)
                    {
                        Form2 frm2 = new Form2();
                        frm2.ShowDialog();
                        this.Hide();//登入成功显示
                    }
                    else
                    {
                        MessageBox.Show("用户登入失败");
                    }
                }
                catch (Exception ex)
                {
    
                    MessageBox.Show(ex.Message);
    
                }
                sqlCon.Close();
                Console.Read();
            }
        }

    类的封装

        class DBCon
        {
            public string strCon = @"Data Source=.;Initial Catalog=wode;Integrated Security=True";
            public SqlConnection sqlCon = new SqlConnection();  //SQL Server数据库连接
            public SqlDataAdapter sda = new SqlDataAdapter();   //数据库适配器
            public DataSet ds = new DataSet();  //数据集
            public DataTable dt = new DataTable();  //内存中数据的一个表
            public SqlDataReader sdr; //SQl数据阅读器
            //数据库连接方法
            public void dbcon() 
            {
                try
                {
                    sqlCon = new SqlConnection(strCon);
                }
                catch (Exception e)
                {
    
                    MessageBox.Show("数据库连接不成功" + e.ToString());
                }
    
            }//填充数据集方法
            public void dbFill(string selstr) 
            {
                dt.Clear();  //清空数据表
                sda = new SqlDataAdapter(selstr, strCon);
                //填充数据集,实质是填充ds中的第0个表
                sda.Fill(ds,"st");
                dt = ds.Tables["st"];
            }
            //判断数据查询是否成功方法
            public void dbSelect(string showInfo) 
            {
                sqlCon.Open();
                SqlCommand sqlcmd = new SqlCommand(showInfo, sqlCon);
                sdr = sqlcmd.ExecuteReader();
            }
            //数据库插入数据库方法
            public void dbInsert(string insertInfo) 
            {
                sqlCon.Open();
                SqlCommand sqlcmd = new SqlCommand(insertInfo, sqlCon);
                try
                {
                    sqlcmd.ExecuteNonQuery();
                }
                catch (Exception e)
                {
    
                    MessageBox.Show("报修失败" + e.ToString());
                }
                sqlCon.Close();
    
    
            }
        
            //数据修改方法
            public void dbUpdate(string updStr) 
            {
                sqlCon.Open();
                SqlCommand sqlcmd = new SqlCommand(updStr, sqlCon);
                try
                {
                    sqlcmd.ExecuteNonQuery();
                    MessageBox.Show("数据修改成功");
                }
                catch (Exception e)
                {
    
                    MessageBox.Show("数据修改失败" + e.ToString());
    
                }
                sqlCon.Close();
            }
            //数据删除方法
            public void dbDelete(string delStr)
            {
                sqlCon.Open();
                SqlCommand sqlcmd = new SqlCommand(delStr, sqlCon);
                try
                {
                    sqlcmd.ExecuteNonQuery();
                    MessageBox.Show("数据删除成功");
                }
                catch (Exception e)
                {
    
                    MessageBox.Show("数据删除失败" + e.ToString());
    
                }
                sqlCon.Close();
            }
    
    
        }

    保修界面

    public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            string selStr = @"select 报修类型 from 报修类型表";
            DBCon db = new DBCon();
    
            private void textBox1_TextChanged(object sender, EventArgs e)
            {
    
            }
    
            private void Form2_Load(object sender, EventArgs e)
            {
    
                db.dbcon();
                db.dbFill(selStr);
                comboBox1.ValueMember = "报修类型";
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                db.dbcon();
                this.timer1.Enabled = true;
               
                string insertInfo = "insert into 报修表(报修类型,,报修地点,报修内容,stuage) values('" + comboBox1.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
                db.dbInsert(insertInfo);
                db.dbFill(selStr);
                
              
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                textBox3.Text=System.DateTime.Now.ToString();
                
            }
        }
    

    PSP耗时分析:

    Personal software process sages

    Time(%)senior student

    估计用时

    13

    需求分析

    2

    生成设计文档

    3

    设计复审

    1

    具体设计

    4

    具体编码

    2

    事后总结

    1

    团队编程总结:

    经过几回的磨合我们之间的分工与合作变得更融洽了。合作的观念也有所增强了,每个人都能做到分配给自己的任务按时完成了,经过几次的合作我也对团队的成员的能力有了和理性的评估。这样在分配任务的时候便会变得更加合理。这样每个人都能做到按时完成自己的分到的任务。做作业的时候我们会碰到我们不能解决的问题会有人去查资料,然后我们一起讨论学习。

    任务的分配

    队长孟强 代码编写与规范

        李俊鹏 数据库的建立与与修改

        王杰   查资料做记录

        乔运超 PSP耗时分析

       娄文涛 代码复查

       郑世杰 测试

       李永朋 测试 

  • 相关阅读:
    centos7 使用docker 一键部署服务器
    node 连接mysql失败
    面试必会---模块化
    es6异步解决方案
    centos7 apache后台转nginx后台
    React + Ts 实现三子棋小游戏
    让你的项目使用Ts吧
    ES6 入门系列 ArrayBuffer
    怎么把使用vuepress搭建的博客部署到Github Pages
    Navicat Premium 15安装教程(完整激活版)
  • 原文地址:https://www.cnblogs.com/Meng-7/p/5041530.html
Copyright © 2011-2022 走看看