protected void btnSave_Click(object sender, System.EventArgs e) { int Count = Parm.Int("hfParmCount"); for (int i = 1; i <= Count; i++) { int IngredRno = Parm.Int("hfIngredRno" + i); decimal Qty = Parm.Dec("txtQty" + i); if (IngredRno != 0) { string Sql = string.Format( "Update Ingredients Set StockedPurchaseQty = {1} Where IngredRno = {0}", IngredRno, Qty); try { db.Exec(Sql); } catch (Exception Ex) { Err Err = new Err(Ex, Sql); Response.Write(Err.Html()); } } } fReport = true; dtBeg = Str.DtTm(hfBegDate.Value); dtEnd = Str.DtTm(hfEndDate.Value); }
private void SaveConversions(int IngredRno) { for (int iConversion = 1; iConversion <= cConversions; iConversion++) { int IngredConvRno = Parm.Int("hfIngredConvRno" + iConversion); decimal Qty = Str.Fract(Parm.Str("txtQty" + iConversion)); int RecipeUnitRno = Parm.Int("hfRecipeUnitRno" + iConversion); decimal PurchaseQty = Parm.Dec("hfPurchaseQty" + iConversion); int PurchaseUnitRno = Parm.Int("hfPurchaseUnitRno" + iConversion); string Sql = string.Empty; bool fRemove = Parm.Bool("chkRemove" + iConversion); if (!fRemove) { try { if (Qty > 0) { if (IngredConvRno == 0) { Sql = string.Format( "Insert Into IngredConv (IngredRno, PurchaseQty, PurchaseUnitRno, RecipeUnitRno, CreatedDtTm, CreatedUser) Values (" + "{0}, {1}, {2}, {3}, GetDate(), {4}); " + "Select Scope_Identity()", IngredRno, PurchaseQty, PurchaseUnitRno, RecipeUnitRno, DB.PutStr(g.User)); IngredConvRno = db.SqlNum(Sql); } Sql = string.Format( "Update IngredConv Set " + "RecipeQty = {1}, " + "UpdatedDtTm = GetDate(), " + "UpdatedUser = {2} " + "Where IngredConvRno = {0}", IngredConvRno, Qty, DB.PutStr(g.User)); db.Exec(Sql); } } catch (Exception Ex) { Err Err = new Err(Ex, Sql); Response.Write(Err.Html()); } } } }
protected void btnSave_Click(object sender, System.EventArgs e) { DateTime Tm = DateTime.Now; fReport = true; dtBeg = Str.DtTm(hfBegDate.Value); dtEnd = Str.DtTm(hfEndDate.Value); string Sql = string.Format( "Delete From ShoppingListDetails Where ShoppingListRno in (Select ShoppingListRno From ShoppingLists Where BegDt = {0} And EndDt = {1});\n" + "Delete From ShoppingLists Where BegDt = {0} And EndDt = {1}", DB.PutDtTm(dtBeg), DB.PutDtTm(dtEnd)); try { db.Exec(Sql); int Count = Parm.Int("hfParmCount"); for (int i = 0; i < Count; i++) { Int32 IngredRno = Parm.Int("hfIngredRno" + i); bool fStocked = Parm.Bool("hfStocked" + i); decimal StockedPurchaseQty = Parm.Dec("hfStockedQty" + i); decimal PurchaseQty = Parm.Dec("hfQty" + i); decimal PurchaseUnitQty = Parm.Dec("hfUnitQty" + i); Int32 PurchaseUnitRno = Parm.Int("hfUnitRno" + i); Int32 VendorRno = Parm.Int("hfVendorRno" + i); Int32 ShoppingListRno; Sql = string.Format( "Select ShoppingListRno From ShoppingLists Where VendorRno = {0} And BegDt = {1} And EndDt = {2}", VendorRno, DB.PutDtTm(dtBeg), DB.PutDtTm(dtEnd)); ShoppingListRno = db.SqlNum(Sql); if (ShoppingListRno == 0) { Sql = string.Format( "Insert Into ShoppingLists (VendorRno, BegDt, EndDt, CreatedDtTm, CreatedUser, UpdatedDtTm, UpdatedUser) " + "Values ({0}, {1}, {2}, {3}, {4}, {5}, {6});" + "Select @@Identity", VendorRno, DB.PutDtTm(dtBeg), DB.PutDtTm(dtEnd), DB.PutDtTm(Tm), DB.PutStr(g.User), DB.PutDtTm(Tm), DB.PutStr(g.User)); ShoppingListRno = db.SqlNum(Sql); } Sql = string.Format( "Insert Into ShoppingListDetails (ShoppingListRno, IngredRno, PurchaseQty, PurchaseUnitQty, PurchaseUnitRno, CreatedDtTm, CreatedUser, UpdatedDtTm, UpdatedUser) " + "Values ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8})", ShoppingListRno, IngredRno, (fStocked ? StockedPurchaseQty : PurchaseQty), PurchaseUnitQty, PurchaseUnitRno, DB.PutDtTm(Tm), DB.PutStr(g.User), DB.PutDtTm(Tm), DB.PutStr(g.User)); db.Exec(Sql); } } catch (Exception Ex) { Err Err = new Err(Ex, Sql); Response.Write(Err.Html()); } }
private void SaveDetails(int Rno) { // force a refresh of last purchase prices Ingred.LoadIngredPurchases(); for (int iDetail = 1; iDetail <= cDetails; iDetail++) { bool fRemove = Parm.Bool("chkRemove" + iDetail); int OrigIngredRno = Parm.Int("hfOrigIngredRno" + iDetail); int IngredRno = Parm.Int("hfIngredRno" + iDetail); if (!fRemove) { int PurchaseDetailRno = Parm.Int("hfPurchaseDetailRno" + iDetail); bool fNewRec = (PurchaseDetailRno == 0); bool fStockedFlg = Parm.Bool("hfStocked" + iDetail); string Ingredient = Parm.Str("txtIngredient" + iDetail); decimal PurchaseQty = Str.Fract(Parm.Str("txtPurchaseQty" + iDetail)); decimal UnitQty = Str.Fract(Parm.Str("txtUnitQty" + iDetail)); int UnitRno = Parm.Int("hfUnitRno" + iDetail); decimal Price = (Parm.Dec("txtPrice" + iDetail)); DateTime Tm = DateTime.Now; String Sql = ""; try { // if a new ingredient, create it if (Ingredient.Length > 0) { if (IngredRno == 0) { // first off, lets see if there is an ingredient with this name, just in case there already is one, probably hidden Sql = string.Format("Select IngredRno, HideFlg From Ingredients Where Name = {0}", DB.PutStr(Ingredient)); DataRow dr = db.DataRow(Sql); if (dr != null) { // the ingredient does indeed exist IngredRno = DB.Int32(dr["IngredRno"]); bool fHide = DB.Bool(dr["HideFlg"]); if (fHide) { // it is hidden, so now unhide it Sql = string.Format("Update Ingredients Set HideFlg = 0 Where IngredRno = {0}", IngredRno); db.Exec(Sql); } } else { // the indgredient does indeed not exist, so create it Sql = string.Format( "Insert Into Ingredients (Name, StockedFlg, CreatedDtTm, CreatedUser) " + "Values ({0}, {1}, GetDate(), {2});" + "Select Scope_Identity()", DB.PutStr(Ingredient), DB.PutBool(fStockedFlg), DB.PutStr(g.User)); IngredRno = db.SqlNum(Sql); } } if (PurchaseDetailRno == 0) { Sql = string.Format( "Insert Into PurchaseDetails (PurchaseRno, IngredRno, CreatedDtTm, CreatedUser) " + "Values ({0}, {1}, GetDate(), {2});" + "Select Scope_Identity()", Rno, IngredRno, DB.PutStr(g.User)); PurchaseDetailRno = db.SqlNum(Sql); } Sql = string.Format( "Update PurchaseDetails Set " + "IngredRno = {1}, " + "PurchaseQty = {2}, " + "PurchaseUnitQty = {3}, " + "PurchaseUnitRno = {4}, " + "Price = {5}, " + "UpdatedDtTm = GetDate(), " + "UpdatedUser = {6} " + "Where PurchaseDetailRno = {0}", PurchaseDetailRno, IngredRno, PurchaseQty, UnitQty, UnitRno, Price, DB.PutStr(g.User)); db.Exec(Sql); // update the ingredient prices Ingred.UpdateWithLastPrice(IngredRno); } } catch (Exception Ex) { Err Err = new Err(Ex, Sql); Response.Write(Err.Html()); } } // if the deleted or changed, update the original ingredient prices if (fRemove || IngredRno != OrigIngredRno) { Ingred.UpdateWithLastPrice(OrigIngredRno); } } }