コード例 #1
0
        /*!
         * \brief This handler handles the updating of the carrier information.
         * \details This handler runs an UPDATE command to change anything about the carrier information that the user wishes.
         * \param sender <b>object</b>
         * \param e <b>RoutedEventArgs</b>
         */

        private void carrierModify_Click(object sender, RoutedEventArgs e)
        {
            carrierParams temp = (carrierParams)carrierList.SelectedItem;

            admin_AddCarrier addCarrier = new admin_AddCarrier();

            addCarrier.ShowDialog();

            carrierParams carrier = new carrierParams {
                carrierName = addCarrier.ResponseTextCarrierName, cityName = addCarrier.ResponseTextCity, FTLRate = double.Parse(addCarrier.ResponseTextFTL), LTLRate = double.Parse(addCarrier.ResponseTextLTL), reefCharge = double.Parse(addCarrier.ResponseTextReefCharge)
            };

            // Connect to database
            string        conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder cmdSB  = new StringBuilder("UPDATE Carrier SET CarrierName='" + carrier.carrierName + "' WHERE CarrierName='" + temp.carrierName + ";  UPDATE CarrierCities SET FTLRate=" + carrier.FTLRate + ", LTLRate=" + carrier.LTLRate + ", reefCharge=" + carrier.reefCharge + " WHERE CarrierID IN (SELECT CarrierID FROM Carrier WHERE CarrierName=" + temp.carrierName + ");");

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            carrierList.DataContext = null;
            carrierList.Items.Clear();
            queryCarrier();
        }
コード例 #2
0
        /*!
         * \brief This handler handles the adding new carriers to the Omnicorp database.
         * \details This handler runs an UPDATE command to change anything about the carrier information that the user wishes.
         * \param sender <b>object</b>
         * \param e <b>RoutedEventArgs</b>
         */

        private void carrierAdd_Click(object sender, RoutedEventArgs e)
        {
            admin_AddCarrier addCarrier = new admin_AddCarrier();

            addCarrier.ShowDialog();

            carrierParams carrier = new carrierParams {
                carrierName = addCarrier.ResponseTextCarrierName, cityName = addCarrier.ResponseTextCity, FTLRate = double.Parse(addCarrier.ResponseTextFTL), LTLRate = double.Parse(addCarrier.ResponseTextLTL), reefCharge = double.Parse(addCarrier.ResponseTextReefCharge)
            };

            // Connect to database
            string        conStr = ConfigurationManager.ConnectionStrings[localUser.CONSTR].ConnectionString;
            StringBuilder cmdSB  = new StringBuilder("INSERT INTO Carrier(CarrierName) VALUES ('" + carrier.carrierName + "'); INSERT INTO CarrierCities (CityName, FTLRate, LTLRate, reefCharge) VALUES ('" + carrier.cityName + "', " + carrier.FTLRate + ", " + carrier.LTLRate + ", " + carrier.reefCharge + ");");

            using (MySqlConnection connection = new MySqlConnection(conStr))
            {
                MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(cmdSB.ToString(), connection);
                try
                {
                    connection.Open();
                    cmd.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }

            carrierList.DataContext = null;
            carrierList.Items.Clear();
            queryCarrier();
        }