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 ch_teachers_professions is exist in the database records /// </summary> /// <param name="tch_pro">the teacher profession you want to delete</param> /// <returns>true if exists. /// false if not exists.</returns> public static bool IsExist(ch_teachers_professions tch_pro) { //check in crew string strSql = "SELECT COUNT(usr_id) FROM ch_teachers_professions WHERE usr_id = " + tch_pro.usr_Id + " AND pro_id = " + tch_pro.pro_Id; int num = Convert.ToInt32(Connect.MathAction(strSql, "ch_teachers_professions")); 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"); }
/// <summary> /// Delete a specific teacher profession /// </summary> /// <param name="tch_pro">the teacher profession to delete</param> public static void DeleteTeacherProfessions(ch_teachers_professions tch_pro) { string deleteQuery = "DELETE * FROM ch_teachers_professions WHERE usr_id=" + tch_pro.usr_Id + " AND pro_id = " + tch_pro.pro_Id; Connect.DoAction(deleteQuery, "ch_teachers_professions"); }
/// <summary> /// Update a specific teacher profession /// </summary> /// <param name="tch_pro">the teacher profession to update</param> public static void UpdateTeacherProfessions(ch_teachers_professions tch_pro) { string updateQuery = "UPDATE ch_teachers_professions SET pro_id = " + tch_pro.pro_Id + " WHERE usr_id = " + tch_pro.usr_Id; Connect.DoAction(updateQuery, "ch_teachers_professions"); }
/// <summary> /// Add a new ch_teachers_professions record to the database /// </summary> /// <param name="tch_pro">a new taecher profession you want to add</param> public static void AddTeacherProfessions(ch_teachers_professions tch_pro) { string insertQuery = "INSERT INTO ch_teachers_professions(pro_id, usr_id) VALUES(" + tch_pro.pro_Id + ", " + tch_pro.usr_Id + ")"; Connect.DoAction(insertQuery, "ch_teachers_professions"); }