Пример #1
0
        public ConversionViewModel()
        {
            // Fill Conversions
            ConversionModel conversion = new ConversionModel();

            Conversions = conversion.GiveCollection(conversion.All());
        }
Пример #2
0
        /*
         * Addition funtions
         */
        #region
        public float AddReceiptsAmount(BindableCollection <ReceiptModel> receipts, int currency)
        {
            float total = 0;

            foreach (ReceiptModel rm in receipts)
            {
                ConversionModel cm = new ConversionModel();
                total += (float)cm.Convert((decimal)rm.Amount, (int)rm.Currency, currency);
            }
            return(total);
        }
 /// <summary>
 /// Method to return a specific conversion provided it's Id
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 #region GetConversionbyId
 public ConversionModel GetConversionbyId(int Id)
 {
     try
     {
         ConversionModel quantity = dBContext.Conversions.Find(Id);
         return(quantity);
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Пример #4
0
        public IActionResult Index(ConversionModel model, string command)
        {
            if (command == "Decimal To Binary")
            {
                model.myOutput = ConversionCalculatorBL.ConvertNumber.toBinary(model.myInput);
            }
            if (command == "Binary To Decimal")
            {
                model.myOutput = ConversionCalculatorBL.ConvertNumber.toDecimal(model.myInput);
            }

            return(View(model));
        }
Пример #5
0
        public void Delete(ConversionModel conversion)
        {
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete this conversion?", "Delete Conversion", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                bool result = conversion.Delete();
                if (result)
                {
                    MessageBox.Show("Conversion Deleted");
                }
            }
        }
 /// <summary>
 /// Method to delete an perviously performed converison provided it''s Id
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 #region DeleteConversionById
 public ConversionModel DeleteConversionById(int Id)
 {
     try
     {
         ConversionModel quantity = dBContext.Conversions.Find(Id);
         if (quantity != null)
         {
             dBContext.Conversions.Remove(quantity);
             dBContext.SaveChanges();
         }
         return(quantity);
     }
     catch (Exception exception)
     {
         throw exception;
     }
 }
Пример #7
0
        private static double ReflectionCalculate(ConversionModel conversion)
        {
            Assembly assembly  = Assembly.GetExecutingAssembly();
            var      refType   = conversion.Formula.Split('|')[0];
            var      refMethod = conversion.Formula.Split('|')[1];
            Type     type      = assembly.GetType(refType);

            var obj = Activator.CreateInstance(type);

            // Alternately you could get the MethodInfo for the TestRunner.Run method
            var args = new object[] { conversion.FromValue };

            return((double)type.InvokeMember(refMethod,
                                             BindingFlags.Default | BindingFlags.InvokeMethod,
                                             null,
                                             obj,
                                             args));
        }
 public IActionResult Conversion([FromBody] ConversionModel quantity)
 {
     try
     {
         Response <ConversionModel> response = quantityMeasurementBL.Conversion(quantity);
         if (response.Success == true)
         {
             return(Ok(new { response.Success, response.Message, response.Data }));
         }
         else
         {
             return(Ok(new { response.Success, response.Message }));
         }
     }
     catch (Exception exception)
     {
         return(BadRequest(new { Success = false, message = exception.Message }));
     }
 }
 public void Save()
 {
     if (CheckAll())
     {
         ConversionModel cm = new ConversionModel()
         {
             First  = this.First.Id,
             Second = this.Second.Id,
             Ratio  = this.Ratio,
         };
         try
         {
             cm = cm.SaveThis();
             MessageBox.Show("Conversion Created", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
         }
         catch (Exception e)
         {
             MessageBox.Show("You already have this conversion", "Failed", MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
 }
Пример #10
0
 public ConversionEdit(ConversionModel con)
 {
     InitializeComponent();
     conversion = con;
     txtmaterial.Items.Add("Coex 65");
     txtmaterial.Items.Add("Coex 70");
     txtmaterial.Items.Add("Coex 94");
     txtmaterial.Items.Add("Coex 120");
     txtmaterial.Items.Add("Coex 160");
     txtmaterial.Items.Add("MPET 12");
     txtmaterial.Items.Add("SPET 12");
     txtmaterial.Items.Add("CPET 12");
     txtmaterial.Items.Add("Nylon 15");
     txtmaterial.Items.Add("BOPP 20");
     txtmaterial.Items.Add("BOPP 25");
     txtmaterial.Items.Add("BOPP 30");
     txtmaterial.Items.Add("BOPP 40");
     txtmaterial.Items.Add("PE 100");
     txtmaterial.Items.Add("PE 125");
     txtmaterial.Items.Add("PE 150");
     txtmaterial.Items.Add("PE 170");
     txtmaterial.Items.Add("PE 180");
     txtmaterial.Items.Add("PE 200");
     txtmaterial.Items.Add("PE 225");
     txtmaterial.Items.Add("PE 250");
     txtmaterial.Items.Add("PE 280");
     txtmaterial.Items.Add("PE 300");
     txtmaterial.Items.Add("PE 325");
     txtmaterial.Items.Add("PE 350");
     txtmaterial.Items.Add("PE 400");
     txtmaterial.Items.Add("PE 425");
     txtmaterial.Items.Add("PE 450");
     txtmaterial.Items.Add("PE 500");
     txtmaterial.Items.Add("PE 525");
     txtmaterial.Items.Add("PE 550");
     BindingContext        = conversion;
     btnver.Clicked       += Btnver_Clicked;
     btnmodificar.Clicked += Btnmodificar_Clicked;
     btneliminar.Clicked  += Btneliminar_Clicked;
 }
        /// <summary>
        /// Method to take a value and option and convert
        /// </summary>
        /// <param name="quantity"></param>
        /// <returns></returns>
        #region Conversion
        public ConversionModel Conversion(ConversionModel quantity)
        {
            bool isOptionValid = Enum.TryParse <ConversionOptions>(quantity.OperationType, true, out ConversionOptions option);

            if (isOptionValid)
            {
                try
                {
                    var param = new SqlParameter[] {
                        new SqlParameter()
                        {
                            ParameterName = "@inputId",
                            SqlDbType     = SqlDbType.Int,
                            Direction     = System.Data.ParameterDirection.Input,
                            Value         = (int)option
                        },
                        new SqlParameter()
                        {
                            ParameterName = "@inputValue",
                            SqlDbType     = SqlDbType.Float,
                            Direction     = ParameterDirection.Input,
                            Value         = quantity.Value
                        }
                    };
                    ConversionModel output = dBContext.Conversions.FromSql("[dbo].[spConvert] @inputId, @inputValue", param).FirstOrDefault();
                    dBContext.SaveChanges();
                    return(output);
                }
                catch (Exception exception)
                {
                    throw new Exception(exception.Message);
                }
            }
            else
            {
                return(quantity);
            }
        }
Пример #12
0
 /// <summary>
 /// business layer login for DeleteConversionbyId Method
 /// </summary>
 /// <param name="Id"></param>
 /// <returns></returns>
 #region DeleteConversionById
 public Response <ConversionModel> DeleteConversionById(int Id)
 {
     try
     {
         Response <ConversionModel> response = new Response <ConversionModel>();
         ConversionModel            model    = this.quantityMeasurementRL.DeleteConversionById(Id);
         if (model is null)
         {
             response.Success = false;
             response.Message = "No such conversion exists.";
         }
         else
         {
             response.Success = true;
             response.Message = "Deletion Successful !!! This is the conversion which has been deleted.";
             response.Data.Add(model);
         }
         return(response);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Пример #13
0
        public ActionResult Index()
        {
            ConversionModel conversions = new ConversionModel();

            return(View(conversions));
        }
Пример #14
0
 public void Eliminar(ConversionModel modelo)
 {
     cnn.Delete(modelo);
 }
Пример #15
0
 public void Actualizar(ConversionModel modelo)
 {
     cnn.Update(modelo);
 }
Пример #16
0
 public void Insertar(ConversionModel modelo)
 {
     cnn.Insert(modelo);
 }
Пример #17
0
 public void View(ConversionModel conversion)
 {
     ActivateItem(new ViewConversionViewModel(conversion));
 }
Пример #18
0
        public ConversionViewModel()
        {
            Nuevo = new Command(() => {
                Material    = "";
                Gauge       = string.Empty;
                Size        = string.Empty;
                NoRolls     = string.Empty;
                WgtRoll     = string.Empty;
                TotalWeight = string.Empty;
                Conversion  = string.Empty;
                Scrap       = string.Empty;
                Finished    = string.Empty;
                Print       = string.Empty;
            }
                                );
            Guardar = new Command(() => {
                ConversionModel modelo = new ConversionModel()
                {
                    Material    = Material,
                    Gauge       = Gauge,
                    Size        = Size,
                    NoRolls     = NoRolls,
                    WgtRoll     = WgtRoll,
                    TotalWeight = TotalWeight,
                    Conversion  = Conversion,
                    Scrap       = Scrap,
                    Finished    = Finished,
                    Print       = Print
                };

                using (var contexto = new DataContextConversion())
                {
                    contexto.Insertar(modelo);
                }
            }
                                  );
            Modificar = new Command(() => {
                ConversionModel modelo = new ConversionModel()
                {
                    Material     = Material,
                    Gauge        = Gauge,
                    Size         = Size,
                    NoRolls      = NoRolls,
                    WgtRoll      = WgtRoll,
                    TotalWeight  = TotalWeight,
                    Conversion   = Conversion,
                    Scrap        = Scrap,
                    Finished     = Finished,
                    Print        = Print,
                    IdConversion = IdConversion
                };

                using (var contexto = new DataContextConversion())
                {
                    contexto.Actualizar(modelo);
                }
            }
                                    );

            Eliminar = new Command(() => {
                ConversionModel modelo = new ConversionModel()
                {
                    Material     = Material,
                    Gauge        = Gauge,
                    Size         = Size,
                    NoRolls      = NoRolls,
                    WgtRoll      = WgtRoll,
                    TotalWeight  = TotalWeight,
                    Conversion   = Conversion,
                    Scrap        = Scrap,
                    Finished     = Finished,
                    Print        = Print,
                    IdConversion = IdConversion
                };

                using (var contexto = new DataContextConversion())
                {
                    contexto.Eliminar(modelo);
                }
            });
        }
Пример #19
0
        private void HandleConversion(ConversionModel conversion)
        {
            var watch = Stopwatch.StartNew();

            conversion.TimeStamp = DateTime.Now;

            _logger.LogInformation($"Received new conversion {conversion.ToJson()}");
            UserModel user = new UserModel {
                UserId = conversion.UserId, GamingSystemId = conversion.GamingSystemId, ProductId = conversion.ProductId
            };
            DailyDealEligibilityModel eligibility = _eligibilityRepository.Get(user).Result;

            if (eligibility != null)
            {
                if (eligibility.HasOffers())
                {
                    OfferModel offer = eligibility.OfferList.FirstOrDefault(o => o.IsClaimed == false);
                    eligibility.OfferList.Remove(offer);

                    offer.IsClaimed     = true;
                    offer.ClaimDateTime = DateTime.Now;
                    eligibility.OfferList.Add(offer);

                    var lowBalance = new LowBalanceEventMessage(conversion, offer);

                    /////////Block
                    var    transaction  = _eligibilityBlockRepository.Get(INSESSION_TRANSACTION_NAME, $"{eligibility.GamingSystemId}-{eligibility.ProductId}-{eligibility.UserId}").Result;
                    IBlock lastBlock    = transaction.GetLastBlock();
                    IBlock currentBlock = new Block(lastBlock.Index, "Conversion_Received_v1", lowBalance.ToJson(), watch.Elapsed, lastBlock.Hash);
                    transaction.Add(currentBlock);

                    if (transaction.IsValid())
                    {
                        _eligibilityRepository.Update(eligibility);
                        PubishTransction(new TransactionMessage.Insession(transaction));

                        Context.System.Scheduler.ScheduleTellOnce(TimeSpan.FromSeconds(60), Self, lowBalance, Self);
                    }
                    else
                    {
                        _logger.LogError($"Invalid transaction for {conversion.GamingSystemId}-{conversion.ProductId}-{conversion.UserId}. Terminating...");
                    }
                    ///////////
                }
                else
                {
                    _logger.LogWarning($"User {user.ToJson()} has no offers left.");
                    /////////Block
                    var    transaction  = _eligibilityBlockRepository.Get(INSESSION_TRANSACTION_NAME, $"{eligibility.GamingSystemId}-{eligibility.ProductId}-{eligibility.UserId}").Result;
                    IBlock lastBlock    = transaction.GetLastBlock();
                    IBlock currentBlock = new Block(lastBlock.Index, "Offers_Used_v1", "", watch.Elapsed, lastBlock.Hash);
                    transaction.Add(currentBlock);

                    if (transaction.IsValid())
                    {
                        _eligibilityRepository.Update(eligibility);
                        PubishTransction(new TransactionMessage.Insession(transaction));
                    }
                    ///////////
                }
            }
            else
            {
                _logger.LogWarning($"Plyer has no eligibility:: {user.ToJson()}");
            }
        }
Пример #20
0
        public void UpdateModel_ValueConversionTests()
        {
            ConversionModel       cm       = new ConversionModel();
            WFObjectValueProvider provider = new WFObjectValueProvider(cm, "");
            DestinationModel      dm       = new DestinationModel();

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;

            WFPageUtilities.UpdateModel(provider, dm, "", null, null);

            Assert.AreEqual(10, dm.stringToShort);
            Assert.AreEqual(10, dm.stringToInt);
            Assert.AreEqual(10, dm.stringToLong);
            Assert.AreEqual(10.1m, dm.stringToDecimal);
            Assert.AreEqual(10.2f, dm.stringToFloat);
            Assert.AreEqual(10, dm.intToShort);
            Assert.AreEqual(10, dm.intToLong);
            Assert.AreEqual(10, dm.intToFloat);
            Assert.AreEqual(default(DateTime), dm.blankToDateTime);
            Assert.AreEqual(default(DateTime), dm.nullToDateTime);
            Assert.AreEqual(default(int), dm.nullToInt);
            Assert.AreEqual(default(int), dm.blankToInt);

            Assert.AreEqual(DateTime.Parse("1/1/2001").ToString(), dm.dateToString);
            Assert.AreEqual(DateTime.Parse("1/1/2002"), dm.stringToDate);

            // Test null =================================
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test "" ===================================
            cm.stringToNullableBoolean  = "";
            cm.stringToNullableDateTime = "";
            cm.stringToNullableDouble   = "";
            cm.stringToNullableInt      = "";

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;

            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test "null" ===============================
            cm.stringToNullableBoolean  = "null";
            cm.stringToNullableDateTime = "null";
            cm.stringToNullableDouble   = "null";
            cm.stringToNullableInt      = "null";

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;
            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test values (except bool)
            cm.stringToNullableDateTime = "1/1/2015";
            cm.stringToNullableDouble   = "0.7";
            cm.stringToNullableInt      = "77";

            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;
            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsTrue(dm.stringToNullableDateTime.HasValue);
            Assert.IsTrue(dm.stringToNullableDouble.HasValue);
            Assert.IsTrue(dm.stringToNullableInt.HasValue);
            Assert.AreEqual(DateTime.Parse("1/1/2015"), dm.stringToNullableDateTime.Value);
            Assert.AreEqual(Double.Parse("0.7"), dm.stringToNullableDouble.Value);
            Assert.AreEqual(Int32.Parse("77"), dm.stringToNullableInt.Value);

            string[] trueValues = { "true", "true,false", "on" };
            foreach (string s in trueValues)
            {
                // truthy values test
                cm.stringToNullableBoolean = s;
                dm.stringToNullableBoolean = null;
                WFPageUtilities.UpdateModel(provider, dm, "", null, null);
                Assert.IsTrue(dm.stringToNullableBoolean.HasValue && dm.stringToNullableBoolean.Value);
            }
        }