Ejemplo n.º 1
0
    public static void LoadIngredConversions()
    {
        string Sql =
            "Select *, " +
            "(Select UnitSingle From Units Where UnitRno = c.PurchaseUnitRno) As PurchaseUnit,\n" +
            "(Select UnitSingle From Units Where UnitRno = c.RecipeUnitRno) As RecipeUnit\n" +
            "From IngredConv c Where PurchaseQty <> 0 And PurchaseQty Is Not Null And RecipeQty <> 0 And RecipeQty Is Not Null Order By IngredRno";

        try
        {
            DataTable dt = DB.DBDataTable(Sql);
            IngredConvs = new IngredConv[dt.Rows.Count];
            int i = 0;
            foreach (DataRow dr in dt.Rows)
            {
                IngredConvs[i] = new IngredConv();
                IngredConvs[i].IngredConvRno   = DB.Int32(dr["IngredConvRno"]);
                IngredConvs[i].IngredRno       = DB.Int32(dr["IngredRno"]);
                IngredConvs[i].PurchaseQty     = DB.Dec(dr["PurchaseQty"]);
                IngredConvs[i].PurchaseUnitRno = DB.Int32(dr["PurchaseUnitRno"]);
                IngredConvs[i].PurchaseUnit    = DB.Str(dr["PurchaseUnit"]);
                IngredConvs[i].RecipeQty       = DB.Dec(dr["RecipeQty"]);
                IngredConvs[i].RecipeUnitRno   = DB.Int32(dr["RecipeUnitRno"]);
                IngredConvs[i].RecipeUnit      = DB.Str(dr["RecipeUnit"]);
                IngredConvs[i].fVisited        = false;
                i++;
            }
        }
        catch (Exception Ex)
        {
            Err Err = new Err(Ex, Sql);
            System.Web.HttpContext.Current.Response.Write(Err.Html());
        }
    }
Ejemplo n.º 2
0
    protected bool FindNextConversion(decimal ConvQty, IngredConv IngredConv, string Level)
    {
        bool fFound = false;

        HttpResponse Resp = System.Web.HttpContext.Current.Response;

        if (fShowConv)
        {
            Resp.Write(string.Format("{0}{1} {2} -> {3} {4}<br/>", Level, IngredConv.RecipeQty, IngredConv.RecipeUnit, IngredConv.PurchaseQty, IngredConv.PurchaseUnit));
        }
        Resp.Flush();

        if (IngredConv.PurchaseUnitRno == PurchaseUnitRno)
        {
            if (fShowConv)
            {
                Resp.Write("^-----------^<br/>");
            }
            Resp.Flush();
            PurchaseQty    = (ConvQty * IngredConv.PurchaseQty / IngredConv.RecipeQty);
            PurchaseQty    = PurchaseQty / PurchaseUnitQty;
            ShowConversion = string.Format(" * {0} {1} / {2} {3} = {4} {5} {6}", Str.ShowFract(IngredConv.PurchaseQty), IngredConv.PurchaseUnit, Str.ShowFract(IngredConv.RecipeQty), IngredConv.RecipeUnit, Str.ShowFract(PurchaseQty), Str.ShowFract(PurchaseUnitQty), PurchaseUnitSingle);
            StepsRemoved   = 1;
            fFound         = true;
        }
        else
        {
            IngredConv.fVisited = true;
            for (int i = 0; i < lstIngredConversions.Count; i++)
            {
                IngredConv SearchIngredConv = lstIngredConversions[i];

                if (!SearchIngredConv.fVisited)
                {
                    // find a matching unit, but not the reverse copy of the same record
                    if (SearchIngredConv.RecipeUnitRno == IngredConv.PurchaseUnitRno && SearchIngredConv.IngredConvRno != IngredConv.IngredConvRno)
                    {
                        if (fFound = FindNextConversion(ConvQty * IngredConv.PurchaseQty / IngredConv.RecipeQty, SearchIngredConv, Level + NextLevel))
                        {
                            ShowConversion = string.Format(" * {0} {1} / {2} {3}{4}", Str.ShowFract(IngredConv.PurchaseQty), IngredConv.PurchaseUnit, Str.ShowFract(IngredConv.RecipeQty), IngredConv.RecipeUnit, ShowConversion);
                            StepsRemoved++;
                            break;
                        }
                    }
                }
            }
        }

        return(fFound);
    }
