using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using System.Data.SqlClient;

namespace Setting
{
    public partial class frmsetting : Form
    {
      
        public frmsetting()
        {
            InitializeComponent();
        }

        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DBSetting;Integrated Security=True");
        private void btn_ok_Click(object sender, EventArgs e)
        {
            SqlCommand sqlcmdedit = new SqlCommand();
            sqlcmdedit.CommandText = "update tblSetting set Theme=@Theme,ExteriorClock=@ExteriorClock,BackgroundClock=@BackgroundClock,BackgroundDate=@BackgroundDate,BackgroundAbout=@BackgroundAbout,BackgroundStoreInfo=@BackgroundStoreInfo,ShowClock=@ShowClock,ShowDate=@ShowDate,ShowAbout=@ShowAbout,ShowStoreInfo=@ShowStoreInfo where ID=@ID";
            sqlcmdedit.Connection = con;
            sqlcmdedit.Parameters.Add("@ID", SqlDbType.NChar).Value = "1";
            sqlcmdedit.Parameters.Add("@Theme", SqlDbType.Int).Value = cmb_theme.SelectedIndex;
            sqlcmdedit.Parameters.Add("@ExteriorClock", SqlDbType.Int).Value = cmb_clock_style.SelectedIndex;
            sqlcmdedit.Parameters.Add("@BackgroundClock", SqlDbType.Int).Value = cmb_clock_bg.SelectedIndex;
            sqlcmdedit.Parameters.Add("@BackgroundDate", SqlDbType.Int).Value = cmb_date_bg.SelectedIndex;
            sqlcmdedit.Parameters.Add("@BackgroundAbout", SqlDbType.Int).Value = cmb_about_bg.SelectedIndex;
            sqlcmdedit.Parameters.Add("@BackgroundStoreInfo", SqlDbType.Int).Value = cmb_info_bg.SelectedIndex;
            sqlcmdedit.Parameters.Add("@ShowClock", SqlDbType.Bit).Value = ch_time.Checked;
            sqlcmdedit.Parameters.Add("@ShowDate", SqlDbType.Bit).Value = ch_date.Checked;
            sqlcmdedit.Parameters.Add("@ShowAbout", SqlDbType.Bit).Value = ch_about.Checked;
            sqlcmdedit.Parameters.Add("@ShowStoreInfo", SqlDbType.Bit).Value = ch_info.Checked;
            con.Open();
            sqlcmdedit.ExecuteNonQuery();
            con.Close();
            this.Close();

            Form1 frm1 = (Form1)Application.OpenForms["Form1"];
            frm1.SetSetting();
        }

        private void frmsetting_Load(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.Connection = con;
            SqlDataReader Myreader;
            cmd.CommandText = "select * from tblSetting where  ID=@ID";
            cmd.Parameters.Add("@ID", SqlDbType.NVarChar).Value = "1";
            con.Open();
            Myreader = cmd.ExecuteReader();
            if (Myreader.Read())
            {
                cmb_theme.SelectedIndex =int.Parse( Myreader[1].ToString());
                cmb_clock_style.SelectedIndex = int.Parse(Myreader[2].ToString());
                cmb_clock_bg.SelectedIndex = int.Parse(Myreader[3].ToString());
                cmb_date_bg.SelectedIndex = int.Parse(Myreader[4].ToString());
                cmb_about_bg.SelectedIndex = int.Parse(Myreader[5].ToString());
                cmb_info_bg.SelectedIndex = int.Parse(Myreader[6].ToString());
                ch_time.Checked =  Myreader[7].ToString()=="True"?true:false;
                ch_date.Checked = Myreader[8].ToString() == "True" ? true : false;
                ch_about.Checked = Myreader[9].ToString() == "True" ? true : false;
                ch_info.Checked = Myreader[10].ToString() == "True" ? true : false;

                Myreader.Close();

            }
            con.Close();
        }

    }
}
