zoukankan      html  css  js  c++  java
  • 最后的冲刺作业

    计划:

    估计需要4-5天

    开发:

    需求分析:

        用户故事:作为一个赛事管理人员,我希望了解每一场比赛的比分,每队的总比分,每队的计分,以便进行排名。

        从分析用例故事可以知道完成此程序需要这两项任务:选择队伍和查询比赛记录。

    生成文档:画了构图

    代码规范:

    使用vs2010

    具体设计:

    下面是活动图:

     

    具体实现:

     

     

    具体代码:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data.SqlClient;
    using System.Data;
    using System.Configuration;
    namespace WindowsFormsApplication1
    {
       public static class SqlHelper
        {
            private static readonly string constr ="server=.;database=itcast;integrated security=true";
            //增删改
            public static int ExecuteNonQuery(string sql, params SqlParameter[] pams)
            {
    
                using (SqlConnection conn = new SqlConnection(constr))
                {
                    using (SqlCommand comm = new SqlCommand(sql, conn))
                    {
                        if (pams != null)
                        {
                            comm.Parameters.AddRange(pams);
                        }
                        conn.Open();
                        return comm.ExecuteNonQuery();
                    }
                }
    
            }
            //返回SqlDataReader
            public static SqlDataReader ExecuteReader(string sql, params SqlParameter[] pams)
            {
    
                SqlConnection conn = new SqlConnection(constr);
                using (SqlCommand comm = new SqlCommand(sql, conn))
                {
                    if (pams != null)
                    {
                        comm.Parameters.AddRange(pams);
    
                    }
                    conn.Open();
                    return comm.ExecuteReader(CommandBehavior.CloseConnection);
    
                }
            }
            public static object ExecuteScalar(string sql, params SqlParameter[] pams)
            {
    
                using (SqlConnection conn = new SqlConnection(constr))
                {
                    using (SqlCommand comm = new SqlCommand(sql, conn))
                    {
                        if (pams != null)
                        {
                            comm.Parameters.AddRange(pams);
                        }
                        conn.Open();
                        return comm.ExecuteScalar();
                    }
    
                }
            }
            public static DataTable ExecuteDataTable(string sql, params SqlParameter[] pams)
            {
                DataTable dt = new DataTable();
    
                using (SqlDataAdapter adapter = new SqlDataAdapter(sql, constr))
                {
                    if (pams != null)
                    {
                        adapter.SelectCommand.Parameters.AddRange(pams);
                    }
                    adapter.Fill(dt);
                }
                return dt;
            }
        }
    }
     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 
    10 namespace WindowsFormsApplication1
    11 {
    12     public partial class Form1 : Form
    13     {
    14         public Form1()
    15         {
    16             InitializeComponent();
    17         }
    18         private void DataGridviewDataBind(string sql = "select * from student")
    19         {
    20             dgvstudent.DataSource = SqlHelper.ExecuteDataTable(sql);
    21             //1.建临时仓库
    22             //DataSet ds = new DataSet();
    23             //2.建路
    24             //string strConn = "data source=.;initial catalog=itcast; integrated security=true";
    25             //SqlConnection connection = new SqlConnection(strConn);
    26             //3.卡车-装数据
    27 
    28             //SqlDataAdapter ada = new SqlDataAdapter(sql, connection);
    29             //4.卸数据
    30             //ada.Fill(ds);
    31         }
    32         private void btn_Click(object sender, EventArgs e)
    33         {
    34             StringBuilder sql = new StringBuilder();
    35             sql.Append("select * from student where 1=1");
    36             string StuNum = txtStuNum1.Text.Trim();
    37             if (!string.IsNullOrEmpty(StuNum))
    38             {
    39                 sql.Append(" and stuNum='" + StuNum + "'");
    40             }
    41             string StuName = txtStuName1.Text.Trim();
    42             if (!string.IsNullOrEmpty(StuName))
    43             {
    44                 sql.Append(" and stuName like '%" + StuName + "%'");
    45             }
    46             string StuClass = txtStuClass1.Text.Trim();
    47             if (!string.IsNullOrEmpty(StuClass))
    48             {
    49                 sql.Append(" and stuClass like '%" + StuClass + "%'");
    50             }
    51             string subject = cmbsubject.Text.Trim();
    52             if (!string.IsNullOrEmpty(subject))
    53             {
    54                 if (subject != "全部")
    55                 {
    56                     sql.Append(" and subject like '%" + subject + "%'");
    57 
    58                 }
    59                 DataGridviewDataBind(sql.ToString());
    60 
    61             }
    62         }
    63     }
    64 }
  • 相关阅读:
    使用XmlDataDocument将数据存储到XML文档
    Dubbo+Nacos 运行异常io.netty.handler.codec.EncoderException: java.lang.NullPointerException
    一、字符串常量Java内部加载
    更高效率,Java快速获取图片尺寸宽高分辨率(支持webp)
    水印宽高比例自适应图片(Java-Thumbnails)
    UEditor 自定义图片视频尺寸校验
    应用宝官方错误日志
    Eclipse使用hibernate插件
    解决Eclipse建立Maven项目后无法建立src/main/java资源文件夹的办法
    [Err] 1022
  • 原文地址:https://www.cnblogs.com/chen-bo/p/6256674.html
Copyright © 2011-2022 走看看