コード例 #1
0
        public UpdateAppointmentForm(AppointmentModel model)
        {
            InitializeComponent();

            RefreshUpdateAppointmentCustomerNameComboBox();

            //For each interface IDataConnection in the "list" of connections
            //(stored in the GlobalConfig class),
            //implement the contract's methods as alias db
            foreach (IDataConnection db in GlobalConfig.Connections)
            {
                db.QueryAppointmentInfo(model);
            }

            updateAppointmentIdTextBox.Text = Convert.ToString(model.AppointmentId);
            AddCustomerIdToCustomerIdTextBox();
            model.CustomerId = Convert.ToInt32(updateAppointmentCustomerIdTextBox.Text);
            updateAppointmentCustomerNameComboBox.Text     = model.CustomerName;
            updateAppointmentTypeTextBox.Text              = model.AppointmentType;
            updateAppointmentStartDateDateTimePicker.Value = model.StartTime.ToLocalTime();
            updateAppointmentStartTimeDateTimePicker.Value = model.StartTime.ToLocalTime();
            updateAppointmentEndDateDateTimePicker.Value   = model.EndTime.ToLocalTime();
            updateAppointmentEndTimeDateTimePicker.Value   = model.EndTime.ToLocalTime();

            updateAppointmentSaveBtn.Enabled = AllowSave();
        }
コード例 #2
0
 private void appointmentUpdateBtn_Click(object sender, EventArgs e)
 {
     if (this.appointmentDgv.CurrentRow != null)
     {
         this.Hide();
         AppointmentModel model = new AppointmentModel();
         model.AppointmentId = Convert.ToInt32(this.appointmentDgv.CurrentRow.Cells[0].Value.ToString());
         new UpdateAppointmentForm(model).ShowDialog();
     }
 }
 public int DeleteThisAppointment(AppointmentModel model)
 {
     //For each interface IDataConnection in the "list" of connections
     //(stored in the GlobalConfig class),
     //implement the contract's methods as alias db
     foreach (IDataConnection db in GlobalConfig.Connections)
     {
         db.DeleteAppointment(model);
     }
     return(0);
 }
コード例 #4
0
 private void appointmentDeleteBtn_Click(object sender, EventArgs e)
 {
     if (this.appointmentDgv.CurrentRow != null)
     {
         AppointmentModel model = new AppointmentModel();
         model.AppointmentId = Convert.ToInt32(this.appointmentDgv.CurrentRow.Cells[0].Value.ToString());
         DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this appointment?", "Delete appointment", MessageBoxButtons.YesNo);
         if (dialogResult == DialogResult.Yes)
         {
             this.Hide();
             new DeleteAppointment(model);
         }
     }
 }
コード例 #5
0
        private void updateAppointmentSaveBtn_Click(object sender, EventArgs e)
        {
            try
            {
                ValidateAppointment(StartDateTime, EndDateTime);

                //Constructor for updating an appointment
                AppointmentModel model = new AppointmentModel(

                    updateAppointmentCustomerNameComboBox.Text,
                    int.Parse(updateAppointmentCustomerIdTextBox.Text),
                    int.Parse(updateAppointmentIdTextBox.Text),
                    updateAppointmentTypeTextBox.Text,
                    StartDateTime.ToUniversalTime(),
                    EndDateTime.ToUniversalTime());


                //For each interface IDataConnection in the "list" of connections
                //(stored in the GlobalConfig class),
                //implement the contract's methods as alias db
                foreach (IDataConnection db in GlobalConfig.Connections)
                {
                    db.UpdateAppointment(model);
                }
                //Clears the text boxes once the appointment was added to the database
                updateAppointmentTypeTextBox.Text = "";


                MessageBox.Show("The appointment was successfully updated.");
            }
            catch (AppointmentOutsideBusinessHrsException aobhe)
            {
                MessageBox.Show(aobhe.Message);
            }
            catch (ConflictingAppointmentException cae)
            {
                MessageBox.Show(cae.Message);
            }
            catch (Exception ex)
            {
            }
            finally
            {
                this.Hide();
                MainForm mainForm = new MainForm();
                mainForm.Show();
            }
        }
コード例 #6
0
        /// <summary>
        /// Updates an appointment and writes record to the mySqlDatabase
        /// </summary>
        /// <param name="model"> The appointment's information </param>
        /// <returns> Returns the appointment information and updates the record in the database </returns>
        public AppointmentModel UpdateAppointment(AppointmentModel model)
        {
            string user = DataBaseHandler.GetCurrentUserName();

            //Updates appointment record
            using (MySqlConnection con = new MySqlConnection(GlobalConfig.CS))
            {
                con.Open();
                MySqlTransaction transaction = con.BeginTransaction();
                var          query           = $"UPDATE appointment SET customerId = '{model.CustomerId}', appointmentId = '{model.AppointmentId}', type = '{model.AppointmentType}', start = STR_TO_DATE('{model.StartTime}', '%m/%d/%Y %h:%i:%s %p'), end = STR_TO_DATE('{model.EndTime}', '%m/%d/%Y %h:%i:%s %p'), lastUpdate = CURRENT_TIMESTAMP, lastUpdateBy = '{user}' WHERE appointmentId = '{model.AppointmentId}'";
                MySqlCommand cmd             = new MySqlCommand(query, con);
                cmd.Transaction = transaction;
                cmd.ExecuteNonQuery();
                transaction.Commit();
                con.Close();
            }
            return(model);
        }
コード例 #7
0
        /// <summary>
        /// Deletes an appointment record from the mySqlDatabase
        /// </summary>
        /// <param name="model"> The appointment's information </param>
        /// <returns> Returns the appointment information and deletes the record from the database </returns>
        public AppointmentModel DeleteAppointment(AppointmentModel model)
        {
            //Deletes an appointment record
            using (MySqlConnection con = new MySqlConnection(GlobalConfig.CS))
            {
                con.Open();
                MySqlTransaction transaction = con.BeginTransaction();
                var          query           = $"DELETE FROM appointment WHERE appointmentId = '{model.AppointmentId}'";
                MySqlCommand cmd             = new MySqlCommand(query, con);
                cmd.Transaction = transaction;
                cmd.ExecuteNonQuery();
                transaction.Commit();
                con.Close();
            }
            MainForm mainForm = new MainForm();

            mainForm.Show();
            return(model);
        }
コード例 #8
0
        /// <summary>
        /// Saves a new appointment record to the database from
        /// values entered into text boxes on add appointment form.
        /// </summary>
        /// <param name="model"> The appointment information </param>
        /// <returns> The appointment information, including the unique identifier </returns>
        public AppointmentModel CreateAppointment(AppointmentModel model)
        {
            //Method-wide variable to set the active user
            string user   = DataBaseHandler.GetCurrentUserName();
            int    userId = DataBaseHandler.GetCurrentUserId();

            //Creates new appointment record
            using (MySqlConnection con = new MySqlConnection(GlobalConfig.CS))
            {
                con.Open();
                MySqlTransaction transaction = con.BeginTransaction();
                var query = "INSERT into appointment (customerId, userId, title, description, location, contact, type, url, start, end, createDate, createdBy, lastUpdate, lastUpdateBy) " +
                            $"VALUES ('{model.CustomerId}', '{userId}', 'not needed', 'not needed', 'not needed', 'not needed', '{model.AppointmentType}', 'not needed', STR_TO_DATE('{model.StartTime}', '%m/%d/%Y %h:%i:%s %p'), STR_TO_DATE('{model.EndTime}', '%m/%d/%Y %h:%i:%s %p'), CURRENT_DATE, '{user}', CURRENT_TIMESTAMP, '{user}')";
                MySqlCommand cmd = new MySqlCommand(query, con);
                cmd.Transaction = transaction;
                cmd.ExecuteNonQuery();
                transaction.Commit();
                con.Close();
            }
            //Dummy initialization value for model.AppointmentId (AppointmentModel object)
            model.AppointmentId = 1;
            //Returns the AppointmentModel object entered into database
            return(model);
        }
 //Included to satisfy contract terms
 public AppointmentModel DeleteAppointment(AppointmentModel model)
 {
     throw new NotImplementedException();
 }
 //Included to satisfy contract terms
 public AppointmentModel QueryAppointmentInfo(AppointmentModel model)
 {
     throw new NotImplementedException();
 }