public static void UpdateWithLastPrice(int IngredRno) { try { Ingred.IngredPurchase Last = Ingred.LastPurchase(IngredRno); Ingred Ing = new Ingred(IngredRno); if (Last != null) { Ing.UpdatePrice(Last.Qty * Last.UnitQty, Last.UnitRno, Last.Price); } else { // not last price, remove the currently set price Ing.UpdatePrice(); } } catch (Exception Ex) { Err Err = new Err(Ex); System.Web.HttpContext.Current.Response.Write(Err.Html()); } }
private void LoadConversions(int IngredRno) { if (IngredRno > 0) { String Sql = ""; try { Sql = string.Format( "Select IngredConvRno, c.PurchaseQty, c.RecipeQty, c.MissingFlg, " + "pu.UnitSingle As PurchaseUnitSingle, pu.UnitPlural As PurchaseUnitPlural, " + "ru.UnitSingle As RecipeUnitSingle, ru.UnitPlural As RecipeUnitPlural " + "From IngredConv c " + "Left Join Units pu On c.PurchaseUnitRno = pu.UnitRno " + "Left Join Units ru On c.RecipeUnitRno = ru.UnitRno " + "Where c.IngredRno = {0} " + "Order By pu.UnitSingle", IngredRno); DataTable dt = db.DataTable(Sql); cConversions = dt.Rows.Count; // prep for finding missing conversions Ingred IngredData = new Ingred(IngredRno); Ingred.LoadIngredPurchases(); Ingred.LoadIngredConversions(); // find any recipe units that doesn't have an easy conversion to the last purchase unit string[] RecipeUnitRnos = { }; Ingred.IngredPurchase Purchase = Ingred.LastPurchase(IngredRno); if (Purchase != null) { Sql = string.Format("Select Distinct UnitRno From RecipeIngredXref Where IngredRno = {0}", IngredRno); RecipeUnitRnos = db.StrArray(Sql); for (int i = 0; i < RecipeUnitRnos.Length; i++) { int RecipeUnitRno = Str.Num(RecipeUnitRnos[i]); if (IngredData.ConversionScaler(RecipeUnitRno, Purchase.UnitRno) == 0) { // needs conversion cConversions++; } else { // doesn't need conversion RecipeUnitRnos[i] = string.Empty; } } } AddLines(); // existing conversions int iRow = 0; foreach (DataRow dr in dt.Rows) { iRow++; TableRow tr = tblConv.Rows[iRow + 1]; HtmlInputHidden hfIngredConvRno = (HtmlInputHidden)tr.FindControl("hfIngredConvRno" + iRow); TextBox txtQty = (TextBox)tr.FindControl("txtQty" + iRow); int iCell = 0; tr.Cells[iCell++].Text = string.Empty; iCell++; hfIngredConvRno.Value = DB.Int32(dr["IngredConvRno"]).ToString(); decimal Qty = DB.Dec(dr["RecipeQty"]); txtQty.Text = Str.ShowFract(Qty); tr.Cells[iCell++].Text = DB.Str(dr["Recipe" + (Qty <= 1 ? "UnitSingle" : "UnitPlural")]); Qty = DB.Dec(dr["PurchaseQty"]); tr.Cells[iCell++].Text = Str.ShowFract(Qty); tr.Cells[iCell++].Text = DB.Str(dr["Purchase" + (Qty <= 1 ? "UnitSingle" : "UnitPlural")]); } // needed new conversions for (int i = 0; i < RecipeUnitRnos.Length; i++) { int RecipeUnitRno = Str.Num(RecipeUnitRnos[i]); if (RecipeUnitRno != 0) { iRow++; TableRow tr = tblConv.Rows[iRow + 1]; HtmlInputHidden hfIngredConvRno = (HtmlInputHidden)tr.FindControl("hfIngredConvRno" + iRow); TextBox txtQty = (TextBox)tr.FindControl("txtQty" + iRow); HiddenField hfRecipeUnitRno = (HiddenField)tr.FindControl("hfRecipeUnitRno" + iRow); HiddenField hfPurchaseQty = (HiddenField)tr.FindControl("hfPurchaseQty" + iRow); HiddenField hfPurchaseUnitRno = (HiddenField)tr.FindControl("hfPurchaseUnitRno" + iRow); int iCell = 0; hfIngredConvRno.Value = "0"; txtQty.Text = ""; hfRecipeUnitRno.Value = RecipeUnitRno.ToString(); hfPurchaseQty.Value = (Purchase.Qty * Purchase.UnitQty).ToString(); hfPurchaseUnitRno.Value = Purchase.UnitRno.ToString(); tr.Cells[iCell++].Text = "<span class=\"NeedConv\"><i class=\"icon-warning-sign\" /> Enter missing quantity</span>"; iCell++; tr.Cells[iCell++].Text = Ingred.Unit(RecipeUnitRno); tr.Cells[iCell++].Text = Str.ShowFract(Purchase.Qty * Purchase.UnitQty); tr.Cells[iCell++].Text = Ingred.Unit(Purchase.UnitRno); } } } catch (Exception Ex) { Err Err = new Err(Ex, Sql); Response.Write(Err.Html()); } } }