예제 #1
0
        private void createButton_Click(object sender, EventArgs e)
        {
            string timestamp = SqlUpdater.CreateTimestamp();
            string userName  = SqlUpdater.GetCurrentUserName();

            if (string.IsNullOrEmpty(nameTextBox.Text) ||
                string.IsNullOrEmpty(phoneNumberTextBox.Text) ||
                string.IsNullOrEmpty(cityTextBox.Text) ||
                string.IsNullOrEmpty(countryTextBox.Text) ||
                string.IsNullOrEmpty(zipCodeTextBox.Text) ||
                string.IsNullOrEmpty(addressTextBox.Text))
            {
                MessageBox.Show("Please complete all fields");
            }
            else
            {
                int countryId = SqlUpdater.CreateRecord(timestamp, userName, "country", $"'{countryTextBox.Text}'");
                int cityId    = SqlUpdater.CreateRecord(timestamp, userName, "city", $"'{cityTextBox.Text}', '{countryId}'");
                int addressId = SqlUpdater.CreateRecord(timestamp, userName, "address", $"'{addressTextBox.Text}', '', '{cityId}', '{zipCodeTextBox.Text}', '{phoneNumberTextBox.Text}'");
                SqlUpdater.CreateRecord(timestamp, userName, "customer", $"'{ nameTextBox.Text}', '{addressId}', '{(activeRadio.Checked ? 1 : 0)}'");

                MessageBox.Show("Customer created.");
                Close();
            }
        }
예제 #2
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            string   timestamp     = SqlUpdater.CreateTimestamp();
            int      userId        = SqlUpdater.GetCurrentUserID();
            string   username      = SqlUpdater.GetCurrentUserName();
            int      appointmentId = Convert.ToInt32(searchTextBox.Text);
            int      customerId    = Convert.ToInt32(customerIDTextBox.Text);
            string   type          = typeTextBox.Text;
            DateTime startTime     = DateTime.Parse(startTextBox.Text).ToUniversalTime();
            DateTime endTime       = DateTime.Parse(endTextBox.Text).ToUniversalTime();
            string   st            = DateTime.Parse(startTextBox.Text).ToUniversalTime().ToString("u");
            string   et            = DateTime.Parse(endTextBox.Text).ToUniversalTime().ToString("u");

            bool pass = Validator();

            if (pass)
            {
                try
                {
                    if (AppHasConflict(startTime, endTime))
                    {
                        throw new AppointmentExceptions();
                    }
                    else
                    {
                        try
                        {
                            if (OutsideBusinessHours(startTime, endTime))
                            {
                                throw new AppointmentExceptions();
                            }
                            else
                            {
                                SqlUpdater.UpdateAppt(customerId, userId, st, et, type, timestamp, username, appointmentId);

                                mainFormObject.UpdateCalendar();
                                MessageBox.Show("Update Successful!");
                                Close();
                            }
                        } catch (AppointmentExceptions ex) { ex.BusinessHours(); }
                    }
                } catch (AppointmentExceptions ex) { ex.ApptOverlap(); }
            }
            else
            {
                MessageBox.Show("Add Appointment Error!");
            }
        }
예제 #3
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string   timestamp = SqlUpdater.CreateTimestamp();
            int      userId    = SqlUpdater.GetCurrentUserID();
            string   username  = SqlUpdater.GetCurrentUserName();
            DateTime startTime = DateTime.Parse(startTextBox.Text).ToUniversalTime();
            DateTime endTime   = DateTime.Parse(endTextBox.Text).ToUniversalTime();

            bool pass = Validator();

            if (pass)
            {
                try
                {
                    if (AppHasConflict(startTime, endTime))
                    {
                        throw new AppointmentExceptions();
                    }
                    else
                    {
                        try
                        {
                            if (OutsideBusinessHours(startTime, endTime))
                            {
                                throw new AppointmentExceptions();
                            }
                            else
                            {
                                SqlUpdater.CreateRecord(timestamp, username, "appointment", $"'{custIDTextBox.Text}', '{DateTime.Parse(startTextBox.Text).ToUniversalTime():u}', '{DateTime.Parse(endTextBox.Text).ToUniversalTime():u}', '{typeTextBox.Text}'", userId);
                                mainFormObject.UpdateCalendar();


                                Close();
                            }
                        }
                        catch (AppointmentExceptions ex) { ex.BusinessHours(); }
                    }
                }
                catch (AppointmentExceptions ex) { ex.ApptOverlap(); }
            }
예제 #4
0
        public bool UpdateCust(Dictionary <string, string> updatedForm)
        {
            MySqlConnection conn = new MySqlConnection(SqlUpdater.conString);

            conn.Open();

            /*string recUpdate = $"UPDATE customer" + $" SET customerName = '{updatedForm["customerName"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" +
             *  $" WHERE customerName = '{cForm["customerName"]}'";
             * MySqlCommand cmd = new MySqlCommand(recUpdate, conn);
             * int customerUpdated = cmd.ExecuteNonQuery();*/

            string recUpdate = $"UPDATE customer" +
                               $" SET customerName = '{updatedForm["customerName"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" +
                               $" WHERE customerName = '{cForm["customerName"]}'";
            MySqlCommand cmd             = new MySqlCommand(recUpdate, conn);
            int          customerUpdated = cmd.ExecuteNonQuery();

            recUpdate = $"UPDATE address" +
                        $" SET address = '{updatedForm["address"]}', postalCode = '{updatedForm["zip"]}', phone = '{updatedForm["phone"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" +
                        $" WHERE address = '{cForm["address"]}'";
            cmd = new MySqlCommand(recUpdate, conn);
            int addressUpdated = cmd.ExecuteNonQuery();

            recUpdate = $"UPDATE city" + $" SET city = '{updatedForm["city"]}, lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" +
                        $" WHERE city = '{cForm["city"]}'";
            cmd = new MySqlCommand(recUpdate, conn);
            int cityUpdated = cmd.ExecuteNonQuery();

            recUpdate = $"UPDATE country" + $" SET country = '{updatedForm["country"]}', lastUpdate = '{SqlUpdater.CreateTimestamp()}', lastUpdateBy = '{SqlUpdater.GetCurrentUserName()}'" +
                        $" WHERE country = '{cForm["country"]}'";
            cmd = new MySqlCommand(recUpdate, conn);
            int countryUpdated = cmd.ExecuteNonQuery();

            conn.Close();

            if (customerUpdated != 0 && addressUpdated != 0 && cityUpdated != 0 && countryUpdated != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }