コード例 #1
0
        private void SaveAllUpdatedList()
        {
            ViewStudents.CloseEditForm();
            ViewStudents.UpdateCurrentRow();
            List <string> updateQueries = new List <string>();


            for (int i = 0; i < ViewStudents.RowCount; i++)
            {
                if (ViewStudents.GetRowCellValue(i, "IsEdited").ToString().Equals("1"))
                {
                    long   courseID = Convert.ToInt64(ViewStudents.GetRowCellValue(i, "CourseID"));
                    string section1 = db.GetValue("SELECT * FROM tblcourse WHERE CourseID = " + courseID + " ", "Abbrv");
                    long   StudID   = Convert.ToInt64(ViewStudents.GetRowCellValue(i, "StudentID"));
                    string StudNum  = ViewStudents.GetRowCellValue(i, "StudNum").ToString();
                    string fname    = ViewStudents.GetRowCellValue(i, "FName").ToString();
                    string lname    = ViewStudents.GetRowCellValue(i, "LName").ToString();
                    string section  = ViewStudents.GetRowCellValue(i, "Section").ToString();
                    string status   = ViewStudents.GetRowCellValue(i, "Status").ToString();
                    string query    = "UPDATE attendance_db.tblstudent SET StudNum = " + StudNum + " , FName = '" + db.CorrectCasing(fname) + "' ,LName = '" + db.CorrectCasing(lname) + "', " +
                                      "Section = '" + section.ToUpper() + "' , Status = 'Active' , CourseID = " + courseID + "  WHERE StudentID = " + StudID + ";";
                    updateQueries.Add(query);
                }
                else if (ViewStudents.GetRowCellValue(i, "IsEdited").ToString().Equals("2"))
                {
                    if (InputValidation(""))
                    {
                        string StudNum  = ViewStudents.GetRowCellValue(i, "StudNum").ToString();
                        string fName    = ViewStudents.GetRowCellValue(i, "FName").ToString();
                        string lName    = ViewStudents.GetRowCellValue(i, "LName").ToString();
                        string section  = ViewStudents.GetRowCellValue(i, "Section").ToString();
                        long   courseID = Convert.ToInt64(ViewStudents.GetRowCellValue(i, "CourseID"));
                        string section1 = db.GetValue("SELECT * FROM tblcourse WHERE CourseID = " + courseID + " ", "Abbrv");
                        string query    = "INSERT INTO `attendance_db`.`tblstudent` (`StudNum`, `FName`, `LName`, `Section`, `Status`, `CourseID` , UserID) " +
                                          "VALUES ('" + StudNum + "', '" + db.CorrectCasing(fName) + "', '" + db.CorrectCasing(lName) + "', '" + section1 + section.ToUpper() + "', 'Active', " + courseID + " , " + 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);
                        grdStudents.DataSource = null;
                        PopulateStudent();
                    }
                }
                else
                {
                    PopulateStudent();
                }
            }
            DateTime dateValue = DateTime.Now;
        }
コード例 #2
0
 private void ViewStudents_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
 {
     if (!e.Column.FieldName.ToString().Equals("IsEdited"))
     {
         if (ViewStudents.GetRowCellValue(e.RowHandle, "StudentID").ToString().Equals(""))
         {
             ViewStudents.SetRowCellValue(e.RowHandle, "IsEdited", "2");
         }
         else
         {
             ViewStudents.SetRowCellValue(e.RowHandle, "IsEdited", "1");
         }
     }
 }
コード例 #3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string id = ViewStudents.GetRowCellValue(selectedIndex, "StudentID").ToString();

            if (DialogResult.Yes == MessageBox.Show("Are you sure, you want to delete the student? " + "\n" + "Note: All data of this student will also deleted.", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                string delete = "DELETE FROM tblstudent WHERE StudentID = " + id + " ;";
                int    result = db.RunUpdateQuery(delete);

                if (result > 0)
                {
                    MessageBox.Show("Students was deleted.");
                    PopulateStudent();
                }
            }
        }
コード例 #4
0
 public bool InputValidation(string cons)
 {
     for (int i = 0; i < ViewStudents.RowCount; i++)
     {
         if (ViewStudents.GetRowCellValue(i, "IsEdited").ToString().Equals("2"))
         {
             string    studNum1 = ViewStudents.GetRowCellValue(i, "StudNum").ToString();
             string    fname    = ViewStudents.GetRowCellValue(i, "FName").ToString();
             string    query    = "SELECT * FROM tblstudent WHERE StudNum = " + studNum1 + " AND UserID = " + userid + "" + cons;
             DataTable dt       = db.SelectQuery(query);
             if (dt.Rows.Count != 0)
             {
                 MessageBox.Show("Student already exist", "Duplicate",
                                 MessageBoxButtons.OK, MessageBoxIcon.Warning);
                 PopulateStudent();
                 return(false);
             }
         }
     }
     return(true);
 }
コード例 #5
0
 private void ViewStudents_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
 {
     try
     {
         if (ViewStudents.GetRowCellValue(e.RowHandle, "IsEdited") == null)
         {
             return;
         }
         else if (ViewStudents.GetRowCellValue(e.RowHandle, "IsEdited").ToString().Equals("1"))
         {
             e.Appearance.BackColor = Color.DeepSkyBlue;
         }
         else if (ViewStudents.GetRowCellValue(e.RowHandle, "IsEdited").ToString().Equals("2"))
         {
             e.Appearance.BackColor = Color.Beige;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }