Esempio n. 1
0
        private void customerCreateButton_Click(object sender, EventArgs e)
        {
            string timestamp = SqlUpdater.createTimestamp();
            string userName  = SqlUpdater.getCurrentUserName();

            if (string.IsNullOrEmpty(customerNameText.Text) ||
                string.IsNullOrEmpty(customerPhoneText.Text) ||
                string.IsNullOrEmpty(customerCityText.Text) ||
                string.IsNullOrEmpty(customerCountryText.Text) ||
                string.IsNullOrEmpty(customerZipText.Text) ||
                string.IsNullOrEmpty(customerAddressText.Text) ||
                (activeYes.Checked == false && activeNo.Checked == false))
            {
                MessageBox.Show("Please complete all fields");
            }
            else
            {
                int countryId = SqlUpdater.createRecord(timestamp, userName, "country", $"'{customerCountryText.Text}'");
                int cityId    = SqlUpdater.createRecord(timestamp, userName, "city", $"'{customerCityText.Text}', '{countryId}'");
                int addressId = SqlUpdater.createRecord(timestamp, userName, "address", $"'{customerAddressText.Text}', '', '{cityId}', '{customerZipText.Text}', '{customerPhoneText.Text}'");
                SqlUpdater.createRecord(timestamp, userName, "customer", $"'{ customerNameText.Text}', '{addressId}', '{(activeYes.Checked ? 1 : 0)}'");

                Close();
            }
        }
Esempio n. 2
0
        public static void writeUserLoginLog(int userId)
        {
            string path = "log.text";
            string log  = $"User with ID {userId} logged in at {SqlUpdater.createTimestamp()}" + Environment.NewLine;

            File.AppendAllText(path, log);
        }
Esempio n. 3
0
        public bool updateCustomer(Dictionary <string, string> updatedForm)
        {
            MySqlConnection c = new MySqlConnection(SqlUpdater.conString);

            c.Open();

            //Customer table
            string recUpdate = $"UPDATE customer" +
                               $" SET customerName = '{updatedForm["customerName"]}', active = '{updatedForm["active"]}', lastUpdate = '{SqlUpdater.createTimestamp()}', lastUpdateBy = '{SqlUpdater.getCurrentUserName()}'" +
                               $" WHERE customerName = '{cForm["customerName"]}'";
            MySqlCommand cmd             = new MySqlCommand(recUpdate, c);
            int          customerUpdated = cmd.ExecuteNonQuery();

            //Address table
            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, c);
            int addressUpdated = cmd.ExecuteNonQuery();



            //City Table
            recUpdate = $"UPDATE city" +
                        $" SET city = '{updatedForm["city"]}', lastUpdate = '{SqlUpdater.createTimestamp()}', lastUpdateBy = '{SqlUpdater.getCurrentUserName()}'" +
                        $" WHERE city = '{cForm["city"]}'";
            cmd = new MySqlCommand(recUpdate, c);
            int cityUpdated = cmd.ExecuteNonQuery();

            //Country Table
            recUpdate = $"UPDATE country" +
                        $" SET country = '{updatedForm["country"]}', lastUpdate = '{SqlUpdater.createTimestamp()}', lastUpdateBy = '{SqlUpdater.getCurrentUserName()}'" +
                        $" WHERE country = '{cForm["country"]}'";
            cmd = new MySqlCommand(recUpdate, c);
            int countryUpdated = cmd.ExecuteNonQuery();

            c.Close();

            if (customerUpdated != 0 && addressUpdated != 0 && cityUpdated != 0 && countryUpdated != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
0
        private void addButton_Click(object sender, EventArgs e)
        {
            string   timestamp = SqlUpdater.createTimestamp();
            int      userId    = SqlUpdater.getCurrentUserID();
            string   username  = SqlUpdater.getCurrentUserName();
            DateTime startTime = startTimeBox.Value.ToUniversalTime();
            DateTime endTime   = endTimeBox.Value.ToUniversalTime();


            try
            {
                if (appHasConflict(startTime, endTime))
                {
                    throw new appointmentException();
                }
                else
                {
                    try
                    {
                        if (outsideBusinessHours(startTime, endTime))
                        {
                            throw new appointmentException();
                        }
                        else
                        {
                            SqlUpdater.createRecord(timestamp, username, "appointment", $"'{customerIdBox.Text}', '{startTimeBox.Value.ToUniversalTime().ToString("u")}', '{endTimeBox.Value.ToUniversalTime().ToString("u")}', '{typeBox.Text}'", userId);
                            mainFormObject.updateCalendar();


                            Close();
                        }
                    }
                    catch (appointmentException ex) { ex.businessHours(); }
                }
            }
            catch (appointmentException ex) { ex.appOverlap(); }
        }
Esempio n. 5
0
        public bool updateAppointment(Dictionary <string, string> updatedForm)
        {
            MySqlConnection c = new MySqlConnection(SqlUpdater.conString);

            c.Open();


            string recUpdate = $"UPDATE appointment" +
                               $" SET customerId = '{updatedForm["customerId"]}', start = '{updatedForm["start"]}', end = '{updatedForm["end"]}', type = '{updatedForm["type"]}', lastUpdate = '{SqlUpdater.createTimestamp()}', lastUpdateBy = '{SqlUpdater.getCurrentUserName()}'" +
                               $" WHERE appointmentId = '{aForm["appointmentId"]}'";
            MySqlCommand cmd = new MySqlCommand(recUpdate, c);
            int          appointmentUpdated = cmd.ExecuteNonQuery();

            c.Close();

            if (appointmentUpdated != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }