예제 #1
0
 private void AddButton_Click(object sender, EventArgs e)
 {
     for (int j = 0; j < ProjectDataGrid.RowCount; j++)
     {
         if (ProjectDataGrid.Rows[j].Cells[ProjectDataGrid.Columns["Select"].Index].Value == null)
         {
             ProjectDataGrid.Rows[j].Cells[ProjectDataGrid.Columns["Select"].Index].Value = false;
         }
     }
     try
     {
         List <int> idi = new List <int>();
         for (int i = 0; i < ProjectDataGrid.RowCount; i++)
         {
             if ((bool)ProjectDataGrid.Rows[i].Cells[ProjectDataGrid.Columns["Select"].Index].Value)
             {
                 idi.Add((int)ProjectDataGrid.Rows[i].Cells[ProjectDataGrid.Columns["Id"].Index].Value);
             }
         }
         foreach (int idk in idi)
         {
             String cmd = String.Format("INSERT INTO GroupProject(ProjectId, GroupId, AssignmentDate) VALUES({0}, {1}, GETDATE())", idk, id);
             DatabaseConnection.getInstance().exectuteQuery(cmd);
         }
         if (idi.Count == 0)
         {
             MessageBox.Show("Nothing was selected.");
         }
         else
         {
             par.Refresh();
             this.Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
        private void AddButton_Click(object sender, EventArgs e)
        {
            int        flag       = 0;
            int        obtainmark = 0;
            List <int> idi        = new List <int>();
            String     ids        = "-1";

            for (int j = 0; j < ProjectDataGrid.RowCount; j++)
            {
                if (ProjectDataGrid.Rows[j].Cells[ProjectDataGrid.Columns["Select"].Index].Value == null)
                {
                    ProjectDataGrid.Rows[j].Cells[ProjectDataGrid.Columns["Select"].Index].Value = false;
                }
            }
            for (int i = 0; i < ProjectDataGrid.RowCount; i++)
            {
                if ((bool)ProjectDataGrid.Rows[i].Cells[ProjectDataGrid.Columns["Select"].Index].Value)
                {
                    idi.Add((int)ProjectDataGrid.Rows[i].Cells[ProjectDataGrid.Columns["Id"].Index].Value);
                    ids = ids + ", " + ProjectDataGrid.Rows[i].Cells[ProjectDataGrid.Columns["Id"].Index].Value.ToString();
                }
            }
            if ((string.IsNullOrEmpty(OMTextBox.Text)))
            {
                flag++;
                obtainmark = 0;
            }
            else if (Regexp("^[0-9]{1,3}", OMTextBox, OMError, "Only valid numbers are allowed.", 3))
            {
                obtainmark = Convert.ToInt32(OMTextBox.Text);
                string cmd    = "SELECT COUNT(*) FROM Evaluation WHERE Id IN (" + ids + ") AND TotalMarks < " + OMTextBox.Text;
                var    reader = DatabaseConnection.getInstance().getData(cmd);
                while (reader.Read())
                {
                    if ((int)reader.GetValue(0) > 0)
                    {
                        flag--;
                        OMError.ForeColor = System.Drawing.Color.Red;
                        OMError.Text      = "Total marks is less than current obtained marks.";
                    }
                }
                flag++;
            }
            if (flag == 1)
            {
                try
                {
                    int    sum    = 0;
                    string cmd    = "SELECT SUM(TotalWeightage) FROM Evaluation JOIN GroupEvaluation ON EvaluationId = Id WHERE GroupId = " + id;
                    var    reader = DatabaseConnection.getInstance().getData(cmd);
                    while (reader.Read())
                    {
                        if (reader.GetValue(0) == null)
                        {
                            sum = (int)reader.GetValue(0) + sum;
                        }
                    }
                    foreach (int idk in idi)
                    {
                        cmd    = "SELECT TotalWeightage FROM Evaluation WHERE Id = " + idk;
                        reader = DatabaseConnection.getInstance().getData(cmd);
                        while (reader.Read())
                        {
                            sum = (int)reader.GetValue(0) + sum;
                            if (sum > 100)
                            {
                                MessageBox.Show("Total Weightage of evaluation/s exceeds 100%.\nCurrent evaluation not added.");
                                flag = 0;
                                break;
                            }
                        }
                    }
                    if (flag != 0)
                    {
                        foreach (int idk in idi)
                        {
                            DateTime s = EDDatePicker.Value;
                            cmd = String.Format("INSERT INTO GroupEvaluation(EvaluationId, GroupId, ObtainedMarks, EvaluationDate) VALUES({0}, {1}, {2}, '{3}')", idk, id, obtainmark, s.Month + "/" + s.Day + "/" + s.Year);
                            DatabaseConnection.getInstance().exectuteQuery(cmd);
                        }
                    }
                    if (idi.Count == 0)
                    {
                        MessageBox.Show("Nothing was selected.");
                    }
                    else if (flag != 0)
                    {
                        par.Refresh();
                        this.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }