コード例 #1
0
    //this function changed**************************************************************************************************************************************************************
    protected void AddUserBTN_Click(object sender, EventArgs e)
    {
        string folderPath = Server.MapPath("~/Images/");
        string ImgPath    = "";

        if (FileUpload1.FileName != "")
        {
            FileUpload1.SaveAs(folderPath + FileUpload1.FileName);
            ImgPath = "/Images/" + FileUpload1.FileName;
        }
        string day = DDLday.SelectedValue, month = DDLmonth.SelectedValue, year = DDLyear.SelectedValue;

        if (day == "יום" || month == "חודש" || year == "שנה")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('תאריך הלידה לא יכול להיות ריק');", true);
            return;
        }
        else if (!u.IsLegalBday(day, month))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('תאריך הלידה לא תקני.');", true);
            return;
        }
        else if (ClassOtDLL.SelectedValue == "בחר")
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('לא נבחרה כיתה.');", true);
            return;
        }
        string        bDay    = day + "/" + month + "/" + year;
        Users         NewUser = new Users(UserIDTB.Text, FNameTB.Text, LNameTB.Text, bDay, ImgPath, "", PasswordTB.Text, TelephoneNumberTB.Text, UserTypeDLL.SelectedValue);
        Administrator admin   = new Administrator();
        int           res1    = admin.AddUser(NewUser);

        if (res1 == 1)
        {
            if (UserTypeDLL.SelectedValue == "4")
            {
                Administrator a   = new Administrator();
                int           num = a.AddPupil(UserIDTB.Text, int.Parse(ClassOtDLL.SelectedValue));
            }
            else if (UserTypeDLL.SelectedValue == "2")
            {
                Administrator d      = new Administrator();
                string        IsMain = "0";
                if (MainTeacherCB.Checked)
                {
                    IsMain = "1"; int num1 = d.AddClassTeacher(UserIDTB.Text, ClassOtDLL.SelectedItem.ToString());
                }

                int num2 = d.AddTeacher(UserIDTB.Text, IsMain);
            }
            else if (UserTypeDLL.SelectedValue == "3")
            {
                //string[] ChildID = new string[int.Parse(NumOfChildDDL.SelectedValue)];
                string[] ChildID = new string[6];

                ChildID[0] = ChildI1DTB.Text;
                ChildID[1] = ChildI2DTB.Text;
                ChildID[2] = ChildI3DTB.Text;
                ChildID[3] = ChildI4DTB.Text;
                ChildID[4] = ChildI5DTB.Text;
                ChildID[5] = ChildI6DTB.Text;

                for (int i = 0; i < ChildID.Length; i++)
                {
                    if (ChildID[i] != "")
                    {
                        Users         GetPupilClass       = new Users();
                        string        ChildCodeClass      = GetPupilClass.GetPupilOtClass(ChildID[i]);
                        Administrator AddMoreThanOneChild = new Administrator();
                        AddMoreThanOneChild.AddParent(UserIDTB.Text, ChildID[i], ChildCodeClass);
                    }
                }
            }
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('משתמש נוסף בהצלחה'); location.href='AAddNewUser.aspx';", true);
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "success", "alert('הייתה בעיה בעדכון המשתמש, בדוק נתונים');", true);
        }
    }