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 mainform4 : Form
    {
        public mainform4()
        {
            InitializeComponent();
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (comboBox2.Text != "")
            {
                string comStr;
                database db4 = new database();
                DataSet ds4 = new DataSet();
                comStr = "select * from tbl_Client where ClientID=" + comboBox2.Text.Trim() + "";
                ds4 = db4.GetDataFromDB(comStr);

                dataGridView1.DataSource = ds4.Tables[0];
                textkehuID.Text = "";
                textBox5.Text = "";
                radioButton4.Checked = false;
                radioButton3.Checked = false;
                textBox4.Text = "";
                textBox2.Text = "";
                comboBox1.Text = "";
                textBox1.Text = "";
                textBox3.Text = "";
            }
            else
            {
                MessageBox.Show("请选择要查询的客户ID号！");
            }

        }
        void combobox2ItemUpdate()
        {
            string sqlstr;
            sqlstr = "select ClientID from tbl_Client";
            database db = new database();
            DataSet ds = new DataSet();
            ds = db.GetDataFromDB(sqlstr);
            if (ds != null)


                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    comboBox2.Items.Add(ds.Tables[0].Rows[i].ItemArray[0]);
                } 
        }
        void combobox1ItemUpdate()
        {
            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)


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

        private void btnDeleete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定要删除客户信息吗？", "删除客户", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                string sqlStr;
                sqlStr = "delete from tbl_Client where ClientID=" +comboBox2 .Text.Trim ()+ "";
                database db = new database();
                bool c=db.UpdataDB(sqlStr);
                if (c) MessageBox.Show("删除成功！");
                
            }
        }

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

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string a="女";
            if (radioButton4.Checked)
                a = "男";

            string sqlStr;
            sqlStr = "Update tbl_Client set ClientName='" + textBox5.Text.Trim() + "',Sex='" + a.Trim() + "',IDNumber='" + textBox4.Text.Trim() + "',NativePlace='" + textBox2.Text.Trim() + "',RoomNo='" + comboBox1.Text.Trim() + "',InDate='" + textBox1.Text.Trim() + "',PrePrice='" + textBox3.Text.Trim() + "' where ClientID=" + textkehuID .Text.Trim () + "";
            database db = new database();
            bool b =db.UpdataDB(sqlStr);
            if (b)
            {
                MessageBox.Show("修改成功！");
            }
            else
            {
                MessageBox.Show("修改失败！");
            }
        }

        private void dataGridView1_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            int n = this.dataGridView1 .CurrentCell.RowIndex;
        textkehuID.Text   = this.dataGridView1 [0, n].Value.ToString();
        textkehuID.Enabled = false;
            textBox5 .Text  = this.dataGridView1 [1, n].Value.ToString();
            if (this.dataGridView1 [2, n].Value.ToString() == "男")
                radioButton4.Checked = true;
            else radioButton3.Checked = true;
            textBox4 .Text   = this.dataGridView1 [3, n].Value.ToString();
            textBox2.Text = dataGridView1 [4, n].Value.ToString();
         comboBox1 .Text   = dataGridView1 [5, n].Value.ToString();
         textBox1 .Text  = dataGridView1 [6, n].Value.ToString();
            textBox3 .Text  =dataGridView1 [7, n].Value.ToString();
            
        }

        private void mainform4_FormClosed(object sender, FormClosedEventArgs e)
        {
            mainform a = new mainform();
            a.Show();

        }

        private void mainform4_Load(object sender, EventArgs e)
        {
            combobox2ItemUpdate();
            combobox1ItemUpdate();
        }

    }
}