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_admins_pg_OnLineExamDesign : System.Web.UI.Page
{
    //**********************************
    SqlConnection con;
    SqlCommand cmd;
    //**********************************
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            C_myClass.MenueItemsCreate(User, panelMenues);
            Label lblTitle = (Label)this.Master.FindControl("lblTitle");
            lblTitle.Text = "طراحی آزمون آنلاین";
            SqlDataSource1.SelectCommand = "SELECT [onlineId], [onlineName], [onlineType], [testNum], [explainNum], [testScore], [explainScore], [designer] FROM [t_OnlineExams] Where userCreator = N'" + User.Identity.Name + "'";
            GridView1.DataBind();
        }
        catch
        {
        }
        finally
        {
        }
    }
    protected void btnAddStudent_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Redirect("pg_OnLineExamAdd.aspx?returnUrl=pg_OnLineExams.aspx");
        }
        catch
        {
        }
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        try
        {
            if (e.CommandName == "QuestionsPress")
            {
                int onlineId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_OnlineExamQuestions.aspx?onlineId=" + onlineId + "&returnUrl=pg_OnLineExams.aspx");
            }
            else if (e.CommandName == "EditPress")
            {
                int onlineId = Int32.Parse(e.CommandArgument.ToString());
                Response.Redirect("pg_OnlineExamEdit.aspx?onlineId=" + onlineId + "&returnUrl=pg_OnLineExams.aspx");
            }
            else if (e.CommandName == "DeletePress")
            {
                int onlineId = Int32.Parse(e.CommandArgument.ToString());
                string conString = RamanConnectionString.LocalConnectionString();
                con = new SqlConnection(conString);
                cmd = con.CreateCommand();
                try
                {
                    con.Open();
                    cmd.CommandText = "delete from t_OnlineExams Where onlineId = " + onlineId;
                    cmd.ExecuteNonQuery();
                    GridView1.DataBind();
                }
                catch
                {
                }
                finally
                {
                    con.Close();
                }
            }
        }
        catch
        {
        }
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            GridView1.PageIndex = e.NewPageIndex;
            SqlDataSource1.SelectCommand = "SELECT [onlineId], [onlineName], [onlineType], [testNum], [explainNum], [testScore], [explainScore], [designer] FROM [t_OnlineExams] Where userCreator = N'" + User.Identity.Name + "'";
            GridView1.DataBind();
        }
        catch
        {
        }
    }
}
