Exemplo n.º 1
0
        /// <summary>
        /// Add a new entry to the DeliveryArea table
        /// </summary>
        public static DeliveryArea Add(string streetName, int startingAddress,
                                       int endingAddress, string addressPrefix, double?deliveryFee)
        {
            DeliveryArea result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddDeliveryArea";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@DeliveryAreaStreetName", SqlDbType.Text, streetName);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaRangeStart", SqlDbType.Int, startingAddress);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaRangeEnd", SqlDbType.Int, endingAddress);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaStreetAddressPrefix", SqlDbType.NChar, addressPrefix);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaFee", SqlDbType.Float, deliveryFee);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new DeliveryArea(Convert.ToInt32(sqlCmd.Parameters["@DeliveryAreaId"].Value),
                                              streetName, startingAddress, endingAddress, addressPrefix, deliveryFee);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update an entry in the DeliveryArea table
        /// </summary>
        public static bool Update(DeliveryArea deliveryArea)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, deliveryArea);
            FinishedWithConnection(cn);
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get an entry from the DeliveryArea table
        /// </summary>
        public static DeliveryArea Get(int id)
        {
            DeliveryArea result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);
            return(result);
        }
Exemplo n.º 4
0
        private static DeliveryArea Get(SqlConnection cn, int id)
        {
            DeliveryArea result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM DeliveryArea WHERE DeliveryAreaId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildDeliveryArea(rdr);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Delete an entry from the DeliveryArea table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();
            DeliveryArea  deliveryArea = Get(cn, id);

            if (deliveryArea != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM DeliveryArea WHERE DeliveryAreaId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
Exemplo n.º 6
0
        private static bool Update(SqlConnection cn, DeliveryArea deliveryArea)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE DeliveryArea SET DeliveryAreaStreetName=@DeliveryAreaStreetName,DeliveryAreaRangeStart=@DeliveryAreaRangeStart,DeliveryAreaRangeEnd=@DeliveryAreaRangeEnd,DeliveryAreaStreetAddressPrefix=@DeliveryAreaStreetAddressPrefix WHERE DeliveryAreaId=@DeliveryAreaId";

                BuildSqlParameter(sqlCmd, "@DeliveryAreaId", SqlDbType.Int, deliveryArea.Id);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaStreetName", SqlDbType.Text, deliveryArea.StreetName);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaRangeStart", SqlDbType.Int, deliveryArea.StartingAddress);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaRangeEnd", SqlDbType.Int, deliveryArea.EndingAddress);
                BuildSqlParameter(sqlCmd, "@DeliveryAreaStreetAddressPrefix", SqlDbType.NChar, deliveryArea.AddressPrefix);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
Exemplo n.º 7
0
 public bool Update()
 {
     return(DeliveryArea.Update(this));
 }