RegisterMaster.aspx.cs

דף זה הוא הקוד מאחור של RegisterMaster.aspx
 avatar
user_2706180
csharp
a month ago
1.8 kB
2
Indexable
Never
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YoadMadrid.Pages
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                // בדיקה אם קיים שם משתמש
                string SQL = $"SELECT COUNT (Admin) FROM " + Helper.tblName +
                    $" WHERE Username='{Request.Form["Username"]}'";

                int count = (int)Helper.GetScalar(SQL);
                if (count > 0)
                {
                    UsernameAlert.InnerHtml = "Username is taken!";
                }
                else
                {
                    // בניית השורה להוספה
                    SQL = $"INSERT INTO " + Helper.tblName +
                       " (Email, FirstName, LastName, Username, Password, PhoneNumber, BirthDate, Country, Gender, Admin, GoalKeeper, Defender, Midfielder, Forward) " +
                       $"VALUES ('{Request.Form["Email"]}', '{Request.Form["FirstName"]}', '{Request.Form["LastName"]}', " +
                       $"'{Request.Form["Username"]}', '{Request.Form["Password"]}', '{Request.Form["PhoneNumber"]}', " +
                       $"'{Request.Form["BirthDate"]}', '{Request.Form["Country"]}', '{Request.Form["Gender"]}', 0, '{Request.Form["GoalKeeper"]}', '{Request.Form["Defender"]}', '{Request.Form["Midfielder"]}', '{Request.Form["Forward"]}');";


                    UsernameAlert.InnerHtml = "";
                    Helper.ExecuteNonQuery(SQL);
                    Response.Redirect("/Pages/MainMaster.aspx");
                }
            }

        }

    }
}
Leave a Comment