using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class rl_students_pg_RegisterResault : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    DataSet ds;
    //********************************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            C_myClass.MenueItemsCreate(User, panelMenues);
            Label lblTitle = (Label)this.Master.FindControl("lblTitle");
            lblTitle.Text = "وضعیت ثبت نام";
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            cmd = con.CreateCommand();
            adp = new SqlDataAdapter(cmd);
            int studentId = _UseFull.C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Students", "studentId", "userName", HttpContext.Current.User.Identity.Name);
            adp.SelectCommand.CommandText = "select * from t_Registers INNER JOIN t_Courses ON t_Registers.courseId = t_Courses.courseId Where t_Registers.studentId = " + studentId;
            ds = new DataSet();
            adp.Fill(ds, "tbl");
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        catch(Exception ex)
        {
            
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "Operation")
            {
                try
                {
                    int regId = Int32.Parse(e.CommandArgument.ToString());
                    string conString = RamanConnectionString.LocalConnectionString();
                    con = new SqlConnection(conString);
                    con.Open();
                    cmd = con.CreateCommand();
                    string regStatus = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Registers", "regStatus", "regId", regId);
                    if (regStatus == "انتظار")
                    {
                        cmd.CommandText = "delete from t_Registers where regId = " + regId;
                        cmd.ExecuteNonQuery();
                        adp = new SqlDataAdapter(cmd);
                        int studentId = _UseFull.C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Students", "studentId", "userName", HttpContext.Current.User.Identity.Name);
                        adp.SelectCommand.CommandText = "select * from t_Registers INNER JOIN t_Courses ON t_Registers.courseId = t_Courses.courseId Where t_Registers.studentId = " + studentId;
                        ds = new DataSet();
                        adp.Fill(ds, "tbl");
                        GridView1.DataSource = ds;
                        GridView1.DataBind();
                    }
                    else if (regStatus == "رد")
                    {
                        Response.Redirect("pg_RegisterCancelReason.aspx?regId=" + regId.ToString() + "&returnUrl=pg_RegisterResault.aspx");
                    }
                    else if (regStatus == "تأیید")
                    {
                        Response.Redirect("pg_RegisterCommitDate.aspx?regId=" + regId.ToString() + "&returnUrl=pg_RegisterResault.aspx");
                    }
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
    }


    protected string FindStatusText(object RegId)
    {
        string res = "";
        try
        {
            int regId = Int32.Parse(RegId.ToString());
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            con.Open();
            cmd = con.CreateCommand();
            string regStatus = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Registers", "regStatus", "regId", regId);
            if (regStatus == "انتظار")
            {
                res = "در انتظار تأیید";
            }
            else if (regStatus == "رد")
            {
                res = "توسط آموزشگاه رد شد";
            }
            else if (regStatus == "تأیید")
            {
                res = "ثبت نام تأیید شد";
            }
        }
        catch
        {
        }
        finally
        {
            con.Close();
        }
        return res;
    }

    protected string FindStatusCssClass(object RegId)
    {
        string res = "";
        try
        {
            int regId = Int32.Parse(RegId.ToString());
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            con.Open();
            cmd = con.CreateCommand();
            string regStatus = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Registers", "regStatus", "regId", regId);
            if (regStatus == "انتظار")
            {
                res = "labelyellow";
            }
            else if (regStatus == "رد")
            {
                res = "labelred";
            }
            else if (regStatus == "تأیید")
            {
                res = "labelgreen";
            }
        }
        catch
        {
        }
        finally
        {
            con.Close();
        }
        return res;
    }

    protected string FindShowButtonText(object RegId)
    {
        string txt = "";
        try
        {
            int regId = Int32.Parse(RegId.ToString());
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            con.Open();
            cmd = con.CreateCommand();
            string regStatus = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Registers", "regStatus", "regId", regId);
            if (regStatus == "انتظار")
            {
                txt = "حذف ثبت نام";
            }
            else if (regStatus == "رد")
            {
                txt = "دلیل رد";
            }
            else if (regStatus == "تأیید")
            {
                txt = "زمان تأیید";
            }
        }
        catch
        {
        }
        finally
        {
            con.Close();
        }
        return txt;
    }

    protected string FindCssClass(object RegId)
    {
        string css = "";
        try
        {
            int regId = Int32.Parse(RegId.ToString());
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            con.Open();
            cmd = con.CreateCommand();
            string regStatus = _UseFull.C_Usefull.FindStringWithIntegerShart(con, cmd, "t_Registers", "regStatus", "regId", regId);
            if (regStatus == "انتظار")
            {
                css = "gridsmallbuttonsfalse";
            }
            else if (regStatus == "رد")
            {
                css = "gridsmallbuttons";
            }
            else if (regStatus == "تأیید")
            {
                css = "gridsmallbuttonstrue";
            }
        }
        catch
        {
        }
        finally
        {
            con.Close();
        }
        return css;
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            GridView1.PageIndex = e.NewPageIndex;
            string conString = RamanConnectionString.LocalConnectionString();
            con = new SqlConnection(conString);
            cmd = con.CreateCommand();
            adp = new SqlDataAdapter(cmd);
            int studentId = _UseFull.C_Usefull.FindIntegerWithStringShart(con, cmd, "t_Students", "studentId", "userName", HttpContext.Current.User.Identity.Name);
            adp.SelectCommand.CommandText = "select * from t_Registers INNER JOIN t_Courses ON t_Registers.courseId = t_Courses.courseId Where t_Registers.studentId = " + studentId;
            ds = new DataSet();
            adp.Fill(ds, "tbl");
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        catch
        {
        }
    }
}
