using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BimaryDetect
{
    public partial class frmChangPassword : Form
    {
        public frmChangPassword()
        {
            InitializeComponent();
        }

        public void dbConnection()
        {
            FirstClass db2 = new FirstClass();
            DataTable dt2 = new DataTable();
            //GlobalClass.GlobalVar = "admin";
            if (GlobalClass.GlobalVar == "admin")
            {
                dt2 = db2.dbOut("SELECT     TOP 100 PERCENT UserName  FROM    userInfo ORDER BY UserName");
                dataGridView1.DataSource = dt2;
            }
            else
            {
                dt2 = db2.dbOut("SELECT     TOP 100 PERCENT UserName  FROM    userInfo WHERE (UserName = '" + GlobalClass.GlobalVar + "') ORDER BY UserName ");
                dataGridView1.DataSource = dt2;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "")
            {
                MessageBox.Show("مقادیر فیلدها نمی توانند خالی باشند");
            }
            else
            {
                FirstClass dbCheck = new FirstClass();
                DataTable dtChek = new DataTable();

                dtChek = dbCheck.dbOut("SELECT     TOP 100 PERCENT UserName, Password FROM userInfo WHERE     (Password = '" + textBox2.Text.Trim() + "' AND UserName = '" + textBox1.Text.Trim() + "') ORDER BY UserName");
                if (dtChek.Rows.Count <= 0)
                {
                    MessageBox.Show("نام کاربری و کلمه عبور همخوانی ندارند");
                }
                else
                {
                    FirstClass dbup1 = new FirstClass();
                    dbup1.cmd.Parameters.Add("@UserName", SqlDbType.NVarChar).Value = textBox1.Text.Trim();
                    dbup1.cmd.Parameters.Add("@PassWord", SqlDbType.NVarChar).Value = textBox3.Text.Trim();
                    dbup1.exeCommand("sp_userInfo_Update");
                    dbConnection();
                    textBox1.Clear();
                    textBox2.Clear();
                    textBox3.Clear();
                    MessageBox.Show("کلمه عبور تعویض شد");
                }
            }
        }

        private void frmChangPassword_Load(object sender, EventArgs e)
        {
            dbConnection();
        }
    }
}