Example #1
0
        protected void LogIn(object sender, EventArgs e)
        {
            var id = 0;
            var name = "";
            var role = 0;
            var loginFrom = new DbConnection();
            loginFrom.ConnectDatabase();
            var loginCommand = new SqlCommand("dbo.loginForm", loginFrom.DbConnect)
            {
                CommandType = CommandType.StoredProcedure
            };
            loginCommand.Parameters.AddWithValue("email", Email.Text);
            loginCommand.Parameters.AddWithValue("password", Password.Text);

            var reader = loginCommand.ExecuteReader();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    id = Convert.ToInt32(reader["UserID"]);
                    name = (Convert.ToString(reader["Name"])).Trim();
                    role = Convert.ToInt32(reader["RoleID"]);
                }
                Session["UserID"] = id;
                Session["Name"] = name;
                Session["Role"] = role;
                Session["Email"] = Email.Text;
                Response.Redirect("~/Default.aspx");
            }
            else
            {
                Response.Redirect("~/Default.aspx");
            }
        }
 /// <summary>
 /// View User Name for Dropdown list
 /// </summary>
 public void ViewUserNameDropdownList()
 {
     var listUserName = new DbConnection();
     listUserName.ConnectDatabase();
     var viewCommand = new SqlCommand("dbo.selectUser", listUserName.DbConnect)
     {
         CommandType = CommandType.StoredProcedure
     };
     var dataAdapter = new SqlDataAdapter(viewCommand);
     var dataSet = new DataSet();
     dataAdapter.Fill(dataSet);
     ddlUserName.DataSource = dataSet;
     ddlUserName.DataTextField = "Name";
     ddlUserName.DataValueField = "UserID";
     ddlUserName.DataBind();
     ddlUserName.Items.Insert(0, new ListItem("-- select --", "none"));
 }
 /// <summary>
 /// View infomation for UserTask managerment
 /// </summary>
 public void BindDataToGridView()
 {
     try
     {
         var dataManager = new DbConnection();
         dataManager.ConnectDatabase();
         var viewCommand = new SqlCommand("dbo.selectUserTask", dataManager.DbConnect)
         {
             CommandType = CommandType.StoredProcedure
         };
         var dataAdapter = new SqlDataAdapter(viewCommand);
         var dataSet = new DataSet();
         dataAdapter.Fill(dataSet);
         gvUserTask.DataSource = dataSet;
         gvUserTask.DataBind();
         ltMessage.Text = "View data compate !";
     }
     catch (Exception ex)
     {
         ltMessage.Text = ex.Message;
     }
 }
        /// <summary>
        /// View userID, TaskID over Dropdownlist
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvUserTask_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            var dataUser = new DbConnection();
            dataUser.ConnectDatabase();
            if (e.Row.RowType == DataControlRowType.DataRow && gvUserTask.EditIndex == e.Row.RowIndex)
            {
                var ddlUserId = (DropDownList)e.Row.FindControl("ddlUser_ID");
                var viewUser = new SqlCommand("select distinct UserID from Users", dataUser.DbConnect);
                var dataAdapterUser = new SqlDataAdapter(viewUser);
                var dataSetUser = new DataSet();
                dataAdapterUser.Fill(dataSetUser);
                ddlUserId.DataSource = dataSetUser;
                ddlUserId.DataTextField = "UserID";
                ddlUserId.DataValueField = "UserID";
                ddlUserId.DataBind();

                var ddlTaskId = (DropDownList)e.Row.FindControl("ddlTask_ID");
                var viewTask = new SqlCommand("select distinct TaskID from Tasks", dataUser.DbConnect);
                var dataAdapterTask = new SqlDataAdapter(viewTask);
                var dataSetTask = new DataSet();
                dataAdapterTask.Fill(dataSetTask);
                ddlTaskId.DataSource = dataSetTask;
                ddlTaskId.DataTextField = "TaskID";
                ddlTaskId.DataValueField = "TaskID";
                ddlTaskId.DataBind();
            }
        }