private void ViewCourse_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { if (!e.Column.FieldName.ToString().Equals("IsEdited")) { if (ViewCourse.GetRowCellValue(e.RowHandle, "CourseID").ToString().Equals("")) { ViewCourse.SetRowCellValue(e.RowHandle, "IsEdited", "2"); } else { ViewCourse.SetRowCellValue(e.RowHandle, "IsEdited", "1"); } } }
private void SaveAllUpdatedList() { ViewCourse.CloseEditForm(); ViewCourse.UpdateCurrentRow(); List <string> updateQueries = new List <string>(); for (int i = 0; i < ViewCourse.RowCount; i++) { if (ViewCourse.GetRowCellValue(i, "IsEdited").ToString().Equals("1")) { long corID = Convert.ToInt64(ViewCourse.GetRowCellValue(i, "CourseID")); string courseName = ViewCourse.GetRowCellValue(i, "CourseName").ToString(); string abbrv = ViewCourse.GetRowCellValue(i, "Abbrv").ToString(); string query = "UPDATE attendance_db.tblcourse SET CourseName = '" + courseName + "' , Abbrv ='" + abbrv.ToUpper() + "' WHERE CourseID = " + corID + ""; updateQueries.Add(query); } else if (ViewCourse.GetRowCellValue(i, "IsEdited").ToString().Equals("2")) { if (InputValidation("")) { string courseName = ViewCourse.GetRowCellValue(i, "CourseName").ToString(); string abbrv = ViewCourse.GetRowCellValue(i, "Abbrv").ToString(); string query = "INSERT INTO attendance_db.tblcourse(CourseName , Abbrv , IsActive , UserID) VALUES('" + db.CorrectCasing(courseName) + "' , '" + abbrv.ToUpper() + "' , 'Active' , " + userid + ")"; updateQueries.Add(query); } } } if (updateQueries.Count > 0) { if (DialogResult.Yes == MessageBox.Show("Are you sure you want to save the following items. ", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { if (db.RunTransaction(updateQueries)) { MessageBox.Show("Selected records updated successfully. ", "Update Record", MessageBoxButtons.OK, MessageBoxIcon.Information); gridCourse.DataSource = null; PopulateCourse(); } } else { PopulateCourse(); } } DateTime dateValue = DateTime.Now; }
private void btnDelete_Click(object sender, EventArgs e) { //if (selectedindex == 0)return; string id = ViewCourse.GetRowCellValue(selectedindex, "CourseID").ToString(); if (DialogResult.Yes == MessageBox.Show("Are you sure, you want to delete the selected item ? ", "Deleted", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { string delete = "UPDATE tblcourse SET IsActive = 'In-Active' WHERE CourseID = " + id; int result = db.RunUpdateQuery(delete); if (result > 0) { MessageBox.Show("Course was deleted."); PopulateCourse(); } } }
public bool InputValidation(string cons) { for (int i = 0; i < ViewCourse.RowCount; i++) { if (ViewCourse.GetRowCellValue(i, "IsEdited").ToString().Equals("2")) { string coursename = ViewCourse.GetRowCellValue(i, "CourseName").ToString(); string abbrv = ViewCourse.GetRowCellValue(i, "Abbrv").ToString(); string query = "SELECT * FROM tblcourse WHERE CourseName = '" + coursename + "' AND Abbrv = '" + abbrv + "' AND UserID = " + userid + "" + cons; DataTable dt = db.SelectQuery(query); if (dt.Rows.Count != 0) { MessageBox.Show("Duplicate Course Name!!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Warning); PopulateCourse(); return(false); } } } return(true); }
private void ViewCourse_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e) { try { if (ViewCourse.GetRowCellValue(e.RowHandle, "IsEdited") == null) { return; } else if (ViewCourse.GetRowCellValue(e.RowHandle, "IsEdited").ToString().Equals("1")) { e.Appearance.BackColor = Color.Aqua; } else if (ViewCourse.GetRowCellValue(e.RowHandle, "IsEdited").ToString().Equals("2")) { e.Appearance.BackColor = Color.Beige; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }