求C#大神来看看!!!!

目前就是已做好表面窗体,问题是如何建立数据库并通过按“入住信息”窗体的button“入住”“预订”保存相关信息 且底层“管理”窗体的每个button如按“201”可只显示201保存的信息图片说明

有大神不?? 求解

弹窗时把你的201参数传过去,保存的数据的时候一块保存就可以了

配置数据库链接信息,下面的为集成验证

 <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=服务器地址;Initial Catalog=数据库名;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
  </connectionStrings>

如果是要填写用户名密码的配置链接如下

 <connectionStrings>
 <add name="SQLDBConnection" providerName="System.Data.SqlClient" connectionString="Data Source=服务器地址; Initial Catalog=数据库名; User ID=用户名; PassWord=密码; Persist Security Info=True;"/>
 </connectionStrings>

在详细信息中的button按钮事件中添加与业务相关的数据访问功能;
你的房间列表信息完全可以从数据库中读取,自动生成201-220房间号,这些按钮完全可以通过调用一个事件实现,只是传的参数不一样而已。
简单的参数传递完全可以通过你按钮的.Text属性获取。然后建立房间详细信息窗体,该窗体定义一个构造方法用来接收参数如"201",202等等,来达到显示不同房间信息的功能。

http://www.cnblogs.com/shaozhuyong/articles/2786239.html

我刚刚给你写了一个例子。一个主窗体Main用于管理客房信息,一个客房详细信息Detail用于显示具体的房间信息
1、主窗体代码

 public Main()
        {
            InitializeComponent();
            this.Text = "客房管理";
        }

        private void Main_Load(object sender, EventArgs e)
        {
            InitBtnList();
        }

        private void InitBtnList()
        {

            Button btn = null;
            //这里可以换成读取数据库
            for (int i = 0; i < 10; i++)
            {
                btn = new Button();
                btn.Text =string.Format("房间【{0}】", i.ToString());
                btn.Tag = i.ToString();
                btn.Click+=new EventHandler(btn_Click);
                this.flowLayoutPanel1.Controls.Add(btn);
            }
        }

        private void btn_Click(object sender, EventArgs e)
        {
            string strNum = ((Button)sender).Tag.ToString();
            //显示房间信息
            Detail win = new Detail(strNum);
            win.Show();
        }

2、详细信息代码

  string strNum = "";
        //获取配置文件中的数据库链接信息
        private static string DB_CONNECTION = System.Configuration.ConfigurationManager.ConnectionStrings["SQLDBConnection"].ToString();
        public Detail()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 新建构造方法
        /// </summary>
        /// <param name="num"></param>
        public Detail(string num)
        {
            InitializeComponent();
            strNum = num;
            this.Text = string.Format("房间信息【{0}】", strNum);
            LoadRoom();
        }
        /// <summary>
        /// 加载房间信息
        /// </summary>
        private void LoadRoom()
        {
            DataSet ds = new System.Data.DataSet();
            SqlDataAdapter adp = null;
            SqlConnection conn = new SqlConnection(DB_CONNECTION);
            //写你的SQL
            SqlCommand cmd = new SqlCommand("select * from tmp where=roomNum="+strNum, conn);
            adp = new SqlDataAdapter(cmd);
            adp.Fill(ds);
            conn.Close();
            adp.Dispose();

            //处理数据显示
            //你自己写吧

        }

3、效果(房间号自动生成,点击每个按钮显示不同房间的信息)
图片说明

public partial class 入住信息 : Form
{
public 入住信息()
{
InitializeComponent();
setData();
}
#region 全局变量
private static string name;//姓名
private static string sex;//性别
private static string card;//证件类型
private static string code;//证件号
private static string phone;//电话
private static DateTime dataTime1;//日期
private static string day;//入住天数
private static double yajin=0; //押金
private static double zhekou;//折扣
private static string kehuleixing;//客户类型
private static string bz;//备注

    #endregion

    #region 保存数据
    private void AddData()
    {
        name = txtName.Text;
        sex = cbSex.Text;
        card = cbCard.Text;
        code = txtCode.Text;
        phone = txtPhone.Text;
        dataTime1 = Convert.ToDateTime(dataTime.Text);
        if (cbDay.Text != "" && txtYJ.Text != "" && cbZK.Text != "" && txtCode.Text != "")
        {
            day = cbDay.Text;
            yajin = Convert.ToDouble(txtYJ.Text);
            zhekou = Convert.ToDouble(cbZK.Text);
            code = txtCode.Text;
        }
        else
        {
            MessageBox.Show("证件号,天数,押金或者折扣不能为空!");
        }
        kehuleixing = cbKHLX.Text;
        bz = txtBZ.Text;
    }
    #endregion

    private void setData()
    {
        txtName.Text = name;
        cbSex.Text = sex;
        cbCard.Text = card;
        txtCode.Text = code;
        txtPhone.Text = phone;
        //dataTime.Text = dataTime1.ToShortDateString();
        cbDay.Text = day;
        txtYJ.Text = yajin.ToString();
        cbZK.Text = zhekou.ToString();
        cbKHLX.Text = kehuleixing;
        txtBZ.Text = bz;
    }
    private void button92_Click(object sender, EventArgs e)
    {
        AddData();
        this.Visible = false;
        this.Close();
        MessageBox.Show("预订成功");
    }

    private void button93_Click(object sender, EventArgs e)
    {
        AddData();
        this.Visible = false;
        this.Close();
        MessageBox.Show("入住成功");
    }

    private void button94_Click(object sender, EventArgs e)
    {
        this.Visible = false;
        this.Close();
        MessageBox.Show("完成退房");
    }

    private void txtYJ_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (int)e.KeyChar != 46)
            e.Handled = true;
        //小数点的处理。
        if ((int)e.KeyChar == 46)                           //小数点
        {
            if (txtYJ.Text.Length <= 0)
                e.Handled = true;   //小数点不能在第一位
            else
            {
                float f;
                float oldf;
                bool b1 = false, b2 = false;
                b1 = float.TryParse(txtYJ.Text, out oldf);
                b2 = float.TryParse(txtYJ.Text + e.KeyChar.ToString(), out f);
                if (b2 == false)
                {
                    if (b1 == true)
                        e.Handled = true;
                    else
                        e.Handled = false;
                }
            }
        }
    }
}

你的意思,是想先分别录入各个房间的信息,然后再点击-个按钮来保存所有录入的临时信息吗?如果是这样我感觉没有必要,这样会占用很多的内存空间,建议你还是录入一个保存一个,处理上你可以通过关闭事件来实现自动保存。