/// <summary> /// Add new task. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AddTaskEventHanlder(object sender, EventArgs e) { DbCommunicator db = DbCommunicator.CreateInstance(_connectionString); try { log.Info("Adding new task"); // Fields validation in add task form. bool validationStatus = FieldValidation(); if (true == validationStatus) { log.Info("Successful validation"); db.OpenConnection(); int isReminder = (true == radioYes.Checked) ? 1 : 0; string query = String.Format(DBQuery.INSERT_TASK, txtTitle.Text, txtItemDesc.Text, DateTime.Parse(clderStartTime.Text).ToString("yyyy-MM-dd HH:mm:ss"), DateTime.Parse(cldrEndTime.Text).ToString("yyyy-MM-dd HH:mm:ss"), cmbStatus.SelectedItem, isReminder, txtNotificationTime.Text, _name ); log.Info("Query to add new task is : " + query); int numberOfRows = db.ExecuteNonQuery(query); if (0 < numberOfRows) { log.Info("New task added successfully with title " + txtTitle.Text); MessageBox.Show("Task added successfully. You will be notified " + txtNotificationTime.Text + " min(s) before the task", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); UpdateGridDataEvent(); } else { log.Info("Failed to add new task."); MessageBox.Show("Failed to add todo task record in database.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { return; } } catch (Exception ex) { log.Error("Exception message is : " + ex.Message); MessageBox.Show("Failed to add todo task record in database.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (null != db) { db.CloseConnection(); } } }
/// <summary> /// Update task event handler /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdateTaskEventHanlder(object sender, EventArgs e) { DbCommunicator db = DbCommunicator.CreateInstance(_connectionString); try { log.Info("Updating task "); // Fields validation in add task form. bool validationStatus = FieldValidation(); if (true == validationStatus) { db.OpenConnection(); int isReminder = (true == radioYes.Checked) ? 1 : 0; string query = String.Format(DBQuery.UPDATE_TASK, txtTitle.Text, txtItemDesc.Text, clderStartTime.Text, cldrEndTime.Text, cmbStatus.SelectedItem, isReminder, txtNotificationTime.Text, _taskId); log.Info("Query to update task is : " + query); int numberOfRows = db.ExecuteNonQuery(query); if (0 < numberOfRows) { MessageBox.Show("Task updated successfully. You will be notified " + txtNotificationTime.Text + " min(s) before the task", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); log.Info("Task updated successfully."); // Fire event to upgrade grid data. UpdateGridDataEvent(); } else { log.Info("Failed to update task."); MessageBox.Show("Failed to update todo task record in database.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else { return; } } catch (Exception ex) { MessageBox.Show("Failed to update todo task record in database.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); log.Info("Exception message is : " + ex.Message); } finally { if (null != db) { db.CloseConnection(); } } }
/// <summary> /// click event handler for register button. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnRegister_Click(object sender, EventArgs e) { DbCommunicator db = DbCommunicator.CreateInstance(_connectionString); try { log.Info("Clicked on Register button on New User form."); //Validate Field on Add user form. bool isValid = FieldsValidator(); if (true == isValid) { db.OpenConnection(); string query = String.Format(DBQuery.INSERT_USER, txtNewUsername.Text, txtNewPassword.Text, txtEmail.Text); int numberofRows = db.ExecuteNonQuery(query); if (0 < numberofRows) { log.Info("New user added successfully."); MessageBox.Show(txtNewUsername.Text + " user added successfully.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { log.Error("Failed to add new user"); MessageBox.Show("Failed to insert new user", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { return; } } catch (Exception ex) { MessageBox.Show("Someting went wrong...", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); log.Error("Exception message is : " + ex.Message); } finally { if (null != db) { db.CloseConnection(); } } }