
using System;
using System.Data;
using System.Data.SqlClient;
namespace TinyHeels.App_Code
{
    class Settings
    {
        public string bName { get; set; }
        public string bMoto { get; set; }
        public string bPhone { get; set; }
        public string bEmail { get; set; }
        public string bAddress { get; set; }
        public string bCurrency { get; set; }

        //----------------------------         Message

        public string burl { get; set; }
        public string bid { get; set; }
        public string bpwd { get; set; }
        public string bmask { get; set; }


        public static string url { get; set; }
        public static string id { get; set; }
        public static string pwd { get; set; }
        public static string mask { get; set; }

        //------------------------ Satic Values
        public static string Name { get; set; }
        public static string Moto { get; set; }
        public static string Phone { get; set; }
        public static string Email { get; set; }
        public static string Address { get; set; }
        public static string Currency { get; set; }
        public static byte[] logo;
        public static byte[] logoReport;
        DBConnection strcon = new DBConnection();

        private byte[] bImage;
        public byte[] BImage
        {
            get { return bImage; }
            set { bImage = value; }
        }

        private byte[] imageReport;
        public byte[] ImageReport
        {
            get { return imageReport; }
            set { imageReport = value; }
        }
        //------------------------------
        public DataTable getSettings()
        {
            try
            {
                SqlConnection connection = strcon.connect();
                using (SqlDataAdapter ds1 = new SqlDataAdapter("SELECT  * from  settings", connection))
                {
                    DataSet ds = new DataSet();
                    ds1.Fill(ds);
                    DataTable dt = new DataTable();
                    dt = ds.Tables[0];
                    connection.Close();
                    return dt;
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
        public void updateSettings()
        {
            try
            {
                SqlConnection connection = strcon.connect();
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "update settings set bName=@bName,bMoto=@bMoto,bAddress=@bAddress,bPhone=@bPhone,bEmail=@bEmail,bGst=@bGst,bServiceCharges=@bServiceCharges,bCurrency=@bCurrency,bLogo=@bLogo,bLogoReport=@bLogoReport,msgUrl=@msgUrl,msgId=@msgId,msgPwd=@msgPwd,msgMask=@msgMask where id='1'";
                cmd.Parameters.AddWithValue("@bName", this.bName);
                cmd.Parameters.AddWithValue("@bMoto", this.bMoto);
                cmd.Parameters.AddWithValue("@bAddress", this.bAddress);
                cmd.Parameters.AddWithValue("@bPhone", this.bPhone);
                cmd.Parameters.AddWithValue("@bEmail", this.bEmail);
                cmd.Parameters.AddWithValue("@bCurrency", this.bCurrency);
                cmd.Parameters.AddWithValue("@bLogo", this.bImage);
                cmd.Parameters.AddWithValue("@bLogoReport", this.ImageReport);
                cmd.Parameters.AddWithValue("@msgUrl", this.burl);
                cmd.Parameters.AddWithValue("@msgId", this.bid);
                cmd.Parameters.AddWithValue("@msgPwd", this.bpwd);
                cmd.Parameters.AddWithValue("@msgMask", this.bmask);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not update settings data");
            }
        }
        public void updateName()
        {
            try
            {
                SqlConnection connection = strcon.connect();
                SqlCommand cmd = connection.CreateCommand();
                cmd.CommandText = "update settings set bName=@bName,bMoto=@bMoto where id='1'";
                cmd.Parameters.AddWithValue("@bName", this.bName);
                cmd.Parameters.AddWithValue("@bMoto", this.bMoto);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                connection.Close();
            }
            catch (Exception ex)
            {
                throw new Exception("Could not update settings data");
            }
        }
    }
}
