protected void Page_Load(object sender, EventArgs e)
        {
            // Log page
            AppUtility.Utility.LogPage();

            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            SqlParameter[] sqlParameters = new SqlParameter[16];

            // First, fill out blank parameters.  If a parameter is going to be used, it will be filled out below.
            // SqlParemeterCollection can't have nulls in it.
            sqlParameters[0] = new SqlParameter("Name", null);
            sqlParameters[1] = new SqlParameter("DescriptionAndNotes", null);
            sqlParameters[2] = new SqlParameter("CategoryID", null);
            sqlParameters[3] = new SqlParameter("FlavorID", null);
            sqlParameters[4] = new SqlParameter("CountryID", null);
            sqlParameters[5] = new SqlParameter("BrandID", null);
            sqlParameters[6] = new SqlParameter("AlcoholProof1", null);
            sqlParameters[7] = new SqlParameter("AlcoholProof2", null);
            sqlParameters[8] = new SqlParameter("LADRating1", null);
            sqlParameters[9] = new SqlParameter("LADRating2", null);
            sqlParameters[10] = new SqlParameter("COMRating1", null);
            sqlParameters[11] = new SqlParameter("COMRating2", null);
            sqlParameters[12] = new SqlParameter("PageNum", 1);
            sqlParameters[13] = new SqlParameter("PageSize", 5000);

            // We just want ingredients that have a review.  So look for ingredients that have a review rating between 0 and 100
            sqlParameters[8] = new SqlParameter("LADRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating1", DataRowVersion.Current, 0);
            sqlParameters[9] = new SqlParameter("LADRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating2", DataRowVersion.Current, 100);

            // Add output parameters
            sqlParameters[14] = new SqlParameter("TotalPages", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalPages", DataRowVersion.Current, 0);
            sqlParameters[15] = new SqlParameter("TotalRows", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalRows", DataRowVersion.Current, 0);

            // Get the list
            _repeaterIngredient.DataSource = simpleData.FetchSP("SearchIngredients", sqlParameters);

            // Light up the ingredients to ingredient repeater
            _repeaterIngredient.DataBind();

            // Module title
            ModuleConfiguration.ModuleTitle = "Liquor/Mixer Reviews";

            // Widgets
            // Send a message to any widget modules that are listening.
            ModuleCommunicationEventArgs args = new ModuleCommunicationEventArgs();
            args.Sender = "Headlines";
            args.Target = "Widget";
            args.Value = new List<string>() {AppUtility.AdRotator.GetAdsenseCode("adsense.list.200x90.linkunit")};

            if (ModuleCommunication != null)
            {
                ModuleCommunication(this, args);
            }

            DoSEO();
        }
Example #2
0
        protected void Page_Init(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            _drBrand = simpleData.FetchSP("GetBrand", new SqlParameter[] { new SqlParameter("BrandID", Request.QueryString["pk"]) }).Rows[0];

            this.Title = (string)_drBrand["Name"];
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable dtDrinks = simpleData.FetchSP("GetArticles", new SqlParameter[] { new SqlParameter("BlurbLength", 1), new SqlParameter("IncludePrivate", 1) });

            _repeaterArticle.DataSource = dtDrinks;
            _repeaterArticle.DataBind();
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;
            DataTable dataTable;

            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.Flavor)) });
            _flavorList.DataSource = dataTable;
            _flavorList.DataValueField = "ListItem_pk";
            _flavorList.DataTextField = "Name";
            _flavorList.DataBind();
        }
Example #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (! _showBlankNotes.Checked)
            {
                SimpleData simpleData = new SimpleData();
                ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
                simpleData.ConnectionString = connectionStringSettings.ConnectionString;

                DataTable dtDrinks = simpleData.FetchSP("GetDrinks", null);

                _repeaterDrink.DataSource = dtDrinks;
                _repeaterDrink.DataBind();
            }
        }
Example #6
0
        protected void LogDrink(int drinkID)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable logDrinkTable;

            logDrinkTable = simpleData.NewRow("LogDrink", "LogDrink_pk");

            logDrinkTable.Rows[0]["DrinkID"] = drinkID;
            logDrinkTable.Rows[0]["Created"] = DateTime.Now;

            int ret = simpleData.Update(logDrinkTable, true);
        }
        protected void _showBlankDescriptions_CheckedChanged(object sender, EventArgs e)
        {
            if (_showBlankDescriptions.Checked)
            {
                SimpleData simpleData = new SimpleData();
                ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
                simpleData.ConnectionString = connectionStringSettings.ConnectionString;
                simpleData.Sql = "SELECT Ingredient_pk, Name FROM Ingredient WHERE Description = '' ORDER BY Name";

                DataTable dtDrinks = simpleData.Fetch();

                _repeaterIngredient.DataSource = dtDrinks;
                _repeaterIngredient.DataBind();
            }
        }
        protected void LogRedirect()
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable logExternalPageTable;

            logExternalPageTable = simpleData.NewRow("LogExternalPage", "LogExternalPage_pk");

            logExternalPageTable.Rows[0]["CurrentPage"] = HttpContext.Current.Request.UrlReferrer == null ? String.Empty : HttpContext.Current.Request.UrlReferrer.ToString();
            logExternalPageTable.Rows[0]["ExternalPage"] = _externalPage;
            logExternalPageTable.Rows[0]["Created"] = DateTime.Now;

            int ret = simpleData.Update(logExternalPageTable, true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //            long bytecount = System.GC.GetTotalMemory(true);

            if (! _showBlankDescriptions.Checked)
            {
                SimpleData simpleData = new SimpleData();
                ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
                simpleData.ConnectionString = connectionStringSettings.ConnectionString;

                DataTable dtIngredients = simpleData.FetchSP("GetIngredients", null);

             //           bytecount = System.GC.GetTotalMemory(true) - bytecount;

                _repeaterIngredient.DataSource = dtIngredients;
                _repeaterIngredient.DataBind();
            }
        }
Example #10
0
        protected void Page_Init(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            _drArticle = simpleData.FetchSP("GetArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) }).Rows[0];

            // Load fields
            this.Title = (string)_drArticle["Title"];
            _subtitleLiteral.Text = (string)_drArticle["Subtitle"];
            _postedLiteral.Text = ((DateTime)_drArticle["Posted"]).ToString("MMMM d, yyyy");

            string body = WebUtility.ConvertDBArticleBodyToHTML((String)_drArticle["Body"]);

            // Make first letter big
            int firstParagraphIndex = body.IndexOf("<p");
            if (firstParagraphIndex >= 0) body = body.Insert(firstParagraphIndex + 2, @" class=""FirstChar"" ");

            _bodyLiteral.Text = body;

            _updatedLiteral.Text = ((DateTime)_drArticle["Updated"]).ToString("d");

            // Get article links in right column
            DataTable dtArticleLinks = simpleData.FetchSP("GetArticleLinks", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) });

            this.RightColumn.Controls.Add(new LiteralControl(CharlesThompson.LiquorAndDrink.AppUI.Content.GetLinkBoxHtml(dtArticleLinks)));

            // Set page meta tags
            HtmlMeta meta = new HtmlMeta();
            meta.Name = "description";
            string metaContent = AppUI.Content.GetArticleMetaDescription(_drArticle);
            meta.Content = metaContent;
            this.Header.Controls.Add(meta);

            // Set ShareThis header script
            this.Header.Controls.Add(new LiteralControl(CacheManager.GetItem(CacheManager.Cache_FileShareThisHeaderScript)));

            // Do share box button script
            StringBuilder shareScript = new StringBuilder();
            _shareDiv.Controls.Add(new LiteralControl(AppUI.Content.GetShareButtonScript(((string)_drArticle["Title"]).Replace("'", ""),
                                                                                           metaContent,
                                                                                           ConfigurationManager.AppSettings["SiteUrl"] + "Articles/" + Convert.ToString(_drArticle["Article_pk"]) + "-" + Utility.UrlEncode((string)_drArticle["Title"]))));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get drink data from cache
            DataView dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                    "GetDrinks",
                                                    "Drink_pk",
                                                     null);

            dataView.RowFilter = "Drink_pk = " + Request.QueryString["pk"];

            if (dataView.Count > 0)
            {
                _drDrinkCache = dataView.ToTable().Rows[0];

                // Get ingredients
                _dtIngredient = simpleData.FetchSP("GetDrinkIngredients", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });

                // Ingredient Profile #####################################
                _dtIngredientProfile = new DataTable();
                _dtIngredientProfile.Columns.Add("Amount", typeof(decimal));
                _dtIngredientProfile.Columns.Add("Name", typeof(string));

                foreach (DataRow row in _dtIngredient.Rows)
                {
                    _dtIngredientProfile.Rows.Add(new object[] { row["AmountWeighted"], row["IngredientName"] });
                }

                _chart.BackgroundImageFileName = Server.MapPath("~") + @"\image\gradient_DrinkProfile.png";
                _chart.ColorModel.CustomPalette = Constant.ChartPalette;
                _chart.ColorModel.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.CustomLinear;
                _chart.DeploymentScenario.ImageURL = _chart.DeploymentScenario.ImageURL;
                _chart.DataSource = _dtIngredientProfile;
                _chart.DataBind();

                // Load fields
                this.Title = (string)_drDrinkCache["Name"] + " - Ingredient Profile";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            SqlParameter[] sqlParameters = new SqlParameter[16];

            // First, fill out blank parameters.  If a parameter is going to be used, it will be filled out below.
            // SqlParemeterCollection can't have nulls in it.
            sqlParameters[0] = new SqlParameter("Name", null);
            sqlParameters[1] = new SqlParameter("DescriptionAndNotes", null);
            sqlParameters[2] = new SqlParameter("CategoryID", null);
            sqlParameters[3] = new SqlParameter("FlavorID", null);
            sqlParameters[4] = new SqlParameter("CountryID", null);
            sqlParameters[5] = new SqlParameter("BrandID", null);
            sqlParameters[6] = new SqlParameter("AlcoholProof1", null);
            sqlParameters[7] = new SqlParameter("AlcoholProof2", null);
            sqlParameters[8] = new SqlParameter("LADRating1", null);
            sqlParameters[9] = new SqlParameter("LADRating2", null);
            sqlParameters[10] = new SqlParameter("COMRating1", null);
            sqlParameters[11] = new SqlParameter("COMRating2", null);
            sqlParameters[12] = new SqlParameter("PageNum", 1);
            sqlParameters[13] = new SqlParameter("PageSize", 5000);

            // We just want ingredients that have a review.  So look for ingredients that have a review rating between 0 and 100
            sqlParameters[8] = new SqlParameter("LADRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating1", DataRowVersion.Current, 0);
            sqlParameters[9] = new SqlParameter("LADRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating2", DataRowVersion.Current, 100);

            // Add output parameters
            sqlParameters[14] = new SqlParameter("TotalPages", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalPages", DataRowVersion.Current, 0);
            sqlParameters[15] = new SqlParameter("TotalRows", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalRows", DataRowVersion.Current, 0);

            // Get the list
            _repeaterIngredient.DataSource = simpleData.FetchSP("SearchIngredients", sqlParameters);

            // Light up the ingredients to ingredient repeater
            _repeaterIngredient.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;
            _dataTable = simpleData.FetchSP("GetIngredientProfile", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });

            _dataTableChart = _dataTable.Copy();
            _dataTableChart.Columns.Remove("Ingredient_pk");
            _dataTableChart.Columns.Remove("Name");
            _dataTableChart.Columns.Remove("Proof");
            _dataTableChart.Columns.Remove("Created");
            _dataTableChart.Columns.Remove("Updated");

            _dataTableChart.Columns["Sour"].ColumnName = "Acidity";
            _dataTableChart.Columns["FreshFruit"].ColumnName = "Fresh Fruit";
            _dataTableChart.Columns["DriedFruit"].ColumnName = "Dried Fruit";

            _chart.BackgroundImageFileName = Server.MapPath("~") + @"\image\gradient_IngredientProfile.png";
            _chart.BackgroundImageStyle = Infragistics.UltraChart.Shared.Styles.ImageFitStyle.Tiled;
            _chart.DeploymentScenario.ImageURL = _chart.DeploymentScenario.ImageURL;
            _chart.DataSource = _dataTableChart;
            _chart.DataBind();

            if (_dataTableChart.Rows[0]["Body"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Sweet"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Sour"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Fresh Fruit"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Dried Fruit"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Spice"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Heat"] == DBNull.Value &&
                _dataTableChart.Rows[0]["Wood"] == DBNull.Value)
                _flavorProfileHeader.InnerHtml = "Flavor Profile (not available)";

            this.Title = (string)_dataTable.Rows[0]["Name"] + " - Flavor Profile";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];

            // Ingredient
            SimpleData simpleData = new SimpleData();
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;
            _dataRow = simpleData.FetchSP("GetIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) }).Rows[0];

            // Load fields
            this.Title = (string)_dataRow["IngredientName"];

            // Categories
            // Get all parents of this category.  We will display the parents as a hierarchy.
            DataTable _parentCategories = simpleData.FetchSP("GetListItemsTreeAllParents", new SqlParameter[] { new SqlParameter("ListItemID", Convert.ToInt32(_dataRow["CategoryID"])) });
            StringBuilder sb = new StringBuilder();
            int counter = 0;

            sb.Append(@"<p style=""line-height: 1.25em"">");

            for (int i = _parentCategories.Rows.Count - 1; i >= 0; i--)
            {
                for (int x = 0; x < counter * 2; x++)
                {
                    sb.Append("&nbsp;");
                }

                sb.Append(@"<a href=""");
                sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                sb.Append("Ingredients/Browse/Category/");
                sb.Append(Convert.ToString(_parentCategories.Rows[i]["ListItem_pk"]));
                sb.Append("-");
                sb.Append(AppUtility.Utility.UrlEncode((string)_parentCategories.Rows[i]["Name"]));
                sb.Append(@"/"">");
                sb.Append((string)_parentCategories.Rows[i]["Name"]);
                sb.Append(@"</a><br>");

                counter++;
            }
            sb.Append(@"</p>");

            _categoryLiteral.Text = sb.ToString();

            // Ingredient name

            if ((int)_dataRow["BrandID"] != 0)
            {
                _brandLink.NavigateUrl = ConfigurationManager.AppSettings["SiteUrl"] + "Ingredients/Browse/Brand/" + Convert.ToString(_dataRow["BrandID"]) + "-" + AppUtility.Utility.UrlEncode((string)_dataRow["BrandName"]) + "/";
                _brandLink.Text = (string)_dataRow["BrandName"];
            }
            else
            {// No brand--don't show the field

                _brandRow.Visible = false;
            }

            if ((int)_dataRow["CountryID"] != 0)
            {
                _countryLink.NavigateUrl = ConfigurationManager.AppSettings["SiteUrl"] + "Ingredients/Browse/Country/" + Convert.ToString(_dataRow["CountryID"]) + "-" + AppUtility.Utility.UrlEncode((string)_dataRow["CountryName"]) + "/";
                _countryLink.Text = (string)_dataRow["CountryName"];
            }
            else
            {// No country--don't show the field

                _countryRow.Visible = false;
            }

            _proofLink.NavigateUrl = ConfigurationManager.AppSettings["SiteUrl"] + "Ingredients/Browse/Proof/" + String.Format("{0:##0.##}", _dataRow["Proof"]) + "-" + String.Format("{0:##0.##}", _dataRow["Proof"]) + "/";
            _proofLink.Text = String.Format("{0:##0.##}", _dataRow["Proof"]) + " (" + String.Format("{0:##0.##%}", (decimal)_dataRow["Proof"] * (decimal).5 / 100) +")";

            // More information
            sb = new StringBuilder();
            bool moreInformationAvailable = false;

            if (_dataRow["IngredientURL"] != DBNull.Value && (string)_dataRow["IngredientURL"] != String.Empty)
            {// We have an ingredient URL--use it

                sb.Append(@"<a target=""_blank"" href=""");
                sb.Append(AppUtility.Utility.ExternalUrlEncode((string)_dataRow["IngredientURL"]));
                sb.Append(@""">");
                sb.Append((string)_dataRow["IngredientName"]);
                sb.Append(@"</a>");
                moreInformationAvailable = true;
            }

            if (_dataRow["BrandURL"] != DBNull.Value && (string)_dataRow["BrandURL"] != String.Empty)
            {// We have an brand URL--use it

                if (sb.Length > 0) sb.Append("<br>");
                sb.Append(@"<a target=""_blank"" href=""");
                sb.Append(AppUtility.Utility.ExternalUrlEncode((string)_dataRow["BrandURL"]));
                sb.Append(@""">");
                sb.Append((string)_dataRow["BrandName"]);
                sb.Append(@"</a>");
                moreInformationAvailable = true;
            }

            if (moreInformationAvailable)
                _moreInformationLiteral.Text = sb.ToString();
            else
            {// More information not available--hide the field

                _moreInformationRow.Visible = false;
            }

            // Flavors ##########################################################################
            DataTable dtFlavors = simpleData.FetchSP("GetIngredientFlavors", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });

            StringBuilder flavors = new StringBuilder();
            foreach (DataRow row in dtFlavors.Rows)
            {
                flavors.Append(@"<a href=""");
                flavors.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                flavors.Append(@"Ingredients/Browse/Flavor/");
                flavors.Append(Convert.ToString(row["ListItem_pk"]));
                flavors.Append("-");
                flavors.Append(AppUtility.Utility.UrlEncode(Convert.ToString(row["Name"])));
                flavors.Append(@"/"">");
                flavors.Append(Convert.ToString(row["Name"]));
                flavors.Append(@"</a>, ");
            }

            // Chop off trailing comma
            if (flavors.Length > 0) flavors.Remove(flavors.Length - 2, 2);

            if (dtFlavors.Rows.Count > 0)
            {
                _flavorsLiteral.Text = flavors.ToString();
            }
            else
            {// No flavors--don't show the field

                _flavorsRow.Visible = false;
            }

            // Price #######################################################
            if (_dataRow["Price"] != DBNull.Value)
            {
                StringBuilder price = new StringBuilder();
                price.Append(String.Format("{0:$##0.##}", _dataRow["Price"]));
                price.Append(" / ");
                price.Append(String.Format("{0:##0.##}", _dataRow["PriceQuantity"]));
                price.Append(" ");
                price.Append((Decimal)_dataRow["PriceQuantity"] > 1 ? (string)_dataRow["UnitAbbreviationPlural"] : (string)_dataRow["UnitAbbreviation"]);
                _priceLiteral.Text = price.ToString();

                _countryLink.Text = (string)_dataRow["CountryName"];
            }
            else
            {// No price--don't show the field

                _priceRow.Visible = false;
            }

            // Ratings ##################################################
            _dtReviews = simpleData.FetchSP("GetIngredientRatings", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });

            if (_dtReviews.Rows.Count > 0)
            {
                _repeaterRatings.DataSource = _dtReviews;
                _repeaterRatings.DataBind();
            }
            else _reviewDiv.Visible = false;

            // Description ##############################################
            if (((string)_dataRow["Description"]).Trim() != string.Empty)
                _descriptionLiteral.Text = WebUtility.ConvertDBDescriptionToHTML((string)_dataRow["Description"]);
            else
                _descriptionDiv.Visible = false;

            // Notes ####################################################
            if (((string)_dataRow["Notes"]).Trim() != string.Empty)
                _notesLiteral.Text = WebUtility.ConvertDBDescriptionToHTML((string)_dataRow["Notes"]);
            else
                _notesDiv.Visible = false;

            // Flavor Profile ########################################################
            DataTable dtFlavorProfile = new DataTable();
            dtFlavorProfile.Columns.Add("Body", typeof(decimal));
            dtFlavorProfile.Columns.Add("Sweet", typeof(decimal));
            dtFlavorProfile.Columns.Add("Acidity", typeof(decimal));
            dtFlavorProfile.Columns.Add("Fresh Fruit", typeof(decimal));
            dtFlavorProfile.Columns.Add("Dried Fruit", typeof(decimal));
            dtFlavorProfile.Columns.Add("Spice", typeof(decimal));
            dtFlavorProfile.Columns.Add("Heat", typeof(decimal));
            dtFlavorProfile.Columns.Add("Wood", typeof(decimal));

            dtFlavorProfile.Rows.Add(new object[] {_dataRow["Body"],
                                                   _dataRow["Sweet"],
                                                   _dataRow["Sour"],
                                                   _dataRow["FreshFruit"],
                                                   _dataRow["DriedFruit"],
                                                   _dataRow["Spice"],
                                                   _dataRow["Heat"],
                                                   _dataRow["Wood"]});

            _chart.BackgroundImageFileName = Server.MapPath("~") + @"\image\gradient_Ingredient.png";
            _chart.BackgroundImageStyle = Infragistics.UltraChart.Shared.Styles.ImageFitStyle.Centered;
            _chart.DeploymentScenario.ImageURL = ConfigurationManager.AppSettings["SiteUrl"] + _chart.DeploymentScenario.ImageURL;
            _chart.DataSource = dtFlavorProfile;
            _chart.DataBind();

            if (_dataRow["Body"] == DBNull.Value &&
                _dataRow["Sweet"] == DBNull.Value &&
                _dataRow["Sour"] == DBNull.Value &&
                _dataRow["FreshFruit"] == DBNull.Value &&
                _dataRow["DriedFruit"] == DBNull.Value &&
                _dataRow["Spice"] == DBNull.Value &&
                _dataRow["Heat"] == DBNull.Value &&
                _dataRow["Wood"] == DBNull.Value)
            {// No flavor profile information so hide the profile

                _profileDiv.Visible = false;
                _flavorProfileHeader.Visible = false;
                _chart.Visible = false;
            }

            DoSEO();

            // Do right column content targeted to this ingredient
            int flavor1ID = -1;
            int flavor2ID = -1;
            if (dtFlavors.Rows.Count > 0) flavor1ID = (int)dtFlavors.Rows[0]["ListItem_pk"];
            if (dtFlavors.Rows.Count > 1) flavor2ID = (int)dtFlavors.Rows[1]["ListItem_pk"];

            //this.RightColumn.Controls.Add(new LiteralControl(CharlesThompson.LiquorAndDrink.AppUI.Content.GetSimilarIngredientsHtml(Convert.ToInt32(Request.QueryString["pk"]),
            //                                                                                                                        (int)_dataRow["CategoryID"],
            //                                                                                                                        (int)_dataRow["BrandID"],
            //                                                                                                                        flavor1ID,
            //                                                                                                                        flavor2ID)));

            // Log this ingredient
            LogIngredient(Convert.ToInt32(Request.QueryString["pk"]));

            // Get ingredient links in right column
            DataTable dtIngredientLinks = simpleData.FetchSP("GetIngredientLinks", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });

            this.RightColumn.Controls.Add(new LiteralControl(CharlesThompson.LiquorAndDrink.AppUI.Content.GetLinkBoxHtml(dtIngredientLinks)));

            // Set page meta tags
            HtmlMeta meta = new HtmlMeta();
            meta.Name = "description";
            string metaContent = AppUI.Content.GetIngredientMetaDescription(_dataRow);
            meta.Content = metaContent;
            this.Header.Controls.Add(meta);

            // Set ShareThis header script
            this.Header.Controls.Add(new LiteralControl(CacheManager.GetItem(CacheManager.Cache_FileShareThisHeaderScript)));

            // Do share box button script
            StringBuilder shareScript = new StringBuilder();
            _shareDiv.Controls.Add(new LiteralControl(AppUI.Content.GetShareButtonScript(((string)_dataRow["IngredientName"]).Replace("'", ""),
                                                                                           metaContent,
                                                                                           ConfigurationManager.AppSettings["SiteUrl"] + "Ingredients/" + Convert.ToString(_dataRow["Ingredient_pk"]) + "-" + Utility.UrlEncode((string)_dataRow["IngredientName"]))));
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["desc"] != null)
            {// This is not a generic search--it is a browse filter--figure out page title

                if (Request.QueryString["filter"] == "search")
                {// Doing a one parameter search to impersonate a browse

                    if (Request.QueryString["cat"] != null)
                        this.Title = "Browse Liquor/Mixers - By Category - " + AppUtility.Utility.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["flavor"] != null)
                        this.Title = "Browse Liquor/Mixers - By Flavor - " + AppUtility.Utility.UrlDecode(Request.QueryString["desc"]);
                }
                else
                {// Doing an actual browse

                    if (Request.QueryString["filter"] == "brand")
                        this.Title = "Browse Liquor/Mixers - By Brand - " + AppUtility.Utility.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["filter"] == "country")
                        this.Title = "Browse Liquor/Mixers - By Country of Origin - " + AppUtility.Utility.UrlDecode(Request.QueryString["desc"]);
                }
            }
            else
            {// These don't use a desc

                if (Request.QueryString["filter"] == "proof")
                {
                    if (Request.QueryString["value2"] == "0")
                        this.Title = "Browse Liquor/Mixers - By Alcohol Proof - No Alcohol";
                    else
                        this.Title = "Browse Liquor/Mixers - By Alcohol Proof - " + Request.QueryString["value1"] + " to " + Request.QueryString["value2"] + " Proof";
                }

                else if (Request.QueryString["filter"] == "name")
                    this.Title = "Browse Liquor/Mixers - By Name";

                else
                {// Must be a genuine search

                    this.Title = "Search Liquor/Mixers - Results";
                }
            }

            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            SqlParameter[] sqlParameters = new SqlParameter[16];

            // First, fill out blank parameters.  If a parameter is going to be used, it will be filled out below.
            // SqlParemeterCollection can't have nulls in it.
            sqlParameters[0] = new SqlParameter("Name", null);
            sqlParameters[1] = new SqlParameter("DescriptionAndNotes", null);
            sqlParameters[2] = new SqlParameter("CategoryID", null);
            sqlParameters[3] = new SqlParameter("FlavorID", null);
            sqlParameters[4] = new SqlParameter("CountryID", null);
            sqlParameters[5] = new SqlParameter("BrandID", null);
            sqlParameters[6] = new SqlParameter("AlcoholProof1", null);
            sqlParameters[7] = new SqlParameter("AlcoholProof2", null);
            sqlParameters[8] = new SqlParameter("LADRating1", null);
            sqlParameters[9] = new SqlParameter("LADRating2", null);
            sqlParameters[10] = new SqlParameter("COMRating1", null);
            sqlParameters[11] = new SqlParameter("COMRating2", null);
            sqlParameters[12] = new SqlParameter("PageNum", 1);
            sqlParameters[13] = new SqlParameter("PageSize", 5000);

            if (Request.QueryString["name"] != null)
            {
                sqlParameters[0] = new SqlParameter("Name", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "Name", DataRowVersion.Current, Request.QueryString["name"]);
            }

            if (Request.QueryString["dn"] != null)
            {
                sqlParameters[1] = new SqlParameter("DescriptionAndNotes", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "DescriptionAndNotes", DataRowVersion.Current, Request.QueryString["dn"]);
            }

            if (Request.QueryString["cat"] != null)
            {
            //                DataTable dtCategory = simpleData.FetchSP("GetListItemsTreeAllChildren",
            //                                                           new SqlParameter[] { new SqlParameter("ListItemID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "ListItemID", DataRowVersion.Current, Request.QueryString["cat"]) });

                sqlParameters[2] = new SqlParameter("CategoryID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "CategoryID", DataRowVersion.Current, Request.QueryString["cat"]);
            }

            if (Request.QueryString["flavor"] != null)
            {
                sqlParameters[3] = new SqlParameter("FlavorID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "FlavorID", DataRowVersion.Current, Request.QueryString["flavor"]);
            }

            if (Request.QueryString["country"] != null)
            {
                sqlParameters[4] = new SqlParameter("CountryID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "CountryID", DataRowVersion.Current, Request.QueryString["country"]);
            }

            if (Request.QueryString["brand"] != null)
            {
                sqlParameters[5] = new SqlParameter("BrandID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "BrandID", DataRowVersion.Current, Request.QueryString["brand"]);
            }

            if (Request.QueryString["proof1"] != null)
            {
                sqlParameters[6] = new SqlParameter("AlcoholProof1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof1", DataRowVersion.Current, Request.QueryString["proof1"]);
            }

            if (Request.QueryString["proof2"] != null)
            {
                sqlParameters[7] = new SqlParameter("AlcoholProof2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof2", DataRowVersion.Current, Request.QueryString["proof2"]);
            }

            if (Request.QueryString["ladrating1"] != null)
            {
                sqlParameters[8] = new SqlParameter("LADRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating1", DataRowVersion.Current, Request.QueryString["ladrating1"]);
            }

            if (Request.QueryString["ladrating2"] != null)
            {
                sqlParameters[9] = new SqlParameter("LADRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating2", DataRowVersion.Current, Request.QueryString["ladrating2"]);
            }

            if (Request.QueryString["comrating1"] != null)
            {
                sqlParameters[10] = new SqlParameter("COMRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "COMRating1", DataRowVersion.Current, Request.QueryString["comrating1"]);
            }

            if (Request.QueryString["comrating2"] != null)
            {
                sqlParameters[11] = new SqlParameter("COMRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "COMRating2", DataRowVersion.Current, Request.QueryString["comrating2"]);
            }

            // Add output parameters
            sqlParameters[14] = new SqlParameter("TotalPages", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalPages", DataRowVersion.Current, 0);
            sqlParameters[15] = new SqlParameter("TotalRows", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalRows", DataRowVersion.Current, 0);

            if (Request.QueryString["filter"] == "search")
            {// Full search requested--crank the search stored procedure

                _repeaterIngredient.DataSource = simpleData.FetchSP("SearchIngredients", sqlParameters);
            }
            else
            {// Browse requested--filter on one column (hopefully from the cache)

                DataView dataView;

                switch (Request.QueryString["filter"])
                {
                    case "name":
                    // Filter by name--just show all

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                       "GetIngredients",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = String.Empty;
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "cat":
                    // Filter by category--this is actually done as a one parameter search above
                        break;

                    case "country":
                    // Filter by country

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                       "GetIngredients",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "CountryID = " + Request.QueryString["value"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "brand":
                    // Filter by brand

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                       "GetIngredients",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "BrandID = " + Request.QueryString["value"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "proof":
                    // Filter by alcohol proof

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                       "GetIngredients",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "Proof >= " + Request.QueryString["value1"] + " AND Proof <= " + Request.QueryString["value2"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "inusebydrinks":
                    // Filter by ingredients in use in drinks

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsInUseByDrinks,
                                                       "GetIngredientsInUseByDrinks",
                                                       "Ingredient_pk",
                                                        null);

                        _repeaterDrink.DataSource = dataView;
                        break;
                }
            }

            if (Request.QueryString["filter"] == "inusebydrinks")
            {// Browse drinks by ingredient

                // Light up the ingredient/brand to drink repeater
                _repeaterDrink.DataBind();
            }
            else
            {// Browse ingredients by filter passed in

                // Light up the ingredients to ingredient repeater
                _repeaterIngredient.DataBind();
            }
        }
Example #16
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["pk"] == "0")
            {// No primary key--add mode

                _pageMode = Constant.PageMode.Add;
            }
            else
            {// We have a primary key--edit mode

                _pageMode = Constant.PageMode.Edit;
            }

            DataTable dataTable;
            DataRow foundRow;
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get drink data from db
            if (_pageMode == Constant.PageMode.Add)
            {
                DataTable dtTemp = simpleData.FetchSP("GetDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                _drDrink = dtTemp.NewRow();
            }
            else
            {
                _drDrink = simpleData.FetchSP("GetDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) }).Rows[0];
            }
            _dtDrinkAttributes = simpleData.FetchSP("GetDrinkAttributes", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
            _dtDrinkAttributes.PrimaryKey = new DataColumn[] { _dtDrinkAttributes.Columns["ListItem_pk"] };
            _dtDrinkFlavors = simpleData.FetchSP("GetDrinkFlavors", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
            _dtDrinkFlavors.PrimaryKey = new DataColumn[] { _dtDrinkFlavors.Columns["ListItem_pk"] };

            // Title
            if (_drDrink["Name"] != DBNull.Value) _titleLiteral.Text = (string)_drDrink["Name"];

            // Load combo items #############################################################################
            // Category
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.DrinkCategory)) });
            _categoryCombo.DataSource = dataTable;
            _categoryCombo.DataBind();

            // Family
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.Family)) });
            _familyCombo.DataSource = dataTable;
            _familyCombo.DataBind();
            _familyCombo.Items.Insert(0, new ListItem(Constant.NotSpecifiedDescription, Convert.ToString(Constant.NotSpecifiedValue)));

            // Structure
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.Structure)) });
            _structureCombo.DataSource = dataTable;
            _structureCombo.DataBind();
            _structureCombo.Items.Insert(0, new ListItem(Constant.NotSpecifiedDescription, Convert.ToString(Constant.NotSpecifiedValue)));

            // Glasses
            dataTable = simpleData.FetchSP("GetGlasses", null);
            _glassCombo.DataSource = dataTable;
            _glassCombo.DataBind();

            // Temp
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.Temperature)) });
            _tempCombo.DataSource = dataTable;
            _tempCombo.DataBind();

            // Private Source
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.PrivateSource)) });
            _privateSourceCombo.DataSource = dataTable;
            _privateSourceCombo.DataBind();

            // Set control states ############################################################################
            if (Page.IsPostBack)
            {// In postback

                // Grab dropdown values from form object (so we don't need to use viewstate)
                _categoryCombo.SelectedValue = Request.Form[_categoryCombo.UniqueID];
                _familyCombo.SelectedValue = Request.Form[_familyCombo.UniqueID];
                _structureCombo.SelectedValue = Request.Form[_structureCombo.UniqueID];
                _glassCombo.SelectedValue = Request.Form[_glassCombo.UniqueID];
                _tempCombo.SelectedValue = Request.Form[_tempCombo.UniqueID];
                _privateSourceCombo.SelectedValue = Request.Form[_privateSourceCombo.UniqueID];
                _instructionsText.Text = Request.Form[_instructionsText.UniqueID];
                _notesText.Text = Request.Form[_notesText.UniqueID];
            }
            else
            {// Not in postback

                if (_pageMode == Constant.PageMode.Edit)
                {// Edit

                    // Name
                    _nameText.Text = (string)_drDrink["Name"];

                    // Private
                    _privateCheck.Checked = (bool)_drDrink["Private"];

                    // Servings
                    _servingsNumber.Value = (decimal)_drDrink["Servings"];

                    // Dilution ratio
                    _dilutionRatioNumber.Value = (decimal)_drDrink["DilutionRatio"];

                    // Instructions
                    _instructionsText.Text = (string)_drDrink["Instructions"];

                    // Notes
                    _notesText.Text = (string)_drDrink["Notes"];

                    if (_drDrink["CategoryID"] == DBNull.Value) _categoryCombo.SelectedIndex = 0;
                    else _categoryCombo.SelectedValue = Convert.ToString(_drDrink["CategoryID"]);

                    if (_drDrink["FamilyID"] == DBNull.Value) _familyCombo.SelectedIndex = 0;
                    else _familyCombo.SelectedValue = Convert.ToString(_drDrink["FamilyID"]);

                    if (_drDrink["StructureID"] == DBNull.Value) _structureCombo.SelectedIndex = 0;
                    else _structureCombo.SelectedValue = Convert.ToString(_drDrink["StructureID"]);

                    foreach (ListItem li in _attributeList.Items)
                    {
                        foundRow = _dtDrinkAttributes.Rows.Find(li.Value);
                        if (foundRow != null) li.Selected = true;
                    }

                    foreach (ListItem li in _flavorList.Items)
                    {
                        foundRow = _dtDrinkFlavors.Rows.Find(li.Value);
                        if (foundRow != null) li.Selected = true;
                    }

                    if (_drDrink["GlassID"] == DBNull.Value) _glassCombo.SelectedIndex = 0;
                    else _glassCombo.SelectedValue = Convert.ToString(_drDrink["GlassID"]);

                    if (_drDrink["TempID"] == DBNull.Value) _tempCombo.SelectedIndex = 0;
                    else _tempCombo.SelectedValue = Convert.ToString(_drDrink["TempID"]);

                    if (_drDrink["PrivateSourceID"] == DBNull.Value) _privateSourceCombo.SelectedIndex = 0;
                    else _privateSourceCombo.SelectedValue = Convert.ToString(_drDrink["PrivateSourceID"]);

                    // Ingredient grid
                    _dtDrinkIngredient = simpleData.FetchSP("GetDrinkIngredients2", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                    _ingredientGrid.DataSource = _dtDrinkIngredient;
                    _ingredientGrid.DataBind();

                    // DrinkSource grid
                    _dtDrinkSource = simpleData.FetchSP("GetSourcesForDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                    _drinkSourceGrid.DataSource = _dtDrinkSource;
                    _drinkSourceGrid.DataBind();

                    // DrinkIngredient grid
                    _dtDrinkIngredient2 = simpleData.FetchSP("GetLinkedIngredientsForDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                    _drinkIngredientGrid.DataSource = _dtDrinkIngredient2;
                    _drinkIngredientGrid.DataBind();

                    // DrinkDrink grid
                    _dtDrinkDrink = simpleData.FetchSP("GetLinkedDrinksForDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                    _drinkDrinkGrid.DataSource = _dtDrinkDrink;
                    _drinkDrinkGrid.DataBind();

                    // DrinkArticle grid
                    _dtDrinkArticle = simpleData.FetchSP("GetLinkedArticlesForDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                    _drinkArticleGrid.DataSource = _dtDrinkArticle;
                    _drinkArticleGrid.DataBind();
                }
                else
                {// Add

                    _servingsNumber.Value = 1;
                    _dilutionRatioNumber.Value = .85;
                    _glassCombo.SelectedValue = "20";
                    _tempCombo.SelectedValue = "88";
                    _privateSourceCombo.SelectedValue = "140";
                }
            }

            // Set up ingredient grid #######################################################################
            _ingredientGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _ingredientGrid.DisplayLayout.AllowUpdateDefault = AllowUpdate.Yes;
            _ingredientGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _ingredientGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _ingredientGrid.DisplayLayout.AddNewBox.Hidden = false;
            _ingredientGrid.Bands[0].AddButtonCaption = "Add New Ingredient";
            _ingredientGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;
            //_ingredientGrid.DisplayLayout.ClientSideEvents.InitializeRowHandler = "InitializeRow";

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _ingredientGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
                _ingredientGrid.Bands[0].Columns.Add("Sort", "Sort");
                _ingredientGrid.Bands[0].Columns.Add("Prefix", "Prefix");
                _ingredientGrid.Bands[0].Columns.Add("Amount", "Amount");
                _ingredientGrid.Bands[0].Columns.Add("UnitID", "UnitID");
                _ingredientGrid.Bands[0].Columns.Add("IngredientID", "IngredientID");
                _ingredientGrid.Bands[0].Columns.Add("Suffix", "Suffix");
                _ingredientGrid.Bands[0].Columns.Add("Principal", "Principal");
            }

            _ingredientGrid.Bands[0].Columns.FromKey("DrinkID").Hidden = true;
            _ingredientGrid.Bands[0].Columns.FromKey("Sort").Width = Unit.Percentage(6);
            _ingredientGrid.Bands[0].Columns.FromKey("Prefix").Width = Unit.Percentage(13);
            _ingredientGrid.Bands[0].Columns.FromKey("Amount").Width = Unit.Percentage(10);
            _ingredientGrid.Bands[0].Columns.FromKey("UnitID").Type = ColumnType.DropDownList;
            _ingredientGrid.Bands[0].Columns.FromKey("UnitID").Width = Unit.Percentage(13);
            _ingredientGrid.Bands[0].Columns.FromKey("IngredientID").Type = ColumnType.DropDownList;
            _ingredientGrid.Bands[0].Columns.FromKey("IngredientID").Width = Unit.Percentage(35);
            _ingredientGrid.Bands[0].Columns.FromKey("Suffix").Width = Unit.Percentage(13);
            _ingredientGrid.Bands[0].Columns.FromKey("Principal").Width = Unit.Percentage(10);

            // Ingredient valuelist
            _vlIngredient = new ValueList();
            _dtIngredient = simpleData.FetchSP("GetIngredients", null);
            _vlIngredient.DataSource = _dtIngredient;
            _vlIngredient.DisplayMember = "Name";
            _vlIngredient.ValueMember = "Ingredient_pk";
            _vlIngredient.DataBind();
            _vlIngredient.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _ingredientGrid.Bands[0].Columns.FromKey("IngredientID").ValueList = _vlIngredient;

            // Unit valuelist
            _vlUnit = new ValueList();
            _dtUnit = simpleData.FetchSP("GetUnits", null);
            _vlUnit.DataSource = _dtUnit;
            _vlUnit.DisplayMember = "Name";
            _vlUnit.ValueMember = "Unit_pk";
            _vlUnit.DataBind();
            _vlUnit.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _ingredientGrid.Bands[0].Columns.FromKey("UnitID").ValueList = _vlUnit;

            // Set up DrinkSource grid #######################################################################
            _drinkSourceGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _drinkSourceGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _drinkSourceGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _drinkSourceGrid.DisplayLayout.AddNewBox.Hidden = false;
            _drinkSourceGrid.Bands[0].AddButtonCaption = "Add New Source";
            _drinkSourceGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _drinkSourceGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
                _drinkSourceGrid.Bands[0].Columns.Add("SourceID", "SourceID");
            }

            _drinkSourceGrid.Bands[0].Columns.FromKey("DrinkID").Hidden = true;
            _drinkSourceGrid.Bands[0].Columns.FromKey("SourceID").Width = Unit.Percentage(100);
            _drinkSourceGrid.Bands[0].Columns.FromKey("SourceID").Type = ColumnType.DropDownList;
            _drinkSourceGrid.Bands[0].Columns.FromKey("SourceID").DefaultValue = DBNull.Value;

            // Source valuelist
            _vlSource = new ValueList();
            _dtSource = simpleData.FetchSP("GetSources", null);
            _vlSource.DataSource = _dtSource;
            _vlSource.DisplayMember = "Name";
            _vlSource.ValueMember = "Source_pk";
            _vlSource.DataBind();
            _vlSource.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _drinkSourceGrid.Bands[0].Columns.FromKey("SourceID").ValueList = _vlSource;

            // Set up DrinkIngredient grid #######################################################################
            _drinkIngredientGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _drinkIngredientGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _drinkIngredientGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _drinkIngredientGrid.DisplayLayout.AddNewBox.Hidden = false;
            _drinkIngredientGrid.Bands[0].AddButtonCaption = "Add New Ingredient Link";
            _drinkIngredientGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _drinkIngredientGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
                _drinkIngredientGrid.Bands[0].Columns.Add("IngredientID", "IngredientID");
            }

            _drinkIngredientGrid.Bands[0].Columns.FromKey("DrinkID").Hidden = true;
            _drinkIngredientGrid.Bands[0].Columns.FromKey("IngredientID").Width = Unit.Percentage(100);
            _drinkIngredientGrid.Bands[0].Columns.FromKey("IngredientID").Type = ColumnType.DropDownList;
            _drinkIngredientGrid.Bands[0].Columns.FromKey("IngredientID").DefaultValue = DBNull.Value;

            // Ingredient valuelist
            //_vlIngredient = new ValueList();
            //_dtIngredient = simpleData.FetchSP("GetIngredients", null);
            //_vlIngredient.DataSource = _dtIngredient;
            //_vlIngredient.DisplayMember = "Name";
            //_vlIngredient.ValueMember = "Ingredient_pk";
            //_vlIngredient.DataBind();
            //_vlIngredient.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _drinkIngredientGrid.Bands[0].Columns.FromKey("IngredientID").ValueList = _vlIngredient;

            // Set up DrinkDrink grid #######################################################################
            _drinkDrinkGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _drinkDrinkGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _drinkDrinkGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _drinkDrinkGrid.DisplayLayout.AddNewBox.Hidden = false;
            _drinkDrinkGrid.Bands[0].AddButtonCaption = "Add New Drink Link";
            _drinkDrinkGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _drinkDrinkGrid.Bands[0].Columns.Add("DrinkID1", "DrinkID1");
                _drinkDrinkGrid.Bands[0].Columns.Add("DrinkID2", "DrinkID2");
            }

            _drinkDrinkGrid.Bands[0].Columns.FromKey("DrinkID1").Hidden = true;
            _drinkDrinkGrid.Bands[0].Columns.FromKey("DrinkID2").Width = Unit.Percentage(100);
            _drinkDrinkGrid.Bands[0].Columns.FromKey("DrinkID2").Type = ColumnType.DropDownList;
            _drinkDrinkGrid.Bands[0].Columns.FromKey("DrinkID2").DefaultValue = DBNull.Value;

            // Drink valuelist
            _vlDrink = new ValueList();
            _dtDrink = simpleData.FetchSP("GetDrinks", null);
            _vlDrink.DataSource = _dtDrink;
            _vlDrink.DisplayMember = "Name";
            _vlDrink.ValueMember = "Drink_pk";
            _vlDrink.DataBind();
            _vlDrink.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _drinkDrinkGrid.Bands[0].Columns.FromKey("DrinkID2").ValueList = _vlDrink;

            // Set up DrinkArticle grid #######################################################################
            _drinkArticleGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _drinkArticleGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _drinkArticleGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _drinkArticleGrid.DisplayLayout.AddNewBox.Hidden = false;
            _drinkArticleGrid.Bands[0].AddButtonCaption = "Add New Article Link";
            _drinkArticleGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _drinkArticleGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
                _drinkArticleGrid.Bands[0].Columns.Add("ArticleID", "ArticleID");
            }

            _drinkArticleGrid.Bands[0].Columns.FromKey("DrinkID").Hidden = true;
            _drinkArticleGrid.Bands[0].Columns.FromKey("ArticleID").Width = Unit.Percentage(100);
            _drinkArticleGrid.Bands[0].Columns.FromKey("ArticleID").Type = ColumnType.DropDownList;
            _drinkArticleGrid.Bands[0].Columns.FromKey("ArticleID").DefaultValue = DBNull.Value;

            // Article valuelist
            _vlArticle = new ValueList();
            _dtArticle = simpleData.FetchSP("GetArticles", null);
            _vlArticle.DataSource = _dtArticle;
            _vlArticle.DisplayMember = "Title";
            _vlArticle.ValueMember = "Article_pk";
            _vlArticle.DataBind();
            _vlArticle.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _drinkArticleGrid.Bands[0].Columns.FromKey("ArticleID").ValueList = _vlArticle;
        }
