public bool updateCOURSE(DTO_Course course) { try { SqlCommand command = new SqlCommand("UPDATE COURSE SET label=@label, period=@period, description=@description, semester =@semester,group_id =@group_id WHERE id =@id", this.getConnection); command.Parameters.Add("@id", SqlDbType.Int).Value = course.id; command.Parameters.Add("@label", SqlDbType.VarChar).Value = course.label; command.Parameters.Add("@period", SqlDbType.VarChar).Value = course.period; command.Parameters.Add("@description", SqlDbType.VarChar).Value = course.description; command.Parameters.Add("@semester", SqlDbType.Int).Value = course.Semester; command.Parameters.Add("@group_id", SqlDbType.Int).Value = course.Groupid; this.openConnection(); if (command.ExecuteNonQuery() == 1) { this.closeConnection(); return(true); } else { this.closeConnection(); return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
public bool insertCOURSE(DTO_Course course) { try { SqlCommand command = new SqlCommand("INSERT INTO COURSE ( id,label, period, description,semester,group_id)" + "VALUES ( @id,@label, @period, @description,@semester,@group_id)", this.getConnection); command.Parameters.Add("@id", SqlDbType.VarChar).Value = course.id; command.Parameters.Add("@label", SqlDbType.VarChar).Value = course.label; command.Parameters.Add("@period", SqlDbType.Int).Value = course.period; command.Parameters.Add("@description", SqlDbType.VarChar).Value = course.description; command.Parameters.Add("@semester", SqlDbType.Int).Value = course.Semester; command.Parameters.Add("@group_id", SqlDbType.Int).Value = course.Groupid; this.openConnection(); if (command.ExecuteNonQuery() == 1) { this.closeConnection(); return(true); } else { this.closeConnection(); return(false); } } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
private void btnAdd_Click(object sender, EventArgs e) { if (this.txtID.Text == "" || this.txtLabel.Text == "" || this.txtPeriod.Text == "" || comboBoxGroup.SelectedItem == null) { MessageBox.Show("Add error", "Add Course", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { try { int Id = int.Parse(this.txtID.Text); string Label = this.txtLabel.Text; int period = int.Parse(this.txtPeriod.Text); string desciption = this.txtDescription.Text; int semester = int.Parse(this.txtSemester.Text); int groupid = (int)comboBoxGroup.SelectedValue; DTO_Course Course = new DTO_Course(Id, Label, period, desciption, semester, groupid); DataTable tb = BUScourse.getCOURSEId(Id); DataTable tb2 = BUScourse.getCOURSELabel(Label, semester); if (tb.Rows.Count > 0) { MessageBox.Show("Register Error ID existence", "Add COURSE", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (tb2.Rows.Count > 0) { MessageBox.Show("Register Error Label existence", "Add COURSE", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (Course.verif()) { if (BUScourse.insertCOURSE(Course) == true) { MessageBox.Show("Add succesfully", "Add Course", MessageBoxButtons.OK, MessageBoxIcon.Information); //Close(); } else { MessageBox.Show("Register Error", "Add User", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnEdit_Click(object sender, EventArgs e) { if (this.txtID.Text == "" || this.txtLabel.Text == "" || this.txtSemester.Text == "") { MessageBox.Show("Field Emty", "Edit Course", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { string label = txtLabel.Text; int period = int.Parse(UpdownPeriod.Value.ToString()); string descrip = txtDescription.Text; int semester = int.Parse(this.txtSemester.Text); if (label == "") { MessageBox.Show("Invalid Label!!", "Invalid Label", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (period >= 10) { try { int id = Convert.ToInt32(txtID.Text); int groupid = (int)comboBoxGroup.SelectedValue; DTO_Course course = new DTO_Course(id, label, period, descrip, semester, groupid); if (BUScourse.updateCOURSE(course) == true && course.verif() == true) { MessageBox.Show("course informationg Updated", "edit course", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Edit Error", "Edit course", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Edit course", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("Emty Fields", "Edit course", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } }
public bool updateCOURSE(DTO_Course course) { return(DALcourse.updateCOURSE(course)); }
public bool insertCOURSE(DTO_Course course) { return(DALcourse.insertCOURSE(course)); }