예제 #1
0
        // Constructor

        public CalculatorCommand(CalculatorObject calculator,
                                 char @operator, int operand)
        {
            this._calculator = calculator;
            this._operator   = @operator;
            this._operand    = operand;
        }
예제 #2
0
 public CalculatorObject AddCalculator(CalculatorObject calculator)
 {
     try
     {
         return(_calculatorManager.AddCalculator(calculator));
     }
     catch (Exception ex)
     {
         ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
         return(new CalculatorObject());
     }
 }
예제 #3
0
        public CalculatorObject AddCalculator(CalculatorObject calculator)
        {
            try
            {
                var calc = new CalculatorServices().AddCalculator(calculator);


                Session["_depotTrunkedOut"] = calc;

                return(new CalculatorObject());
            }
            catch (Exception)
            {
                return(new CalculatorObject());
            }
        }
        public CalculatorObject Calculator(DepotTrunkedOutObject depotTrunked)
        {
            try
            {
                var obj = new CalculatorObject();
                using (var db = new ImportPermitEntities())
                {
                    var depotTrunkedOut = new DepotTrunkedOut
                    {
                        DepotId = depotTrunked.DepotId,
                        QuantityTrunkedOutInDepot = depotTrunked.QuantityTrunkedOutInDepot,
                        TrunkedOutDate            = depotTrunked.TrunkedOutDate
                    };

                    db.DepotTrunkedOuts.Add(depotTrunkedOut);

                    //update the calculator

                    var calc = db.Calculators.FirstOrDefault(c => c.Id >= 1);
                    if (calc != null)
                    {
                        var quantityInCountry = calc.QuantityInCountry;
                        var currentQuantity   = quantityInCountry - depotTrunked.QuantityTrunkedOutInDepot;
                        calc.QuantityInCountry = currentQuantity;
                        calc.Counter           = calc.Counter + 1;
                        db.Calculators.Attach(calc);
                        db.Entry(calc).State  = EntityState.Modified;
                        obj.QuantityInCountry = currentQuantity.ToString();
                        obj.Good = true;
                        //to get the daily consumption, fetch the first row and last row in the depotTrunkedOut table, minus the dates and get num of days then use it to divide the QuantityInCountry
                        db.SaveChanges();

                        return(obj);
                    }
                    obj.Bad = true;
                    return(obj);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(null);
            }
        }