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; }
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; }
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; }
// Create dynamic combos and add them to the grid public ValueList[] CreateCombos(ValueList[] _valueListCombos) { string sColumnaGrid = ""; string sTaulaCombo = ""; // bool FirstTime = true; // Create one WebCombo for each relation // if (_valueListCombos == null) // { _valueListCombos = new ValueList[_ds.Relations.Count]; // FirstTime = true; // } // else // { // FirstTime = false; // } for (int auxx = 0; auxx < _ds.Relations.Count; auxx++) { sColumnaGrid = _ds.Relations[auxx].ChildColumns[0].ColumnName; sTaulaCombo = _ds.Relations[auxx].ParentTable.TableName; // if (!FirstTime) // { // // Create a ValueList for Drop-Down // ValueList vl = _valueListCombos[auxx]; // vl.DataBind(); // // // Special table (Globalizes table CODES) // if (_ds.Tables[sTaulaCombo].TableName == "CODES") // { // _rm.GlobalizeTable(_ds.Tables[sTaulaCombo], "COD_LIT_ID", "COD_NEWDESC", true); // } // // _grid.Columns.FromKey(sColumnaGrid).AllowUpdate = _bReadOnly ? AllowUpdate.No : AllowUpdate.Yes; // _grid.Columns.FromKey(sColumnaGrid).Type = ColumnType.DropDownList; // _grid.Columns.FromKey(sColumnaGrid).ValueList.DisplayStyle = ValueListDisplayStyle.DisplayText; // _grid.Columns.FromKey(sColumnaGrid).ValueList = vl; // } // else // { // Special table (Globalizes table CODES) if (_ds.Tables[sTaulaCombo].TableName == "CODES") { _rm.GlobalizeTable(_ds.Tables[sTaulaCombo], "COD_LIT_ID", "COD_NEWDESC", true); } // Create a ValueList for Drop-Down ValueList vl = new ValueList(); vl.DataMember = sTaulaCombo; // Convention: The id of the filed always is field 0, and the description always 1. vl.ValueMember = _ds.Tables[sTaulaCombo].Columns[0].ColumnName; vl.DisplayMember = _ds.Tables[sTaulaCombo].Columns[1].ColumnName; vl.DataSource = _ds.Tables[sTaulaCombo]; vl.DataBind(); vl.ValueListItems.Insert(0, -999999, "-"); _grid.Columns.FromKey(sColumnaGrid).AllowUpdate = _bReadOnly ? AllowUpdate.No : AllowUpdate.Yes; _grid.Columns.FromKey(sColumnaGrid).Type = ColumnType.DropDownList; _grid.Columns.FromKey(sColumnaGrid).ValueList.DisplayStyle = ValueListDisplayStyle.DisplayText; _grid.Columns.FromKey(sColumnaGrid).ValueList = vl; _valueListCombos[auxx] = vl; // } } return(_valueListCombos); }