Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 56.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using WebFormsMvp;
  8. using WebFormsMvp.Web;
  9. using UniSS.Logic.Models;
  10. using UniSS.Logic.Views;
  11. using UniSS.Logic.Presenters;
  12. using UniSS.DataModel;
  13. using System.Web.UI.HtmlControls;
  14. using UniSS.Encryption;
  15. using System.Web.Security;
  16. using UniSS.WebSite.Utility;
  17. using UniSS.WebSite.MasterPages;
  18. using System.IO;
  19. using System.Configuration;
  20. using UniSS.Repositories.Domain;
  21. using UniSS.Repositories.Enrolment;
  22.  
  23. namespace UniSS.WebSite.Students
  24. {
  25. //public enum FormControlMode { INSERT_MODE, EDIT_MODE }
  26.  
  27. public partial class StudentsEditControl : MvpUserControl<StudentsEditModel>, IStudentsEditView
  28. {
  29. public bool session_STUDENTS_INSERT = false;
  30. public int FACULTY_ID = 0;
  31. public UniSS.DataModel.Students CurrentStudent;
  32. string PageName = string.Empty;
  33. string errorString = Resources.Resources.ResourceManager.GetString("Error");
  34. string infoString = Resources.Resources.ResourceManager.GetString("Information");
  35.  
  36. protected void Page_Load(object sender, EventArgs e)
  37. {
  38. AutoDataBind = false;
  39.  
  40. if (Page.ToString() != "ASP.students_studentsinsert_aspx" && (Session["StudentId"] == null || Session["StudentId"].ToString() == "0"))
  41. Response.Redirect("~/Default.aspx");
  42.  
  43. FACULTY_ID = UserProfile.GetUserProfile(this.Page.User.Identity.Name).Faculty.Value;
  44. PageName = (Path.GetFileName(Request.Path)).Split(new char[] { '.' })[0];
  45.  
  46. if (Session["InsertedStudent"] == null)
  47. {
  48. pnlInsertedStudent.Visible = false;
  49. }
  50.  
  51. if (!Page.IsPostBack)
  52. {
  53. if (!UserProfile.GetUserProfile(this.Page.User.Identity.Name).AllowedControls.Contains(this.Page.ToString()))
  54. Response.Redirect("~/NoCredentials.aspx");
  55. //Fill the independent DropDownLists with data
  56. OnGettingData(FACULTY_ID);
  57. LoadData_Init();
  58.  
  59. if (Page.ToString() == "ASP.students_studentsinsert_aspx")
  60. {
  61. Session["students_insert"] = true;
  62. this.CurrentStudent = new DataModel.Students();
  63. enrolmentData.Visible = true;
  64. if (Session["InsertedStudent"] != null)
  65. {
  66. pnlInsertedStudent.Visible = true;
  67. lblInsertedStudent.Text = Session["InsertedStudent"].ToString();
  68. Session["InsertedStudent"] = null;
  69. }
  70. }
  71. else
  72. {
  73. AuditHelper.LogViewActivity("Лични податоци", this.Page.User.Identity.Name);
  74. enrolmentData.Visible = false;
  75. if (Session["StudentId"] != null)
  76. {
  77. Session["students_insert"] = false;
  78. this.CurrentStudent = GetStudent(Convert.ToInt32(Session["StudentId"]));
  79. LoadData_ForEditing();
  80. }
  81. else
  82. Response.Redirect("~/Default.aspx");
  83. }
  84.  
  85. OnSetInsertMode(true);
  86. }
  87. else
  88. {
  89. //CurrentStudent = ViewState["CurrentStudent"] as UniSS.DataModel.Students;
  90. }
  91.  
  92.  
  93. lblIndeksErr.Visible = false;
  94. session_STUDENTS_INSERT = Convert.ToBoolean(Session["students_insert"]);
  95.  
  96. studentsDsabled.Visible = !Roles.IsUserInRole(this.Page.User.Identity.Name, "Студенти") &&
  97. (UniSS.WebSite.UserProfile.GetUserProfile(this.Page.User.Identity.Name).GlobalPermissions.Contains("personal_insert_" + PageName) ||
  98. UniSS.WebSite.UserProfile.GetUserProfile(this.Page.User.Identity.Name).LocalPermissions.Contains("personal_insert_" + PageName));
  99. //pnlVis.Enabled = !Roles.IsUserInRole(this.Page.User.Identity.Name, "Студенти");
  100. if (Page.ToString() != "ASP.students_studentsinsert_aspx")
  101. UIContext.MakeLinkActive(this.Page, "StudentsEdit");
  102.  
  103. if (Session["Inserted"] != null)
  104. {
  105. Session["Inserted"] = null;
  106. var message = Resources.Resources.ResourceManager.GetString("InsertStudentSuccess");
  107. UIContext.ShowMessage(this.Page, infoString, message, MasterPages.ModalType.confirmation);
  108. }
  109. }
  110.  
  111. protected void Page_PreRender(object sender, EventArgs e)
  112. {
  113. //ViewState["CurrentStudent"] = CurrentStudent;
  114. }
  115.  
  116.  
  117.  
  118. #region "Page methods"
  119.  
  120. protected void btnResetPass_Click(object sender, EventArgs e)
  121. {
  122. try
  123. {
  124. MembershipUser user = Membership.GetUser(Guid.Parse(hidUserId.Value));
  125. user.IsApproved = true;
  126. Membership.UpdateUser(user);
  127. Guid userId = Guid.Parse(user.ProviderUserKey.ToString());
  128. OnUpdateLocked(new DataModel.Students() { UserNameID = userId });
  129.  
  130. string pass = user.ResetPassword();
  131.  
  132. string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
  133. string verifyUrl = "Account/Recovery.aspx?user=" + userId;
  134. string fullPath = urlBase + verifyUrl;
  135. string AppPath = Request.PhysicalApplicationPath;
  136.  
  137. try
  138. {
  139. MailHelper.SendMail(2, user.Email, new List<string>() { fullPath, user.Email, user.Email, pass });
  140. }
  141. catch
  142. {
  143. var message = Resources.Resources.ResourceManager.GetString("EmailCantSend");
  144. UIContext.ShowMessage(this.Page, infoString, message, MasterPages.ModalType.information);
  145. }
  146.  
  147. UniSS.DataModel.AuditLog log = new DataModel.AuditLog();
  148. log.UserName = this.Page.User.Identity.Name;
  149. log.EventDate = DateTime.Now;
  150. log.TableName = "aspnet_Membership";
  151. log.Actions = "U";
  152. log.NewData = "Password: " + pass;
  153. log.ChangedColumns = "Password";
  154. AuditHelper.LogActivity(log);
  155. var messagePassword = Resources.Resources.ResourceManager.GetString("PasswordReset");
  156. UIContext.ShowMessage(this.Page, infoString, messagePassword, ModalType.information);
  157. }
  158. catch (Exception)
  159. {
  160. var message = Resources.Resources.ResourceManager.GetString("StudentNoUsername");
  161. UIContext.ShowMessage(this.Page, infoString, message, ModalType.warning);
  162. }
  163. }
  164.  
  165. protected void DropDownList_DataBound(object sender, EventArgs e)
  166. {
  167. DropDownList ddl = sender as DropDownList;
  168.  
  169. if (ddl.Items.FindByValue("0") == null && ddl.Items.FindByValue("") == null)
  170. {
  171. if (ddl.ID == "ddlBirthPlace" || ddl.ID == "ddlBirthCommunity" || ddl.ID == "ddlLivingPlace" || ddl.ID == "ddlLivingCommunity")
  172. {
  173. var other = Resources.Resources.ResourceManager.GetString("Other");
  174. ddl.Items.Insert(ddl.Items.Count, new ListItem(other, "0"));
  175. }
  176. else
  177. {
  178. var choose = Resources.Resources.ResourceManager.GetString("Choose");
  179. ddl.Items.Insert(0, new ListItem("< " + choose + " >", "0"));
  180. }
  181. }
  182. }
  183.  
  184. protected void DropDownListOther_SelectedIndexChanged(object sender, EventArgs e)
  185. {
  186. CheckDropDown_Other((DropDownList)sender);
  187. }
  188.  
  189. private void CheckDropDown_Other(DropDownList ddl)
  190. {
  191. TextBox txt = pnlVis.FindControl("txt" + ddl.ID.Substring(3)) as TextBox;
  192. HtmlTableRow row = pnlVis.FindControl("tr" + ddl.ID.Substring(3)) as HtmlTableRow;
  193.  
  194. if (ddl.SelectedValue == "0")
  195. {
  196. txt.Visible = true;
  197. row.Visible = true;
  198. }
  199. else
  200. {
  201. txt.Visible = false;
  202. row.Visible = false;
  203. }
  204. }
  205.  
  206. protected void LoadData_Init()
  207. {
  208. dataBirthCountryId.DataSource = Model.AllCountries;
  209. dataBirthCountryId.DataBind();
  210.  
  211. dataPreviousEducationLanguageId.DataSource = Model.AllLanguages;
  212. dataPreviousEducationLanguageId.DataBind();
  213.  
  214. dataNationalityId.DataSource = Model.AllNationalities;
  215. dataNationalityId.DataBind();
  216.  
  217. dataLivingCountryId.DataSource = Model.AllCountries;
  218. dataLivingCountryId.DataBind();
  219.  
  220. dataFatherEducation.DataSource = Model.AllEducationLevels;
  221. dataFatherEducation.DataBind();
  222.  
  223. dataMotherEducation.DataSource = Model.AllEducationLevels;
  224. dataMotherEducation.DataBind();
  225.  
  226. dataPreviousEducationCountryId.DataSource = Model.AllCountries;
  227. dataPreviousEducationCountryId.DataBind();
  228.  
  229. dataCitizenshipId.DataSource = Model.AllCountries;
  230. dataCitizenshipId.DataBind();
  231.  
  232. ddlBirthPlace.DataSource = Model.AllPlaces;
  233. ddlBirthPlace.DataBind();
  234.  
  235. ddlBirthCommunity.DataSource = Model.AllCommunities;
  236. ddlBirthCommunity.DataBind();
  237.  
  238. //ddldataProfession.Items.Add(new ListItem("< Изберете >", ""));
  239. //ddldataProfession.Items.Add(new ListItem("УКИМ", "УКИМ"));
  240. //ddldataProfession.Items.Add(new ListItem("Друг универзитет", "Друг"));
  241.  
  242. //ddldataEmployment.Items.Add(new ListItem("< Изберете >", ""));
  243. //ddldataEmployment.Items.Add(new ListItem("Економски фак. на УКИМ", "ЕФ УКИМ"));
  244. //ddldataEmployment.Items.Add(new ListItem("Друг факултет", "Друг"));
  245. var choose = Resources.Resources.ResourceManager.GetString("Choose");
  246. var ects = Resources.Resources.ResourceManager.GetString("Ects");
  247. var oldregime = Resources.Resources.ResourceManager.GetString("OldRegime");
  248.  
  249. ddlRezim.Items.Add(new ListItem("< " + choose + " >", ""));
  250. ddlRezim.Items.Add(new ListItem(ects, "EKTS"));
  251. ddlRezim.Items.Add(new ListItem(oldregime, "STARO"));
  252.  
  253. ddlLivingPlace.DataSource = Model.AllPlaces;
  254. ddlLivingPlace.DataBind();
  255.  
  256. ddlLivingCommunity.DataSource = Model.AllCommunities;
  257. ddlLivingCommunity.DataBind();
  258.  
  259. ddlStatus.DataSource = Model.AllStudentStatus;
  260. ddlStatus.DataBind();
  261.  
  262.  
  263. ddlCurrentRevision.DataSource = GetRevisions();
  264. ddlCurrentRevision.DataBind();
  265.  
  266. ddlCycle.DataSource = Model.AllStudyCycles;
  267. ddlCycle.DataBind();
  268.  
  269. ddlSchoolType.DataSource = Model.SchoolTypes;
  270. ddlSchoolType.DataBind();
  271.  
  272. var terms = Model.Terms.ToList();
  273. var period = Resources.Resources.ResourceManager.GetString("EnrollmentPeriod");
  274. var t = new TermRefactored() { Id = 0, Name = period };
  275. terms.Insert(0, t);
  276. ddlTerms.DataSource = terms;
  277. ddlTerms.DataBind();
  278. }
  279.  
  280. protected void ddlStatus_Changed(object sender, EventArgs e)
  281. {
  282. ddlKvota.DataSource = GetQuotas();
  283. ddlKvota.DataBind();
  284. }
  285.  
  286. protected void LoadData_ForEditing()
  287. {
  288. txtPassport.Text = CurrentStudent.Passport;
  289. txtPassportExpiryDate.Text = string.Format("{0:d}", CurrentStudent.PassportExpiryDate);
  290.  
  291. hidUserId.Value = CurrentStudent.UserNameID.HasValue
  292. ? CurrentStudent.UserNameID.Value.ToString()
  293. : string.Empty;
  294. txtIndeks.Text = CurrentStudent.Indeks;
  295. dataEmbg.Text = CurrentStudent.EMBG;
  296. dataSurname.Text = CurrentStudent.Surname;
  297. dataFathersName.Text = CurrentStudent.FathersName;
  298. dataName.Text = CurrentStudent.Name;
  299. dataBridesName.Text = CurrentStudent.BridesName;
  300. dataBirthDate.Text = String.Format("{0:d}", CurrentStudent.BirthDate);
  301. dataSex.SelectedValue = CurrentStudent.Sex.ToString();
  302. dataNationalityId.SelectedValue = CurrentStudent.NationalityID.ToString();
  303. dataCitizenshipId.SelectedValue = CurrentStudent.CitizenshipID.ToString();
  304. chkStipendija.Checked = CurrentStudent.IsUsingScholarsip;
  305. dataScholarshipInfo.Text = CurrentStudent.ScholarshipInfo;
  306. ddlCurrentRevision.SelectedValue = CurrentStudent.CurrentRevisionID.ToString();
  307. txtMasterStudentBookNo.Text = CurrentStudent.MasterStudentBookNo;
  308. chkMedicalCheck.Checked = CurrentStudent.MedicalCheck == true;
  309. txtServiceComment.Text = CurrentStudent.ServiceComment;
  310. dataPreviousEducation.Text = CurrentStudent.PreviousEducation;
  311. if (CurrentStudent.SchoolTypeId.HasValue) ddlSchoolType.SelectedValue = CurrentStudent.SchoolTypeId.ToString();
  312. dataPreviousEducationProfession.Text = CurrentStudent.PreviousEducationProfession;
  313. dataPreviousEducationYear.Text = CurrentStudent.PreviousEducationYear.ToString();
  314. dataPreviousEducationGrade.Text = CurrentStudent.PreviousEducationGrade;
  315. if (CurrentStudent.PreviousEducationCountryID != null) dataPreviousEducationCountryId.SelectedValue = CurrentStudent.PreviousEducationCountryID.ToString();
  316. //ddldataProfession.SelectedValue = CurrentStudent.Profession;
  317. txtDataProfession.Text = CurrentStudent.Profession;
  318. dataProfessionFather.Text = CurrentStudent.ProfessionFather;
  319. //ddldataEmployment.SelectedValue = CurrentStudent.Employment;
  320. txtDataEmloyment.Text = CurrentStudent.Employment;
  321. if (CurrentStudent.FatherEducation != null) dataFatherEducation.SelectedValue = CurrentStudent.FatherEducation.ToString();
  322. ddlRezim.SelectedValue = CurrentStudent.ProfessionMother;
  323. if (CurrentStudent.MotherEducation != null) dataMotherEducation.SelectedValue = CurrentStudent.MotherEducation.ToString();
  324. dataStartYear.Text = CurrentStudent.StartYear.ToString();
  325. ddlStatus.SelectedValue = CurrentStudent.StudentStatusID.ToString();
  326. ddlCycle.SelectedValue = CurrentStudent.StudyCycleID.ToString();
  327. dataHighSchoolDiplomaNr.Text = CurrentStudent.HighSchoolDiplomaNr;
  328. if (CurrentStudent.PreviousEducationCredits != null) dataPreviousEducationCredits.Text = String.Format("{0:0.00}", CurrentStudent.PreviousEducationCredits);
  329. dataPermanentAddress.Text = CurrentStudent.PermanentAddress;
  330. dataTemporaryAddress.Text = CurrentStudent.TemporaryAddress;
  331. dataTelephone.Text = CurrentStudent.Telephone;
  332. dataGsm.Text = CurrentStudent.GSM;
  333. dataEmail.Text = CurrentStudent.EMail;
  334. if (CurrentStudent.PreviousEducationLanguageID != null) dataPreviousEducationLanguageId.SelectedValue = CurrentStudent.PreviousEducationLanguageID.ToString();
  335. if (CurrentStudent.LivingCountryID != null) dataLivingCountryId.SelectedValue = CurrentStudent.LivingCountryID.ToString();
  336. if (CurrentStudent.BirthCountryID != null) dataBirthCountryId.SelectedValue = CurrentStudent.BirthCountryID.ToString();
  337.  
  338.  
  339. //DropDowns with other data
  340. if (CurrentStudent.BirthPlaceID != null)
  341. {
  342. trBirthPlace.Visible = txtBirthPlace.Visible = false;
  343. ddlBirthPlace.SelectedValue = CurrentStudent.BirthPlaceID.ToString();
  344. }
  345. else
  346. {
  347. if (!string.IsNullOrEmpty(CurrentStudent.BirthPlaceOther))
  348. {
  349. trBirthPlace.Visible = txtBirthPlace.Visible = true;
  350. txtBirthPlace.Text = CurrentStudent.BirthPlaceOther;
  351. }
  352. //ddlBirthPlace.SelectedValue = "0";
  353. }
  354.  
  355. if (CurrentStudent.BirthCommunityID != null)
  356. {
  357. trBirthCommunity.Visible = txtBirthCommunity.Visible = false;
  358. ddlBirthCommunity.SelectedValue = CurrentStudent.BirthCommunityID.ToString();
  359. }
  360. else
  361. {
  362. if (!string.IsNullOrEmpty(CurrentStudent.BirthCommunityOther))
  363. {
  364. trBirthCommunity.Visible = txtBirthCommunity.Visible = true;
  365. txtBirthCommunity.Text = CurrentStudent.BirthCommunityOther;
  366. }
  367. //ddlBirthCommunity.SelectedValue = "0";
  368. }
  369.  
  370. if (CurrentStudent.LivingPlaceID != null)
  371. {
  372. trLivingPlace.Visible = txtLivingPlace.Visible = false;
  373. ddlLivingPlace.SelectedValue = CurrentStudent.LivingPlaceID.ToString();
  374. }
  375. else
  376. {
  377. if (!string.IsNullOrEmpty(CurrentStudent.LivingPlaceOther))
  378. {
  379. trLivingPlace.Visible = txtLivingPlace.Visible = true;
  380. txtLivingPlace.Text = CurrentStudent.LivingPlaceOther;
  381. }
  382. //ddlLivingPlace.SelectedValue = "0";
  383. }
  384.  
  385. if (CurrentStudent.LivingCommunityID != null)
  386. {
  387. trLivingCommunity.Visible = txtLivingCommunity.Visible = false;
  388. ddlLivingCommunity.SelectedValue = CurrentStudent.LivingCommunityID.ToString();
  389. }
  390. else
  391. {
  392. trLivingCommunity.Visible = txtLivingCommunity.Visible = true;
  393. txtLivingCommunity.Text = CurrentStudent.LivingCommunityOther;
  394. //ddlLivingCommunity.SelectedValue = "0";
  395. }
  396.  
  397.  
  398. //get data for selected revision and cycle
  399. ddlDepartman.DataSource = GetProgrammes();
  400. ddlDepartman.DataBind();
  401.  
  402. if (ddlDepartman.Items.FindByValue(CurrentStudent.StartProgrammeID.ToString()) != null)
  403. ddlDepartman.SelectedValue = CurrentStudent.StartProgrammeID.ToString();
  404.  
  405. ddlKvota.DataSource = GetQuotas();
  406. ddlKvota.DataBind();
  407.  
  408. if (ddlKvota.Items.FindByValue(CurrentStudent.StartQuotaPriceID.ToString()) != null)
  409. ddlKvota.SelectedValue = CurrentStudent.StartQuotaPriceID.ToString();
  410.  
  411. }
  412.  
  413. protected void LoadCurrentStudent_withData()
  414. {
  415. int t = 0;
  416. decimal d = 0;
  417. DateTime dt;
  418.  
  419. CurrentStudent.Passport = txtPassport.Text;
  420. CurrentStudent.PassportExpiryDate = (txtPassportExpiryDate.Text.Length == 10 ? Convert.ToDateTime(txtPassportExpiryDate.Text) : (DateTime?)null);
  421.  
  422. CurrentStudent.Indeks = txtIndeks.Text;
  423. CurrentStudent.EMBG = dataEmbg.Text;
  424. CurrentStudent.Surname = dataSurname.Text;
  425. CurrentStudent.FathersName = dataFathersName.Text;
  426. CurrentStudent.Name = dataName.Text;
  427. CurrentStudent.BridesName = dataBridesName.Text;
  428. CurrentStudent.BirthDate = Convert.ToDateTime(dataBirthDate.Text);
  429. CurrentStudent.Sex = Convert.ToBoolean(dataSex.SelectedValue);
  430. CurrentStudent.NationalityID = Convert.ToInt32(dataNationalityId.SelectedValue);
  431. CurrentStudent.CitizenshipID = Convert.ToInt32(dataCitizenshipId.SelectedValue);
  432. CurrentStudent.IsUsingScholarsip = Convert.ToBoolean(chkStipendija.Checked);
  433. CurrentStudent.ScholarshipInfo = dataScholarshipInfo.Text;
  434. CurrentStudent.CurrentRevisionID = Convert.ToInt32(ddlCurrentRevision.SelectedValue);
  435. CurrentStudent.MasterStudentBookNo = txtMasterStudentBookNo.Text;
  436. CurrentStudent.MedicalCheck = chkMedicalCheck.Checked;
  437. CurrentStudent.ServiceComment = txtServiceComment.Text;
  438. CurrentStudent.BirthCountryID = dataBirthCountryId.SelectedIndex > 0 ? Convert.ToInt32(dataBirthCountryId.SelectedValue) : (int?)null;
  439. CurrentStudent.PreviousEducation = dataPreviousEducation.Text;
  440. CurrentStudent.SchoolTypeId = Convert.ToInt32(ddlSchoolType.SelectedValue);
  441. CurrentStudent.PreviousEducationProfession = dataPreviousEducationProfession.Text;
  442. CurrentStudent.PreviousEducationYear = int.TryParse(dataPreviousEducationYear.Text, out t) ? t : (int?)null;
  443. CurrentStudent.PreviousEducationGrade = dataPreviousEducationGrade.Text;
  444. CurrentStudent.PreviousEducationCountryID = dataPreviousEducationCountryId.SelectedIndex > 0 ? Convert.ToInt32(dataPreviousEducationCountryId.SelectedValue) : (int?)null;
  445. //CurrentStudent.Profession = ddldataProfession.SelectedValue;
  446. CurrentStudent.Profession = txtDataProfession.Text;
  447. CurrentStudent.ProfessionFather = dataProfessionFather.Text;
  448. //CurrentStudent.Employment = ddldataEmployment.SelectedValue;
  449. CurrentStudent.Employment = txtDataEmloyment.Text;
  450. CurrentStudent.FatherEducation = dataFatherEducation.SelectedIndex > 0 ? Convert.ToInt32(dataFatherEducation.SelectedValue) : (int?)null;
  451. CurrentStudent.ProfessionMother = ddlRezim.SelectedValue;
  452. CurrentStudent.MotherEducation = dataMotherEducation.SelectedIndex > 0 ? Convert.ToInt32(dataMotherEducation.SelectedValue) : (int?)null;
  453. CurrentStudent.StartYear = Convert.ToInt32(dataStartYear.Text);
  454. CurrentStudent.StudentStatusID = Convert.ToInt32(ddlStatus.SelectedValue);
  455. CurrentStudent.StudyCycleID = Convert.ToInt32(ddlCycle.SelectedValue);
  456.  
  457. //if (CurrentStudent.LastProgrammeId == null) CurrentStudent.StartProgrammeID = Convert.ToInt32(ddlDepartman.SelectedValue);
  458. //CurrentStudent.LastProgrammeId = Convert.ToInt32(ddlDepartman.SelectedValue);
  459. CurrentStudent.StartProgrammeID = Convert.ToInt32(ddlDepartman.SelectedValue);
  460.  
  461. CurrentStudent.StartQuotaPriceID = Convert.ToInt32(ddlKvota.SelectedValue);
  462. CurrentStudent.HighSchoolDiplomaNr = dataHighSchoolDiplomaNr.Text;
  463. CurrentStudent.PreviousEducationCredits = decimal.TryParse(dataPreviousEducationCredits.Text, out d) ? d : (decimal?)null;
  464. CurrentStudent.LivingCountryID = dataLivingCountryId.SelectedIndex > 0 && int.TryParse(dataLivingCountryId.SelectedValue, out t) ? t : (int?)null;
  465. CurrentStudent.PreviousEducationLanguageID = dataPreviousEducationLanguageId.SelectedIndex > 0 && int.TryParse(dataPreviousEducationLanguageId.SelectedValue, out t) ? t : (int?)null;
  466. CurrentStudent.PermanentAddress = dataPermanentAddress.Text;
  467. CurrentStudent.TemporaryAddress = dataTemporaryAddress.Text;
  468. CurrentStudent.Telephone = dataTelephone.Text;
  469. CurrentStudent.GSM = dataGsm.Text;
  470. CurrentStudent.EMail = dataEmail.Text;
  471.  
  472.  
  473. //DropDowns with other data
  474. if (ddlBirthPlace.SelectedValue != "0")
  475. {
  476. CurrentStudent.BirthPlaceID = Convert.ToInt32(ddlBirthPlace.SelectedValue);
  477. CurrentStudent.BirthPlaceOther = "";
  478. }
  479. else
  480. {
  481. CurrentStudent.BirthPlaceID = (int?)null;
  482. CurrentStudent.BirthPlaceOther = txtBirthPlace.Text;
  483. }
  484.  
  485. if (ddlBirthCommunity.SelectedValue != "0")
  486. {
  487. CurrentStudent.BirthCommunityID = Convert.ToInt32(ddlBirthCommunity.SelectedValue);
  488. CurrentStudent.BirthCommunityOther = "";
  489. }
  490. else
  491. {
  492. CurrentStudent.BirthCommunityID = (int?)null;
  493. CurrentStudent.BirthCommunityOther = txtBirthCommunity.Text;
  494. }
  495.  
  496. if (ddlLivingPlace.SelectedValue != "0")
  497. {
  498. CurrentStudent.LivingPlaceID = Convert.ToInt32(ddlLivingPlace.SelectedValue);
  499. CurrentStudent.LivingPlaceOther = "";
  500. }
  501. else
  502. {
  503. CurrentStudent.LivingPlaceID = (int?)null;
  504. CurrentStudent.LivingPlaceOther = txtLivingPlace.Text;
  505. }
  506.  
  507. if (ddlLivingCommunity.SelectedValue != "0")
  508. {
  509. CurrentStudent.LivingCommunityID = Convert.ToInt32(ddlLivingCommunity.SelectedValue);
  510. CurrentStudent.LivingCommunityOther = "";
  511. }
  512. else
  513. {
  514. CurrentStudent.LivingCommunityID = (int?)null;
  515. CurrentStudent.LivingCommunityOther = txtLivingCommunity.Text;
  516. }
  517. }
  518.  
  519. protected void UpdateButton_Click(object sender, EventArgs e)
  520. {
  521. UpdateStudent();
  522. }
  523.  
  524. protected void InsertButton_Click(object sender, EventArgs e)
  525. {
  526. InsertStudent();
  527. }
  528.  
  529. protected void CancelButton_Click(object sender, EventArgs e)
  530. {
  531. Response.Redirect("~/Students/StudentsInsert.aspx");
  532. }
  533.  
  534.  
  535. protected void ddlProgrammes_SelectedIndexChanged(object sender, EventArgs e)
  536. {
  537. ddlKvota.DataSource = GetQuotas();
  538. ddlKvota.DataBind();
  539. }
  540.  
  541. protected void ddlRevisions_SelectedIndexChanged(object sender, EventArgs e)
  542. {
  543. ddlDepartman.DataSource = GetProgrammes();
  544. ddlDepartman.DataBind();
  545.  
  546. ddlKvota.DataSource = GetQuotas();
  547. ddlKvota.DataBind();
  548. }
  549.  
  550. protected void ddlStudyCycle_SelectedIndexChanged(object sender, EventArgs e)
  551. {
  552. ddlDepartman.DataSource = GetProgrammes();
  553. ddlDepartman.DataBind();
  554.  
  555. ddlKvota.DataSource = GetQuotas();
  556. ddlKvota.DataBind();
  557. }
  558.  
  559.  
  560. //protected void fvStudents_Updated(object sender, FormViewUpdatedEventArgs e)
  561. //{
  562. // if (e.Exception != null)
  563. // {
  564. // UIContext.ShowMessage(this.Page, "Грешка", "Настана грешка. Податоците за студентот не се валидно внесени!. <br /><br />" + e.Exception.Message.Replace('\'', ' ').Replace('\\', ' '), MasterPages.ModalType.error);
  565. // e.ExceptionHandled = true;
  566. // }
  567. //}
  568.  
  569. //protected void fvStudents_Inserted(object sender, FormViewInsertedEventArgs e)
  570. //{
  571. // if (e.Exception != null)
  572. // {
  573. // UIContext.ShowMessage(this.Page, "Грешка", "Настана грешка. Податоците за студентот не се валидно внесени!. <br /><br />" + e.Exception.Message.Replace('\'', ' ').Replace('\\', ' '), MasterPages.ModalType.error);
  574. // e.ExceptionHandled = true;
  575. // }
  576. //}
  577.  
  578.  
  579. protected void btnPredlogIndeks_Click(object sender, EventArgs e)
  580. {
  581. try
  582. {
  583. OnGetSuggestedIndeks(FACULTY_ID);
  584. }
  585. catch (Exception err)
  586. {
  587. var algorithm = Resources.Resources.ResourceManager.GetString("IndexAlgorithmError");
  588. UIContext.ShowMessageError(this.Page, errorString, algorithm, ErrorHelper.GetError(err), ModalType.error);
  589. }
  590.  
  591. txtIndeks.Text = this.Model.SuggestedIndeks;
  592. }
  593.  
  594. protected void btnSignOut_onClick(object sender, EventArgs e)
  595. {
  596. int id = 0; Int32.TryParse(Session["StudentId"].ToString(), out id);
  597. UniSS.DataModel.SignOuts sign = new SignOuts();
  598. sign.StudentID = id;
  599. sign.DocumentNo = txtDocNo.Text;
  600. this.CurrentStudent = GetStudent(Convert.ToInt32(Session["StudentId"]));
  601. var userId = CurrentStudent.UserNameID;
  602. CurrentStudent.UserNameID = null;
  603. if (userId.HasValue)
  604. {
  605. OnEditStudentsEdit(CurrentStudent);
  606. MembershipUser user = Membership.GetUser(userId);
  607. if (user != null)
  608. {
  609. Membership.DeleteUser(user.UserName);
  610. }
  611. }
  612. DateTime? d = null;
  613. try
  614. {
  615. Convert.ToDateTime(txtDateSign.Text);
  616. }
  617. catch { }
  618. if (d.HasValue)
  619. sign.Date = d.Value;
  620. else
  621. sign.Date = DateTime.Now;
  622. sign.Description = txtDescSign.Text;
  623. OnSignOutStudentEdit(id, true, sign);
  624. }
  625.  
  626. protected void btnSignIn_onClick(object sender, EventArgs e)
  627. {
  628. int id = 0; Int32.TryParse(Session["StudentId"].ToString(), out id);
  629. OnSignOutStudentEdit(id, false, null);
  630. }
  631. #endregion
  632.  
  633.  
  634. #region Insert_Edit_Methods
  635.  
  636. //Vnesuvanje na student ************************************************************************
  637. protected void InsertStudent()
  638. {
  639. if (IsEmailTaken(dataEmail.Text, null))
  640. {
  641. var message = Resources.Resources.ResourceManager.GetString("EmailAlreadyExists");
  642. UIContext.ShowMessage(this.Page, errorString, message, MasterPages.ModalType.error);
  643. return;
  644. }
  645.  
  646. if (!IsIndeksValid(null, txtIndeks.Text))
  647. {
  648. var message = Resources.Resources.ResourceManager.GetString("IndexOccupied");
  649. UIContext.ShowMessage(this.Page, errorString, message, MasterPages.ModalType.error);
  650. return;
  651. }
  652.  
  653. //Kreiranje na username
  654. string password = RijndaelCrypto.GeneratePassPhrase(8);
  655. MembershipUser user = CreateUser(dataEmail.Text, password, dataName.Text, dataSurname.Text);
  656.  
  657. //user = Membership.GetUser(dataEmail.Text);
  658. Guid userID = Guid.Parse(user.ProviderUserKey.ToString());
  659.  
  660.  
  661. //Napolni go studentot so podatoci
  662. CurrentStudent = new DataModel.Students();
  663. LoadCurrentStudent_withData();
  664. CurrentStudent.FacultyId = FACULTY_ID;
  665. CurrentStudent.UserNameID = userID;
  666.  
  667. //Vnesi go Studentot vo baza
  668. try
  669. {
  670. OnInsertStudentsEdit(CurrentStudent);
  671. }
  672. catch (Exception ex)
  673. {
  674. Membership.DeleteUser(user.UserName);
  675. var message = Resources.Resources.ResourceManager.GetString("ErrorInfoStudentData");
  676. UIContext.ShowMessage(this.Page, errorString, message + " <br /><br />" + ex.Message.Replace('\'', ' ').Replace('\\', ' '), MasterPages.ModalType.error);
  677. }
  678.  
  679. if (UIContext.IsUsingCAS(FACULTY_ID))
  680. {
  681. UIContext.CreateCASUser(CurrentStudent.Indeks, CurrentStudent.EMail, "student");
  682. }
  683. else
  684. {
  685. //Prakanje na email za avtentifikacija
  686. bool isEmailSent = SendEmail(userID, user.Email, dataName.Text, dataSurname.Text, password);
  687. }
  688.  
  689. //Dolu pravi Redirect do Edit, taka da nemozi da se prikazi poraka
  690. //if (!isEmailSent)
  691. // UIContext.ShowMessage(this.Page, "Грешка", "Студентот успешно е внесен, но настана грешка при праќањето на емаил порака со деталите за најава. ", MasterPages.ModalType.error);
  692. //else
  693. // UIContext.ShowMessage(this.Page, "Успешно", "Податоците за студентот се успешно зачувани", MasterPages.ModalType.confirmation);
  694.  
  695. //stavi go studentot vo edit mode
  696. Session["students_insert"] = false;
  697. Session["StudentId"] = CurrentStudent.ID;
  698. Session["Inserted"] = true;
  699. if (ViewState["ApplicantId"] != null)
  700. {
  701. OnUpdateApplicant(Convert.ToInt32(ViewState["ApplicantId"]));
  702. ViewState["ApplicantId"] = null;
  703. }
  704. var studentinsertSuccess = Resources.Resources.ResourceManager.GetString("InsertStudentSuccess");
  705. var withindexNumber = Resources.Resources.ResourceManager.GetString("WithIndexNumber");
  706. Session["InsertedStudent"] =String.Format(studentinsertSuccess + " - {0} {1} " + withindexNumber + " {2}.", dataName.Text , dataSurname.Text , txtIndeks.Text);
  707. Response.Redirect("~/Students/StudentsInsert.aspx");
  708. }
  709.  
  710.  
  711. //Editiranje na student ************************************************************************
  712. protected void UpdateStudent()
  713. {
  714. this.CurrentStudent = GetStudent(Convert.ToInt32(Session["StudentId"]));
  715. bool HasAlreadyEmail = false;
  716.  
  717.  
  718. if (IsEmailTaken(dataEmail.Text, this.CurrentStudent.UserNameID))
  719. {
  720. var emailexists = Resources.Resources.ResourceManager.GetString("EmailAlreadyExists");
  721. UIContext.ShowMessage(this.Page, errorString, emailexists, MasterPages.ModalType.error);
  722. return;
  723. }
  724.  
  725. if (!IsIndeksValid(this.CurrentStudent.ID, txtIndeks.Text))
  726. {
  727. var indexoccupied = Resources.Resources.ResourceManager.GetString("IndexOccupied");
  728. UIContext.ShowMessage(this.Page, errorString, indexoccupied, MasterPages.ModalType.error);
  729. return;
  730. }
  731.  
  732. bool exists = true;
  733. //Priprema za update na user
  734. MembershipUser user = Membership.GetUser(this.CurrentStudent.UserNameID);
  735. string password = "";
  736. Guid? userID = this.CurrentStudent.UserNameID;
  737.  
  738. if (user != null)
  739. { //Update na user
  740. HasAlreadyEmail = true;
  741. user.Email = dataEmail.Text;
  742. Membership.UpdateUser(user);
  743. }
  744. else if (CurrentStudent.StudentStatusID <= 3)
  745. { //Kreiranje na user
  746. password = RijndaelCrypto.GeneratePassPhrase(8);
  747. user = CreateUser(dataEmail.Text, password, dataName.Text, dataSurname.Text);
  748. //user = Membership.GetUser(dataEmail.Text);
  749. userID = Guid.Parse(user.ProviderUserKey.ToString());
  750. exists = false;
  751. }
  752.  
  753.  
  754. //Update Studentot vo baza
  755. CurrentStudent = GetStudent(Convert.ToInt32(Session["StudentId"]));
  756. LoadCurrentStudent_withData();
  757. CurrentStudent.FacultyId = FACULTY_ID;
  758. CurrentStudent.UserNameID = userID;
  759.  
  760. try
  761. {
  762. if (CurrentStudent.StudentStatusID > 3)
  763. {
  764. CurrentStudent.UserNameID = null;
  765. }
  766.  
  767. OnEditStudentsEdit(CurrentStudent);
  768.  
  769. if (CurrentStudent.StudentStatusID > 3)
  770. {
  771. Membership.DeleteUser(user.UserName);
  772. }
  773. }
  774. catch (Exception ex)
  775. {
  776. if (!exists)
  777. {
  778. CurrentStudent.UserNameID = null;
  779. OnEditStudentsEdit(CurrentStudent);
  780. Membership.DeleteUser(user.UserName);
  781. }
  782. var errorinfo = Resources.Resources.ResourceManager.GetString("ErrorInfoStudentData");
  783. UIContext.ShowMessage(this.Page, errorString, errorString + ". <br /><br />" + ex.Message.Replace('\'', ' ').Replace('\\', ' '), MasterPages.ModalType.error);
  784. return;
  785. }
  786.  
  787.  
  788. //Prakanje na email za avtentifikacija samo dokolku nema email prethodno
  789. bool isEmailSent = true;
  790. if (!HasAlreadyEmail)
  791. {
  792. if (UIContext.IsUsingCAS(FACULTY_ID))
  793. {
  794. UIContext.CreateCASUser(CurrentStudent.Indeks, CurrentStudent.EMail, "student");
  795. }
  796. else
  797. {
  798. isEmailSent = SendEmail((Guid)userID, user.Email, dataName.Text, dataSurname.Text, password);
  799. }
  800. }
  801. if (!isEmailSent)
  802. {
  803. UIContext.ShowMessage(this.Page, errorString, "Студентот успешно е внесен, но настана грешка при праќањето на емаил порака со деталите за најава. ", MasterPages.ModalType.error);
  804. }
  805. else
  806. {
  807. var success = Resources.Resources.ResourceManager.GetString("Success");
  808. var studentData = Resources.Resources.ResourceManager.GetString("");
  809. UIContext.ShowMessage(this.Page, "Успешно", "Податоците за студентот се успешно зачувани", MasterPages.ModalType.confirmation);
  810. }
  811. }
  812.  
  813.  
  814.  
  815.  
  816. protected bool IsEmailTaken(string email, Guid? userId)
  817. {
  818. string username = Membership.GetUserNameByEmail(email);
  819. bool isEmailTaken = !string.IsNullOrEmpty(username);
  820. //MembershipUser userByEmail = Membership.GetUser(username);
  821. //MembershipUser userByEmail = Membership.GetUser(email);
  822. if (userId == null)
  823. { //se raboti za nov student.
  824. return isEmailTaken; //ako postoi znaci e zafaten
  825. }
  826. else
  827. {
  828. if (!isEmailTaken)
  829. { //ne e najden baraniot email, vrati deka ne e zafaten
  830. return false;
  831. }
  832. else
  833. { //postoi baraniot email, proveri dali se raboti za sopstveniot
  834. MembershipUser userByID = Membership.GetUser(userId);
  835. MembershipUser userByUsername = Membership.GetUser(username);
  836. if (userByUsername.Email == userByID.Email) //se raboti za sopstveniot email, velime deka ne e zafaten (za da posluzi da mozi da se updejtira istiot)
  837. return false;
  838. else //ne e sopstveniot email, na nekoj drug korisnik e => emailot e zafaten
  839. return true;
  840. }
  841. }
  842. }
  843.  
  844. protected bool SendEmail(Guid userID, string email, string name, string surname, string password)
  845. {
  846. string urlBase = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
  847. string verifyUrl = "Account/Recovery.aspx?newuser=true&user=" + userID;
  848. string fullPath = urlBase + verifyUrl;
  849. string AppPath = Request.PhysicalApplicationPath;
  850.  
  851. try
  852. {
  853. //string facultyName = ((AdminMaster)((NestedMaster)this.Page.Master.Master).Master).labelLogo.Text;
  854. //string facultyName = ((MasterPages.AdminMaster)this.Page.Master).labelLogo.Text;
  855. string facultyName = "";
  856. MailHelper.SendMail(3, email, new List<string>() { fullPath, email, email, password, facultyName });
  857. //MailHelper.SendMail(3, email, new List<string>() { fullPath, email, email, password, "Ime na fakultet" });
  858. }
  859. catch
  860. {
  861.  
  862. return false;
  863. }
  864. return true;
  865. }
  866.  
  867. protected MembershipUser CreateUser(string email, string password, string name, string surname)
  868. {
  869. MembershipUser user = Membership.CreateUser(Guid.NewGuid().ToString(), password, email);
  870.  
  871. if (!Roles.IsUserInRole(user.UserName, "Студенти"))
  872. Roles.AddUserToRole(user.UserName, "Студенти");
  873.  
  874. //MembershipUser user = Membership.GetUser(email);
  875. if (UIContext.IsUsingCAS(FACULTY_ID))
  876. user.IsApproved = true;
  877. else
  878. user.IsApproved = false;
  879. user.Comment = FACULTY_ID.ToString();
  880. Membership.UpdateUser(user);
  881.  
  882.  
  883. UserProfile profile = UserProfile.GetUserProfile(user.UserName);
  884. profile.Faculty = FACULTY_ID;
  885. profile.Name = name;
  886. profile.Surname = surname;
  887. profile.Save();
  888.  
  889.  
  890. //Audit log
  891. UniSS.DataModel.AuditLog log = new DataModel.AuditLog();
  892. log.UserName = this.Page.User.Identity.Name;
  893. log.EventDate = DateTime.Now;
  894. log.TableName = "aspnet_Membership";
  895. log.Actions = "i";
  896. log.NewData = "UserName: " + email;
  897. log.ChangedColumns = "UserName";
  898. AuditHelper.LogActivity(log);
  899.  
  900. return user;
  901. }
  902.  
  903. protected void btnEnrolmentInsert_Click(object sender, EventArgs e)
  904. {
  905. OnGetApplicant(txtEnrolmentSearch.Text, Convert.ToInt32(ddlTerms.SelectedValue));
  906.  
  907. if (Model.Applicant != null)
  908. {
  909. int termId = Convert.ToInt32(ddlTerms.SelectedValue);
  910. var rang = Model.Applicant.ApplicantRang.Where(x => x.ListType != 9 && x.ListType != 10 && x.ListType != 13 && x.RangLists.TermId == termId && x.RangLists.Final == true).FirstOrDefault();
  911. if (rang != null)
  912. {
  913. if (Model.Applicant.AcceptedAsStudent == true)
  914. {
  915. lblApplicantRangInfo.Text = string.Format("<div class='alert alert-success'>Апликантот веќе е внесен во листата на студенти на факултетот. </div>");
  916. }
  917. else
  918. {
  919. lblApplicantRangInfo.Text = string.Format("<div class='alert alert-success'>Апликантот е рангиран на студиската програма <font color='Red'>{0}</font> во квота <font color='Red'>{1}</font></div>", rang.StudyProgramme.Programmes.Name, rang.ApplicantQuotaTypes.Name);
  920. InitControlsFromApplicant();
  921. ViewState["ApplicantId"] = Model.Applicant.Id;
  922. }
  923. }
  924. else
  925. {
  926. lblApplicantRangInfo.Text = "<div class='alert alert-error'>Кандидатот не е рангиран на избраниот уписен рок.</div>";
  927. }
  928. }
  929. else
  930. {
  931. UIContext.ShowMessage(this.Page, "Информација", "Апликантот не постои.", ModalType.information);
  932. }
  933. }
  934.  
  935. public void InitControlsFromApplicant()
  936. {
  937. txtPassport.Text = Model.Applicant.Passport;
  938. int termId = Convert.ToInt32(ddlTerms.SelectedValue);
  939. var rang = Model.Applicant.ApplicantRang.Where(x => x.RangLists.Final == true && x.RangLists.TermId == termId).FirstOrDefault();
  940.  
  941. try
  942. {
  943. OnGetSuggestedIndeks(FACULTY_ID);
  944. txtIndeks.Text = this.Model.SuggestedIndeks;
  945. }
  946. catch { }
  947.  
  948. dataEmbg.Text = Model.Applicant.Embg;
  949. dataSurname.Text = Model.Applicant.Surname;
  950. dataFathersName.Text = Model.Applicant.FathersName;
  951. dataName.Text = Model.Applicant.Name;
  952. dataBridesName.Text = Model.Applicant.BridesName;
  953. dataBirthDate.Text = String.Format("{0:d}", Model.Applicant.BirthDate);
  954. dataSex.SelectedValue = Model.Applicant.Sex.ToString();
  955. if (Model.Applicant.NationalityId.HasValue)
  956. dataNationalityId.SelectedValue = Model.Applicant.NationalityId.ToString();
  957.  
  958. if (Model.Applicant.CitizenshipId.HasValue)
  959. dataCitizenshipId.SelectedValue = Model.Applicant.CitizenshipId.ToString();
  960.  
  961. ddlCurrentRevision.SelectedValue = rang.StudyProgramme.Programmes.RevisionID.ToString();
  962.  
  963. dataPreviousEducation.Text = Model.Applicant.SchoolId.HasValue ?
  964. Model.Applicant.Schools.Name : string.Empty;
  965. if (Model.Applicant.SchoolTypeId.HasValue) ddlSchoolType.SelectedValue = Model.Applicant.SchoolTypeId.ToString();
  966. dataPreviousEducationYear.Text = Model.Applicant.YearGraduating.HasValue ?
  967. Model.Applicant.YearGraduating.ToString() : string.Empty;
  968. dataPreviousEducationGrade.Text = Model.Applicant.HighSchoolPoints.ToString();
  969.  
  970. txtDataProfession.Text = Model.Applicant.SchoolType.Name;
  971. dataProfessionFather.Text = Model.Applicant.GuardianOccupation;
  972.  
  973. ddlStatus.SelectedValue = Model.Applicant.StudyType == 1 ?
  974. "1" : "2";
  975. ddlCycle.SelectedValue = Model.Applicant.StudyCycleId.ToString();
  976.  
  977. dataPermanentAddress.Text = Model.Applicant.StreetNameNo;
  978.  
  979. dataGsm.Text = Model.Applicant.Gsm;
  980. dataEmail.Text = Model.Applicant.Email;
  981. dataStartYear.Text = DateTime.Now.Year.ToString();
  982.  
  983. if (Model.Applicant.PreviousLanguageId != null) dataPreviousEducationLanguageId.SelectedValue = Model.Applicant.PreviousLanguageId.ToString();
  984. if (Model.Applicant.LivingCountryId != null) dataLivingCountryId.SelectedValue = Model.Applicant.LivingCountryId.ToString();
  985. if (Model.Applicant.BirthCountryId != null) dataBirthCountryId.SelectedValue = Model.Applicant.BirthCountryId.ToString();
  986.  
  987.  
  988. if (Model.Applicant.BirthCommunityId != null)
  989. {
  990. trBirthCommunity.Visible = txtBirthCommunity.Visible = false;
  991. ddlBirthCommunity.SelectedValue = Model.Applicant.BirthCommunityId.ToString();
  992. }
  993. else
  994. {
  995. if (!string.IsNullOrEmpty(Model.Applicant.BirthCommunityOther))
  996. {
  997. trBirthCommunity.Visible = txtBirthCommunity.Visible = true;
  998. txtBirthCommunity.Text = Model.Applicant.BirthCommunityOther;
  999. }
  1000. //ddlBirthCommunity.SelectedValue = "0";
  1001. }
  1002.  
  1003. if (Model.Applicant.BirthPlaceId != null)
  1004. {
  1005. trBirthPlace.Visible = txtBirthPlace.Visible = false;
  1006. ddlBirthPlace.SelectedValue = Model.Applicant.BirthPlaceId.ToString();
  1007. }
  1008. else
  1009. {
  1010. if (!string.IsNullOrEmpty(Model.Applicant.BirthPlaceOther))
  1011. {
  1012. trBirthPlace.Visible = txtBirthPlace.Visible = true;
  1013. txtBirthPlace.Text = Model.Applicant.BirthPlaceOther;
  1014. }
  1015. }
  1016.  
  1017. if (Model.Applicant.LivingPlaceId != null)
  1018. {
  1019. trLivingPlace.Visible = txtLivingPlace.Visible = false;
  1020. ddlLivingPlace.SelectedValue = Model.Applicant.LivingPlaceId.ToString();
  1021. }
  1022. else
  1023. {
  1024. if (!string.IsNullOrEmpty(Model.Applicant.LivingPlaceOther))
  1025. {
  1026. trLivingPlace.Visible = txtLivingPlace.Visible = true;
  1027. txtLivingPlace.Text = Model.Applicant.LivingPlaceOther;
  1028. }
  1029. //ddlLivingPlace.SelectedValue = "0";
  1030. }
  1031.  
  1032. if (Model.Applicant.LivingCommunityId != null)
  1033. {
  1034. trLivingCommunity.Visible = txtLivingCommunity.Visible = false;
  1035. ddlLivingCommunity.SelectedValue = Model.Applicant.LivingCommunityId.ToString();
  1036. }
  1037. else
  1038. {
  1039. trLivingCommunity.Visible = txtLivingCommunity.Visible = true;
  1040. txtLivingCommunity.Text = Model.Applicant.LivingCommunityOther;
  1041. //ddlLivingCommunity.SelectedValue = "0";
  1042. }
  1043.  
  1044.  
  1045. //get data for selected revision and cycle
  1046. ddlDepartman.DataSource = GetProgrammes();
  1047. ddlDepartman.DataBind();
  1048.  
  1049. if (ddlDepartman.Items.FindByValue(rang.StudyProgramme.ProgrammeId.ToString()) != null)
  1050. ddlDepartman.SelectedValue = rang.StudyProgramme.ProgrammeId.ToString();
  1051.  
  1052. ddlKvota.DataSource = GetQuotas();
  1053. ddlKvota.DataBind();
  1054.  
  1055. string quotaId = string.Empty;
  1056. try
  1057. {
  1058. quotaId = CalcucalteQuota(rang.ListType.Value);
  1059. }
  1060. catch (Exception err)
  1061. {
  1062. UIContext.ShowMessageError(this.Page, "Грешка", "Не постојат квоти за избраната студиска програма", ErrorHelper.GetError(err), ModalType.error);
  1063. }
  1064.  
  1065. if (ddlKvota.Items.FindByValue(quotaId) != null)
  1066. ddlKvota.SelectedValue = quotaId;
  1067. }
  1068.  
  1069. public string CalcucalteQuota(int rangId)
  1070. {
  1071. if (rangId == 1)
  1072. return Model.AllQuotaPrices.Where(x => x.QuotaId == 1).FirstOrDefault().ID.ToString();
  1073. else if (rangId == 2)
  1074. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1075. else if (rangId == 3)
  1076. return Model.AllQuotaPrices.Where(x => x.QuotaId == 4).FirstOrDefault().ID.ToString();
  1077. else if (rangId == 4)
  1078. return Model.AllQuotaPrices.Where(x => x.QuotaId == 18).FirstOrDefault().ID.ToString();
  1079. else if (rangId == 5)
  1080. return Model.AllQuotaPrices.Where(x => x.QuotaId == 4).FirstOrDefault().ID.ToString();
  1081. else if (rangId == 6)
  1082. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1083. else if (rangId == 7)
  1084. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1085. else if (rangId == 8)
  1086. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1087. else if (rangId == 11)
  1088. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1089. else if (rangId == 12)
  1090. return Model.AllQuotaPrices.Where(x => x.QuotaId == 3).FirstOrDefault().ID.ToString();
  1091. else
  1092. return string.Empty;
  1093. }
  1094. #endregion
  1095.  
  1096.  
  1097. #region "Select Methods"
  1098. public UniSS.DataModel.Students GetCurrentStudent(int studentId, int studyCycleID, int revisionID, int programmesID, int quotaPriceID, int facultyID)
  1099. {
  1100. OnGetStudentsEdit(studentId, studyCycleID, revisionID, programmesID, quotaPriceID, facultyID);
  1101.  
  1102. if (studentId == 0)
  1103. return new UniSS.DataModel.Students();
  1104. return this.Model.CurrentStudent;
  1105. }
  1106.  
  1107. public UniSS.DataModel.Students GetStudent(int studentID)
  1108. {
  1109. OnGetStudentsEdit(studentID, 0, 0, 0, 0, 0);
  1110. return Model.CurrentStudent;
  1111. }
  1112.  
  1113.  
  1114.  
  1115. public IEnumerable<UniSS.DataModel.Programmes> GetProgrammes()
  1116. {
  1117. int studyCycleID = Convert.ToInt32(ddlCycle.SelectedValue);
  1118. int revisionID = Convert.ToInt32(ddlCurrentRevision.SelectedValue);
  1119.  
  1120. OnGettingProgrammes(studyCycleID, revisionID, FACULTY_ID);
  1121. return this.Model.AllProgrammes;
  1122. }
  1123.  
  1124. public IEnumerable<UniSS.Repositories.Domain.QuotaPricesRefactored> GetQuotas()
  1125. {
  1126. int programmeID = Convert.ToInt32(ddlDepartman.SelectedValue);
  1127. int status = 0; Int32.TryParse(ddlStatus.SelectedValue, out status);
  1128. OnGettingQuotasPrices(programmeID, status);
  1129. return this.Model.AllQuotaPrices;
  1130. }
  1131.  
  1132. public IEnumerable<UniSS.DataModel.Revisions> GetRevisions()
  1133. {
  1134. return this.Model.AllRevisions;
  1135. }
  1136.  
  1137. public bool IsIndeksValid(int? studentId, string indeks)
  1138. {
  1139. OnCheckingIndeksIfValid(studentId, indeks);
  1140. return Model.IsIndeksValid;
  1141. }
  1142.  
  1143. #endregion
  1144.  
  1145.  
  1146. #region "Event handlers"
  1147. public event EventHandler<GetStudentsEditEventArgs> GetStudentsEdit;
  1148. public void OnGetStudentsEdit(int studentId, int studyCycleID, int revisionID, int programmesID, int quotaPriceID, int facultyID)
  1149. {
  1150. if (GetStudentsEdit != null)
  1151. GetStudentsEdit(this, new GetStudentsEditEventArgs(studentId, studyCycleID, revisionID, programmesID, quotaPriceID, facultyID));
  1152. }
  1153.  
  1154. public event EventHandler<EditStudentsEditEventArgs> EditStudentsEdit;
  1155. public void OnEditStudentsEdit(UniSS.DataModel.Students student)
  1156. {
  1157. if (EditStudentsEdit != null)
  1158. EditStudentsEdit(this, new EditStudentsEditEventArgs(student));
  1159. }
  1160.  
  1161. public event EventHandler<EditStudentsEditEventArgs> InsertStudentsEdit;
  1162. public void OnInsertStudentsEdit(UniSS.DataModel.Students student)
  1163. {
  1164. if (InsertStudentsEdit != null)
  1165. InsertStudentsEdit(this, new EditStudentsEditEventArgs(student));
  1166. }
  1167.  
  1168. public event EventHandler<SetInsertModeEventArgs> SetInsertMode;
  1169. public void OnSetInsertMode(bool CanInsert)
  1170. {
  1171. if (SetInsertMode != null)
  1172. SetInsertMode(this, new SetInsertModeEventArgs(CanInsert));
  1173. }
  1174.  
  1175. public event EventHandler<GetSuggestedIndeksEventArgs> GetSuggestedIndeks;
  1176. public void OnGetSuggestedIndeks(int facultyId)
  1177. {
  1178. if (GetSuggestedIndeks != null)
  1179. GetSuggestedIndeks(this, new GetSuggestedIndeksEventArgs(facultyId));
  1180. }
  1181.  
  1182. public event EventHandler<SignOutStudentEditEventArgs> SignOutStudentEdit;
  1183. public void OnSignOutStudentEdit(int studentId, bool signedOut, UniSS.DataModel.SignOuts signOut)
  1184. {
  1185. SignOutStudentEdit(this, new SignOutStudentEditEventArgs(studentId, signedOut, signOut));
  1186. }
  1187.  
  1188. public event EventHandler<GetStudentsEditEventArgs> GettingData;
  1189. public void OnGettingData(int facultyID)
  1190. {
  1191. if (GettingData != null)
  1192. GettingData(this, new GetStudentsEditEventArgs(0, 0, 0, 0, 0, facultyID));
  1193. }
  1194.  
  1195. public event EventHandler<GetStudentsEditEventArgs> GettingProgrammes;
  1196. public void OnGettingProgrammes(int studyCycleID, int revisionID, int facultyID)
  1197. {
  1198. if (GettingProgrammes != null)
  1199. GettingProgrammes(this, new GetStudentsEditEventArgs(0, studyCycleID, revisionID, 0, 0, facultyID));
  1200. }
  1201.  
  1202. public event EventHandler<GetStudentsEditEventArgs> GettingQuotasPrices;
  1203. public void OnGettingQuotasPrices(int programmesID, int Status)
  1204. {
  1205. if (GettingQuotasPrices != null)
  1206. GettingQuotasPrices(this, new GetStudentsEditEventArgs(Status, 0, 0, programmesID, 0, 0));
  1207. }
  1208.  
  1209. public event EventHandler<CheckingIndeksIfValidEventArgs> CheckingIndeksIfValid;
  1210. public void OnCheckingIndeksIfValid(int? studentId, string indeks)
  1211. {
  1212. if (CheckingIndeksIfValid != null)
  1213. CheckingIndeksIfValid(this, new CheckingIndeksIfValidEventArgs(studentId, indeks, FACULTY_ID));
  1214. }
  1215.  
  1216. public event EventHandler<GetApplicantEventArgs> GetApplicant;
  1217. public void OnGetApplicant(string search, int termId)
  1218. {
  1219. if (GetApplicant != null)
  1220. GetApplicant(this, new GetApplicantEventArgs(search, termId));
  1221. }
  1222.  
  1223. public event EventHandler<GetApplicantEventArgs> UpdateApplicant;
  1224. public void OnUpdateApplicant(int Id)
  1225. {
  1226. if (UpdateApplicant != null)
  1227. UpdateApplicant(this, new GetApplicantEventArgs(null, Id));
  1228. }
  1229.  
  1230. public event EventHandler<EditStudentsEditEventArgs> UpdateLocked;
  1231. public void OnUpdateLocked(UniSS.DataModel.Students s)
  1232. {
  1233. if (UpdateLocked != null)
  1234. UpdateLocked(this, new EditStudentsEditEventArgs(s));
  1235. }
  1236. #endregion
  1237. }
  1238. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement