Example #1
0
    /// <summary>
    /// Initializes Categories which belong to current Company and Available.
    /// </summary>
    private void InitCategoryCollection()
    {
        Dictionary<int, Category> dc = new Dictionary<int, Category>();

        SqlConnection conn = new SqlConnection(
            ConfigurationManager.ConnectionStrings["TotoCafeDB"].ConnectionString
                                              );
        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "SELECT Category.* FROM Category " +
                                      "INNER JOIN Availability ON Category.AvailabilityID = Availability.AvailabilityID " +
                                      "WHERE (Category.CompanyID = @CompanyID) AND (Availability.Availability = @Availability)";
        cmd.Parameters.AddWithValue("@Availability", "AVAILABLE");
        cmd.Parameters.AddWithValue("@CompanyID", this.CompanyID);

        cmd.Connection = conn;

        try
        {
            conn.Open();

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Category c = new Category();

                c.CategoryID = int.Parse(dr["CategoryID"].ToString());
                c.CategoryName = dr["CategoryName"].ToString();
                c.AvailabilityID = int.Parse(dr["AvailabilityID"].ToString());
                c.InitProductList();

                dc.Add(c.CategoryID, c);

            }
        }
        catch (Exception) { }
        finally { conn.Close(); }
        this.Categories = dc;
    }