コード例 #1
0
ファイル: User_Add.aspx.cs プロジェクト: 165295s/ASP_Project
        protected void Submit_User(object sender, EventArgs e)
        {
            if ((string)(Session["UserID"]) == null)
            {
                int check = 0;
                try
                {
                    DatabaseDAO user = new DatabaseDAO();
                    check = user.AddUser(User_Input_Username.Value, User_Input_Name.Value, User_Input_Email.Value, DateTime.Now, Select_Permission_Level.Value);


                    if (check == 1)
                    {
                        ScriptManager.RegisterStartupScript(Page, GetType(), "AlertDisplay", "displaySuccess('Successfully Created New Account: " + User_Input_Name.Value + " With Permission Level Of: " + Select_Permission_Level.Value + "');", true);
                    }
                    else if (check == 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, GetType(), "AlertFailureDisplay", "displayFailure('There seems to be an error! Please notify the Administrators.');", true);
                    }

                    User_Input_Name.Value = "";

                    User_Input_Email.Value = "";
                    Select_Permission_Level.SelectedIndex = 0;
                    User_Input_Username.Value             = "";
                }
                catch (Exception ex)
                {
                    ErrorLog.WriteErrorLog(ex.ToString());
                    ScriptManager.RegisterStartupScript(Page, GetType(), "AlertFailureDisplay", "displayFailure();", true);
                }
            }
            else
            {
                int check = 0;
                try
                {
                    string      UserID = (string)(Session["UserID"]);
                    DatabaseDAO user   = new DatabaseDAO();
                    check = user.EditUser(User_Input_Name.Value, User_Input_Email.Value, Select_Permission_Level.Value, User_Input_Username.Value, UserID, DateTime.Now);
                    if (check == 1)
                    {
                        ScriptManager.RegisterStartupScript(Page, GetType(), "AlertDisplay", "displaySuccess('Successfully Updated Account:" + User_Input_Name.Value + "');", true);
                    }
                    else if (check == 0)
                    {
                        ScriptManager.RegisterStartupScript(Page, GetType(), "AlertFailureDisplay", "displayFailure();", true);
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog.WriteErrorLog(ex.ToString());
                    ScriptManager.RegisterStartupScript(Page, GetType(), "AlertFailureDisplay", "displayFailure();", true);
                }
            }
        }