예제 #1
0
 private void ClearFields()
 {
     addNew                  = true;
     UserIdLabel.Text        = "";
     CreateDate.Text         = DateTime.Now.ToString();
     LastModified.Text       = DateTime.Now.ToString();
     comboBox1.SelectedIndex = GetImportance.FromString("Moderate");
     descriptions.Text       = "";
     button1.Text            = "Add New";
 }
예제 #2
0
 private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     try
     {
         addNew                  = false;
         UserIdLabel.Text        = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
         CreateDate.Text         = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
         LastModified.Text       = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
         comboBox1.SelectedIndex = GetImportance.FromString(dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString());
         descriptions.Text       = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
         button1.Text            = "Update";
     }
     catch (ArgumentOutOfRangeException)
     {
     }
 }
예제 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (addNew)
     {
         // add new event
         DialogResult dr;
         dr = MessageBox.Show("Do you really want to add new Event?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (dr == DialogResult.Yes)
         {
             if (AddEvent(descriptions.Text, GetImportance.FromString(comboBox1.SelectedItem.ToString())) == 1)
             {
                 //success
                 dataGridView1.DataSource = GetAllEvents(UserId);
                 ClearFields();
                 MessageBox.Show("Successfully Added Event", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             else
             {
                 //failed
                 MessageBox.Show("Failed to Add Event", "Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         //update event
         DialogResult dr;
         dr = MessageBox.Show("Do you really want to update the Event?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
         if (dr == DialogResult.Yes)
         {
             if (UpdateEvent(Convert.ToInt32(UserIdLabel.Text), CreateDate.Text, descriptions.Text, GetImportance.FromString(comboBox1.Text)) == 1)
             {
                 //success
                 dataGridView1.DataSource = GetAllEvents(UserId);
                 ClearFields();
                 MessageBox.Show("Successfully updated user", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             else
             {
                 //failed
                 MessageBox.Show("Failed to update", "Something went wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
예제 #4
0
 private List <Events> GetAllEvents(int id)
 {
     using (var database = new DatabaseConnection())
     {
         List <Events> events = new List <Events>();
         string        sql    = "SELECT * FROM EventsList WHERE UserId=" + id;
         using (var reader = database.GetSqlData(sql))
         {
             while (reader.Read())
             {
                 events.Add(new Events()
                 {
                     Id              = Convert.ToInt32(reader["Id"]),
                     UserId          = Convert.ToInt32(reader["UserId"]),
                     CreateDate      = DateTime.Parse(reader["CreateDate"].ToString()),
                     LastModified    = DateTime.Parse(reader["LastModified"].ToString()),
                     Description     = reader["Description"].ToString(),
                     EventImportance = GetImportance.FromInt(Convert.ToInt32(reader["Importance"]))
                 });
             }
         }
         return(events);
     }
 }