Example #17
0
        protected void _saveButton_Click(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable updateTable;

            // Save Drink table fields #############################################################
            // Add a new row if this is an add
            if (_pageMode == Constant.PageMode.Add)
            {
                updateTable = simpleData.NewRow("Drink", "Drink_pk");
            }
            else
            {
                updateTable = simpleData.FetchForUpdate("Drink", new string[] { "Drink_pk" }, "Drink_pk", Convert.ToInt32(Request.QueryString["pk"]));
            }

            updateTable.Rows[0]["Name"] = _nameText.Text;
            updateTable.Rows[0]["Private"] = _privateCheck.Checked;
            updateTable.Rows[0]["Servings"] = _servingsNumber.Value;
            updateTable.Rows[0]["DilutionRatio"] = _dilutionRatioNumber.Value;
            updateTable.Rows[0]["CategoryID"] = Convert.ToInt32(_categoryCombo.SelectedValue);
            if (_familyCombo.SelectedValue == Convert.ToString(Constant.NotSpecifiedValue)) updateTable.Rows[0]["FamilyID"] = DBNull.Value;
                else updateTable.Rows[0]["FamilyID"] = Convert.ToInt32(_familyCombo.SelectedValue);
            if (_structureCombo.SelectedValue == Convert.ToString(Constant.NotSpecifiedValue)) updateTable.Rows[0]["StructureID"] = DBNull.Value;
                else updateTable.Rows[0]["StructureID"] = Convert.ToInt32(_structureCombo.SelectedValue);
            updateTable.Rows[0]["GlassID"] = Convert.ToInt32(_glassCombo.SelectedValue);
            updateTable.Rows[0]["TemperatureID"] = Convert.ToInt32(_tempCombo.SelectedValue);
            updateTable.Rows[0]["PrivateSourceID"] = Convert.ToInt32(_privateSourceCombo.SelectedValue);
            updateTable.Rows[0]["Instructions"] = _instructionsText.Text;
            updateTable.Rows[0]["Notes"] = _notesText.Text;
            if (_pageMode == Constant.PageMode.Add) updateTable.Rows[0]["Created"] = DateTime.Now;
            updateTable.Rows[0]["Updated"] = DateTime.Now;

            int pk = 0;

            if (_pageMode == Constant.PageMode.Add)
            {
                int ret = simpleData.Update(updateTable, true);
                pk = ret;
            }
            else
            {
                int ret = simpleData.Update(updateTable, false);
                pk = Convert.ToInt32(Request.QueryString["pk"]);
            }
            // Save attributes records ###################################################################
            DataTable dtDrinkAttributes = simpleData.FetchForUpdate("DrinkAttribute", new string[] {"DrinkID", "AttributeID"}, "DrinkID", pk);

            foreach (DataRow row in dtDrinkAttributes.Rows)
            {
                row.Delete();
            }

            foreach (ListItem li in _attributeList.Items)
            {
                if (li.Selected) dtDrinkAttributes.Rows.Add(new object[] {pk,
                                                                          Convert.ToInt32(li.Value),
                                                                          DateTime.Now,
                                                                          DateTime.Now});
            }

            if (dtDrinkAttributes.Rows.Count > 0) simpleData.Update(dtDrinkAttributes, false);

            // Save flavors records ###################################################################
            DataTable dtDrinkFlavors = simpleData.FetchForUpdate("DrinkFlavor", new string[] { "DrinkID", "FlavorID" }, "DrinkID", pk);

            foreach (DataRow row in dtDrinkFlavors.Rows)
            {
                row.Delete();
            }

            foreach (ListItem li in _flavorList.Items)
            {
                if (li.Selected) dtDrinkFlavors.Rows.Add(new object[] {pk,
                                                                       Convert.ToInt32(li.Value),
                                                                       DateTime.Now,
                                                                       DateTime.Now});
            }

            if (dtDrinkFlavors.Rows.Count > 0) simpleData.Update(dtDrinkFlavors, false);

            // Save out ingredients ##################################################################
            DataTable dtDrinkIngredient = simpleData.FetchForUpdate("DrinkIngredient", new string[] {"DrinkID", "IngredientID"}, "DrinkID", pk);

            foreach (DataRow row in dtDrinkIngredient.Rows)
            {
                row.Delete();
            }

            foreach (UltraGridRow row in _ingredientGrid.Rows)
            {
                dtDrinkIngredient.Rows.Add(new object[] {pk,
                                                         row.Cells.FromKey("IngredientID").Value,
                                                         row.Cells.FromKey("Sort").Value ?? 0,
                                                         row.Cells.FromKey("Amount").Value ?? 0,
                                                         row.Cells.FromKey("UnitID").Value,
                                                         row.Cells.FromKey("Principal").Value,
                                                         row.Cells.FromKey("Prefix").Value ?? String.Empty,
                                                         row.Cells.FromKey("Suffix").Value ?? String.Empty,
                                                         DateTime.Now,
                                                         DateTime.Now});
            }

            if (dtDrinkIngredient.Rows.Count > 0) simpleData.Update(dtDrinkIngredient, false);

            // Save out DrinkSource links ##################################################################
            DataTable dtDrinkSource = simpleData.FetchForUpdate("DrinkSource", new string[] { "DrinkID", "SourceID" }, "DrinkID", pk);
            dtDrinkSource.Constraints.Clear();

            foreach (DataRow row in dtDrinkSource.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtDrinkSource, false);

            foreach (UltraGridRow row in _drinkSourceGrid.Rows)
            {
                dtDrinkSource.Rows.Add(new object[] {pk,
                                                     row.Cells.FromKey("SourceID").Value});
            }

            if (_drinkSourceGrid.Rows.Count > 0) simpleData.Update(dtDrinkSource, false);

            // Save out DrinkIngredient links ##################################################################
            DataTable dtDrinkIngredientLink = simpleData.FetchForUpdate("DrinkIngredient2", new string[] { "DrinkID", "IngredientID" }, "DrinkID", pk);
            dtDrinkIngredientLink.Constraints.Clear();

            foreach (DataRow row in dtDrinkIngredientLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtDrinkIngredientLink, false);

            foreach (UltraGridRow row in _drinkIngredientGrid.Rows)
            {
                dtDrinkIngredientLink.Rows.Add(new object[] {pk,
                                                             row.Cells.FromKey("IngredientID").Value});
            }

            if (_drinkIngredientGrid.Rows.Count > 0) simpleData.Update(dtDrinkIngredientLink, false);

            // Save out DrinkDrink links ##################################################################
            DataTable dtDrinkDrinkLink = simpleData.FetchForUpdate("DrinkDrink", new string[] { "DrinkID1", "DrinkID2" }, "DrinkID1", pk);
            dtDrinkDrinkLink.Constraints.Clear();

            foreach (DataRow row in dtDrinkDrinkLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtDrinkDrinkLink, false);

            foreach (UltraGridRow row in _drinkDrinkGrid.Rows)
            {
                dtDrinkDrinkLink.Rows.Add(new object[] {pk,
                                                        row.Cells.FromKey("DrinkID2").Value});
            }

            if (_drinkDrinkGrid.Rows.Count > 0) simpleData.Update(dtDrinkDrinkLink, false);

            // Save out DrinkArticle links ##################################################################
            DataTable dtDrinkArticleLink = simpleData.FetchForUpdate("DrinkArticle", new string[] { "DrinkID", "ArticleID" }, "DrinkID", pk);
            dtDrinkArticleLink.Constraints.Clear();

            foreach (DataRow row in dtDrinkArticleLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtDrinkArticleLink, false);

            foreach (UltraGridRow row in _drinkArticleGrid.Rows)
            {
                dtDrinkArticleLink.Rows.Add(new object[] {pk,
                                                          row.Cells.FromKey("ArticleID").Value});
            }

            if (_drinkArticleGrid.Rows.Count > 0) simpleData.Update(dtDrinkArticleLink, false);

            Response.Redirect("Drinks.aspx", true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataView dataView;
            SimpleData simpleData = new SimpleData();

            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get ingredients ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsInUseByDrinks,
                                           "GetIngredientsInUseByDrinks",
                                           "Ingredient_pk",
                                            null);

            _ingredient.DataSource = dataView;
            _ingredient.DataBind();

            _ingredient.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set the category value to the value in the form

                _ingredient.SelectedValue = Request.Form[_ingredient.UniqueID];
            }
            else
            {// Not in postback--set the category to not specified

                _ingredient.SelectedIndex = 0;
            }

            // Get ingredient brands #########################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientBrandsInUseByDrinks,
                                           "GetIngredientBrandsInUseByDrinks",
                                           "Brand_pk",
                                            null);

            _ingredientBrand.DataSource = dataView;
            _ingredientBrand.DataBind();

            _ingredientBrand.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set the category value to the value in the form

                _ingredientBrand.SelectedValue = Request.Form[_ingredientBrand.UniqueID];
            }
            else
            {// Not in postback--set the category to not specified

                _ingredientBrand.SelectedIndex = 0;
            }

            // Get categories ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinkCategories,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.DrinkCategory)) });

            _category.DataSource = dataView;
            _category.DataBind();

            _category.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _category.SelectedValue = Request.Form[_category.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _category.SelectedIndex = 0;
            }

            // Get families ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetFamilies,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.Family)) });

            _family.DataSource = dataView;
            _family.DataBind();

            _family.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _family.SelectedValue = Request.Form[_family.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _family.SelectedIndex = 0;
            }

            // Get structures ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetStructures,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.Structure)) });

            _structure.DataSource = dataView;
            _structure.DataBind();

            _structure.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _structure.SelectedValue = Request.Form[_structure.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _structure.SelectedIndex = 0;
            }

            // Get attributes ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetAttributes,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.Attribute)) });

            _attribute.DataSource = dataView;
            _attribute.DataBind();

            _attribute.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _attribute.SelectedValue = Request.Form[_attribute.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _attribute.SelectedIndex = 0;
            }

            // Get flavors ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetFlavors,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.Flavor)) });

            _flavor.DataSource = dataView;
            _flavor.DataBind();

            _flavor.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _flavor.SelectedValue = Request.Form[_flavor.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _flavor.SelectedIndex = 0;
            }

            // Get glasses ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetGlasses,
                                           "GetGlasses",
                                           "Glass_pk",
                                            null);

            _glass.DataSource = dataView;
            _glass.DataBind();

            _glass.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _glass.SelectedValue = Request.Form[_glass.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _glass.SelectedIndex = 0;
            }

            // Get temperatures ################################################################
            dataView = CacheManager.GetItem(CacheManager.Cache_GetTemps,
                                           "GetListItems",
                                           "ListItem_pk",
                                            new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(AppUtility.Constant.List.Temperature)) });

            _temp.DataSource = dataView;
            _temp.DataBind();

            _temp.Items.Insert(0, new ListItem(CharlesThompson.Web.Utility.Constant.NotSpecifiedDescription, Convert.ToString(CharlesThompson.Web.Utility.Constant.NotSpecifiedValue)));

            if (Page.IsPostBack)
            {// In postback--so set to the value in the form

                _temp.SelectedValue = Request.Form[_temp.UniqueID];
            }
            else
            {// Not in postback--set to not specified

                _temp.SelectedIndex = 0;
            }
        }