Ejemplo n.º 3
0
    private static IList <IngredConv> FindIngredConversions(int IngredRno)
    {
        IList <IngredConv> lstIngredConversions = new List <IngredConv>();

        // first find all the ingredient conversions
        foreach (IngredConv IngredConv in IngredConvs)
        {
            if (IngredConv.IngredRno == IngredRno)
            {
                lstIngredConversions.Add(IngredConv);
            }
        }

        // next find all the standard conversions
        foreach (IngredConv IngredConv in IngredConvs)
        {
            if (IngredConv.IngredRno == 0)
            {
                lstIngredConversions.Add(IngredConv);
            }
        }

        // now copy the found conversions but in reverse order
        int Len = lstIngredConversions.Count;

        for (int i = 0; i < Len; i++)
        {
            IngredConv IngredConv = lstIngredConversions[i];
            IngredConv Reverse    = new IngredConv();
            Reverse.IngredConvRno   = IngredConv.IngredConvRno;
            Reverse.IngredRno       = IngredConv.IngredRno;
            Reverse.RecipeQty       = IngredConv.PurchaseQty;
            Reverse.RecipeUnitRno   = IngredConv.PurchaseUnitRno;
            Reverse.RecipeUnit      = IngredConv.PurchaseUnit;
            Reverse.PurchaseQty     = IngredConv.RecipeQty;
            Reverse.PurchaseUnitRno = IngredConv.RecipeUnitRno;
            Reverse.PurchaseUnit    = IngredConv.RecipeUnit;
            Reverse.fVisited        = IngredConv.fVisited;

            lstIngredConversions.Add(Reverse);
        }

        return(lstIngredConversions);
    }
Ejemplo n.º 4
0
    public static void AddIngredConv(int IngredConvRno, int IngredRno, decimal PurchaseQty, int PurchaseUnitRno, string PurchaseUnit, decimal RecipeQty, int RecipeUnitRno, string RecipeUnit)
    {
        int i = IngredConvs.Length;

        IngredConv[] temp = new IngredConv[i + 1];
        IngredConvs.CopyTo(temp, 0);
        IngredConvs = temp;

        IngredConvs[i] = new IngredConv();
        IngredConvs[i].IngredConvRno   = IngredConvRno;
        IngredConvs[i].IngredRno       = IngredRno;
        IngredConvs[i].PurchaseQty     = PurchaseQty;
        IngredConvs[i].PurchaseUnitRno = PurchaseUnitRno;
        IngredConvs[i].PurchaseUnit    = PurchaseUnit;
        IngredConvs[i].RecipeQty       = RecipeQty;
        IngredConvs[i].RecipeUnitRno   = RecipeUnitRno;
        IngredConvs[i].RecipeUnit      = RecipeUnit;
        IngredConvs[i].fVisited        = false;
    }
Ejemplo n.º 5
0
    protected decimal NextConversionScaler(decimal Scaler, int ToUnitRno, string ToUnit, IngredConv IngredConv, string Level)
    {
        decimal NextScaler = 0;

        HttpResponse Resp = System.Web.HttpContext.Current.Response;

        if (fShowConv)
        {
            Resp.Write(string.Format("{0}{1} {2} -> {3} {4}<br/>", Level, IngredConv.RecipeQty, IngredConv.RecipeUnit, IngredConv.PurchaseQty, IngredConv.PurchaseUnit));
        }
        Resp.Flush();

        if (IngredConv.PurchaseUnitRno == ToUnitRno)
        {
            if (fShowConv)
            {
                Resp.Write("^-----------^<br/>");
            }
            Resp.Flush();
            NextScaler     = Scaler * IngredConv.PurchaseQty / IngredConv.RecipeQty;
            ShowConversion = string.Format(" * {0} {1} / {2} {3} = {4} {5}", Str.ShowFract(IngredConv.PurchaseQty), IngredConv.PurchaseUnit, Str.ShowFract(IngredConv.RecipeQty), IngredConv.RecipeUnit, Str.ShowFract(NextScaler), ToUnit);
            StepsRemoved   = 1;
        }
        else
        {
            IngredConv.fVisited = true;
            foreach (IngredConv SearchIngredConv in lstIngredConversions)
            {
                if (!SearchIngredConv.fVisited)
                {
                    // find a matching unit, but not the reverse copy of the same record
                    if (SearchIngredConv.RecipeUnitRno == IngredConv.PurchaseUnitRno && SearchIngredConv.IngredConvRno != IngredConv.IngredConvRno)
                    {
                        if ((NextScaler = NextConversionScaler(Scaler * IngredConv.PurchaseQty / IngredConv.RecipeQty, ToUnitRno, ToUnit, SearchIngredConv, Level + NextLevel)) != 0)
                        {
                            ShowConversion = string.Format(" * {0} {1} / {2} {3}{4}", Str.ShowFract(IngredConv.PurchaseQty), IngredConv.PurchaseUnit, Str.ShowFract(IngredConv.RecipeQty), IngredConv.RecipeUnit, ShowConversion);
                            StepsRemoved++;
                            break;
                        }
                    }
                }
            }
        }

        return(NextScaler);
    }