public void DeleteSemester(SemesterEdit toEdit)
 {
     Semester s = this.repository.GetSemester(toEdit.SemesterName, toEdit.SemesterNo, toEdit.SemesterYear);
     if (s != null && s.SubjectsDatas.Count > 0)
         throw new UpdateException("Nie można usunąć semestru,\nponieważ posiada powiązania");
     else
     {
         this.repository.DeleteSpecialization(s);
     }
 }
 public SemesterEdit GetSemesterEdit(string semesterName, int semesterNo, int semesterYear)
 {
     Semester s = this.repository.GetSemester(semesterName, semesterNo, semesterYear);
     if (s != null)
     {
         SemesterEdit se = new SemesterEdit()
         {
             SemesterID = s.SemesterID,
             SemesterName = s.Name,
             SemesterNo = s.Semester1,
             SemesterYear = s.StudyYear
         };
         return se;
     }
     return null;
 }
        public bool EditSemester(SemesterEdit toEdit)
        {
            if (toEdit != null)
            {
                Semester s = this.repository.GetSemester(toEdit.SemesterName, toEdit.SemesterNo, toEdit.SemesterYear);
                if (s != null && s.SemesterID != toEdit.SemesterID && s.Name.ToLower().Equals(toEdit.SemesterName.ToLower()) && 
                    s.Semester1 == toEdit.SemesterNo && s.StudyYear == toEdit.SemesterYear)
                    toEdit.AddError("Semestr o takich danych\njuż istnieje");

                if (toEdit.IsValid)
                {
                    s = this.repository.GetSemester(toEdit.SemesterID);
                    s.Name = toEdit.SemesterName;
                    s.Semester1 = toEdit.SemesterNo;
                    s.StudyYear = toEdit.SemesterYear;

                    this.repository.EditSemester(s);
                    return true;
                }
            }
            return false;
        }
        private void dgSemesters_CellDoubleClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            lblValidation.Text = string.Empty;
            if (e.Row.Index >= 0)
            {
                int no = 0;
                int year = 0;

                int.TryParse(dgSemesters.Rows[e.Row.Index].Cells["cNo"].Value.ToString(), out no);
                int.TryParse(dgSemesters.Rows[e.Row.Index].Cells["cYear"].Value.ToString(), out year);

                SemesterEdit semester = SemesterController.Instance.GetSemesterEdit(
                    dgSemesters.Rows[e.Row.Index].Cells["cName"].Value.ToString(),
                    no, year);

                if (semester != null)
                {
                    toEdit = semester;
                    Enable();
                    tbNewSemesterName.Text = semester.SemesterName;
                    tbNewSemestrNo.Text = semester.SemesterNo.ToString();
                    tbNewSemesterYear.Text = semester.SemesterYear.ToString();
                }
                else
                {
                    lblValidation.Text = "Semestr nie istnieje";
                    toEdit = null;
                }
            }
        }
 private void btnDelete_Click(object sender, EventArgs e)
 {
     lblValidation.Text = string.Empty;
     if (toEdit != null)
     {
         try
         {
             SemesterController.Instance.DeleteSemester(toEdit);
             FillWithSemesters();
             toEdit = null;
             Disable();
             Clear();
             changes = true;
         }
         catch (UpdateException ex)
         {
             lblValidation.Text = ex.Message;
         }
     }
 }
 private void btnCancel_Click(object sender, EventArgs e)
 {
     if (toEdit != null)
     {
         toEdit = null;
         Disable();
         Clear();
     }
 }