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); }
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 _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); }