| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 543 人关注过本帖
标题:求助关于程序类的设计!
只看楼主 加入收藏
zhaoxili
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:327
专家分:479
注 册:2009-1-3
结帖率:92.31%
收藏
已结贴  问题点数:20 回复次数:6 
求助关于程序类的设计!
  大家看我的程序,里面有重复使用的代码段,但是我却不知道怎么才可以定义成类,重复调用,另外程序中查询数据有一个按钮,怎么样才可以让查询到最后一个数据的时候,按钮不可用!
搜索更多相关主题的帖子: 设计 
2009-09-10 15:03
zhaoxili
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:327
专家分:479
注 册:2009-1-3
收藏
得分:0 
我无法上传附件,麻烦大大去免费网盘下载,谢谢   

在网盘  需要帮助的程序  里面

http://e.
conn.rar (1.3 MB)


[ 本帖最后由 zhaoxili 于 2009-9-10 15:07 编辑 ]
2009-09-10 15:06
NTYLWJ
Rank: 7Rank: 7Rank: 7
等 级:黑侠
帖 子:191
专家分:698
注 册:2008-12-2
收藏
得分:5 
你的程序呢?
2009-09-10 15:06
zhaoxili
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:327
专家分:479
注 册:2009-1-3
收藏
得分:0 
哥们真快  等待中……………………
2009-09-10 15:08
zhaoxili
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:327
专家分:479
注 册:2009-1-3
收藏
得分:0 
  怎么没有动静了啊  有不忙的高手吗 求助啊
2009-09-10 18:30
uubird
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:74
专家分:133
注 册:2009-7-2
收藏
得分:15 
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
 
namespace conn
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            btn_close.Enabled = false;
            btn_r.Enabled = false;
        }
        private SqlConnection con;
        private SqlDataReader reader;
        private SqlCommand cmd = new SqlCommand();
 
        private void button1_Click(object sender, EventArgs e)
        {
            
           conn_q();//1.....>>>1;
        }
 
        private void btn_close_Click(object sender, EventArgs e)
        {
            con.Close();
            btn_close.Enabled = false;
            btn_r.Enabled = false;
            btn_open.Enabled = true;
            txt_name.Enabled = false;
        }
 
        private void btn_fclose_Click(object sender, EventArgs e)
        {
            if(con.State!=ConnectionState.Closed)
            {
                con.Close();
                MessageBox.Show("数据连接已经关闭,现在可以安全关闭软件。","数据关闭提示");
            }
            Application.Exit();
        }
 
        private void btn_r_Click(object sender, EventArgs e)
        {
            if (btn_r.Text == "查询")
            {
                btn_r.Text = "重新查询";
                 conn_t();//2.......>>1;
            }
            else
            {
                if (reader != null)
                {
                    reader.Close();
                }
                con.Close();
                conn_q();//1......>>>2;
 
                conn_t();//2.......>>2;
            }
        }
 
        private void btn_next_Click(object sender, EventArgs e)
        {
            
           conn_r();//3.....>>>1;
            
 
        }
 
       ///<summery>
       ///1....
       ///</summery>
        private void conn_q()
        {
            string strcon;
 
                try
                {
                    if (txtDatabase.Text == "" && txtDatasource.Text == "" && txtLoginname.Text == "" && txtPassword.Text == "")
                        MessageBox.Show("有重要数据未填写,请确定填写完整!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    else
                    {
                        con = new SqlConnection();
                        strcon = "data source=" + this.txtDatasource.Text.Trim();
                        strcon += ";user id=" + this.txtLoginname.Text.Trim();
                        strcon += ";password=" + this.txtPassword.Text.Trim();
                        strcon += ";initial catalog=" + this.txtDatabase.Text.Trim();
                        con.ConnectionString = strcon;
                        //con.ConnectionString = "data source = (local);initial catalog = Address; user id = sa;password =sa";
                        con.Open();
 
                        //MessageBox.Show("数据库连接成功");                          
 
                        btn_open.Enabled = false;
                        btn_r.Enabled = true;
                        btn_close.Enabled = true;
                        txt_name.Enabled = true;
                    }
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("数据返回失败。原因:" + ex.Message);
                }
        }
        ///<summery>
       ///2....
       ///</summery>
        private void conn_t()
        {
            if (txt_name.Text == "")
                {
                    string strsql = "select * from 联系人";
                     = strsql;
 
                }
                else
                {
 
                    string strsql = "select name,number,number2 from 联系人 where name='" + txt_name.Text.Trim() + "'";
                     = strsql;
 
                }
                cmd.Connection = con;
                try
                {
                    reader = cmd.ExecuteReader();
                    conn_r();//3.....>>>2;
 
                }
                catch (SqlException ex)
                {
                    MessageBox.Show("查询失败,原因" + ex.Message, "提示");
                }
        }
       ///<summery>
       ///3....
       ///</summery>
        private void conn_r()
        {
            if (reader.Read())
            {
                this.txt_r_name.Text = reader[0].ToString();
                this.txt_r_number.Text = reader[1].ToString();
                this.txt_r_number2.Text = reader[2].ToString();
            }
        }
    }
}
2009-09-10 21:15
zhaoxili
Rank: 6Rank: 6
等 级:侠之大者
威 望:1
帖 子:327
专家分:479
注 册:2009-1-3
收藏
得分:0 
马上去尝试  先谢谢楼上的
2009-09-11 22:06
快速回复:求助关于程序类的设计!
数据加载中...
 
   



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

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