| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 533 人关注过本帖
标题:想请各位大神帮忙把这段代码注释下!
只看楼主 加入收藏
余谦
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2013-3-7
结帖率:85.71%
收藏
已结贴  问题点数:20 回复次数:3 
想请各位大神帮忙把这段代码注释下!
程序代码:
    public partial class FrmMain : Form
    {
        private SqlConnection sqlConn;

        public FrmMain()
        {
            InitializeComponent();
            sqlConn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ConnectionString);
        }

        private void btnSearchUser_Click(object sender, EventArgs e)//查询
        {
            StringBuilder strSql = new StringBuilder("select * from test where 1=1 ");

            if (!string.IsNullOrEmpty(txtGonoSelect.Text))
            {
                strSql.Append(" and gono='" + txtGonoSelect.Text.Replace("'", "''") + "'");
            }

            if (!string.IsNullOrEmpty(txtNameSelect.Text))
            {
                strSql.Append(" and name='" + txtNameSelect.Text.Replace("'", "''") + "'");
            }

            using (SqlDataAdapter da = new SqlDataAdapter(strSql.ToString(), sqlConn))
            {
                DataTable dt = new DataTable();
                da.Fill(dt);
                dgvSelect.DataSource = dt;

            }
        }

        private void btnInsertUser_Click(object sender, EventArgs e)//新增
        {
            if (string.IsNullOrEmpty(txtGonoInsert.Text))
            {
                MessageBox.Show("工号信息不能为空!", "系统提示:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            using (SqlCommand cmd = new SqlCommand())
            {               
                cmd.Connection = sqlConn;
                 = CommandType.Text;
                 = "insert into test(gono,name) values(@gono,@name)";
                cmd.Parameters.Add("@gono", SqlDbType.Char, 6).Value = txtGonoInsert.Text.Replace("'", "''");
                cmd.Parameters.Add("@name", SqlDbType.Char, 10).Value = txtNameInsert.Text.Replace("'", "''");

                try
                {
                    sqlConn.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException)
                {
                    throw new ApplicationException();
                }
                finally
                {
                    sqlConn.Close();
                }

                dgvInsert.DataSource = userInfoGet();
            }           
        }

        private DataTable userInfoGet()
        {
            SqlDataAdapter da = new SqlDataAdapter("select id,gono,name from test", sqlConn);
            DataTable dt = new DataTable();
            da.Fill(dt);

            return dt;
        }

        private void btnUserDelete_Click(object sender, EventArgs e)//删除
        {
            if (dgvDelete.SelectedRows.Count == 0)
            {
                MessageBox.Show("请选择要删除的行!");
                return;
            }

            foreach (DataGridViewRow dr in dgvDelete.SelectedRows)
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    cmd.Connection = sqlConn;
                     = CommandType.Text;
                     = "delete from test where id='"+ dr.Cells["idDelete"].Value +"'";

                    try
                    {
                        sqlConn.Open();
                        cmd.ExecuteNonQuery();
                    }
                    catch (SqlException)
                    {
                        throw new ApplicationException();
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
            }

            dgvDelete.DataSource = userInfoGet();
        }

        private void btnSelect_Click(object sender, EventArgs e)//1
        {
            tbMain.SelectedIndex = 1;
        }

        private void btnInsert_Click(object sender, EventArgs e)//2
        {
            tbMain.SelectedIndex = 2;
        }

        private void btnUpdate_Click(object sender, EventArgs e)//3
        {
            tbMain.SelectedIndex = 3;
            dgvUpdate.DataSource = userInfoGet();
        }       

        private void btnDelete_Click(object sender, EventArgs e)//4
        {
            dgvDelete.DataSource = userInfoGet();
            tbMain.SelectedIndex = 4;
        }

        private void dgvUpdate_CellDoubleClick(object sender, DataGridViewCellEventArgs e)//更新
        {
            string id = dgvUpdate.CurrentRow.Cells["idUpdate"].Value.ToString();
            string gono = dgvUpdate.CurrentRow.Cells["gonoUpdate"].Value.ToString();
            string name = dgvUpdate.CurrentRow.Cells["nameUpdate"].Value.ToString();
            string returnBlag = string.Empty;

            using (FrmUserUpdate frmUserUpdate = new FrmUserUpdate(id, gono, name, sqlConn))
            {
                frmUserUpdate.ShowDialog(this);
                returnBlag = frmUserUpdate.ReturnBlag;
            }

            if (returnBlag == "Confirm")
            {
                //dgvUpdate.DataSource = userInfoGet();
            }
            dgvUpdate.DataSource = userInfoGet();
        }
2013-05-07 14:23
lantian8134
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:8
帖 子:115
专家分:789
注 册:2013-1-11
收藏
得分:10 
这也太多了吧
你标注一下哪几句看不懂
2013-05-07 16:52
lxb932979339
Rank: 5Rank: 5
等 级:职业侠客
威 望:4
帖 子:84
专家分:313
注 册:2013-4-24
收藏
得分:10 
不少。。
2013-05-07 16:55
zhengjianwei
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-7-16
收藏
得分:0 
                dgvInsert.DataSource = userInfoGet();//绑定数据显示出来

                SqlDataAdapter da = new SqlDataAdapter("select id,gono,name from test order by id desc", sqlConn);
                DataTable dt = new DataTable();
                da.Fill(dt);
                dgvInsert.DataSource = dt;
2013-07-16 16:11
快速回复:想请各位大神帮忙把这段代码注释下!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.074348 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved