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

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

        //private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        //{

        //}

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            //string s;
            //database db;
            //DataSet ds;
            //s = "select * from ";
            string comStr;
            database db4 = new database();
            DataSet ds4 = new DataSet();
            comStr = "select * from tbl_Client where ClientID=" + comboBox1.Text.Trim() + "";
            ds4 = db4.GetDataFromDB(comStr);

            dataGridView1.DataSource = ds4.Tables[0];

        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            string a = "",b="",c="",d="",i="";
           

          int n = this.dataGridView1.CurrentCell.RowIndex;
            a= dataGridView1[6, n].Value.ToString();
            c = dataGridView1[7, n].Value.ToString();
            d = dataGridView1[9, n].Value.ToString();
            i = dataGridView1[5, n].Value.ToString();
            b = textBox1.Text.Trim();
            DateTime dt1 = Convert.ToDateTime(a);
            DateTime dt2 = Convert.ToDateTime(b);
            TimeSpan span = dt2.Subtract(dt1);
            int dayDiff = span.Days + 1;
            label6.Visible = true;
            double x;
            x = dayDiff * Convert.ToInt32(d) * Convert.ToDouble(textBox2.Text.Trim()) + Convert.ToInt32(textBox3.Text.Trim());
            dayDiff = Convert.ToInt32(c);
            label6.Text = x.ToString();
            label7.Visible = true;
            label10.Visible = true;
            label10.Text = dayDiff.ToString();
            label8.Visible = true;
            label11.Visible = true;
            x = x - dayDiff;
            label11.Text = x.ToString();
            string sqlstr;
            sqlstr ="Update tbl_room set inornot=" +false+ " where roomno='" +i.Trim ()+ "'";

            database db = new database();
           
           db.UpdataDB(sqlstr);

        }
        

        private void mainform5_Load(object sender, EventArgs e)
        {
            
        
            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++)
                {
                    comboBox1.Items.Add(ds.Tables[0].Rows[i].ItemArray[0].ToString ());
                } 
       
        }

        

        
    }
}