Esempio n. 1
0
        public static int InsertReservation(ReservationsCS sr)
        {
            //declare return variable
            int new_id = 0;
            //connection object -> ConfigurationManager namespace
            //access to web.config -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_CorwinConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("reservations_insert", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@new_id", SqlDbType.Int).Direction = ParameterDirection.Output;
            cmd.Parameters.Add(
                "@guest_id", SqlDbType.Int).Value = sr.Guest_Id;
            cmd.Parameters.Add(
                "@tbl_id", SqlDbType.Int).Value = sr.Table_Id;
            cmd.Parameters.Add(
                "@user_id", SqlDbType.Int).Value = sr.User_Id;
            cmd.Parameters.Add(
                "@res_date", SqlDbType.Date).Value = sr.Res_Date;
            cmd.Parameters.Add(
                "@res_time", SqlDbType.Time).Value = sr.Res_Time;
            cmd.Parameters.Add(
                "@res_guest_cnt", SqlDbType.Int).Value = sr.Res_Guest_Cnt;
            cmd.Parameters.Add(
                "@res_spec_req", SqlDbType.VarChar).Value = sr.Res_Sp_Req;

            // Open database connection -> execute command
            try
            {
                cn.Open();
                //execute -> stored procedure
                cmd.ExecuteNonQuery();
                new_id = Convert.ToInt32(cmd.Parameters["@new_id"].Value);
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
            }
            finally
            {
                cn.Close();
            }
            return(new_id);
        }
Esempio n. 2
0
        public static bool UpdateReservation(ReservationsCS sr)
        {
            //declare return variable
            bool blnSuccess = false;
            //connection object -> ConfigurationManager namespace
            //access web.config setting -> connection strings & key values
            SqlConnection cn = new SqlConnection(
                ConfigurationManager.ConnectionStrings["SE256_CorwinConnectionString"].ConnectionString);
            SqlCommand cmd = new SqlCommand("reservations_update", cn);

            // Mark the Command -> Stored Procedure
            cmd.CommandType = CommandType.StoredProcedure;

            // Add Parameters -> Stored Procedure
            cmd.Parameters.Add(
                "@res_id", SqlDbType.Int).Value = sr.Res_Id;
            cmd.Parameters.Add(
                "@guest_id", SqlDbType.Int).Value = sr.Guest_Id;
            cmd.Parameters.Add(
                "@tbl_id", SqlDbType.Int).Value = sr.Table_Id;
            cmd.Parameters.Add(
                "@user_id", SqlDbType.Int).Value = sr.User_Id;
            cmd.Parameters.Add(
                "@res_date", SqlDbType.Date).Value = sr.Res_Date;
            cmd.Parameters.Add(
                "@res_time", SqlDbType.Time).Value = sr.Res_Time;
            cmd.Parameters.Add(
                "@res_guest_cnt", SqlDbType.Int).Value = sr.Res_Guest_Cnt;
            cmd.Parameters.Add(
                "@res_spec_req", SqlDbType.VarChar).Value = sr.Res_Sp_Req;
            // Open database connection -> execute command
            try
            {
                cn.Open();
                cmd.ExecuteNonQuery();
                blnSuccess = true;
            }
            catch (Exception exc)
            {
                //error -> notify user
                exc.ToString();
                blnSuccess = false;
            }
            finally
            {
                cn.Close();
            }
            return(blnSuccess);
        }