Example #19
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["pk"] == "0")
            {// No primary key--add mode

                _pageMode = Constant.PageMode.Add;
            }
            else
            {// We have a primary key--edit mode

                _pageMode = Constant.PageMode.Edit;
            }

            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get article data from db
            if (_pageMode == Constant.PageMode.Add)
            {
                DataTable dtTemp = simpleData.FetchSP("GetArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) });
                _drArticle = dtTemp.NewRow();
            }
            else
            {
                _drArticle = simpleData.FetchSP("GetArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) }).Rows[0];
            }

            if (! Page.IsPostBack)
            {// First time

                if (_pageMode == Constant.PageMode.Edit)
                {// Edit

                    _titleLiteral.Text = (string)_drArticle["Title"];
                    _titleText.Text = (string)_drArticle["Title"];
                    _subtitleText.Text = (string)_drArticle["Subtitle"];
                    _iconFileText.Text = (string)_drArticle["IconFile"];
                    _privateCheck.Checked = (bool)_drArticle["Private"];
                    _blurbText.Text = (string)_drArticle["Blurb"];
                    _bodyText.Text = (string)_drArticle["Body"];

                    // ArticleDrink grid
                    _dtArticleDrink = simpleData.FetchSP("GetLinkedDrinksForArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) });
                    _articleDrinkGrid.DataSource = _dtArticleDrink;
                    _articleDrinkGrid.DataBind();

                    // ArticleIngredient grid
                    _dtArticleIngredient = simpleData.FetchSP("GetLinkedIngredientsForArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) });
                    _articleIngredientGrid.DataSource = _dtArticleIngredient;
                    _articleIngredientGrid.DataBind();

                    // ArticleArticle grid
                    _dtArticleArticle = simpleData.FetchSP("GetLinkedArticlesForArticle", new SqlParameter[] { new SqlParameter("ArticleID", Request.QueryString["pk"]) });
                    _articleArticleGrid.DataSource = _dtArticleArticle;
                    _articleArticleGrid.DataBind();
                }
            }

            // Set up ArticleDrink grid #######################################################################
            _articleDrinkGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _articleDrinkGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _articleDrinkGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _articleDrinkGrid.DisplayLayout.AddNewBox.Hidden = false;
            _articleDrinkGrid.Bands[0].AddButtonCaption = "Add New Drink Link";
            _articleDrinkGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _articleDrinkGrid.Bands[0].Columns.Add("ArticleID", "ArticleID");
                _articleDrinkGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
            }

            _articleDrinkGrid.Bands[0].Columns.FromKey("ArticleID").Hidden = true;
            _articleDrinkGrid.Bands[0].Columns.FromKey("DrinkID").Width = Unit.Percentage(100);
            _articleDrinkGrid.Bands[0].Columns.FromKey("DrinkID").Type = ColumnType.DropDownList;
            _articleDrinkGrid.Bands[0].Columns.FromKey("DrinkID").DefaultValue = DBNull.Value;

            // Drink valuelist
            _vlDrink = new ValueList();
            _dtDrink = simpleData.FetchSP("GetDrinks", null);
            _vlDrink.DataSource = _dtDrink;
            _vlDrink.DisplayMember = "Name";
            _vlDrink.ValueMember = "Drink_pk";
            _vlDrink.DataBind();
            _vlDrink.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _articleDrinkGrid.Bands[0].Columns.FromKey("DrinkID").ValueList = _vlDrink;

            // Set up ArticleIngredient grid #######################################################################
            _articleIngredientGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _articleIngredientGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _articleIngredientGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _articleIngredientGrid.DisplayLayout.AddNewBox.Hidden = false;
            _articleIngredientGrid.Bands[0].AddButtonCaption = "Add New Ingredient Link";
            _articleIngredientGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _articleIngredientGrid.Bands[0].Columns.Add("ArticleID", "ArticleID");
                _articleIngredientGrid.Bands[0].Columns.Add("IngredientID", "IngredientID");
            }

            _articleIngredientGrid.Bands[0].Columns.FromKey("ArticleID").Hidden = true;
            _articleIngredientGrid.Bands[0].Columns.FromKey("IngredientID").Width = Unit.Percentage(100);
            _articleIngredientGrid.Bands[0].Columns.FromKey("IngredientID").Type = ColumnType.DropDownList;
            _articleIngredientGrid.Bands[0].Columns.FromKey("IngredientID").DefaultValue = DBNull.Value;

            // Ingredient valuelist
            _vlIngredient = new ValueList();
            _dtIngredient = simpleData.FetchSP("GetIngredients", null);
            _vlIngredient.DataSource = _dtIngredient;
            _vlIngredient.DisplayMember = "Name";
            _vlIngredient.ValueMember = "Ingredient_pk";
            _vlIngredient.DataBind();
            _vlIngredient.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _articleIngredientGrid.Bands[0].Columns.FromKey("IngredientID").ValueList = _vlIngredient;

            // Set up ArticleArticle grid #######################################################################
            _articleArticleGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _articleArticleGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _articleArticleGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _articleArticleGrid.DisplayLayout.AddNewBox.Hidden = false;
            _articleArticleGrid.Bands[0].AddButtonCaption = "Add New Article Link";
            _articleArticleGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _articleArticleGrid.Bands[0].Columns.Add("ArticleID1", "ArticleID1");
                _articleArticleGrid.Bands[0].Columns.Add("ArticleID2", "ArticleID2");
            }

            _articleArticleGrid.Bands[0].Columns.FromKey("ArticleID1").Hidden = true;
            _articleArticleGrid.Bands[0].Columns.FromKey("ArticleID2").Width = Unit.Percentage(100);
            _articleArticleGrid.Bands[0].Columns.FromKey("ArticleID2").Type = ColumnType.DropDownList;
            _articleArticleGrid.Bands[0].Columns.FromKey("ArticleID2").DefaultValue = DBNull.Value;

            // Article valuelist
            _vlArticle = new ValueList();
            _dtArticle = simpleData.FetchSP("GetArticles", null);
            _vlArticle.DataSource = _dtArticle;
            _vlArticle.DisplayMember = "Title";
            _vlArticle.ValueMember = "Article_pk";
            _vlArticle.DataBind();
            _vlArticle.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _articleArticleGrid.Bands[0].Columns.FromKey("ArticleID2").ValueList = _vlArticle;
        }
        protected void _saveButton_Click(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable updateTable;

            // Save Drink table fields #############################################################
            // Add a new row if this is an add
            if (_pageMode == Constant.PageMode.Add)
            {
                updateTable = simpleData.NewRow("Ingredient", "Ingredient_pk");
            }
            else
            {
                updateTable = simpleData.FetchForUpdate("Ingredient", new string[] { "Ingredient_pk" }, "Ingredient_pk", Convert.ToInt32(Request.QueryString["pk"]));
            }

            updateTable.Rows[0]["Name"] = _nameText.Text;
            updateTable.Rows[0]["NamePlural"] = _namePluralText.Text;

            updateTable.Rows[0]["CategoryID"] = Convert.ToInt32(_categoryCombo.SelectedValue);

            if (_brandCombo.SelectedValue == Convert.ToString(Constant.NotSpecifiedValue)) updateTable.Rows[0]["BrandID"] = DBNull.Value;
            else updateTable.Rows[0]["BrandID"] = Convert.ToInt32(_brandCombo.SelectedValue);

            if (_countryCombo.SelectedValue == Convert.ToString(Constant.NotSpecifiedValue)) updateTable.Rows[0]["CountryID"] = DBNull.Value;
            else updateTable.Rows[0]["CountryID"] = Convert.ToInt32(_countryCombo.SelectedValue);

            updateTable.Rows[0]["Proof"] = _proofNumber.Value;
            updateTable.Rows[0]["DissolvedVolumeRatio"] = _dissolvedVolumeRatioNumber.Value;
            updateTable.Rows[0]["URL"] = _urlText.Value;

            if (_bodyNumber.Text != "[none]") updateTable.Rows[0]["Body"] = _bodyNumber.Value;
            if (_sweetNumber.Text != "[none]") updateTable.Rows[0]["Sweet"] = _sweetNumber.Value;
            if (_sourNumber.Text != "[none]") updateTable.Rows[0]["Sour"] = _sourNumber.Value;
            if (_freshFruitNumber.Text != "[none]") updateTable.Rows[0]["FreshFruit"] = _freshFruitNumber.Value;
            if (_driedFruitNumber.Text != "[none]") updateTable.Rows[0]["DriedFruit"] = _driedFruitNumber.Value;
            if (_spiceNumber.Text != "[none]") updateTable.Rows[0]["Spice"] = _spiceNumber.Value;
            if (_heatNumber.Text != "[none]") updateTable.Rows[0]["Heat"] = _heatNumber.Value;
            if (_woodNumber.Text != "[none]") updateTable.Rows[0]["Wood"] = _woodNumber.Value;

            updateTable.Rows[0]["Description"] = _descriptionText.Text;
            updateTable.Rows[0]["Notes"] = _notesText.Text;

            if (_pageMode == Constant.PageMode.Add) updateTable.Rows[0]["Created"] = DateTime.Now;
            updateTable.Rows[0]["Updated"] = DateTime.Now;

            int pk = 0;

            if (_pageMode == Constant.PageMode.Add)
            {
                int ret = simpleData.Update(updateTable, true);
                pk = ret;
            }
            else
            {
                int ret = simpleData.Update(updateTable, false);
                pk = Convert.ToInt32(Request.QueryString["pk"]);
            }

            // Save flavor records ###################################################################
            DataTable dtIngredientFlavors = simpleData.FetchForUpdate("IngredientFlavor", new string[] { "IngredientID", "FlavorID" }, "IngredientID", pk);

            foreach (DataRow row in dtIngredientFlavors.Rows)
            {
                row.Delete();
            }

            foreach (ListItem li in _flavorList.Items)
            {
                if (li.Selected) dtIngredientFlavors.Rows.Add(new object[] {pk,
                                                                            Convert.ToInt32(li.Value),
                                                                            DateTime.Now,
                                                                            DateTime.Now});
            }

            if (dtIngredientFlavors.Rows.Count > 0) simpleData.Update(dtIngredientFlavors, false);

            // Save out IngredientDrink links ##################################################################
            DataTable dtIngredientDrinkLink = simpleData.FetchForUpdate("DrinkIngredient2", new string[] { "DrinkID", "IngredientID" }, "IngredientID", pk);
            dtIngredientDrinkLink.Constraints.Clear();

            foreach (DataRow row in dtIngredientDrinkLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtIngredientDrinkLink, false);

            foreach (UltraGridRow row in _ingredientDrinkGrid.Rows)
            {
                dtIngredientDrinkLink.Rows.Add(new object[] {row.Cells.FromKey("DrinkID").Value,
                                                             pk});
            }

            if (_ingredientDrinkGrid.Rows.Count > 0) simpleData.Update(dtIngredientDrinkLink, false);

            // Save out IngredientIngredient links ##################################################################
            DataTable dtIngredientIngredientLink = simpleData.FetchForUpdate("IngredientIngredient", new string[] { "IngredientID1", "IngredientID2" }, "IngredientID1", pk);
            dtIngredientIngredientLink.Constraints.Clear();

            foreach (DataRow row in dtIngredientIngredientLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtIngredientIngredientLink, false);

            foreach (UltraGridRow row in _ingredientIngredientGrid.Rows)
            {
                dtIngredientIngredientLink.Rows.Add(new object[] {pk,
                                                                  row.Cells.FromKey("IngredientID2").Value});
            }

            if (_ingredientIngredientGrid.Rows.Count > 0) simpleData.Update(dtIngredientIngredientLink, false);

            // Save out IngredientArticle links ##################################################################
            DataTable dtIngredientArticleLink = simpleData.FetchForUpdate("IngredientArticle", new string[] { "IngredientID", "ArticleID" }, "IngredientID", pk);
            dtIngredientArticleLink.Constraints.Clear();

            foreach (DataRow row in dtIngredientArticleLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtIngredientArticleLink, false);

            foreach (UltraGridRow row in _ingredientArticleGrid.Rows)
            {
                dtIngredientArticleLink.Rows.Add(new object[] {pk,
                                                               row.Cells.FromKey("ArticleID").Value});
            }

            if (_ingredientArticleGrid.Rows.Count > 0) simpleData.Update(dtIngredientArticleLink, false);

            Response.Redirect("Ingredients.aspx", true);
        }
