Beispiel #1
0
        /// <summary>
        /// Fill grid
        /// </summary>
        private void FillGrid()
        {
            DbCommunicator db = DbCommunicator.CreateInstance(_connectionString);

            try
            {
                log.Info("Get data to fill grid");
                db.OpenConnection();
                dataSet.Clear();
                dataSet = db.ExecuteQuery(DBQuery.GET_TASK_DATA, "task");
                dataGridView.DataSource = dataSet.Tables["task"];
            }
            catch (Exception ex)
            {
                log.Error("Exception message is : " + ex.Message);
                throw ex;
            }
            finally
            {
                if (null != db)
                {
                    db.CloseConnection();
                }
            }
        }
Beispiel #2
0
        /// <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();
                }
            }
        }
Beispiel #3
0
        /// <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();
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Check login status
        /// </summary>
        public void Login()
        {
            DbCommunicator db = DbCommunicator.CreateInstance(_connectionString);

            try
            {
                log.Info("Checking login for user.");
                db.OpenConnection();
                string query        = String.Format(DBQuery.GET_USER_COUNT, txtUserName.Text, txtPassword.Text);
                int    numberOfRows = db.ExecuteScalar(query);
                if (0 < numberOfRows)
                {
                    log.Info("Successful login for user" + txtUserName.Text);
                    // On login success open form main.
                    LoginSuccessEvent();
                }
                else
                {
                    log.Error("Login failed for " + txtUserName.Text);
                    MessageBox.Show("Invalid credentails. \nPlease check username/password.",
                                    this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Something went wrong",
                                this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                log.Error("Exception message is : " + ex.Message);
                Application.Exit();
            }
            finally {
                if (null != db)
                {
                    db.CloseConnection();
                }
            }
        }