Ejemplo n.º 1
0
        /// <summary>
        /// Adds an adress to the database. Needs to be supplied with a customer ID.
        /// </summary>
        public int AddAdressToDatabase(Adresses adress, int thisCustomerID, SqlConnection connection)
        {
            SqlConnection myConnection = connection;

            int tID = 0;

            try
            {
                myConnection.Open();

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection  = myConnection;
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.CommandText = "spAddAdress";


                SqlParameter paramCity   = new SqlParameter("@City", SqlDbType.VarChar);
                SqlParameter paramPostal = new SqlParameter("@Postal", SqlDbType.VarChar);
                SqlParameter paramID     = new SqlParameter("@NewIDA", SqlDbType.Int);
                SqlParameter paramStreet = new SqlParameter("@Street", SqlDbType.VarChar);

                paramID.Direction = ParameterDirection.Output;

                paramStreet.Value = adress.Street;
                paramCity.Value   = adress.City;
                paramPostal.Value = adress.Postal;

                myCommand.Parameters.Add(paramStreet);
                myCommand.Parameters.Add(paramCity);
                myCommand.Parameters.Add(paramPostal);
                myCommand.Parameters.Add(paramID);


                myCommand.ExecuteNonQuery();

                tID = (int)paramID.Value;

                myCommand             = new SqlCommand();
                myCommand.Connection  = connection;
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.CommandText = "spConnectAIDtoCID";

                SqlParameter paramCID = new SqlParameter("@CID", SqlDbType.Int);
                SqlParameter paramAID = new SqlParameter("@AID", SqlDbType.Int);

                paramCID.Value = thisCustomerID;
                paramAID.Value = tID;

                myCommand.Parameters.Add(paramCID);
                myCommand.Parameters.Add(paramAID);
                myCommand.ExecuteNonQuery();
            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { myConnection.Close(); }


            return(tID);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds an adress to the database. Needs to be supplied with a customer ID.
        /// </summary>
        public int AddAdressToDatabase(Adresses adress, int thisCustomerID, SqlConnection connection)
        {
            SqlConnection myConnection = connection;

            int tID = 0;

            try
            {

                myConnection.Open();

                SqlCommand myCommand = new SqlCommand();
                myCommand.Connection = myConnection;
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.CommandText = "spAddAdress";

                SqlParameter paramCity = new SqlParameter("@City", SqlDbType.VarChar);
                SqlParameter paramPostal = new SqlParameter("@Postal", SqlDbType.VarChar);
                SqlParameter paramID = new SqlParameter("@NewIDA", SqlDbType.Int);
                SqlParameter paramStreet = new SqlParameter("@Street", SqlDbType.VarChar);

                paramID.Direction = ParameterDirection.Output;

                paramStreet.Value = adress.Street;
                paramCity.Value = adress.City;
                paramPostal.Value = adress.Postal;

                myCommand.Parameters.Add(paramStreet);
                myCommand.Parameters.Add(paramCity);
                myCommand.Parameters.Add(paramPostal);
                myCommand.Parameters.Add(paramID);

                myCommand.ExecuteNonQuery();

                tID = (int)paramID.Value;

                myCommand = new SqlCommand();
                myCommand.Connection = connection;
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.CommandText = "spConnectAIDtoCID";

                SqlParameter paramCID = new SqlParameter("@CID", SqlDbType.Int);
                SqlParameter paramAID = new SqlParameter("@AID", SqlDbType.Int);

                paramCID.Value = thisCustomerID;
                paramAID.Value = tID;

                myCommand.Parameters.Add(paramCID);
                myCommand.Parameters.Add(paramAID);
                myCommand.ExecuteNonQuery();

            }
            catch (Exception e) { Console.WriteLine(e.Message); }
            finally { myConnection.Close(); }

            return tID;
        }
Ejemplo n.º 3
0
        protected void bAddAdress_Click(object sender, EventArgs e)
        {
            int thisID = -1;
            string thisSSN = contactGrid.SelectedRow.Cells[4].Text;
            Console.WriteLine("SNN is: " + thisSSN);
            thisID = sql.GetCustomerID(thisSSN, contactConnection);

            if (thisID == -1)
                throw new Exception("ID is empty");

            Adresses thisAdress = new Adresses(txStreet.Text, txCity.Text, "");
            sql.AddAdressToDatabase(thisAdress, thisID, contactConnection);

            adressGrid.DataBind();
        }