首页 > 代码库 > 18周个人总结

18周个人总结

计划

 .评估这个任务需要七天的时间

开发

 .需求分析

作为一个赛事管理者。我希望知道每个队伍的比分,以便生成排名。

.生成设计文档

技术分享

 .具体设计

技术分享技术分享

.具体代码

 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();
                }
            }

        }
        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);
22             //DataSet ds = new DataSet();
24             //string strConn = "data source=.;initial catalog=itcast; integrated security=true";
25             //SqlConnection connection = new SqlConnection(strConn);
28             //SqlDataAdapter ada = new SqlDataAdapter(sql, connection);
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 }

 

 报告

.仍需努力修改

 

18周个人总结