Example #21
0
        public static string GetSimilarIngredientsHtmlOld(int ingredientID, int categoryID, int brandID, int flavor1ID, int flavor2ID)
        {
            // First, get the ingredient's name
            DataView dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                    "GetIngredients",
                                                    "Ingredient_pk",
                                                     null);

            dataView.RowFilter = "Ingredient_pk = " + Convert.ToString(ingredientID);
            string ingredientName = (string)dataView[0]["Name"];

            // Now get similar drinks/ingredients
            StringBuilder sb = new StringBuilder();
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable dtSimilar = simpleData.FetchSP("GetIngredientSimilar", new SqlParameter[] { new SqlParameter("IngredientID", ingredientID),
                                                                                                  new SqlParameter("CategoryID", categoryID),
                                                                                                  new SqlParameter("BrandID", brandID),
                                                                                                  new SqlParameter("Flavor1ID", flavor1ID),
                                                                                                  new SqlParameter("Flavor2ID", flavor2ID) });
            DataRow[] matchedRows;

            // Drinks that use this ingredient
            matchedRows = dtSimilar.Select("SimilarType = 'drink'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Drinks that use " + ingredientName + "</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"drinks/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            if (matchedRows.Length == 0)
            {// There are no drinks that directly use this ingredient--find drinks that use child category ingredients

                matchedRows = dtSimilar.Select("SimilarType = 'drinkchildren'", "Description ASC");
                if (matchedRows.Length > 0)
                {
                    // Get ingredient category name
                    DataView dv = CacheManager.GetItem(CacheManager.Cache_GetDrinkCategories,
                                                      "GetListItems",
                                                      "ListItem_pk",
                                                       new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.IngredientCategory)) });

                    dv.RowFilter = "ListItem_pk = " + Convert.ToString(categoryID);
                    string categoryName = (string)dv[0]["Name"];

                    sb.Append("<h4>Drinks that use " + categoryName + "</h4>");
                    sb.Append(@"<ul class=""unstyled"">");

                    foreach (DataRow row in matchedRows)
                    {
                        sb.Append(@"<li>");
                        sb.Append(@"<a href=""");
                        sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                        sb.Append(@"drinks/");
                        sb.Append(Convert.ToString(row["PK"]));
                        sb.Append("-");
                        sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                        sb.Append(@""">");
                        sb.Append((string)row["Description"]);
                        sb.Append(@"</a></li>");
                    }

                    sb.Append(@"</ul>");
                }
            }

            // Ingredients with the same category
            matchedRows = dtSimilar.Select("SimilarType = 'category'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Ingredients in the same category</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"ingredients/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            // Ingredients with the same brand
            matchedRows = dtSimilar.Select("SimilarType = 'brand'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Ingredients from the same brand</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"ingredients/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            // Ingredients with the same flavors
            matchedRows = dtSimilar.Select("SimilarType = 'flavor'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Ingredients with similar flavors</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"ingredients/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            return sb.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["pk"] == "0")
            {// No primary key--add mode

                _pageMode = Constant.PageMode.Add;
            }
            else
            {// We have a primary key--edit mode

                _pageMode = Constant.PageMode.Edit;
            }

            DataTable dataTable;
            DataRow foundRow;
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get ingredient data from db
            if (_pageMode == Constant.PageMode.Add)
            {
                DataTable dtTemp = simpleData.FetchSP("GetIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });
                _drIngredient = dtTemp.NewRow();
            }
            else
            {
                _drIngredient = simpleData.FetchSP("GetIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) }).Rows[0];
            }

            _dtIngredientFlavors = simpleData.FetchSP("GetIngredientFlavors", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });
            _dtIngredientFlavors.PrimaryKey = new DataColumn[] { _dtIngredientFlavors.Columns["ListItem_pk"] };

            // Title
            if (_drIngredient["IngredientName"] != DBNull.Value) _titleLiteral.Text = (string)_drIngredient["IngredientName"];

            // Load combo items #############################################################################
            // Category
            dataTable = simpleData.FetchSP("GetListItemsTreeDepthFirst", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.IngredientCategory)) });
            _categoryCombo.DataSource = dataTable;
            _categoryCombo.DataBind();

            // Brands
            dataTable = simpleData.FetchSP("GetBrands", null);
            _brandCombo.DataSource = dataTable;
            _brandCombo.DataBind();
            _brandCombo.Items.Insert(0, new ListItem(Constant.NotSpecifiedDescription, Convert.ToString(Constant.NotSpecifiedValue)));

            // Countries
            dataTable = simpleData.FetchSP("GetListItems", new SqlParameter[] { new SqlParameter("ListID", Convert.ToInt32(Constant.List.Country)) });
            _countryCombo.DataSource = dataTable;
            _countryCombo.DataBind();
            _countryCombo.Items.Insert(0, new ListItem(Constant.NotSpecifiedDescription, Convert.ToString(Constant.NotSpecifiedValue)));

            // Flavors are done in Page_Init

            // Set control states ############################################################################
            if (Page.IsPostBack)
            {// In postback

                // Grab dropdown values from form object (so we don't need to use viewstate)
                _categoryCombo.SelectedValue = Request.Form[_categoryCombo.UniqueID];
                _brandCombo.SelectedValue = Request.Form[_brandCombo.UniqueID];
                _countryCombo.SelectedValue = Request.Form[_countryCombo.UniqueID];
                _descriptionText.Text = Request.Form[_descriptionText.UniqueID];
                _notesText.Text = Request.Form[_notesText.UniqueID];
            }
            else
            {// Not in postback

                if (_pageMode == Constant.PageMode.Edit)
                {// Edit

                    // Name
                    _nameText.Text = (string)_drIngredient["IngredientName"];

                    // Name Plural
                    _namePluralText.Text = (string)_drIngredient["IngredientNamePlural"];

                    // Category
                    if (_drIngredient["CategoryID"] == DBNull.Value) _categoryCombo.SelectedIndex = 0;
                    else _categoryCombo.SelectedValue = Convert.ToString(_drIngredient["CategoryID"]);

                    // Brand
                    if (_drIngredient["BrandID"] == DBNull.Value) _brandCombo.SelectedIndex = 0;
                    else _brandCombo.SelectedValue = Convert.ToString(_drIngredient["BrandID"]);

                    // Country
                    if (_drIngredient["CountryID"] == DBNull.Value) _countryCombo.SelectedIndex = 0;
                    else _countryCombo.SelectedValue = Convert.ToString(_drIngredient["CountryID"]);

                    // Flavors
                    foreach (ListItem li in _flavorList.Items)
                    {
                        foundRow = _dtIngredientFlavors.Rows.Find(li.Value);
                        if (foundRow != null) li.Selected = true;
                    }

                    // Proof
                    _proofNumber.Value = (decimal)_drIngredient["Proof"];

                    // Dissolved Volume Ratio
                    _dissolvedVolumeRatioNumber.Value = (decimal)_drIngredient["DissolvedVolumeRatio"];

                    // URL
                    _urlText.Text = (string)_drIngredient["IngredientURL"];

                    // Flavor profile
                    if (_drIngredient["Body"] != DBNull.Value) _bodyNumber.Value = (decimal)_drIngredient["Body"];
                    if (_drIngredient["Sweet"] != DBNull.Value) _sweetNumber.Value = (decimal)_drIngredient["Sweet"];
                    if (_drIngredient["Sour"] != DBNull.Value) _sourNumber.Value = (decimal)_drIngredient["Sour"];
                    if (_drIngredient["FreshFruit"] != DBNull.Value) _freshFruitNumber.Value = (decimal)_drIngredient["FreshFruit"];
                    if (_drIngredient["DriedFruit"] != DBNull.Value) _driedFruitNumber.Value = (decimal)_drIngredient["DriedFruit"];
                    if (_drIngredient["Spice"] != DBNull.Value) _spiceNumber.Value = (decimal)_drIngredient["Spice"];
                    if (_drIngredient["Heat"] != DBNull.Value) _heatNumber.Value = (decimal)_drIngredient["Heat"];
                    if (_drIngredient["Wood"] != DBNull.Value) _woodNumber.Value = (decimal)_drIngredient["Wood"];

                    // Description
                    _descriptionText.Text = (string)_drIngredient["Description"];

                    // Notes
                    _notesText.Text = (string)_drIngredient["Notes"];

                    // IngredientDrink grid
                    _dtIngredientDrink2 = simpleData.FetchSP("GetLinkedDrinksForIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });
                    _ingredientDrinkGrid.DataSource = _dtIngredientDrink2;
                    _ingredientDrinkGrid.DataBind();

                    // IngredientIngredient grid
                    _dtIngredientIngredient = simpleData.FetchSP("GetLinkedIngredientsForIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });
                    _ingredientIngredientGrid.DataSource = _dtIngredientIngredient;
                    _ingredientIngredientGrid.DataBind();

                    // IngredientArticle grid
                    _dtIngredientArticle = simpleData.FetchSP("GetLinkedArticlesForIngredient", new SqlParameter[] { new SqlParameter("IngredientID", Request.QueryString["pk"]) });
                    _ingredientArticleGrid.DataSource = _dtIngredientArticle;
                    _ingredientArticleGrid.DataBind();
                }
                else
                {// Add

                    _dissolvedVolumeRatioNumber.Value = 1;
                }
            }

            // Set up IngredientDrink grid #######################################################################
            _ingredientDrinkGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _ingredientDrinkGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _ingredientDrinkGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _ingredientDrinkGrid.DisplayLayout.AddNewBox.Hidden = false;
            _ingredientDrinkGrid.Bands[0].AddButtonCaption = "Add New Drink Link";
            _ingredientDrinkGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _ingredientDrinkGrid.Bands[0].Columns.Add("IngredientID", "IngredientID");
                _ingredientDrinkGrid.Bands[0].Columns.Add("DrinkID", "DrinkID");
            }

            _ingredientDrinkGrid.Bands[0].Columns.FromKey("IngredientID").Hidden = true;
            _ingredientDrinkGrid.Bands[0].Columns.FromKey("DrinkID").Width = Unit.Percentage(100);
            _ingredientDrinkGrid.Bands[0].Columns.FromKey("DrinkID").Type = ColumnType.DropDownList;
            _ingredientDrinkGrid.Bands[0].Columns.FromKey("DrinkID").DefaultValue = DBNull.Value;

            // Drink valuelist
            _vlDrink = new ValueList();
            _dtDrink = simpleData.FetchSP("GetDrinks", null);
            _vlDrink.DataSource = _dtDrink;
            _vlDrink.DisplayMember = "Name";
            _vlDrink.ValueMember = "Drink_pk";
            _vlDrink.DataBind();
            _vlDrink.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _ingredientDrinkGrid.Bands[0].Columns.FromKey("DrinkID").ValueList = _vlDrink;

            // Set up IngredientIngredient grid #######################################################################
            _ingredientIngredientGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _ingredientIngredientGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _ingredientIngredientGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _ingredientIngredientGrid.DisplayLayout.AddNewBox.Hidden = false;
            _ingredientIngredientGrid.Bands[0].AddButtonCaption = "Add New Ingredient Link";
            _ingredientIngredientGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _ingredientIngredientGrid.Bands[0].Columns.Add("IngredientID1", "IngredientID1");
                _ingredientIngredientGrid.Bands[0].Columns.Add("IngredientID2", "IngredientID2");
            }

            _ingredientIngredientGrid.Bands[0].Columns.FromKey("IngredientID1").Hidden = true;
            _ingredientIngredientGrid.Bands[0].Columns.FromKey("IngredientID2").Width = Unit.Percentage(100);
            _ingredientIngredientGrid.Bands[0].Columns.FromKey("IngredientID2").Type = ColumnType.DropDownList;
            _ingredientIngredientGrid.Bands[0].Columns.FromKey("IngredientID2").DefaultValue = DBNull.Value;

            // Drink valuelist
            _vlDrink = new ValueList();
            _dtDrink = simpleData.FetchSP("GetIngredients", null);
            _vlDrink.DataSource = _dtDrink;
            _vlDrink.DisplayMember = "Name";
            _vlDrink.ValueMember = "Ingredient_pk";
            _vlDrink.DataBind();
            _vlDrink.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _ingredientIngredientGrid.Bands[0].Columns.FromKey("IngredientID2").ValueList = _vlDrink;

            // Set up IngredientArticle grid #######################################################################
            _ingredientArticleGrid.DisplayLayout.AllowAddNewDefault = AllowAddNew.Yes;
            _ingredientArticleGrid.DisplayLayout.AllowDeleteDefault = AllowDelete.Yes;
            _ingredientArticleGrid.DisplayLayout.CellClickActionDefault = CellClickAction.Edit;
            _ingredientArticleGrid.DisplayLayout.AddNewBox.Hidden = false;
            _ingredientArticleGrid.Bands[0].AddButtonCaption = "Add New Article Link";
            _ingredientArticleGrid.DisplayLayout.RowSelectorsDefault = RowSelectors.Yes;

            if (_pageMode == Constant.PageMode.Add)
            {// Add mode--need to build columns

                _ingredientArticleGrid.Bands[0].Columns.Add("IngredientID", "IngredientID");
                _ingredientArticleGrid.Bands[0].Columns.Add("ArticleID", "ArticleID");
            }

            _ingredientArticleGrid.Bands[0].Columns.FromKey("IngredientID").Hidden = true;
            _ingredientArticleGrid.Bands[0].Columns.FromKey("ArticleID").Width = Unit.Percentage(100);
            _ingredientArticleGrid.Bands[0].Columns.FromKey("ArticleID").Type = ColumnType.DropDownList;
            _ingredientArticleGrid.Bands[0].Columns.FromKey("ArticleID").DefaultValue = DBNull.Value;

            // Article valuelist
            _vlArticle = new ValueList();
            _dtArticle = simpleData.FetchSP("GetArticles", null);
            _vlArticle.DataSource = _dtArticle;
            _vlArticle.DisplayMember = "Title";
            _vlArticle.ValueMember = "Article_pk";
            _vlArticle.DataBind();
            _vlArticle.DisplayStyle = ValueListDisplayStyle.DisplayText;
            _ingredientArticleGrid.Bands[0].Columns.FromKey("ArticleID").ValueList = _vlArticle;
        }
Example #23
0
        public static string GetSimilarDrinksHtmlOld(int drinkID, int categoryID, int familyID, int structureID, int flavor1ID, int flavor2ID, int flavor3ID, int glassID)
        {
            StringBuilder sb = new StringBuilder();
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable dtSimilar = simpleData.FetchSP("GetDrinkSimilar", new SqlParameter[] { new SqlParameter("DrinkID", drinkID),
                                                                                             new SqlParameter("CategoryID", categoryID),
                                                                                             new SqlParameter("FamilyID", familyID),
                                                                                             new SqlParameter("StructureID", structureID),
                                                                                             new SqlParameter("Flavor1ID", flavor1ID),
                                                                                             new SqlParameter("Flavor2ID", flavor2ID),
                                                                                             new SqlParameter("Flavor3ID", flavor3ID),
                                                                                             new SqlParameter("GlassID", glassID) });
            DataRow[] matchedRows;

            // Drinks in the same category (using structure under the covers)
            matchedRows = dtSimilar.Select("SimilarType = 'structure'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Drinks in the same category</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"drinks/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            // Drinks with the same flavors
            matchedRows = dtSimilar.Select("SimilarType = 'flavor'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Drinks with similar flavors</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"drinks/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            // Drinks with the same glass
            matchedRows = dtSimilar.Select("SimilarType = 'glass'", "Description ASC");
            if (matchedRows.Length > 0)
            {
                sb.Append("<h4>Drinks served in the same glass</h4>");
                sb.Append(@"<ul class=""unstyled"">");

                foreach (DataRow row in matchedRows)
                {
                    sb.Append(@"<li>");
                    sb.Append(@"<a href=""");
                    sb.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    sb.Append(@"drinks/");
                    sb.Append(Convert.ToString(row["PK"]));
                    sb.Append("-");
                    sb.Append(AppUtility.Utility.UrlEncode((string)row["Description"]));
                    sb.Append(@""">");
                    sb.Append((string)row["Description"]);
                    sb.Append(@"</a></li>");
                }

                sb.Append(@"</ul>");
            }

            return sb.ToString();
        }
Example #24
0
        public static DataTable GetSimilarDrinksDataTable(int drinkID, int structureID, int glassID)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable dtSimilar = simpleData.FetchSP("GetDrinkSimilar", new SqlParameter[] { new SqlParameter("DrinkID", drinkID),
                                                                                             new SqlParameter("StructureID", structureID),
                                                                                             new SqlParameter("GlassID", glassID) });
            return dtSimilar;
        }
Example #25
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            // Get drink data from db
            _drDrink = simpleData.FetchSP("GetDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) }).Rows[0];

            // Get drink data from cache
            DataView dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                    "GetDrinks",
                                                    "Drink_pk",
                                                     null);

            dataView.RowFilter = "Drink_pk = " + Request.QueryString["pk"];

            // Get source data from cache
            DataView sourceView = CacheManager.GetItem(CacheManager.Cache_GetSourcesPublic,
                                                       "GetSourcesPublic",
                                                       "Source_pk",
                                                       null);

            if (dataView.Count > 0)
            {
                _drDrinkCache = dataView.ToTable().Rows[0];

                // Populate fields ##############################################################################
                this.Title = (string)_drDrinkCache["Name"];

                _servingsLiteral.Text = ((Decimal)_drDrinkCache["Servings"]).ToString("###.#");

                _categoryLink.NavigateUrl = @"Drinks/Browse/Category/" + Convert.ToString(_drDrinkCache["CategoryID"]) + "-" + AppUtility.Utility.UrlEncode((string)_drDrinkCache["CategoryName"]) + "/";
                _categoryLink.Text = (string)_drDrinkCache["CategoryName"];

                _familyLink.Text = (string)_drDrinkCache["FamilyName"];
                if (_familyLink.Text.Trim().Length > 0) _familyLink.NavigateUrl = @"Drinks/Browse/Family/" + Convert.ToString(_drDrinkCache["FamilyID"]) + "-" + AppUtility.Utility.UrlEncode((string)_drDrinkCache["FamilyName"]) + "/";

                _structureLink.Text = (string)_drDrinkCache["StructureName"];
                if (_structureLink.Text.Trim().Length > 0) _structureLink.NavigateUrl = @"Drinks/Browse/Structure/" + Convert.ToString(_drDrinkCache["StructureID"]) + "-" + AppUtility.Utility.UrlEncode((string)_drDrinkCache["StructureName"]) + "/";

                // Attributes are down below

                _proofLiteral.Text = ((Decimal)_drDrinkCache["FinalProof"]).ToString("###.#");

                _strengthLiteral.Text = ((Decimal)_drDrinkCache["Strength"]).ToString("###.#");

                // Flavors are down below

                _glassLink.NavigateUrl = @"Drinks/Browse/Glass/" + Convert.ToString(_drDrinkCache["GlassID"]) + "-" + AppUtility.Utility.UrlEncode((string)_drDrinkCache["GlassName"]) + "/";
                _glassLink.Text = (string)_drDrinkCache["GlassName"];

                _tempLink.NavigateUrl = @"Drinks/Browse/Temp/" + Convert.ToString(_drDrinkCache["TempID"]) + "-" + AppUtility.Utility.UrlEncode((string)_drDrinkCache["TempName"]) + "/";
                _tempLink.Text = (string)_drDrinkCache["TempName"];

                // Sources ###############################################
                DataTable dtDrinkSource = simpleData.FetchSP("GetSourcesForDrink", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                StringBuilder sourceList = new StringBuilder();

                foreach (DataRow row in dtDrinkSource.Rows)
                {
                    if ((int)row["SourceID"] != 1)  // Hide if Charles is the source
                    {
                        sourceView.RowFilter = "Source_pk = " + Convert.ToString(row["SourceID"]);

                        sourceList.Append(@"<a href=""");
                        sourceList.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                        sourceList.Append(@"Resources/");
                        sourceList.Append(Convert.ToString(row["SourceID"]));
                        sourceList.Append("-");
                        sourceList.Append(AppUtility.Utility.UrlEncode(Convert.ToString(sourceView[0]["Name"])));
                        sourceList.Append(@"/"">");
                        sourceList.Append(Convert.ToString(sourceView[0]["Name"]));
                        sourceList.Append(@"</a>, ");
                    }
                }

                // Chop off trailing comma
                if (sourceList.Length > 0) sourceList.Remove(sourceList.Length - 2, 2);

                if (sourceList.Length > 0) _sourceLiteral.Text = sourceList.ToString();
                else _sourceRow.Visible = false;                                            // no sources so hide this field

                _instructionsLiteral.Text = WebUtility.ConvertDBDescriptionToHTML((string)_drDrink["Instructions"]);

                if (((string)_drDrink["Notes"]).Trim() != string.Empty)
                    _notesLiteral.Text = WebUtility.ConvertDBDescriptionToHTML((string)_drDrink["Notes"]);
                else
                    _notesH2.Visible = false;

                // Get ingredients
                _dtIngredient = simpleData.FetchSP("GetDrinkIngredients", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });
                _ingredients.DataSource = _dtIngredient;
                _ingredients.DataBind();

                // Ingredient Profile #####################################
                _dtIngredientProfile = new DataTable();
                _dtIngredientProfile.Columns.Add("Amount", typeof(decimal));
                _dtIngredientProfile.Columns.Add("Name", typeof(string));

                foreach (DataRow row in _dtIngredient.Rows)
                {
                    _dtIngredientProfile.Rows.Add(new object[] { row["AmountWeighted"], row["IngredientName"] });
                }

                _chart.BackgroundImageFileName = Server.MapPath("~") + @"\image\gradient_Drink.png";
                _chart.ColorModel.CustomPalette = AppUtility.Constant.ChartPalette;
                _chart.ColorModel.ModelStyle = Infragistics.UltraChart.Shared.Styles.ColorModels.CustomLinear;
                _chart.DeploymentScenario.ImageURL = ConfigurationManager.AppSettings["SiteUrl"] + _chart.DeploymentScenario.ImageURL;
                _chart.DataSource = _dtIngredientProfile;
                _chart.DataBind();

                // Attributes ################################################
                DataTable dataTableAttributes = simpleData.FetchSP("GetDrinkAttributes", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });

                StringBuilder attributes = new StringBuilder();
                foreach (DataRow row in dataTableAttributes.Rows)
                {
                    attributes.Append(@"<a href=""");
                    attributes.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    attributes.Append(@"Drinks/Browse/Attribute/");
                    attributes.Append(Convert.ToString(row["ListItem_pk"]));
                    attributes.Append("-");
                    attributes.Append(AppUtility.Utility.UrlEncode(Convert.ToString(row["Name"])));
                    attributes.Append(@"/"">");
                    attributes.Append(Convert.ToString(row["Name"]));
                    attributes.Append(@"</a>, ");
                }

                // Chop off trailing comma
                if (attributes.Length > 0) attributes.Remove(attributes.Length - 2, 2);

                _attributesLiteral.Text = attributes.ToString();

                // Flavors ################################################
                DataTable dtFlavors = simpleData.FetchSP("GetDrinkFlavors", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });

                StringBuilder flavors = new StringBuilder();
                foreach (DataRow row in dtFlavors.Rows)
                {
                    flavors.Append(@"<a href=""");
                    flavors.Append(ConfigurationManager.AppSettings["SiteUrl"]);
                    flavors.Append(@"Drinks/Browse/Flavor/");
                    flavors.Append(Convert.ToString(row["ListItem_pk"]));
                    flavors.Append("-");
                    flavors.Append(AppUtility.Utility.UrlEncode(Convert.ToString(row["Name"])));
                    flavors.Append(@"/"">");
                    flavors.Append(Convert.ToString(row["Name"]));
                    flavors.Append(@"</a>, ");
                }

                // Chop off trailing comma
                if (flavors.Length > 0) flavors.Remove(flavors.Length - 2, 2);

                _flavorsLiteral.Text = flavors.ToString();

                // Do right column content targeted to this ingredient
                int flavor1ID = -1;
                int flavor2ID = -1;
                int flavor3ID = -1;
                if (dtFlavors.Rows.Count > 0) flavor1ID = (int)dtFlavors.Rows[0]["ListItem_pk"];
                if (dtFlavors.Rows.Count > 1) flavor2ID = (int)dtFlavors.Rows[1]["ListItem_pk"];
                if (dtFlavors.Rows.Count > 2) flavor2ID = (int)dtFlavors.Rows[2]["ListItem_pk"];

                this.RightColumn.Controls.Add(new LiteralControl(CharlesThompson.LiquorAndDrink.AppUI.Content.GetSimilarDrinksHtmlOld(Convert.ToInt32(Request.QueryString["pk"]),
                                                                                                                                  (int)_drDrinkCache["CategoryID"],
                                                                                                                                  (int)_drDrinkCache["FamilyID"],
                                                                                                                                  (int)_drDrinkCache["StructureID"],
                                                                                                                                   flavor1ID,
                                                                                                                                   flavor2ID,
                                                                                                                                   flavor3ID,
                                                                                                                                  (int)_drDrinkCache["GlassID"])));
                // Log this drink
                LogDrink(Convert.ToInt32(Request.QueryString["pk"]));

                // Get drink links in right column
                DataTable dtDrinkLinks = simpleData.FetchSP("GetDrinkLinks", new SqlParameter[] { new SqlParameter("DrinkID", Request.QueryString["pk"]) });

                this.RightColumn.Controls.Add(new LiteralControl(CharlesThompson.LiquorAndDrink.AppUI.Content.GetLinkBoxHtml(dtDrinkLinks)));

                // Set page meta tags
                HtmlMeta meta = new HtmlMeta();
                meta.Name = "description";
                string metaContent = AppUI.Content.GetDrinkMetaDescription(_drDrink, _dtIngredient);
                meta.Content = metaContent;
                this.Header.Controls.Add(meta);

                // Set ShareThis header script
                this.Header.Controls.Add(new LiteralControl(CacheManager.GetItem(CacheManager.Cache_FileShareThisHeaderScript)));

                // Do share box button script
                StringBuilder shareScript = new StringBuilder();
                _shareDiv.Controls.Add(new LiteralControl(AppUI.Content.GetShareButtonScript(((string)_drDrinkCache["Name"]).Replace("'", ""),
                                                                                               metaContent,
                                                                                               ConfigurationManager.AppSettings["SiteUrl"] + "Drinks/" + Convert.ToString(_drDrink["Drink_pk"]) + "-" + Utility.UrlEncode((string)_drDrink["Name"]))));
            }
        }
