Example #1
0
        public List<typediscountcard> GetAllTypeDiscount()
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("SELECT id, discount,  coundition FROM TypeDiscountCard", con);
            cmd.CommandType = CommandType.Text;

            // Создать коллекцию для всех записей
            List<typediscountcard> list = new List<typediscountcard>();
            try
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    typediscountcard emp = new typediscountcard(
                    (int)reader["id"],
                    (int)reader["discount"],
                    (int)reader["coundition"]);

                    list.Add(emp);
                }
                reader.Close();
                return list;
            }
            catch
            {
                throw new ApplicationException("Ошибка данныx. вернуть все типы дисконтов");
            }
            finally
            {
                con.Close();
            }
        }
Example #2
0
        public int AddTypeDiscount(typediscountcard emp1)
        {
            SqlConnection con = new SqlConnection(connectionString);
            SqlCommand cmd = new SqlCommand("Insert into TypeDiscountCard(discount, coundition) values (@discount,@coundition) SET @id = @@IDENTITY ", con);
            cmd.CommandType = CommandType.Text;
            cmd.Parameters.Add(new SqlParameter("@discount", SqlDbType.Int, 3));
            cmd.Parameters["@discount"].Value = emp1.Discount;
            cmd.Parameters.Add(new SqlParameter("@coundition", SqlDbType.Int, 6));
            cmd.Parameters["@coundition"].Value = emp1.Coundition;
            cmd.Parameters.Add(new SqlParameter("@id", SqlDbType.Int, 6));
            cmd.Parameters["@id"].Direction = ParameterDirection.Output;

            try
            {
                con.Open();
                cmd.ExecuteNonQuery();
                return (int)cmd.Parameters["@id"].Value;
            }
            catch
            {
                return 0;
                throw new ApplicationException("Ошибка данныx. добавление типа дисконта");

            }
            finally
            {
                con.Close();
            }
        }