using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 小型宾馆管理系统
{
    public partial class mainform3 : Form
    {
        public mainform3()
        {
            InitializeComponent();
        }
        void RefreshData()
        {
            string comStr;
            database db = new database();
            DataSet ds = new DataSet();
            comStr = "select * from tbl_Client";
            ds = db.GetDataFromDB(comStr);
            if (ds == null)
            {
                MessageBox.Show("没有任何记录！");
            }
            else
            {
                dataGridView1.DataSource = ds.Tables[0];
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string x;
            x = "select price from tbl_room where roomNo='" +cmbboxRoomNo .Text.Trim ()+ "'";
            database db = new database();
            DataSet ds = new DataSet();
            ds = db.GetDataFromDB(x);
            x=ds.Tables[0].Rows[0].ItemArray[0].ToString();
            try
            {
                string sqlStr;
            string a="";
            if (radioBtnMan.Checked) a = radioBtnMan.Text;
            if (radioBtnWoman.Checked) a = radioBtnWoman.Text;
            sqlStr = "insert into tbl_Client(Clientname,Sex,IDNumber,NativePlace,roomNO,InDate,prePrice,Daycost) values ('"+ txtoxName .Text .Trim ()+"','" + a.Trim ()+ "','" + txtboxID .Text .Trim () + "','" + txtboxPlace .Text .Trim () + "','" + cmbboxRoomNo .Text .Trim () + "','"+txtInDate .Text .Trim() +"','"+txtPrePrice .Text.Trim ()+"','"+x.Trim ()+"')";
            database db3 = new database();
            bool b;
            b = db3.UpdataDB(sqlStr);
            if (b)
            {
                MessageBox.Show("添加成功！");
                string comStr;
                database db4 = new database();
                DataSet ds4 = new DataSet();
                comStr = "select * from tbl_Client where IDNumber='" + txtboxID .Text.Trim () + "'";
                ds4 = db4.GetDataFromDB(comStr);
               dataGridView1.DataSource = ds4.Tables[0];
                string sqlStr2;
                sqlStr2 = "Update tbl_room set inornot=" +true+ " where roomno='" + cmbboxRoomNo .Text.Trim()+ "'";
                database db2 = new database();
                db2.UpdataDB(sqlStr2);
                
            }
            }
            catch(Exception ex) 
            {MessageBox .Show (ex.Message );

            }
            cmbboxRoomNo.Items.Remove(cmbboxRoomNo .Text .Trim());
            
 
            
        }

        private void btn_Cancle_Click(object sender, EventArgs e)
        {
            mainform a = new mainform();
            a.Show();
            this.Hide();
        }

        private void mainform3_Load(object sender, EventArgs e)
        {


            

            string sqlstr;
            sqlstr = "select roomNo from tbl_room where inornot="+false +"";
            database db = new database();
            DataSet ds = new DataSet();
            ds = db.GetDataFromDB(sqlstr);
           
            if(ds != null)
            //{
            // dataGridView1.DataSource = ds.Tables[0];
            // cmbboxRoomNo.DataSource = ds.Tables[0];
            // cmbboxRoomNo.DisplayMember = ds.Tables[0].Columns[0].ToString ();
                    
            //}

                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    cmbboxRoomNo.Items.Add(ds.Tables[0].Rows[i].ItemArray[0]);
                }
        
        }

        private void mainform3_FormClosed(object sender, FormClosedEventArgs e)
        {
            mainform a = new mainform();
            a.Show();
            this.Hide();
        }
    }
}