Example #26
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["desc"] != null)
            {// This is not a generic search--it is a browse filter--figure out page title

                if (Request.QueryString["filter"] == "search")
                {// Doing a one parameter search to impersonate a browse

                    if (Request.QueryString["attr"] != null)
                        Page.Title = "Browse Drinks - By Attribute - " + CharlesThompson.LiquorAndDrink.AppUtility.Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["ingred"] != null)
                        Page.Title = "Browse Drinks - By Ingredient - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["brand"] != null)
                        Page.Title = "Browse Drinks - By Ingredient Brand - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["flavor"] != null)
                        Page.Title = "Browse Drinks - By Flavor - " + Shared.UrlDecode(Request.QueryString["desc"]);
                }
                else
                {// Doing an actual browse

                    if (Request.QueryString["filter"] == "cat")
                        Page.Title = "Browse Drinks - By Category - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["filter"] == "family")
                        Page.Title = "Browse Drinks - By Family - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["filter"] == "struct")
                        Page.Title = "Browse Drinks - By Structure - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["filter"] == "glass")
                        Page.Title = "Browse Drinks - By Glass - " + Shared.UrlDecode(Request.QueryString["desc"]);

                    else if (Request.QueryString["filter"] == "temp")
                        Page.Title = "Browse Drinks - By Temperature - " + Shared.UrlDecode(Request.QueryString["desc"]);
                }
            }
            else
            {// These don't use a desc

                if (Request.QueryString["filter"] == "proof")
                {
                    if (Request.QueryString["value2"] == "0")
                        Page.Title = "Browse Drinks - By Alcohol Proof - No Alcohol";
                    else
                        Page.Title = "Browse Drinks - By Alcohol Proof - " + Request.QueryString["value1"] + " to " + Request.QueryString["value2"] + " Proof";
                }

                else if (Request.QueryString["filter"] == "strength")
                {
                    switch (Request.QueryString["value2"])
                    {
                        case "0": Page.Title = "Browse Drinks - By Alcohol Strength - No Alcohol"; break;
                        case "0.5": Page.Title = "Browse Drinks - By Alcohol Strength - Weak"; break;
                        case "1.5": Page.Title = "Browse Drinks - By Alcohol Strength - Single"; break;
                        case "2.5": Page.Title = "Browse Drinks - By Alcohol Strength - Double"; break;
                        case "3.5": Page.Title = "Browse Drinks - By Alcohol Strength - Triple"; break;
                        case "4.5": Page.Title = "Browse Drinks - By Alcohol Strength - Quadruple"; break;
                    }
                }

                else if (Request.QueryString["filter"] == "name")
                    Page.Title = "Browse Drinks - By Name";

                else
                {// Must be a genuine search

                    Page.Title = "Search Drinks - Results";
                }
            }

            SqlParameter[] sqlParameters = new SqlParameter[19];

            // First, fill out blank parameters.  If a parameter is going to be used, it will be filled out below.
            // SqlParemeterCollection can't have nulls in it.
            sqlParameters[0] = new SqlParameter("Name", null);
            sqlParameters[1] = new SqlParameter("InstructionsAndNotes", null);
            sqlParameters[2] = new SqlParameter("CategoryID", null);
            sqlParameters[3] = new SqlParameter("FamilyID", null);
            sqlParameters[4] = new SqlParameter("StructureID", null);
            sqlParameters[5] = new SqlParameter("AttributeID", null);
            sqlParameters[6] = new SqlParameter("IngredientID", null);
            sqlParameters[7] = new SqlParameter("IngredientBrandID", null);
            sqlParameters[8] = new SqlParameter("AlcoholProof1", null);
            sqlParameters[9] = new SqlParameter("AlcoholProof2", null);
            sqlParameters[10] = new SqlParameter("AlcoholStrength1", null);
            sqlParameters[11] = new SqlParameter("AlcoholStrength2", null);
            sqlParameters[12] = new SqlParameter("FlavorID", null);
            sqlParameters[13] = new SqlParameter("GlassID", null);
            sqlParameters[14] = new SqlParameter("TempID", null);
            sqlParameters[15] = new SqlParameter("PageNum", 1);
            sqlParameters[16] = new SqlParameter("PageSize", 5000);

            if (Request.QueryString["name"] != null)
            {
                sqlParameters[0] = new SqlParameter("Name", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "Name", DataRowVersion.Current, Request.QueryString["name"]);
            }

            if (Request.QueryString["in"] != null)
            {
                sqlParameters[1] = new SqlParameter("InstructionsAndNotes", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "InstructionsAndNotes", DataRowVersion.Current, Request.QueryString["in"]);
            }

            if (Request.QueryString["cat"] != null)
            {
                sqlParameters[2] = new SqlParameter("CategoryID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "CategoryID", DataRowVersion.Current, Request.QueryString["cat"]);
            }

            if (Request.QueryString["fam"] != null)
            {
                sqlParameters[3] = new SqlParameter("FamilyID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "FamilyID", DataRowVersion.Current, Request.QueryString["fam"]);
            }

            if (Request.QueryString["struct"] != null)
            {
                sqlParameters[4] = new SqlParameter("StructureID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "StructureID", DataRowVersion.Current, Request.QueryString["struct"]);
            }

            if (Request.QueryString["attr"] != null)
            {
                sqlParameters[5] = new SqlParameter("AttributeID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AttributeID", DataRowVersion.Current, Request.QueryString["attr"]);
            }

            if (Request.QueryString["ingred"] != null)
            {
                sqlParameters[6] = new SqlParameter("IngredientID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "PrincipalIngredientID", DataRowVersion.Current, Request.QueryString["ingred"]);
            }

            if (Request.QueryString["brand"] != null)
            {
                sqlParameters[7] = new SqlParameter("IngredientBrandID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "PrincipalIngredientBrandID", DataRowVersion.Current, Request.QueryString["brand"]);
            }

            if (Request.QueryString["proof1"] != null)
            {
                sqlParameters[8] = new SqlParameter("AlcoholProof1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof1", DataRowVersion.Current, Request.QueryString["proof1"]);
            }

            if (Request.QueryString["proof2"] != null)
            {
                sqlParameters[9] = new SqlParameter("AlcoholProof2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof2", DataRowVersion.Current, Request.QueryString["proof2"]);
            }

            if (Request.QueryString["strength1"] != null)
            {
                sqlParameters[10] = new SqlParameter("AlcoholStrength1", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 5, 1, "AlcoholStrength1", DataRowVersion.Current, Request.QueryString["strength1"]);
            }

            if (Request.QueryString["strength2"] != null)
            {
                sqlParameters[11] = new SqlParameter("AlcoholStrength2", SqlDbType.Decimal, 0, ParameterDirection.Input, true, 5, 1, "AlcoholStrength2", DataRowVersion.Current, Request.QueryString["strength2"]);
            }

            if (Request.QueryString["flavor"] != null)
            {
                sqlParameters[12] = new SqlParameter("FlavorID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "FlavorID", DataRowVersion.Current, Request.QueryString["flavor"]);
            }

            if (Request.QueryString["glass"] != null)
            {
                sqlParameters[13] = new SqlParameter("GlassID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "GlassID", DataRowVersion.Current, Request.QueryString["glass"]);
            }

            if (Request.QueryString["temp"] != null)
            {
                sqlParameters[14] = new SqlParameter("TempID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "TempID", DataRowVersion.Current, Request.QueryString["temp"]);
            }

            // Add output parameters
            sqlParameters[17] = new SqlParameter("TotalPages", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalPages", DataRowVersion.Current, 0);
            sqlParameters[18] = new SqlParameter("TotalRows", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalRows", DataRowVersion.Current, 0);

            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            if (Request.QueryString["filter"] == "search")
            {// Full search requested--crank the search stored procedure

                _repeater.DataSource = simpleData.FetchSP("SearchDrinks", sqlParameters);
            }
            else
            {// Browse requested--filter on one column (hopefully from the cache)

                DataView dataView;

                switch (Request.QueryString["filter"])
                {
                    case "name":
                    // Filter by name (just show all)

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = String.Empty;
                        _repeater.DataSource = dataView;

                        break;

                    case "cat":
                    // Filter by category

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "CategoryID = " + Request.QueryString["value"];
                        _repeater.DataSource = dataView;

                        break;

                    case "family":
                    // Filter by family

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "FamilyID = " + Request.QueryString["value"];
                        _repeater.DataSource = dataView;

                        break;

                    case "struct":
                    // Filter by structure

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "StructureID = " + Request.QueryString["value"];
                        _repeater.DataSource = dataView;

                        break;

                    case "proof":
                    // Filter by alcohol proof

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "FinalProof >= " + Request.QueryString["value1"] + " AND FinalProof <= " + Request.QueryString["value2"];
                        _repeater.DataSource = dataView;

                        break;

                    case "strength":
                    // Filter by alcohol strength

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "Strength >= " + Request.QueryString["value1"] + " AND Strength <= " + Request.QueryString["value2"];
                        _repeater.DataSource = dataView;

                        break;

                    case "glass":
                    // Filter by glass

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "GlassID = " + Request.QueryString["value"];
                        _repeater.DataSource = dataView;

                        break;

                    case "temp":
                    // Filter by temperature

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetDrinks,
                                                       "GetDrinks",
                                                       "Drink_pk",
                                                        null);

                        dataView.RowFilter = "TempID = " + Request.QueryString["value"];
                        _repeater.DataSource = dataView;

                        break;
                }
            }

            _repeater.DataBind();
        }
Example #27
0
            public static void GetData(string cacheItemKey, 
                                       string storedProcedure, 
                                       string primaryKeyColumn, 
                                       SqlParameter[] sqlParameters)
            {
                // Since each request that saw the cache originally null
                // will eventually get here, need to ensure that it
                // has not already been retrieved by another request
                if (System.Web.HttpRuntime.Cache[cacheItemKey] == null)
                {// Cache is still empty--fill it from the database

                    SimpleData simpleData = new SimpleData();
                    ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
                    simpleData.ConnectionString = connectionStringSettings.ConnectionString;

                    DataTable dataTable = simpleData.FetchSP(storedProcedure, sqlParameters);
                    dataTable.PrimaryKey = new System.Data.DataColumn[] { dataTable.Columns[primaryKeyColumn] };

                    System.Web.HttpRuntime.Cache.Insert(cacheItemKey,
                                                        dataTable,
                                                        null,
                                                        DateTime.Now.AddMinutes(Convert.ToDouble(ConfigurationManager.AppSettings["CacheTimeout"])),
                                                        System.Web.Caching.Cache.NoSlidingExpiration);
                }
            }
        protected void Page_Load(object sender, EventArgs e)
        {
            int rowCount = 0;

            // Log page
            AppUtility.Utility.LogPage();

            if (Request.QueryString["desc"] != null)
            {// This is not a generic search--it is a browse filter--figure out page title

                if (Request.QueryString["filter"] == "search")
                {// Doing a one parameter search to impersonate a browse

                    if (Request.QueryString["cat"] != null)
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Category - " + WebUtility.TitleCase(AppUtility.Utility.UrlDecode(Request.QueryString["desc"]));

                    else if (Request.QueryString["flavor"] != null)
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Flavor - " + WebUtility.TitleCase(AppUtility.Utility.UrlDecode(Request.QueryString["desc"]));
                }
                else
                {// Doing an actual browse

                    if (Request.QueryString["filter"] == "brand")
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Brand - " + WebUtility.TitleCase(AppUtility.Utility.UrlDecode(Request.QueryString["desc"]));

                    else if (Request.QueryString["filter"] == "country")
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Country of Origin - " + WebUtility.TitleCase(AppUtility.Utility.UrlDecode(Request.QueryString["desc"]));
                }
            }
            else
            {// These don't use a desc

                if (Request.QueryString["filter"] == "proof")
                {
                    if (Request.QueryString["value2"] == "0")
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Alcohol Proof - No Alcohol";
                    else
                        ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Alcohol Proof - " + Request.QueryString["value1"] + " to " + Request.QueryString["value2"] + " Proof";
                }

                else if (Request.QueryString["filter"] == "name")
                {
                    ModuleConfiguration.ModuleTitle = "Cocktail Ingredients";
                    _metaDescription = "A huge list of cocktail ingredients.";
                }
                else if (Request.QueryString["filter"] == "inusebydrinks")
                {// drinks/browse/ingredient, browse drinks by ingredient, showing all ingredients in use in drinks

                    ModuleConfiguration.ModuleTitle = "Cocktail Ingredients";
                    _metaDescription = "A huge list of cocktail ingredients.";
                    _subheadParagraph.InnerText = "Click on a cocktail ingredient to see which drink recipes use it.";
                }
                else
                {// Must be a genuine search

                    ModuleConfiguration.ModuleTitle = "Liquor/Mixers - Search Results";
                }
            }

            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            SqlParameter[] sqlParameters = new SqlParameter[16];

            // First, fill out blank parameters.  If a parameter is going to be used, it will be filled out below.
            // SqlParemeterCollection can't have nulls in it.
            sqlParameters[0] = new SqlParameter("Name", null);
            sqlParameters[1] = new SqlParameter("DescriptionAndNotes", null);
            sqlParameters[2] = new SqlParameter("CategoryID", null);
            sqlParameters[3] = new SqlParameter("FlavorID", null);
            sqlParameters[4] = new SqlParameter("CountryID", null);
            sqlParameters[5] = new SqlParameter("BrandID", null);
            sqlParameters[6] = new SqlParameter("AlcoholProof1", null);
            sqlParameters[7] = new SqlParameter("AlcoholProof2", null);
            sqlParameters[8] = new SqlParameter("LADRating1", null);
            sqlParameters[9] = new SqlParameter("LADRating2", null);
            sqlParameters[10] = new SqlParameter("COMRating1", null);
            sqlParameters[11] = new SqlParameter("COMRating2", null);
            sqlParameters[12] = new SqlParameter("PageNum", 1);
            sqlParameters[13] = new SqlParameter("PageSize", 5000);

            if (Request.QueryString["name"] != null)
            {
                sqlParameters[0] = new SqlParameter("Name", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "Name", DataRowVersion.Current, Request.QueryString["name"]);
            }

            if (Request.QueryString["dn"] != null)
            {
                sqlParameters[1] = new SqlParameter("DescriptionAndNotes", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 0, 0, "DescriptionAndNotes", DataRowVersion.Current, Request.QueryString["dn"]);
            }

            if (Request.QueryString["cat"] != null)
            {
            //                DataTable dtCategory = simpleData.FetchSP("GetListItemsTreeAllChildren",
            //                                                           new SqlParameter[] { new SqlParameter("ListItemID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "ListItemID", DataRowVersion.Current, Request.QueryString["cat"]) });

                sqlParameters[2] = new SqlParameter("CategoryID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "CategoryID", DataRowVersion.Current, Request.QueryString["cat"]);
            }

            if (Request.QueryString["flavor"] != null)
            {
                sqlParameters[3] = new SqlParameter("FlavorID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "FlavorID", DataRowVersion.Current, Request.QueryString["flavor"]);
            }

            if (Request.QueryString["country"] != null)
            {
                sqlParameters[4] = new SqlParameter("CountryID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "CountryID", DataRowVersion.Current, Request.QueryString["country"]);
            }

            if (Request.QueryString["brand"] != null)
            {
                sqlParameters[5] = new SqlParameter("BrandID", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "BrandID", DataRowVersion.Current, Request.QueryString["brand"]);
            }

            if (Request.QueryString["proof1"] != null)
            {
                sqlParameters[6] = new SqlParameter("AlcoholProof1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof1", DataRowVersion.Current, Request.QueryString["proof1"]);
            }

            if (Request.QueryString["proof2"] != null)
            {
                sqlParameters[7] = new SqlParameter("AlcoholProof2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "AlcoholProof2", DataRowVersion.Current, Request.QueryString["proof2"]);
            }

            if (Request.QueryString["ladrating1"] != null)
            {
                sqlParameters[8] = new SqlParameter("LADRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating1", DataRowVersion.Current, Request.QueryString["ladrating1"]);
            }

            if (Request.QueryString["ladrating2"] != null)
            {
                sqlParameters[9] = new SqlParameter("LADRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "LADRating2", DataRowVersion.Current, Request.QueryString["ladrating2"]);
            }

            if (Request.QueryString["comrating1"] != null)
            {
                sqlParameters[10] = new SqlParameter("COMRating1", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "COMRating1", DataRowVersion.Current, Request.QueryString["comrating1"]);
            }

            if (Request.QueryString["comrating2"] != null)
            {
                sqlParameters[11] = new SqlParameter("COMRating2", SqlDbType.Int, 0, ParameterDirection.Input, true, 0, 0, "COMRating2", DataRowVersion.Current, Request.QueryString["comrating2"]);
            }

            // Add output parameters
            sqlParameters[14] = new SqlParameter("TotalPages", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalPages", DataRowVersion.Current, 0);
            sqlParameters[15] = new SqlParameter("TotalRows", SqlDbType.Int, 0, ParameterDirection.Output, true, 0, 0, "TotalRows", DataRowVersion.Current, 0);

            if (Request.QueryString["filter"] == "search")
            {// Full search requested--crank the search stored procedure

                _repeaterIngredient.DataSource = simpleData.FetchSP("SearchIngredients", sqlParameters);
                rowCount = ((DataTable)_repeaterIngredient.DataSource).Rows.Count;
            }
            else
            {// Browse requested--filter on one column (hopefully from the cache)

                DataView dataView = null;

                switch (Request.QueryString["filter"])
                {
                    case "name":
                    // Filter by name--just show all

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsWithDetailPage,
                                                       "GetIngredientsWithDetailPage",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = String.Empty;
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "cat":
                    // Filter by category--this is actually done as a one parameter search above
                        break;

                    case "country":
                    // Filter by country

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsWithDetailPage,
                                                       "GetIngredientsWithDetailPage",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "CountryID = " + Request.QueryString["value"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "brand":
                    // Filter by brand

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsWithDetailPage,
                                                       "GetIngredientsWithDetailPage",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "BrandID = " + Request.QueryString["value"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "proof":
                    // Filter by alcohol proof

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsWithDetailPage,
                                                       "GetIngredientsWithDetailPage",
                                                       "Ingredient_pk",
                                                        null);

                        dataView.RowFilter = "Proof >= " + Request.QueryString["value1"] + " AND Proof <= " + Request.QueryString["value2"];
                        _repeaterIngredient.DataSource = dataView;
                        break;

                    case "inusebydrinks":
                    // Filter by ingredients in use in drinks

                        dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredientsInUseByDrinks,
                                                       "GetIngredientsInUseByDrinks",
                                                       "Ingredient_pk",
                                                        null);

                        _repeaterDrink.DataSource = dataView;
                        break;
                }

                rowCount = dataView.Count;
            }

            if (Request.QueryString["filter"] == "inusebydrinks")
            {// Browse drinks by ingredient

                // Light up the ingredient/brand to drink repeater
                _repeaterDrink.DataBind();
            }
            else
            {// Browse ingredients by filter passed in

                if (Request.QueryString["type"] == "browse" && Request.QueryString["filter"] == "brand")
                {// A browse request was made for a list of ingredients that belong to a particular brand.  We do not do
                 // this kind of browsing anymore so throw a 404 instead.

                        HttpContext.Current.Response.StatusCode = 404;
                        HttpContext.Current.Response.End();
                }

                if (Request.QueryString["type"] == "browse" && Request.QueryString["filter"] == "country")
                {// A browse request was made for a list of ingredients from a particular country.  We do not do
                 // this kind of browsing anymore so throw a 404 instead.

                        HttpContext.Current.Response.StatusCode = 404;
                        HttpContext.Current.Response.End();
                }

                if (rowCount == 0)
                {// No records returned

                    if (Request.QueryString["type"] == "browse" && Request.QueryString["filter"] == "search" && Request.QueryString["cat"] != null)
                    {// A request was made for a list of ingredients for a particlar ingredient category.  We have cleaned
                     // out a long of categories.  If the request is for one of the categories that no longer exists, the
                     // page would just show a blank list.  This is not good for SEO so we need to throw a 404 instead.

                        HttpContext.Current.Response.StatusCode = 404;
                        HttpContext.Current.Response.End();
                    }

                    if (Request.QueryString["type"] == "browse" && Request.QueryString["filter"] == "search" && Request.QueryString["flavor"] != null)
                    {// A request was made for a list of ingredients with a particular flavor.  We have cleaned
                     // out a lot of flavors.  If the request is for one of the categories that no longer exists, the
                     // page would just show a blank list.  This is not good for SEO so we need to throw a 404 instead.

                        HttpContext.Current.Response.StatusCode = 404;
                        HttpContext.Current.Response.End();
                    }
                }

                // Light up the ingredients to ingredient repeater
                _repeaterIngredient.DataBind();
            }

            // Widgets
            // Send a message to any widget modules that are listening.
            ModuleCommunicationEventArgs args = new ModuleCommunicationEventArgs();
            args.Sender = "Headlines";
            args.Target = "Widget";
            args.Value = new List<string>() {AppUtility.AdRotator.GetAdsenseCode("adsense.list.200x90.linkunit")};

            if (ModuleCommunication != null)
            {
                ModuleCommunication(this, args);
            }

            // Log page
            AppUtility.Utility.LogPage();

            DoSEO();
        }
Example #29
0
        public static DataTable GetSimilarIngredientsDataTable(int ingredientID, int categoryID, int brandID, int flavor1ID, int flavor2ID)
        {
            // First, get the ingredient's name
            DataView dataView = CacheManager.GetItem(CacheManager.Cache_GetIngredients,
                                                    "GetIngredients",
                                                    "Ingredient_pk",
                                                     null);

            dataView.RowFilter = "Ingredient_pk = " + Convert.ToString(ingredientID);
            string ingredientName = (string)dataView[0]["IngredientName"];

            // Now get similar drinks/ingredients
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable dtSimilar = simpleData.FetchSP("GetIngredientSimilar", new SqlParameter[] { new SqlParameter("IngredientID", ingredientID),
                                                                                                  new SqlParameter("CategoryID", categoryID),
                                                                                                  new SqlParameter("BrandID", brandID),
                                                                                                  new SqlParameter("Flavor1ID", flavor1ID),
                                                                                                  new SqlParameter("Flavor2ID", flavor2ID) });
            return dtSimilar;
        }
Example #30
0
        protected void _saveButton_Click(object sender, EventArgs e)
        {
            SimpleData simpleData = new SimpleData();
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["db"];
            simpleData.ConnectionString = connectionStringSettings.ConnectionString;

            DataTable updateTable;

            // Save Article table fields #############################################################
            // Add a new row if this is an add
            if (_pageMode == Constant.PageMode.Add)
            {
                updateTable = simpleData.NewRow("Article", "Article_pk");
            }
            else
            {
                updateTable = simpleData.FetchForUpdate("Article", new string[] { "Article_pk" }, "Article_pk", Convert.ToInt32(Request.QueryString["pk"]));
            }

            updateTable.Rows[0]["Title"] = _titleText.Text;
            updateTable.Rows[0]["Subtitle"] = _subtitleText.Text;
            updateTable.Rows[0]["IconFile"] = _iconFileText.Text;
            updateTable.Rows[0]["Private"] = _privateCheck.Checked;

            updateTable.Rows[0]["Blurb"] = _blurbText.Text;
            updateTable.Rows[0]["Body"] = _bodyText.Text;

            if (_pageMode == Constant.PageMode.Add) updateTable.Rows[0]["Created"] = DateTime.Now;
            updateTable.Rows[0]["Updated"] = DateTime.Now;

            int pk = 0;

            if (_pageMode == Constant.PageMode.Add)
            {
                int ret = simpleData.Update(updateTable, true);
                pk = ret;
            }
            else
            {
                int ret = simpleData.Update(updateTable, false);
                pk = Convert.ToInt32(Request.QueryString["pk"]);
            }

            // Save out DrinkArticle links ##################################################################
            DataTable dtDrinkArticleLink = simpleData.FetchForUpdate("DrinkArticle", new string[] { "DrinkID", "ArticleID" }, "ArticleID", pk);
            dtDrinkArticleLink.Constraints.Clear();

            foreach (DataRow row in dtDrinkArticleLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtDrinkArticleLink, false);

            foreach (UltraGridRow row in _articleDrinkGrid.Rows)
            {
                dtDrinkArticleLink.Rows.Add(new object[] {row.Cells.FromKey("DrinkID").Value,
                                                          pk});
            }

            if (dtDrinkArticleLink.Rows.Count > 0) simpleData.Update(dtDrinkArticleLink, false);

            // Save out IngredientArticle links ##################################################################
            DataTable dtIngredientArticleLink = simpleData.FetchForUpdate("IngredientArticle", new string[] { "IngredientID", "ArticleID" }, "ArticleID", pk);
            dtIngredientArticleLink.Constraints.Clear();

            foreach (DataRow row in dtIngredientArticleLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtIngredientArticleLink, false);

            foreach (UltraGridRow row in _articleIngredientGrid.Rows)
            {
                dtIngredientArticleLink.Rows.Add(new object[] {row.Cells.FromKey("IngredientID").Value,
                                                               pk});
            }

            if (_articleIngredientGrid.Rows.Count > 0) simpleData.Update(dtIngredientArticleLink, false);

            // Save out ArticleArticle links ##################################################################
            DataTable dtArticleArticleLink = simpleData.FetchForUpdate("ArticleArticle", new string[] { "ArticleID1", "ArticleID2" }, "ArticleID1", pk);
            dtArticleArticleLink.Constraints.Clear();

            foreach (DataRow row in dtArticleArticleLink.Rows)
            {
                row.Delete();
            }

            simpleData.Update(dtArticleArticleLink, false);

            foreach (UltraGridRow row in _articleArticleGrid.Rows)
            {
                dtArticleArticleLink.Rows.Add(new object[] {pk,
                                                            row.Cells.FromKey("ArticleID2").Value});
            }

            if (dtArticleArticleLink.Rows.Count > 0) simpleData.Update(dtArticleArticleLink, false);

            Response.Redirect("Articles.aspx", true);
        }