using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace ajans
{
    class login:connection
    {
        protected string user_name;
        protected string password;

        public login()
        {
            user_name = "";
            password = "";
        }

        public DataSet SelectAccountLogin()
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "SELECT user_name, password FROM login";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "login");
            objconn.Close();
            return objds;
        }

        public DataSet SelectAccount(string user,string pass)
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "SELECT user_name, password FROM login";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "login");
            objconn.Close();
            return objds;
        }

        public DataSet SelectAccount()
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "SELECT top(1) ajans_name,ajans_manage_name,ajans_address,ajans_tel1,ajans_tel2,ajans_tel3 FROM ajans order by ajans_id desc";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "ajans");
            objconn.Close();
            return objds;
        }

        public void InsertAjansSetting(string ajnNAme, string ajnMname, string ajnAddress, string ajnTel1, string ajnTel2, string ajnTel3)
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "Insert into ajans values(N'" + ajnNAme + "',N'" + ajnMname + "',N'" + ajnAddress + "',N'" + ajnTel1 + "',N'" + ajnTel2 + "',N'" + ajnTel3 + "')";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void InsertLogin()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "Insert into login values('','')";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void UpdateLoginUserPass(string User,string Pass)
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE login SET user_name='" + User + "',password='" + Pass + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public void UpdateLoginUserPass(string Pass)
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "UPDATE password SET password='" + Pass + "'";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }

        public DataSet SelectPassword()
        {
            objds.Clear();
            objda.SelectCommand = new SqlCommand();
            objda.SelectCommand.Connection = objconn;
            objda.SelectCommand.CommandText = "SELECT password FROM password";
            objda.SelectCommand.CommandType = CommandType.Text;
            objconn.Open();
            objda.Fill(objds, "password");
            objconn.Close();
            return objds;
        }

        public void InsertPassword()
        {
            objcomm.Connection = objconn;
            objcomm.CommandText = "Insert into password values('')";
            objconn.Open();
            objcomm.ExecuteNonQuery();
            objconn.Close();
        }
    }
}
