//config changes private void okButton_Click(object sender, EventArgs e) { this.clearErrors();//clear error message ConfigForm conf = new ConfigForm("Είστε σίγουρος ότι θέλετε να επιβεβαιώσετε τις αλλαγές σας;\nΟι αλλαγές θα είναι οριστικές!", "Όχι", "Ναι", Color.LimeGreen, "Επιβεβαίωση επεξεργασίας"); //he want to do the changes if (conf.ShowDialog(this) == DialogResult.OK) { String newTitle = this.lessonTextbox.Text; //get new title String newDesc = this.descriptionTextbox.Text; //get new description bool closeFlag = true; //flag for no close this form, true close, false= there is error not close int check; //disable error labels this.clearErrors(); //change title and desc if (!this.lesson.Equals(newTitle)) { if (!(String.IsNullOrEmpty(newTitle) || String.IsNullOrWhiteSpace(newTitle))) //if title is empty then don't call database { check = 0; check = db.uLesson(user, this.descriptionTextbox.Text, this.lessonTextbox.Text, lesson); if (check == 1) //everything was okey { this.lesson = newTitle; this.desc = newDesc; } else if (check == -5) { errorsLabel.Text = "Υπάρχει ήδη μάθημα με αυτόν τον τίτλο.\n"; closeFlag = false; } } else { errorsLabel.Text = "Δεν μπορείτε να εισάγεται κενό τίτλο μαθήματος!\n"; closeFlag = false; } } else { check = 0; check = db.uLesson(user, this.descriptionTextbox.Text, lesson); if (check == 1) //everything was okey { this.lesson = newTitle; this.desc = newDesc; } else { errorsLabel.Text = "Κάτι πήγε στραβά στην επεξεργασία περιγραφής.\n"; closeFlag = false; } } //delete units for (int i = 0; i < units.Count; i++) { //check if checkbox is checked bool flag = false; try { flag = (bool)this.unitsDataGridView.Rows[i].Cells[1].Value; } catch //it was null {} if (flag) { check = db.dUnit(this.user, this.lesson, units.ElementAt(i)); if (check != 1) { closeFlag = false; errorsLabel.Text += "Κάτι πήγε στραβά στη διαγραφή ενότητα\n"; } } else //change name of unit { String editUnitFlag = ""; try { editUnitFlag = (String)this.unitsDataGridView.Rows[i].Cells[0].Value.ToString(); } catch { } //there was null exception. now there is only blank or empty string with try catch and this field/flag if (!(String.IsNullOrEmpty(editUnitFlag) || String.IsNullOrWhiteSpace(editUnitFlag))) { String newUnit = this.unitsDataGridView.Rows[i].Cells[0].Value.ToString(); //new name != old name if (!newUnit.Equals(units.ElementAt(i).ToString())) { check = db.uUnit(user, lesson, newUnit, units.ElementAt(i)); if (check == -5) { Console.Write(check); closeFlag = false; errorsLabel.Text += "Δε μπορείτε να έχετε το ίδιο όνομα σε παραπάνω απο μία ενότητα.\n"; } else if (check != 1) { Console.Write(check); closeFlag = false; errorsLabel.Text += "Κάτι πήγε λάθος στη μετονομασία ενότητας.\n"; } } } else { closeFlag = false; errorsLabel.Text += "Δε μπορείτε να αποθηκεύσετε κενό τίτλο ενότητας.\n"; } } } //create units if (units.Count < this.unitsDataGridView.Rows.Count - 1) { for (int i = units.Count; i < this.unitsDataGridView.Rows.Count - 1; i++) { String unitName = this.unitsDataGridView.Rows[i].Cells[0].Value.ToString(); if (!String.IsNullOrEmpty(unitName) && !String.IsNullOrWhiteSpace(unitName)) { check = db.iUnit(unitName, user, lesson); if (check != 1) { closeFlag = false; this.errorsLabel.Text += "Υπήρξε πρόβλημα με την δημιουργία ενότητας.\n"; } } else { this.errorsLabel.Text += "Δε μπορείτε να εισάγεται κενό όνομα ενότητας."; closeFlag = false; } } } father.loadLessons(); //load lessons, refresh them if (closeFlag) //all good { MessageBox.Show("Η επεξεργασία μαθήμητος πραγματοποιήθηκε με επιτυχία."); this.Close(); this.Dispose(); } else //there are errors { errorsLabel.Visible = true; errorTittleLabel.Visible = true; } } conf.Dispose(); }