protected void Send_Click(object sender, EventArgs e) { //בדיקה אם קיים בWS Cities.Cities ctyWs = new Cities.Cities(); if (!ctyWs.IsExist(DDLCity.SelectedItem.Text)) { lblErr.Text = "העיר כבר לא קיימת במאגר הנתונים הארצי"; return; } //add cty to db ch_cities cty = new ch_cities(); cty.cty_Name = DDLCity.SelectedItem.Text; ch_citiesSvc.AddCity(cty); ch_users usr1 = new ch_users(); usr1.usr_Identity = txtStuIdentity.Text.Trim(); usr1.usr_First_Name = txtFirstName.Text.Trim(); usr1.usr_Last_Name = txtLastName.Text.Trim(); DateTime dt = Convert.ToDateTime(DateTextBox.Text); usr1.usr_Birth_Date = dt.ToString("yyyy/MM/dd"); usr1.usr_Gender = rbtGender.SelectedValue; usr1.cty_Id = ch_citiesSvc.GetIdByCtyName(cty.cty_Name); usr1.usr_Address = txtAddress.Text.Trim(); usr1.usr_Home_Phone = txtHomePhone.Text.Trim(); usr1.usr_Cellphone = txtCellphone.Text.Trim(); usr1.sc_Id = Convert.ToInt32(DDLSchools.SelectedValue); usr1.usr_Email = txtEmail.Text.Trim(); usr1.usr_Password = txtStuIdentity.Text.Trim() + "s"; usr1.lvl_Id = 0; ch_students stu1 = new ch_students(); stu1.usr_Id = ch_usersSvc.GetMaxId(); stu1.rm_Id = Convert.ToInt32(ddlRooms.SelectedValue); stu1.stu_Mom_Identity = txtMomIdentity.Text.Trim(); stu1.stu_Mom_First_Name = txtMomFirstName.Text.Trim(); stu1.stu_Mom_Cellphone = txtMomCellphone.Text; stu1.stu_Dad_Identity = txtDadIdentity.Text; stu1.stu_Dad_First_Name = txtDadFirstName.Text; stu1.stu_Dad_Cellphone = txtDadCellphone.Text; // ביצוע הרשמה וכתיבת השגיאות אם יש! lblErr.Text = ch_usersSvc.AddUser(usr1); stu1.usr_Id = ch_usersSvc.GetMaxId(); lblErr.Text = ch_studentsSvc.AddStudent(stu1); //אם אין שגיאות בהרשמה if (lblErr.Text == "") { //Response.Write("<script>alert('המשתמש נרשם בהצלחה');</script>"); Response.Redirect("StudentsData.aspx"); } }
protected void btnSend_Click(object sender, EventArgs e) { ch_users usr1 = new ch_users(); usr1.usr_Identity = txtIdentity.Text.Trim(); usr1.usr_Password = txtPassword.Text.Trim(); lblErr.Text = ""; if (ch_usersSvc.Login(usr1)) { DataSet ds = ch_usersSvc.GetUserByIdentity(usr1.usr_Identity); int id = Convert.ToInt32(ds.Tables["ch_users"].Rows[0][0].ToString()); Session["sc_id"] = ds.Tables["ch_users"].Rows[0]["sc_id"].ToString(); Session["usr_id"] = id; Session["usr_type"] = ch_usersSvc.GetUsrType(id); Session["lvl_id"] = Convert.ToInt32(ds.Tables["ch_users"].Rows[0][13].ToString()); Session["gender"] = ds.Tables["ch_users"].Rows[0]["usr_gender"].ToString(); Session["fullName"] = ds.Tables["ch_users"].Rows[0]["usr_first_name"].ToString() + " " + ds.Tables["ch_users"].Rows[0]["usr_last_name"].ToString(); Response.Redirect("Default.aspx"); } else { lblErr.Text = "אימייל או סיסמא לא נכונים :("; } }
protected void Send_Click(object sender, EventArgs e) { //add cty to db ch_cities cty = new ch_cities(); cty.cty_Name = DDLCity.SelectedItem.Text; //בדיקה אם קיים בWS Cities.Cities ctyWs = new Cities.Cities(); if (!ctyWs.IsExist(cty.cty_Name)) { lblErr.Text = "העיר כבר לא קיימת במאגר הנתונים הארצי"; return; } ch_citiesSvc.AddCity(cty); ch_users usr1 = new ch_users(); usr1.usr_Identity = txtTchIdentity.Text.Trim(); usr1.usr_First_Name = txtFirstName.Text.Trim(); usr1.usr_Last_Name = txtLastName.Text.Trim(); DateTime dt = Convert.ToDateTime(DateTextBox.Text); usr1.usr_Birth_Date = dt.ToString("yyyy/MM/dd"); usr1.usr_Gender = rbtGender.SelectedValue; usr1.cty_Id = ch_citiesSvc.GetIdByCtyName(cty.cty_Name); usr1.usr_Address = txtAddress.Text.Trim(); usr1.usr_Home_Phone = txtHomePhone.Text.Trim(); usr1.usr_Cellphone = txtCellphone.Text.Trim(); usr1.sc_Id = Convert.ToInt32(DDLSchools.SelectedValue); usr1.usr_Email = txtEmail.Text.Trim(); usr1.usr_Password = txtTchIdentity.Text.Trim() + "t"; usr1.lvl_Id = Convert.ToInt32(ddlLevels.SelectedValue); // ביצוע הרשמה וכתיבת השגיאות אם יש! lblErr.Text = ch_usersSvc.AddUser(usr1); ch_teachers tch1 = new ch_teachers(); tch1.usr_Id = ch_usersSvc.GetMaxId(); lblErr.Text = ch_teachersSvc.AddTeacher(tch1); foreach (ListItem li in lbProfessions.Items) { if (li.Selected) { ch_teachers_professions tch_pro = new ch_teachers_professions(Convert.ToInt32(li.Value), tch1.usr_Id); ch_teachers_professionsSvc.AddTeacherProfessions(tch_pro); } } //אם אין שגיאות בהרשמה if (lblErr.Text == "") { //Response.Write("<script>alert('המשתמש נרשם בהצלחה');</script>"); Response.Redirect("TeachersData.aspx"); } }
/// <summary> /// Check if the user credentials are exist in database /// </summary> /// <param name="usr1">the user that want to login</param> /// <returns>true if the exist, false if not exist</returns> public static bool Login(ch_users usr1) { string strSql = "SELECT COUNT(usr_id) FROM ch_users WHERE usr_identity = '" + usr1.usr_Identity + "' AND usr_password='******'"; int num = Convert.ToInt32(Connect.MathAction(strSql, "ch_users")); if (num > 0) { return(true); } return(false); }
/// <summary> /// Add a new user to database /// </summary> /// <param name="usr1">the new user to add</param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string AddUser(ch_users usr1) { if (IsUserExists(usr1)) { return("User already Registered!"); } string strSql = "INSERT INTO ch_users(usr_identity, usr_first_name, usr_last_name, usr_birth_date, usr_gender, cty_id, usr_address, usr_home_phone, usr_cellphone, sc_id, usr_email, usr_password, lvl_id) "; strSql += "VALUES('" + usr1.usr_Identity + "','" + usr1.usr_First_Name + "', '" + usr1.usr_Last_Name + "', '" + usr1.usr_Birth_Date + "', '" + usr1.usr_Gender + "', " + usr1.cty_Id + ", '" + usr1.usr_Address + "', '" + usr1.usr_Home_Phone + "', '" + usr1.usr_Cellphone + "', " + usr1.sc_Id + ", '" + usr1.usr_Email + "', '" + usr1.usr_Password + "', " + usr1.lvl_Id + ")"; Connect.DoAction(strSql, "ch_users"); return(""); }
/// <summary> /// Update user by a new one /// </summary> /// <param name="usr_id">user id of the user to update</param> /// <param name="newUsr1">the new user to update</param> /// <returns>string of an error or a string.Empty if the action is completed</returns> public static string UpdateUserById(int usr_id, ch_users newUsr1) { if (IsEmailExistInOtherUser(usr_id, newUsr1.usr_Email)) { return("Email already exist"); } if (IsIdentityExistInOtherUser(usr_id, newUsr1.usr_Identity)) { return("Identity already exist"); } string strSql = "UPDATE ch_users SET usr_identity='" + newUsr1.usr_Identity + "', usr_first_name='" + newUsr1.usr_First_Name + "', usr_last_name='" + newUsr1.usr_Last_Name + "', usr_birth_date='" + newUsr1.usr_Birth_Date + "', usr_gender='" + newUsr1.usr_Gender + "', cty_id=" + newUsr1.cty_Id + ", usr_address='" + newUsr1.usr_Address + "', usr_home_phone='" + newUsr1.usr_Home_Phone + "', usr_cellphone='" + newUsr1.usr_Cellphone + "', sc_id=" + newUsr1.sc_Id + ", usr_email='" + newUsr1.usr_Email + "', lvl_id='" + newUsr1.lvl_Id + "' WHERE usr_id=" + usr_id; Connect.DoAction(strSql, "ch_users"); return(""); }
/// <summary> /// check if the user exist /// </summary> /// <param name="usr1">the user to check</param> /// <returns>true if exist false if not</returns> public static bool IsUserExists(ch_users usr1) { string strSql; int num; strSql = "SELECT COUNT(usr_email) FROM ch_users WHERE usr_email = '" + usr1.usr_Email + "'"; num = Convert.ToInt32(Connect.MathAction(strSql, "ch_users")); if (num > 0) { return(true); } strSql = "SELECT COUNT(usr_id) FROM ch_users WHERE usr_identity = '" + usr1.usr_Identity + "'"; num = Convert.ToInt32(Connect.MathAction(strSql, "ch_users")); if (num > 0) { return(true); } return(false); }
protected void Send_Click(object sender, EventArgs e) { //add cty to db ch_cities cty = new ch_cities(); cty.cty_Name = DDLCity.SelectedItem.Text; //בדיקה אם קיים בWS Cities.Cities ctyWs = new Cities.Cities(); if (!ctyWs.IsExist(cty.cty_Name)) { lblErr.Text = "העיר כבר לא קיימת במאגר הנתונים הארצי"; return; } ch_citiesSvc.AddCity(cty); int usr_id = Convert.ToInt32(Session["usr_id"]); ch_users newUsr1 = new ch_users(); newUsr1.sc_Id = Convert.ToInt32(DDLSchools.SelectedValue); newUsr1.usr_Address = txtAddress.Text; newUsr1.usr_Birth_Date = DateTextBox.Text; newUsr1.cty_Id = ch_citiesSvc.GetIdByCtyName(cty.cty_Name); newUsr1.usr_Email = txtEmail.Text; newUsr1.usr_First_Name = txtFirstName.Text; newUsr1.usr_Gender = rbtGender.SelectedValue; newUsr1.usr_Home_Phone = txtHomePhone.Text; newUsr1.usr_Cellphone = txtCellphone.Text; newUsr1.usr_Identity = txtIdentity.Text; newUsr1.usr_Last_Name = txtLastName.Text; if (ch_usersSvc.GetUsrType(usr_id) == "tch") { if (ValidateTch()) { foreach (ListItem li in lbProfessions.Items) { ch_teachers_professions tch_pro = new ch_teachers_professions(Convert.ToInt32(li.Value), usr_id); if (!ch_teachers_professionsSvc.IsExist(tch_pro) && li.Selected) { ch_teachers_professionsSvc.AddTeacherProfessions(tch_pro); } else if (ch_teachers_professionsSvc.IsExist(tch_pro) && !li.Selected) { ch_teachers_professionsSvc.DeleteTeacherProfessions(tch_pro); } } } else { lblErr.Text = "הכנס מקצועות עליהם עברת הכשרה"; } } if (ch_usersSvc.GetUsrType(usr_id) == "crw") { ch_crew newCrw1 = new ch_crew(); newCrw1.job_Id = Convert.ToInt32(ddlJobs.SelectedValue); newCrw1.usr_Id = usr_id; ch_crewSvc.UpdateCrwById(newCrw1); } ch_usersSvc.UpdateUserById(usr_id, newUsr1); //update sessions Session["sc_id"] = newUsr1.sc_Id; Session["gender"] = newUsr1.usr_Gender; Session["fullName"] = newUsr1.usr_First_Name + " " + newUsr1.usr_Last_Name; Response.Redirect("UsrProfile.aspx"); }