Example #1
0
        public async Task <IActionResult> Edit(Guid id, [Bind("MeasurementUnitId,Unit")] MeasurementUnit measurementUnit)
        {
            if (id != measurementUnit.MeasurementUnitId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(measurementUnit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!MeasurementUnitExists(measurementUnit.MeasurementUnitId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(measurementUnit));
        }
 public CoreUnitConverter(MeasurementUnit inputUnit, MeasurementUnit outputUnit, string unitDomain, bool isFrequentlyUsedConverter)
 {
     InputUnit  = inputUnit;
     OutputUnit = outputUnit;
     UnitDomain = unitDomain;
     IsFrequentlyUsedConverter = isFrequentlyUsedConverter;
 }
Example #3
0
        public async Task <ActionResult> Create(MeasurementUnit model)
        {
            var exist = _db.MeasurementUnits.Any(n => n.MeasurementUnitName == model.MeasurementUnitName);

            if (exist)
            {
                ModelState.AddModelError("MeasurementUnitName", "Measurement Unit Name already exist!");
            }
            if (!ModelState.IsValid)
            {
                return(View($"_Create", model));
            }

            _db.MeasurementUnits.Add(model);

            var task = await _db.SaveChangesAsync();

            if (task != 0)
            {
                return(Content("success"));
            }

            ModelState.AddModelError("", "Unable to insert record!");
            return(View($"_Create", model));
        }
Example #4
0
        public MgBufferControlImpl(IMapViewer viewer, string defaultLayerName, MeasurementUnit units)
        {
            InitializeComponent();
            this.Title = Strings.TitleBuffer;
            _viewer = viewer;
            _sessionId = Guid.NewGuid().ToString();
            var provider = viewer.GetProvider();
            _resSvc = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            _featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);

            cmbUnits.DataSource = Enum.GetValues(typeof(MeasurementUnit));
            cmbUnits.SelectedItem = units;
            cmbBorderPattern.DataSource = Enum.GetValues(typeof(StockPattern));
            cmbFillPattern.DataSource = Enum.GetValues(typeof(StockPattern));

            cmbBorderPattern.SelectedItem = StockPattern.Solid;
            cmbFillPattern.SelectedItem = StockPattern.Solid;

            pnlFillColor.BackColor = Color.Red;
            pnlBorderColor.BackColor = Color.Black;

            numBufferDistance.Value = 1;
            numFillTransparency.Value = 50;
            numLineThickness.Value = 1;

            txtBufferLayer.Text = defaultLayerName;

            _viewer.SelectionChanged += new EventHandler(OnViewerSelectedChanged);
            OnViewerSelectedChanged(this, EventArgs.Empty);
        }
        public MeasurementUnit Get(RestaurantDatabaseSettings ctx, int measurementUnitId)
        {
            MeasurementUnit result = null;

            using (OracleConnection conn = new OracleConnection(ctx.ConnectionString))
            {
                string query = $"SELECT " +
                               $"{MeasurementUnit.ColumnNames.Id}, " +
                               $"{MeasurementUnit.ColumnNames.Code}, " +
                               $"{MeasurementUnit.ColumnNames.Description} " +
                               $"FROM UnidadMedida " +
                               $"WHERE {MeasurementUnit.ColumnNames.Id} = {measurementUnitId}";
                OracleCommand cmd = new OracleCommand(query, conn);
                conn.Open();

                OracleDataReader reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    result = new MeasurementUnit()
                    {
                        Id          = Convert.ToInt32(reader[MeasurementUnit.ColumnNames.Id]),
                        Code        = reader[MeasurementUnit.ColumnNames.Code]?.ToString(),
                        Description = reader[MeasurementUnit.ColumnNames.Description]?.ToString()
                    };
                }

                reader.Dispose();
            }

            return(result);
        }
Example #6
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (Name != null)
         {
             hashCode = hashCode * 59 + Name.GetHashCode();
         }
         if (Per100g != null)
         {
             hashCode = hashCode * 59 + Per100g.GetHashCode();
         }
         if (MeasurementUnit != null)
         {
             hashCode = hashCode * 59 + MeasurementUnit.GetHashCode();
         }
         if (Rank != null)
         {
             hashCode = hashCode * 59 + Rank.GetHashCode();
         }
         if (DataPoints != null)
         {
             hashCode = hashCode * 59 + DataPoints.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         return(hashCode);
     }
 }
Example #7
0
        public AlertTrigger(
            string deviceName,
            double thresholdValueInBytes,
            TriggerMode mode,
            MeasurementUnit eventUnit)
        {
            if (String.IsNullOrWhiteSpace(deviceName))
            {
                throw new ArgumentNullException($"Specify {nameof(deviceName)}");
            }
            if (thresholdValueInBytes <= 0)
            {
                throw new ArgumentException($"{nameof(thresholdValueInBytes)} should be greater than zero");
            }

            DeviceName = deviceName.EndsWith(":\\")
                ? deviceName
                : $"{deviceName}:\\";
            ThresholdValueInBytes = thresholdValueInBytes;
            Mode = mode;
            if (mode == TriggerMode.Accuracy)
            {
                var temp = new DiskSize(thresholdValueInBytes, eventUnit);
                ThresholdValueInBytes = temp.ConvertTo(MeasurementUnit.Byte).Size;
            }
            EventUnit = eventUnit;
        }
Example #8
0
        public async Task <ApiResult <bool> > UpdateMeasurementUnit(int id, MeasurementUnit measurementUnit)
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();
                _logger.LogInformation("Update measurementUnit");

                measurementUnit.Id = id;

                var result = await _measurementUnitService.UpdateMeasurementUnit(measurementUnit);

                _logger.LogInformation("Update measurementUnit complete");

                stopwatch.Stop();
                result.ExecutionTime = stopwatch.Elapsed.TotalMilliseconds;
                _logger.LogInformation($"Execution time: {result.ExecutionTime}ms");

                return(result);
            }
            catch (Exception ex)
            {
                _logger.LogInformation($"Update measurementUnit error: {ex}");

                return(new ApiResult <bool>
                {
                    Result = false,
                    ApiCode = ApiCode.UnknownError,
                    ErrorMessage = ex.ToString()
                });
            }
        }
        private void CustomMeasurementForm_ContentLoaded(object sender, DataFormContentLoadEventArgs e)
        {
            ComboBox  measurementUnits = CustomMeasurementForm.FindNameInContent("MeasurementUnits") as ComboBox;
            DataField customUnitField  = CustomMeasurementForm.FindNameInContent("CustomUnitField") as DataField;

            context.Load <MeasurementUnit>(context.GetMeasurementUnitsQuery(), LoadBehavior.RefreshCurrent,
                                           (MeasurementUnitsLoaded) =>
            {
                if (!MeasurementUnitsLoaded.HasError)
                {
                    measurementUnits.ItemsSource   = MeasurementUnitsLoaded.Entities;
                    measurementUnits.SelectedIndex = 0;
                }
            }, null);

            measurementUnits.SelectionChanged += (sev, eve) =>
            {
                MeasurementUnit selected = measurementUnits.SelectedItem as MeasurementUnit;

                if (selected != null)
                {
                    if (selected.id > 0)
                    {
                        customUnitField.Visibility = Visibility.Collapsed;
                        selectedUnit = selected;
                    }
                    else
                    {
                        customUnitField.Visibility = Visibility.Visible;
                        selectedUnit = null;
                    }
                }
            };
        }
Example #10
0
        /// <summary>
        /// Draws the element's shape using specified <b>IRenderEngine</b>
        /// object.
        /// <seealso cref="Draw"/>
        /// </summary>
        /// <param name="engine">
        /// The <see cref="IRenderEngine"/> object that provides the rendering
        /// infrastructure.
        /// </param>
        protected override void DrawShape(IRenderEngine engine)
        {
            base.DrawShape(engine);

            MeasurementUnit rowHeight = RowHeight;
            Size2D          rowSize   = new Size2D(Width, RowHeight);
            MeasurementUnit bottom    = Location.Y.AddValue(Height);
            MeasurementUnit midPoint  = Location.Y.AddValue(rowHeight);

            Rendering.DrawLine(engine,
                               new Point2D(base.Location.X, midPoint),
                               new Point2D(base.Location.X.AddValue(Width), midPoint));

            Point2D lefTop = Location;

            engine.Graphics.TextProperties.HorizontalAlignment = StringAlignment.Center;

            Rendering.DrawString(engine, schema.Name, new Rectangle2D(lefTop, rowSize));
            lefTop.Y = lefTop.Y.AddValue(rowHeight);

            foreach (ColumnSchema column in schema.Columns)
            {
                engine.Graphics.TextProperties.HorizontalAlignment = StringAlignment.Near;
                Rendering.DrawString(engine, column.Name, new Rectangle2D(lefTop, rowSize));
                lefTop.Y = lefTop.Y.AddValue(rowHeight);
                if (lefTop.Y > bottom)
                {
                    break;
                }
            }

            //ElementLine line = new ElementLine();
            //line.Size = Width;
        }
        /// <summary>
        /// Add an Unit row view model to the list of <see cref="MeasurementUnit"/>
        /// </summary>
        /// <param name="unit">
        /// The <see cref="Unit"/> that is to be added
        /// </param>
        private IMeasurementUnitRowViewModel <MeasurementUnit> AddUnitRowViewModel(MeasurementUnit unit)
        {
            var linearConversionUnit = unit as LinearConversionUnit;

            if (linearConversionUnit != null)
            {
                return(new LinearConversionUnitRowViewModel(linearConversionUnit, this.Session, this));
            }
            var derivedUnit = unit as DerivedUnit;

            if (derivedUnit != null)
            {
                return(new DerivedUnitRowViewModel(derivedUnit, this.Session, this));
            }
            var simpleUnit = unit as SimpleUnit;

            if (simpleUnit != null)
            {
                return(new SimpleUnitRowViewModel(simpleUnit, this.Session, this));
            }
            var prefixedUnit = unit as PrefixedUnit;

            if (prefixedUnit != null)
            {
                return(new PrefixedUnitRowViewModel(prefixedUnit, this.Session, this));
            }
            throw new Exception("No MeasurementUnit to return");
        }
Example #12
0
        /// <summary>
        /// Create the default scale update subscription
        /// </summary>
        private void CreateMeasurementUnitUpdateSubscription()
        {
            if (this.measurementUnitObject != null && this.Thing.Unit == this.measurementUnitObject)
            {
                return;
            }

            if (this.measurementUnitSubscription != null)
            {
                this.measurementUnitSubscription.Dispose();
            }

            if (this.Thing.Unit == null)
            {
                return;
            }

            this.measurementUnitObject       = this.Thing.Unit;
            this.measurementUnitSubscription = CDPMessageBus.Current.Listen <ObjectChangedEvent>(this.measurementUnitObject)
                                               .Where(objectChange => objectChange.EventKind == EventKind.Updated)
                                               .ObserveOn(RxApp.MainThreadScheduler)
                                               .Subscribe(x => { this.MeasurementUnit = this.measurementUnitObject.ShortName; });

            this.MeasurementUnit = this.measurementUnitObject.ShortName;
        }
Example #13
0
        /// <summary>
        /// Returns true if BrandedFoodObjectServing instances are equal
        /// </summary>
        /// <param name="other">Instance of BrandedFoodObjectServing to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(BrandedFoodObjectServing other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Size == other.Size ||
                     Size != null &&
                     Size.Equals(other.Size)
                     ) &&
                 (
                     MeasurementUnit == other.MeasurementUnit ||
                     MeasurementUnit != null &&
                     MeasurementUnit.Equals(other.MeasurementUnit)
                 ) &&
                 (
                     SizeFulltext == other.SizeFulltext ||
                     SizeFulltext != null &&
                     SizeFulltext.Equals(other.SizeFulltext)
                 ));
        }
Example #14
0
    protected void rolMeasurementUnitsConverts_ItemDataBound(object sender, ReorderListItemEventArgs e)
    {
        ReorderListItem         rolItem         = e.Item as ReorderListItem;
        LinkButton              btn             = rolItem.FindControl("btnUpdate") as LinkButton;
        Label                   textLine        = rolItem.FindControl("lbMeasurementUnitsConvertText") as Label;
        MeasurementUnitsConvert MeasuresConvert = e.Item.DataItem as MeasurementUnitsConvert;

        if (MeasuresConvert != null)
        {
            btn.PostBackUrl = string.Format("~/Admin/MeasurementUnitsConvert.aspx?ConvertId={0}", MeasuresConvert.ConvertId);
            string   from    = MeasuresConvert.FromQuantity.ToString();
            string[] fromStr = from.Split('.');
            if (fromStr[1] == "00")
            {
                from = fromStr[0];
            }

            string   to    = MeasuresConvert.ToQuantity.ToString();
            string[] toStr = to.Split('.');
            if (toStr[1] == "00")
            {
                to = toStr[0];
            }

            Food            food = BusinessFacade.Instance.GetFood(MeasuresConvert.FoodId);
            MeasurementUnit sourceMeasureUnit = BusinessFacade.Instance.GetMeasurementUnit(MeasuresConvert.FromUnitId);
            MeasurementUnit targetMeasureUnit = BusinessFacade.Instance.GetMeasurementUnit(MeasuresConvert.ToUnitId);

            textLine.Text = string.Format("{0} {1} {2} = {3} {4}", from, sourceMeasureUnit.UnitName, food.FoodName, to, targetMeasureUnit.UnitName);
        }

        //btn = rolItem.FindControl("btnDelete") as LinkButton;
        // btn.Visible = MeasuresConvert.AllowDelete;
    }
Example #15
0
        public async Task <ActionResult> Edit(MeasurementUnit model)
        {
            var exist = _db.MeasurementUnits.Any(n => (n.MeasurementUnitName == model.MeasurementUnitName) && n.MeasurementUnitId != model.MeasurementUnitId);

            if (exist)
            {
                ModelState.AddModelError("MeasurementUnitName", "Measurement Unit Name must be unique!");
            }

            if (!ModelState.IsValid)
            {
                return(View(Request.IsAjaxRequest() ? "_Edit" : "Edit", model));
            }

            model.InsertDate = DateTime.Now;
            _db.MeasurementUnits.Update(model);
            var task = await _db.SaveChangesAsync();

            if (task != 0)
            {
                return(Request.IsAjaxRequest() ? (ActionResult)Content("success") : RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Unable to update");
            Response.StatusCode = (int)HttpStatusCode.BadRequest;
            return(View(Request.IsAjaxRequest() ? "_Edit" : "Edit", model));
        }
Example #16
0
 // SelectedIngredient.MeasurementUnit
 private void InitializeUnitsComboBox(MeasurementUnit measurementUnit)
 {
     _measurementUnit = measurementUnit;
     comboBoxMeasuringUnits.Items.Clear();
     if (!measurementUnit.IsVolume() &&
         !measurementUnit.IsWeight())
     {
         comboBoxMeasuringUnits.Items.Add(Types.Strings.UnmeasuredUnits);
     }
     else if (measurementUnit.IsWeight())
     {
         comboBoxMeasuringUnits.Items.Add(Types.Strings.WeightPound);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.WeightOunce);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.WeightGram);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.WeightMilligram);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.WeightKilogram);
     }
     else if (measurementUnit.IsVolume())
     {
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeGallon);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeQuart);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumePint);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeCup);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeTablespoon);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeTeaspoon);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeLiter);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeFluidOunce);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeMilliliter);
         comboBoxMeasuringUnits.Items.Add(Types.Strings.VolumeKiloliter);
     }
 }
        public MeasurementUnitCreationDialogViewModel()
        {
            _canModifyQuantity = false;

            CancelCommand = new DelegateCommand <Window>(
                parentDialog =>
            {
                parentDialog.DialogResult = false;
            });

            ConfirmCommand = new DelegateCommand <Window>(
                parentDialog =>
            {
                MeasurementUnitInstance = new MeasurementUnit()
                {
                    MeasurableQuantityID = _selectedMeasurableQuantity.ID,
                    Name   = _name,
                    Symbol = _symbol
                };

                MeasurementUnitInstance.Create();

                parentDialog.DialogResult = true;
            },
                parentDialog => !HasErrors);
        }
        public JsonResult GetData()
        {
            List <MeasurementUnit> vList = new List <MeasurementUnit>();

            /*
             * MeasurementUnit vMu = new MeasurementUnit();
             * vMu.MUType="New";
             * vMu.MUid = 1;
             *
             * MeasurementUnit vMu2 = new MeasurementUnit();
             * vMu2.MUType = "New2";
             * vMu2.MUid = 2;
             *
             * vList.Add(vMu);
             * vList.Add(vMu2);
             */
            Entities _contextEntities = new Entities();
            //var vMeasurementType = new SqlParameter("@Type", pDataViewModel.Type);
            List <Procedures.MeasurementUnitTypes> vMeasurementUnitTypes =
                _contextEntities.Database.SqlQuery <Procedures.MeasurementUnitTypes>("GetAllMeasurementUnits").ToList();

            foreach (var item in vMeasurementUnitTypes)
            {
                MeasurementUnit vMeasurementUnit = new MeasurementUnit();
                vMeasurementUnit.MUType = item.Type;
                vMeasurementUnit.MUid   = item.Id.ToString();
                vList.Add(vMeasurementUnit);
            }

            var json = JsonConvert.SerializeObject(vList);

            return(Json(json, JsonRequestBehavior.AllowGet));
        }
        private void buttonYield_PreviewMouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            PosDialogWindow         window  = IngredientAmountControl.CreateInDefaultWindow(Types.Strings.IngredientEditorEditRecipeYield);
            IngredientAmountControl control = window.DockedControl as IngredientAmountControl;
            PosDialogWindow         parent  = Window.GetWindow(this) as PosDialogWindow;

            control.MeasurementUnit = MeasurementUnit;
            control.Amount          = (ExtendedIngredientYield.HasValue ?
                                       ExtendedIngredientYield.Value : 0);

            window.ShowDialog(parent);
            if (!window.ClosedByUser)
            {
                double amount = 0;
                if (control.Amount > 0)
                {
                    amount = UnitConversion.Convert(control.Amount,
                                                    control.MeasurementUnit, MeasurementUnit);
                    _extendedIngredientYield = amount;
                }
                else
                {
                    _extendedIngredientYield = null;
                }
                buttonYield.Text   = amount.ToString(CultureInfo.InvariantCulture);
                labelUnits.Content = MeasurementUnit.ToString() +
                                     (Math.Abs(amount - 1) > double.Epsilon ? Types.Strings.S : "");
                if (YieldAmountChanged != null)
                {
                    YieldAmountChanged.Invoke(this, new EventArgs());
                }
                DoValueChangedEvent();
            }
            e.Handled = true;
        }
 public SelectionDrawModeInfo(SelectionDrawMode drawMode, double width, double height, MeasurementUnit units)
 {
     DrawMode = drawMode;
     Width    = width;
     Height   = height;
     Units    = units;
 }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            unit = new MeasurementUnit();

            // set name type mapping
            jointtype_mapping = new Dictionary <string, JointType>();
            jointtype_mapping.Add(Head.Name, JointType.Head);
            jointtype_mapping.Add(ShoulderCenter.Name, JointType.ShoulderCenter);
            jointtype_mapping.Add(ShoulderLeft.Name, JointType.ShoulderLeft);
            jointtype_mapping.Add(ShoulderRight.Name, JointType.ShoulderRight);
            jointtype_mapping.Add(HandLeft.Name, JointType.HandLeft);
            jointtype_mapping.Add(HandRight.Name, JointType.HandRight);
            jointtype_mapping.Add(WristLeft.Name, JointType.WristLeft);
            jointtype_mapping.Add(WristRight.Name, JointType.WristRight);
            jointtype_mapping.Add(ElbowLeft.Name, JointType.ElbowLeft);
            jointtype_mapping.Add(ElbowRight.Name, JointType.ElbowRight);
            jointtype_mapping.Add(Spine.Name, JointType.Spine);
            jointtype_mapping.Add(HipCenter.Name, JointType.HipCenter);
            jointtype_mapping.Add(HipLeft.Name, JointType.HipLeft);
            jointtype_mapping.Add(HipRight.Name, JointType.HipRight);
            jointtype_mapping.Add(KneeLeft.Name, JointType.KneeLeft);
            jointtype_mapping.Add(KneeRight.Name, JointType.KneeRight);
            jointtype_mapping.Add(AnkleLeft.Name, JointType.AnkleLeft);
            jointtype_mapping.Add(AnkleRight.Name, JointType.AnkleRight);
            jointtype_mapping.Add(FootLeft.Name, JointType.FootLeft);
            jointtype_mapping.Add(FootRight.Name, JointType.FootRight);

            planeButtons.Add(XY);
            planeButtons.Add(YZ);
            planeButtons.Add(XZ);
        }
Example #22
0
        MeasurementUnit IInventoryGeneralFacade.GetMeasurementUnitByID(int id)
        {
            MeasurementUnit measurementUnit = new MeasurementUnit();

            measurementUnit = Database.MeasurementUnits.Single(m => m.IID == id && m.IsRemoved == 0);
            return(measurementUnit);
        }
Example #23
0
        void ProcessFile(int dataColumn)
        {
            try
            {
                var words = FileIOLib.CSVFileParser.ParseFile(Filename);


                _rowCount = words.GetLength(0);
                _colCount = words.GetLength(1);
                if (_rowCount == 0 || _colCount == 0 || _headerRowCount >= _rowCount)
                {
                    throw new Exception("File does not contain data.");
                }
                if (dataColumn > _colCount - 1)
                {
                    throw new Exception("No data in specified column. Likely incorrect probe count or type.");
                }

                InputUnits = MeasurementUnit.GetMeasurementUnit(words);

                if (InputUnits == null)
                {
                    InputUnits = new MeasurementUnit(LengthUnit.MICRON);
                }
                data.AddRange(ExtractProbeData(words, dataColumn));


                double scalingFactor = OutputUnits.ConversionFactor / InputUnits.ConversionFactor;
                ScaleData(scalingFactor);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #24
0
    public static List <Beer> GetBeers(Country co)
    {
        //list
        List <Beer> list = new List <Beer>();
        //query
        string query = "select be_id, be_grd_alcoh,be_presentation,be_level_ferm,be_unitMeas,be_content,beer.br_code,cla_code,be_price,be_image from beer join brand on beer.br_code= brand.br_code join country on country.cn_code = brand.cn_code where country.cn_code=@CON";
        //command
        MySqlCommand command = new MySqlCommand(query);

        command.Parameters.AddWithValue("@CON", co.Id);
        //execute query
        DataTable table = MySqlConnection.ExecuteQuery(command);

        //iterate rows
        foreach (DataRow row in table.Rows)
        {
            //read fields
            int              id              = (int)row["be_id"];
            double           gradoalcohol    = (double)row["be_grd_alcoh"];
            PresentationType presentation    = (PresentationType)(int)row["be_presentation"];
            Fermentation     fermentation    = (Fermentation)(int)row["be_level_ferm"];
            MeasurementUnit  measurementUnit = (MeasurementUnit)row["be_unitMeas"];
            double           content         = (double)row["be_content"];
            Brand            brand           = new Brand((string)row["br_code"]);
            Clasification    clasification   = new Clasification((string)row["cla_code"]);
            double           price           = (double)row["be_price"];
            string           image           = (string)row["be_image"];
            //add country to list
            list.Add(new Beer(id, gradoalcohol, presentation, fermentation, measurementUnit, content, brand, clasification, price, image));
        }
        //return list
        return(list);
    }
Example #25
0
        /// <summary>
        /// Add a new entry to the IngredientSet table
        /// </summary>
        public static IngredientSet Add(int extendedIngredientId, int ingredientId,
                                        double amount, MeasurementUnit measurementUnit)
        {
            IngredientSet result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddIngredientSet";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@IngredientSetExtendedIngredientId", SqlDbType.Int, extendedIngredientId);
                BuildSqlParameter(sqlCmd, "@IngredientSetIngredientId", SqlDbType.Int, ingredientId);
                BuildSqlParameter(sqlCmd, "@IngredientSetAmount", SqlDbType.Float, amount);
                BuildSqlParameter(sqlCmd, "@IngredientSetMeasurementUnit", SqlDbType.SmallInt, measurementUnit);
                BuildSqlParameter(sqlCmd, "@IngredientSetId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new IngredientSet(Convert.ToInt32(sqlCmd.Parameters["@IngredientSetId"].Value),
                                               extendedIngredientId, ingredientId, amount, measurementUnit);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
Example #26
0
        internal static XUnit ParseUnit(string unit)
        {
            if (unit == "0")
            {
                return(XUnit.Zero);
            }

            Match m = gXUnitValidator.Match(unit);

            if (!m.Success)
            {
                throw new ArgumentException($"Unit {unit} is not a unit expression", nameof(unit));
            }

            float n = float.Parse(m.Groups[1].Value, CultureInfo.InvariantCulture);

            MeasurementUnit mm = m.Groups[5].Value switch
            {
                "pt" => MeasurementUnit.Point,
                "cm" => MeasurementUnit.Centimeter,
                "mm" => MeasurementUnit.Millimeter,
                "in" => MeasurementUnit.Inch,
                "px" => MeasurementUnit.Pixel,
                "%" => MeasurementUnit.Percent,
                _ => throw new ArgumentException($"Unknown unit {m.Groups[4].Value}")
            };

            return(new XUnit(n, mm));
        }
Example #27
0
        private void OnUnitsButtonDropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            LocalizedMeasurementUnit tag = e.ClickedItem.Tag as LocalizedMeasurementUnit;

            this.unit = tag.Unit;
            this.OnUnitsChanged();
        }
Example #28
0
    /// <summary>
    /// Creates an object with data from the databas
    /// </summary>
    /// <param name="id">Country Id</param>
    public Beer(int id)
    {
        //query
        string query = "select be_id, be_grd_alcoh,be_presentation, be_level_ferm,be_unitMeas,be_content,br_code,cla_code,be_price from beer where be_id = @ID";
        //command
        MySqlCommand command = new MySqlCommand(query);

        //parameters
        command.Parameters.AddWithValue("@ID", id);
        //execute query
        DataTable table = MySqlConnection.ExecuteQuery(command);

        //check if rows were found
        if (table.Rows.Count > 0)
        {
            //read first and only row
            DataRow row = table.Rows[0];
            //read data
            _id              = (int)row["be_id"];
            _gradoAlcohol    = (double)row["be_grd_alcoh"];
            _presentation    = (PresentationType)(int)row["be_presentation"];
            _fermentation    = (Fermentation)row["be_nicel_ferm"];
            _measurementUnit = (MeasurementUnit)row["be_unitMeas"];
            _content         = (double)row["be_content"];
            _brand           = (Brand)row["br_code"];
            _clasification   = (Clasification)row["cla_code"];
            _price           = (double)row["be_price"];
        }
    }
Example #29
0
        internal bool SaveMeasurementUnit(MeasurementUnit unit)
        {
            using (DataContext)
            {
                try
                {
                    if (!DataContext.MeasurementUnits.Contains(unit))
                    {
                        unit.CreatedDate = DateTime.Now;
                        unit.SortOrder   = DataContext.MeasurementUnits.Max(mu => mu.SortOrder) + 1;
                        DataContext.MeasurementUnits.Add(unit);
                        //DataContext.MeasurementUnits.InsertOnSubmit(unit);
                    }
                    else
                    {
                        string unitName = unit.UnitName;
                        unit          = DataContext.MeasurementUnits.Single(mu => mu.UnitId == unit.UnitId);
                        unit.UnitName = unitName;
                    }

                    unit.ModifiedDate = DateTime.Now;
                    DataContext.SaveChanges();
                    //DataContext.SubmitChanges();
                    return(true);
                }
                catch
                {
                    return(false);
                }
            }
        }
Example #30
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         var hashCode = 41;
         // Suitable nullity checks etc, of course :)
         if (MeasurementUnit != null)
         {
             hashCode = hashCode * 59 + MeasurementUnit.GetHashCode();
         }
         if (Description != null)
         {
             hashCode = hashCode * 59 + Description.GetHashCode();
         }
         if (Modifier != null)
         {
             hashCode = hashCode * 59 + Modifier.GetHashCode();
         }
         if (GramWeight != null)
         {
             hashCode = hashCode * 59 + GramWeight.GetHashCode();
         }
         if (DataPoints != null)
         {
             hashCode = hashCode * 59 + DataPoints.GetHashCode();
         }
         if (Footnote != null)
         {
             hashCode = hashCode * 59 + Footnote.GetHashCode();
         }
         return(hashCode);
     }
 }
Example #31
0
        public void CorrectUnit(string text, float n, MeasurementUnit unit)
        {
            XUnit u = Creator.ParseUnit(text);

            u.Value.Should().Be(n);
            u.Type.Should().Be(unit);
        }
 public ActionResult Save(MeasurementUnit unit)
 {
     if (this.ModelState.IsValid)
     {
         _daoFactory.MeasurementUnit().SaveOrUpdate(unit);
         return RedirectToAction("Index");
     }
     return View(unit.Id == 0 ? "Create" : "Edit", unit);
 }
Example #33
0
 public MgLineMeasureControlImpl(IMapViewer viewer, MeasurementUnit preferredUnit)
 {
     InitializeComponent();
     this.Title = Strings.TitleMeasure;
     _viewer = viewer;
     _segments = new BindingList<MeasuredLineSegment>();
     cmbUnits.DataSource = Enum.GetValues(typeof(MeasurementUnit));
     cmbUnits.SelectedItem = preferredUnit;
     lstSegments.DataSource = _segments;
     _mapCs = _viewer.GetProvider().GetMapCoordinateSystem();
 }
Example #34
0
 public Double ConvertTo(MeasurementUnit system, Double weight)
 {
     switch (system)
     {
         case MeasurementUnit.Imperial:
             // 1kg = 2.205 lbs
             return weight * 2.205;
         case MeasurementUnit.Metric:
             return weight;
         case MeasurementUnit.Stone:
             // 1kg = 0.157473044 stone
             return weight * 0.157473044;
         default:
             throw new ArgumentException(
                 string.Format(
                     CultureInfo.CurrentUICulture,
                     "Measurement system of type {0} cannot be found",
                     Enum.GetName(typeof(MeasurementUnit), system)));
     }
 }
Example #35
0
        public void CoordinatesToStrings(MeasurementUnit units, int x, int y, out string xString, out string yString, out string unitsString)
        {
            string unitsAbbreviation = GetUnitsAbbreviation(units);

            unitsString = GetUnitsAbbreviation(units);

            if (units == MeasurementUnit.Pixel)
            {
                xString = x.ToString();
                yString = y.ToString();
            }
            else
            {
                double physicalX = PixelToPhysicalX(x, units);
                xString = physicalX.ToString("F2");

                double physicalY = PixelToPhysicalY(y, units);
                yString = physicalY.ToString("F2");
            }
        }
Example #36
0
        //
        //   Conversion Matrix:
        //
        // GetPhysical[X|Y](x, unit), where dpu = this.dpuX or dpuY
        //
        //            dpu |  px  |  in  |  cm        |
        //        unit    |      |      |            |
        //   -------------+------+------+------------+
        //        px      |  x   |  x   |      x     |
        //   -------------+------+------+------------+
        //        in      | x /  | x /  | x /        |
        //                |  96  | dpuX | (dpuX*2.54)|
        //   -------------+------+------+------------+
        //        cm      | x /  |x*2.54| x / dpuX   |
        //                |  37.8| /dpuX|            |
        //   -------------+------+------+------------+
        public static double PixelToPhysical(double pixel, MeasurementUnit resultUnit, MeasurementUnit dpuUnit, double dpu)
        {
            double result;

            if (resultUnit == MeasurementUnit.Pixel)
            {
                result = pixel;
            }
            else
            {
                if (resultUnit == dpuUnit)
                {
                    result = pixel / dpu;
                }
                else if (dpuUnit == MeasurementUnit.Pixel)
                {
                    double defaultDpu = GetDefaultDpu(dpuUnit);
                    result = pixel / defaultDpu;
                }
                else if (dpuUnit == MeasurementUnit.Centimeter && resultUnit == MeasurementUnit.Inch)
                {
                    result = pixel / (CmPerInch * dpu);
                }
                else // if (dpuUnit == MeasurementUnit.Inch && resultUnit == MeasurementUnit.Centimeter)
                {
                    result = (pixel * CmPerInch) / dpu;
                }
            }

            return result;
        }
Example #37
0
        public static double GetDefaultDpu(MeasurementUnit units)
        {
            double dpu;

            switch (units)
            {
                case MeasurementUnit.Inch:
                    dpu = defaultDpi;
                    break;

                case MeasurementUnit.Centimeter:
                    dpu = defaultDpcm;
                    break;

                case MeasurementUnit.Pixel:
                    dpu = 1.0;
                    break;

                default:
                    throw new InvalidEnumArgumentException("DpuUnit", (int)units, typeof(MeasurementUnit));
            }

            return dpu;
        }
Example #38
0
 public void RemoveUnit(MeasurementUnit removeMe)
 {
     this.comboBoxHandler.AddUnit(removeMe);            
 }
 /// <summary>
 /// Gets the unit as <see cref="string"/>.
 /// </summary>
 /// <returns>The unit as <see cref="string"/>.</returns>
 public static string GetUnitAsString(MeasurementUnit unit)
 {
     switch (unit)
     {
         case MeasurementUnit.Meters:
             return "Meter";
         case MeasurementUnit.Kilograms:
             return "Kilogramm";
         case MeasurementUnit.MetersPerSecond:
             return "Meter / Sekunde";
         case MeasurementUnit.Seconds:
             return "Sekunden";
         case MeasurementUnit.Unspecified:
         default:
             return "N/A";
     }
 }
Example #40
0
 private void OnUnitsComboBox1UnitsChanged(object sender, System.EventArgs e)
 {
     this.constrainer.Units = unitsComboBox1.Units;
     this.unitsLabel1.Text = unitsComboBox1.UnitsText;
     UpdateSizeText();
     TryToEnableOkButton();
 }
Example #41
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.constrainCheckBox = new System.Windows.Forms.CheckBox();
     this.newWidthLabel1 = new System.Windows.Forms.Label();
     this.newHeightLabel1 = new System.Windows.Forms.Label();
     this.okButton = new System.Windows.Forms.Button();
     this.cancelButton = new System.Windows.Forms.Button();
     this.pixelWidthUpDown = new System.Windows.Forms.NumericUpDown();
     this.pixelHeightUpDown = new System.Windows.Forms.NumericUpDown();
     this.resizedImageHeader = new PaintDotNet.HeaderLabel();
     this.asteriskLabel = new System.Windows.Forms.Label();
     this.asteriskTextLabel = new System.Windows.Forms.Label();
     this.absoluteRB = new System.Windows.Forms.RadioButton();
     this.percentRB = new System.Windows.Forms.RadioButton();
     this.pixelsLabel1 = new System.Windows.Forms.Label();
     this.percentUpDown = new System.Windows.Forms.NumericUpDown();
     this.percentSignLabel = new System.Windows.Forms.Label();
     this.resolutionLabel = new System.Windows.Forms.Label();
     this.resolutionUpDown = new System.Windows.Forms.NumericUpDown();
     this.unitsComboBox2 = new PaintDotNet.UnitsComboBox();
     this.unitsComboBox1 = new PaintDotNet.UnitsComboBox();
     this.printWidthUpDown = new System.Windows.Forms.NumericUpDown();
     this.printHeightUpDown = new System.Windows.Forms.NumericUpDown();
     this.newWidthLabel2 = new System.Windows.Forms.Label();
     this.newHeightLabel2 = new System.Windows.Forms.Label();
     this.pixelsLabel2 = new System.Windows.Forms.Label();
     this.unitsLabel1 = new System.Windows.Forms.Label();
     this.pixelSizeHeader = new PaintDotNet.HeaderLabel();
     this.printSizeHeader = new PaintDotNet.HeaderLabel();
     this.resamplingLabel = new System.Windows.Forms.Label();
     this.resamplingAlgorithmComboBox = new System.Windows.Forms.ComboBox();
     ((System.ComponentModel.ISupportInitialize)(this.pixelWidthUpDown)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.pixelHeightUpDown)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.percentUpDown)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.resolutionUpDown)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.printWidthUpDown)).BeginInit();
     ((System.ComponentModel.ISupportInitialize)(this.printHeightUpDown)).BeginInit();
     this.SuspendLayout();
     //
     // constrainCheckBox
     //
     this.constrainCheckBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.constrainCheckBox.Location = new System.Drawing.Point(27, 101);
     this.constrainCheckBox.Name = "constrainCheckBox";
     this.constrainCheckBox.Size = new System.Drawing.Size(248, 16);
     this.constrainCheckBox.TabIndex = 25;
     this.constrainCheckBox.CheckedChanged += new System.EventHandler(this.constrainCheckBox_CheckedChanged);
     //
     // newWidthLabel1
     //
     this.newWidthLabel1.Location = new System.Drawing.Point(32, 145);
     this.newWidthLabel1.Name = "newWidthLabel1";
     this.newWidthLabel1.Size = new System.Drawing.Size(79, 16);
     this.newWidthLabel1.TabIndex = 0;
     this.newWidthLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // newHeightLabel1
     //
     this.newHeightLabel1.Location = new System.Drawing.Point(32, 169);
     this.newHeightLabel1.Name = "newHeightLabel1";
     this.newHeightLabel1.Size = new System.Drawing.Size(79, 16);
     this.newHeightLabel1.TabIndex = 3;
     this.newHeightLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // okButton
     //
     this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.okButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.okButton.Location = new System.Drawing.Point(142, 315);
     this.okButton.Name = "okButton";
     this.okButton.Size = new System.Drawing.Size(72, 23);
     this.okButton.TabIndex = 17;
     this.okButton.Click += new System.EventHandler(this.okButton_Click);
     //
     // cancelButton
     //
     this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
     this.cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
     this.cancelButton.Location = new System.Drawing.Point(220, 315);
     this.cancelButton.Name = "cancelButton";
     this.cancelButton.Size = new System.Drawing.Size(72, 23);
     this.cancelButton.TabIndex = 18;
     this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
     //
     // pixelWidthUpDown
     //
     this.pixelWidthUpDown.Location = new System.Drawing.Point(120, 144);
     this.pixelWidthUpDown.Maximum = new System.Decimal(new int[] {
                                                                      2147483647,
                                                                      0,
                                                                      0,
                                                                      0});
     this.pixelWidthUpDown.Minimum = new System.Decimal(new int[] {
                                                                      2147483647,
                                                                      0,
                                                                      0,
                                                                      -2147483648});
     this.pixelWidthUpDown.Name = "pixelWidthUpDown";
     this.pixelWidthUpDown.Size = new System.Drawing.Size(72, 20);
     this.pixelWidthUpDown.TabIndex = 1;
     this.pixelWidthUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.pixelWidthUpDown.Value = new System.Decimal(new int[] {
                                                                    4,
                                                                    0,
                                                                    0,
                                                                    0});
     this.pixelWidthUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.pixelWidthUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.pixelWidthUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     this.pixelWidthUpDown.Leave += new System.EventHandler(this.OnUpDownLeave);
     //
     // pixelHeightUpDown
     //
     this.pixelHeightUpDown.Location = new System.Drawing.Point(120, 168);
     this.pixelHeightUpDown.Maximum = new System.Decimal(new int[] {
                                                                       2147483647,
                                                                       0,
                                                                       0,
                                                                       0});
     this.pixelHeightUpDown.Minimum = new System.Decimal(new int[] {
                                                                       2147483647,
                                                                       0,
                                                                       0,
                                                                       -2147483648});
     this.pixelHeightUpDown.Name = "pixelHeightUpDown";
     this.pixelHeightUpDown.Size = new System.Drawing.Size(72, 20);
     this.pixelHeightUpDown.TabIndex = 4;
     this.pixelHeightUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.pixelHeightUpDown.Value = new System.Decimal(new int[] {
                                                                     3,
                                                                     0,
                                                                     0,
                                                                     0});
     this.pixelHeightUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.pixelHeightUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.pixelHeightUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     this.pixelHeightUpDown.Leave += new System.EventHandler(this.OnUpDownLeave);
     //
     // resizedImageHeader
     //
     this.resizedImageHeader.Location = new System.Drawing.Point(6, 8);
     this.resizedImageHeader.Name = "resizedImageHeader";
     this.resizedImageHeader.Size = new System.Drawing.Size(290, 16);
     this.resizedImageHeader.TabIndex = 19;
     this.resizedImageHeader.TabStop = false;
     //
     // asteriskLabel
     //
     this.asteriskLabel.Location = new System.Drawing.Point(275, 28);
     this.asteriskLabel.Name = "asteriskLabel";
     this.asteriskLabel.Size = new System.Drawing.Size(13, 16);
     this.asteriskLabel.TabIndex = 15;
     this.asteriskLabel.Visible = false;
     //
     // asteriskTextLabel
     //
     this.asteriskTextLabel.Location = new System.Drawing.Point(8, 290);
     this.asteriskTextLabel.Name = "asteriskTextLabel";
     this.asteriskTextLabel.Size = new System.Drawing.Size(255, 16);
     this.asteriskTextLabel.TabIndex = 16;
     this.asteriskTextLabel.Visible = false;
     //
     // absoluteRB
     //
     this.absoluteRB.Checked = true;
     this.absoluteRB.Location = new System.Drawing.Point(8, 78);
     this.absoluteRB.Name = "absoluteRB";
     this.absoluteRB.Width = 264;
     this.absoluteRB.AutoSize = true;
     this.absoluteRB.TabIndex = 24;
     this.absoluteRB.TabStop = true;
     this.absoluteRB.CheckedChanged += new System.EventHandler(this.OnRadioButtonCheckedChanged);
     //
     // percentRB
     //
     this.percentRB.Location = new System.Drawing.Point(8, 51);
     this.percentRB.Name = "percentRB";
     this.percentRB.TabIndex = 22;
     this.percentRB.AutoSize = true;
     this.percentRB.Width = 10;
     this.percentRB.CheckedChanged += new System.EventHandler(this.OnRadioButtonCheckedChanged);
     //
     // pixelsLabel1
     //
     this.pixelsLabel1.Location = new System.Drawing.Point(200, 145);
     this.pixelsLabel1.Name = "pixelsLabel1";
     this.pixelsLabel1.Width = 93;
     this.pixelsLabel1.TabIndex = 2;
     this.pixelsLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // percentUpDown
     //
     this.percentUpDown.Location = new System.Drawing.Point(120, 54);
     this.percentUpDown.Maximum = new System.Decimal(new int[] {
                                                                   2000,
                                                                   0,
                                                                   0,
                                                                   0});
     this.percentUpDown.Name = "percentUpDown";
     this.percentUpDown.Size = new System.Drawing.Size(72, 20);
     this.percentUpDown.TabIndex = 23;
     this.percentUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.percentUpDown.Value = new System.Decimal(new int[] {
                                                                 100,
                                                                 0,
                                                                 0,
                                                                 0});
     this.percentUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.percentUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.percentUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     //
     // percentSignLabel
     //
     this.percentSignLabel.Location = new System.Drawing.Point(200, 55);
     this.percentSignLabel.Name = "percentSignLabel";
     this.percentSignLabel.Size = new System.Drawing.Size(32, 16);
     this.percentSignLabel.TabIndex = 13;
     this.percentSignLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // resolutionLabel
     //
     this.resolutionLabel.Location = new System.Drawing.Point(32, 193);
     this.resolutionLabel.Name = "resolutionLabel";
     this.resolutionLabel.Size = new System.Drawing.Size(79, 16);
     this.resolutionLabel.TabIndex = 6;
     this.resolutionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // resolutionUpDown
     //
     this.resolutionUpDown.DecimalPlaces = 2;
     this.resolutionUpDown.Location = new System.Drawing.Point(120, 192);
     this.resolutionUpDown.Maximum = new System.Decimal(new int[] {
                                                                      65535,
                                                                      0,
                                                                      0,
                                                                      0});
     this.resolutionUpDown.Minimum = new System.Decimal(new int[] {
                                                                      1,
                                                                      0,
                                                                      0,
                                                                      327680});
     this.resolutionUpDown.Name = "resolutionUpDown";
     this.resolutionUpDown.Size = new System.Drawing.Size(72, 20);
     this.resolutionUpDown.TabIndex = 7;
     this.resolutionUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.resolutionUpDown.Value = new System.Decimal(new int[] {
                                                                    72,
                                                                    0,
                                                                    0,
                                                                    0});
     this.resolutionUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.resolutionUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.resolutionUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     this.resolutionUpDown.Leave += new System.EventHandler(this.OnUpDownLeave);
     //
     // unitsComboBox2
     //
     this.unitsComboBox2.Location = new System.Drawing.Point(200, 192);
     this.unitsComboBox2.Name = "unitsComboBox2";
     this.unitsComboBox2.PixelsAvailable = false;
     this.unitsComboBox2.Size = new System.Drawing.Size(88, 21);
     this.unitsComboBox2.TabIndex = 8;
     this.unitsComboBox2.Units = PaintDotNet.MeasurementUnit.Inch;
     this.unitsComboBox2.UnitsDisplayType = PaintDotNet.UnitsDisplayType.Ratio;
     this.unitsComboBox2.UnitsChanged += new System.EventHandler(this.OnUnitsComboBox2UnitsChanged);
     //
     // unitsComboBox1
     //
     this.unitsComboBox1.Location = new System.Drawing.Point(200, 235);
     this.unitsComboBox1.Name = "unitsComboBox1";
     this.unitsComboBox1.PixelsAvailable = false;
     this.unitsComboBox1.Size = new System.Drawing.Size(88, 21);
     this.unitsComboBox1.TabIndex = 12;
     this.unitsComboBox1.Units = PaintDotNet.MeasurementUnit.Inch;
     this.unitsComboBox1.UnitsChanged += new System.EventHandler(this.OnUnitsComboBox1UnitsChanged);
     //
     // printWidthUpDown
     //
     this.printWidthUpDown.DecimalPlaces = 2;
     this.printWidthUpDown.Location = new System.Drawing.Point(120, 235);
     this.printWidthUpDown.Maximum = new System.Decimal(new int[] {
                                                                      2147483647,
                                                                      0,
                                                                      0,
                                                                      0});
     this.printWidthUpDown.Minimum = new System.Decimal(new int[] {
                                                                      2147483647,
                                                                      0,
                                                                      0,
                                                                      -2147483648});
     this.printWidthUpDown.Name = "printWidthUpDown";
     this.printWidthUpDown.Size = new System.Drawing.Size(72, 20);
     this.printWidthUpDown.TabIndex = 11;
     this.printWidthUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.printWidthUpDown.Value = new System.Decimal(new int[] {
                                                                    2,
                                                                    0,
                                                                    0,
                                                                    0});
     this.printWidthUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.printWidthUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.printWidthUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     this.printWidthUpDown.Leave += new System.EventHandler(this.OnUpDownLeave);
     //
     // printHeightUpDown
     //
     this.printHeightUpDown.DecimalPlaces = 2;
     this.printHeightUpDown.Location = new System.Drawing.Point(120, 259);
     this.printHeightUpDown.Maximum = new System.Decimal(new int[] {
                                                                       2147483647,
                                                                       0,
                                                                       0,
                                                                       0});
     this.printHeightUpDown.Minimum = new System.Decimal(new int[] {
                                                                       2147483647,
                                                                       0,
                                                                       0,
                                                                       -2147483648});
     this.printHeightUpDown.Name = "printHeightUpDown";
     this.printHeightUpDown.Size = new System.Drawing.Size(72, 20);
     this.printHeightUpDown.TabIndex = 14;
     this.printHeightUpDown.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
     this.printHeightUpDown.Value = new System.Decimal(new int[] {
                                                                     1,
                                                                     0,
                                                                     0,
                                                                     0});
     this.printHeightUpDown.Enter += new System.EventHandler(this.OnUpDownEnter);
     this.printHeightUpDown.KeyUp += new System.Windows.Forms.KeyEventHandler(this.OnUpDownKeyUp);
     this.printHeightUpDown.ValueChanged += new System.EventHandler(this.upDown_ValueChanged);
     this.printHeightUpDown.Leave += new System.EventHandler(this.OnUpDownLeave);
     //
     // newWidthLabel2
     //
     this.newWidthLabel2.Location = new System.Drawing.Point(32, 236);
     this.newWidthLabel2.Name = "newWidthLabel2";
     this.newWidthLabel2.Size = new System.Drawing.Size(79, 16);
     this.newWidthLabel2.TabIndex = 10;
     this.newWidthLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // newHeightLabel2
     //
     this.newHeightLabel2.Location = new System.Drawing.Point(32, 260);
     this.newHeightLabel2.Name = "newHeightLabel2";
     this.newHeightLabel2.Size = new System.Drawing.Size(79, 16);
     this.newHeightLabel2.TabIndex = 13;
     this.newHeightLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // pixelsLabel2
     //
     this.pixelsLabel2.Location = new System.Drawing.Point(200, 169);
     this.pixelsLabel2.Name = "pixelsLabel2";
     this.pixelsLabel2.Size = new System.Drawing.Size(93, 16);
     this.pixelsLabel2.TabIndex = 5;
     this.pixelsLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // unitsLabel1
     //
     this.unitsLabel1.Location = new System.Drawing.Point(200, 261);
     this.unitsLabel1.Name = "unitsLabel1";
     this.unitsLabel1.Size = new System.Drawing.Size(94, 16);
     this.unitsLabel1.TabIndex = 15;
     //
     // pixelSizeHeader
     //
     this.pixelSizeHeader.Location = new System.Drawing.Point(25, 125);
     this.pixelSizeHeader.Name = "pixelSizeHeader";
     this.pixelSizeHeader.Size = new System.Drawing.Size(271, 14);
     this.pixelSizeHeader.TabIndex = 26;
     this.pixelSizeHeader.TabStop = false;
     //
     // printSizeHeader
     //
     this.printSizeHeader.Location = new System.Drawing.Point(25, 216);
     this.printSizeHeader.Name = "printSizeHeader";
     this.printSizeHeader.Size = new System.Drawing.Size(271, 14);
     this.printSizeHeader.TabIndex = 9;
     this.printSizeHeader.TabStop = false;
     //
     // resamplingLabel
     //
     this.resamplingLabel.Location = new System.Drawing.Point(6, 30);
     this.resamplingLabel.Name = "resamplingLabel";
     this.resamplingLabel.AutoSize = true;
     this.resamplingLabel.Size = new System.Drawing.Size(88, 16);
     this.resamplingLabel.TabIndex = 20;
     this.resamplingLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
     //
     // resamplingAlgorithmComboBox
     //
     this.resamplingAlgorithmComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
     this.resamplingAlgorithmComboBox.ItemHeight = 13;
     this.resamplingAlgorithmComboBox.Location = new System.Drawing.Point(120, 27);
     this.resamplingAlgorithmComboBox.Name = "resamplingAlgorithmComboBox";
     this.resamplingAlgorithmComboBox.Size = new System.Drawing.Size(152, 21);
     this.resamplingAlgorithmComboBox.Sorted = true;
     this.resamplingAlgorithmComboBox.TabIndex = 21;
     this.resamplingAlgorithmComboBox.SelectedIndexChanged += new System.EventHandler(this.OnResamplingAlgorithmComboBoxSelectedIndexChanged);
     //
     // ResizeDialog
     //
     this.AcceptButton = this.okButton;
     this.AutoScaleDimensions = new SizeF(96F, 96F);
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
     this.CancelButton = this.cancelButton;
     this.ClientSize = new System.Drawing.Size(298, 344);
     this.Controls.Add(this.printSizeHeader);
     this.Controls.Add(this.pixelSizeHeader);
     this.Controls.Add(this.unitsLabel1);
     this.Controls.Add(this.pixelsLabel2);
     this.Controls.Add(this.newHeightLabel2);
     this.Controls.Add(this.newWidthLabel2);
     this.Controls.Add(this.printHeightUpDown);
     this.Controls.Add(this.printWidthUpDown);
     this.Controls.Add(this.unitsComboBox1);
     this.Controls.Add(this.unitsComboBox2);
     this.Controls.Add(this.resolutionUpDown);
     this.Controls.Add(this.resolutionLabel);
     this.Controls.Add(this.resizedImageHeader);
     this.Controls.Add(this.cancelButton);
     this.Controls.Add(this.okButton);
     this.Controls.Add(this.asteriskLabel);
     this.Controls.Add(this.asteriskTextLabel);
     this.Controls.Add(this.absoluteRB);
     this.Controls.Add(this.percentRB);
     this.Controls.Add(this.pixelWidthUpDown);
     this.Controls.Add(this.pixelHeightUpDown);
     this.Controls.Add(this.pixelsLabel1);
     this.Controls.Add(this.newHeightLabel1);
     this.Controls.Add(this.newWidthLabel1);
     this.Controls.Add(this.resamplingAlgorithmComboBox);
     this.Controls.Add(this.resamplingLabel);
     this.Controls.Add(this.constrainCheckBox);
     this.Controls.Add(this.percentUpDown);
     this.Controls.Add(this.percentSignLabel);
     this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
     this.MaximizeBox = false;
     this.MinimizeBox = false;
     this.Name = "ResizeDialog";
     this.ShowInTaskbar = false;
     this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
     this.Controls.SetChildIndex(this.percentSignLabel, 0);
     this.Controls.SetChildIndex(this.percentUpDown, 0);
     this.Controls.SetChildIndex(this.constrainCheckBox, 0);
     this.Controls.SetChildIndex(this.resamplingLabel, 0);
     this.Controls.SetChildIndex(this.resamplingAlgorithmComboBox, 0);
     this.Controls.SetChildIndex(this.newWidthLabel1, 0);
     this.Controls.SetChildIndex(this.newHeightLabel1, 0);
     this.Controls.SetChildIndex(this.pixelsLabel1, 0);
     this.Controls.SetChildIndex(this.pixelHeightUpDown, 0);
     this.Controls.SetChildIndex(this.pixelWidthUpDown, 0);
     this.Controls.SetChildIndex(this.percentRB, 0);
     this.Controls.SetChildIndex(this.absoluteRB, 0);
     this.Controls.SetChildIndex(this.asteriskTextLabel, 0);
     this.Controls.SetChildIndex(this.asteriskLabel, 0);
     this.Controls.SetChildIndex(this.okButton, 0);
     this.Controls.SetChildIndex(this.cancelButton, 0);
     this.Controls.SetChildIndex(this.resizedImageHeader, 0);
     this.Controls.SetChildIndex(this.resolutionLabel, 0);
     this.Controls.SetChildIndex(this.resolutionUpDown, 0);
     this.Controls.SetChildIndex(this.unitsComboBox2, 0);
     this.Controls.SetChildIndex(this.unitsComboBox1, 0);
     this.Controls.SetChildIndex(this.printWidthUpDown, 0);
     this.Controls.SetChildIndex(this.printHeightUpDown, 0);
     this.Controls.SetChildIndex(this.newWidthLabel2, 0);
     this.Controls.SetChildIndex(this.newHeightLabel2, 0);
     this.Controls.SetChildIndex(this.pixelsLabel2, 0);
     this.Controls.SetChildIndex(this.unitsLabel1, 0);
     this.Controls.SetChildIndex(this.pixelSizeHeader, 0);
     this.Controls.SetChildIndex(this.printSizeHeader, 0);
     ((System.ComponentModel.ISupportInitialize)(this.pixelWidthUpDown)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.pixelHeightUpDown)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.percentUpDown)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.resolutionUpDown)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.printWidthUpDown)).EndInit();
     ((System.ComponentModel.ISupportInitialize)(this.printHeightUpDown)).EndInit();
     this.ResumeLayout(false);
 }
Example #42
0
 public ToolConfigStrip_SelectionDrawModeUnitsChangeHandler(ToolConfigStrip toolConfigStrip, Document activeDocument)
 {
     this.toolConfigStrip = toolConfigStrip;
     this.activeDocument = activeDocument;
     this.oldUnits = toolConfigStrip.SelectionDrawModeInfo.Units;
 }
Example #43
0
        /// <summary>
        /// Creates a blank document of the given size in a new workspace, and activates that workspace.
        /// </summary>
        /// <remarks>
        /// If isInitial=true, then last workspace added by this method is kept track of, and if it is not modified by
        /// the time the next workspace is added, then it will be removed.
        /// </remarks>
        /// <returns>true if everything was successful, false if there wasn't enough memory</returns>
        public bool CreateBlankDocumentInNewWorkspace(Size size, MeasurementUnit dpuUnit, double dpu, bool isInitial)
        {
            DocumentWorkspace dw1 = this.activeDocumentWorkspace;
            if (dw1 != null)
            {
                dw1.SuspendRefresh();
            }

            try
            {
                Document untitled = new Document(size.Width, size.Height);
                untitled.DpuUnit = dpuUnit;
                untitled.DpuX = dpu;
                untitled.DpuY = dpu;

                BitmapLayer bitmapLayer;

                try
                {
                    using (new WaitCursorChanger(this))
                    {
                        bitmapLayer = Layer.CreateBackgroundLayer(size.Width, size.Height);
                    }
                }

                catch (OutOfMemoryException)
                {
                    Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
                    return false;
                }

                using (new WaitCursorChanger(this))
                {
                    bool focused = false;

                    if (this.ActiveDocumentWorkspace != null && this.ActiveDocumentWorkspace.Focused)
                    {
                        focused = true;
                    }

                    untitled.Layers.Add(bitmapLayer);

                    DocumentWorkspace dw = this.AddNewDocumentWorkspace();
                    this.Widgets.DocumentStrip.LockDocumentWorkspaceDirtyValue(dw, false);
                    dw.SuspendRefresh();

                    try
                    {
                        dw.Document = untitled;
                    }

                    catch (OutOfMemoryException)
                    {
                        Utility.ErrorBox(this, PdnResources.GetString("NewImageAction.Error.OutOfMemory"));
                        RemoveDocumentWorkspace(dw);
                        untitled.Dispose();
                        return false;
                    }

                    dw.ActiveLayer = (Layer)dw.Document.Layers[0];

                    this.ActiveDocumentWorkspace = dw;

                    dw.SetDocumentSaveOptions(null, null, null);
                    dw.History.ClearAll();
                    dw.History.PushNewMemento(
                        new NullHistoryMemento(PdnResources.GetString("NewImageAction.Name"), 
                        this.FileNewIcon));

                    dw.Document.Dirty = false;
                    dw.ResumeRefresh();

                    if (isInitial)
                    {
                        this.initialWorkspace = dw;
                    }

                    if (focused)
                    {
                        this.ActiveDocumentWorkspace.Focus();
                    }

                    this.Widgets.DocumentStrip.UnlockDocumentWorkspaceDirtyValue(dw);
                }
            }

            finally
            {
                if (dw1 != null)
                {
                    dw1.ResumeRefresh();
                }
            }

            return true;
        }
Example #44
0
        private int[] GetSubdivs(MeasurementUnit unit)
        {
            switch (unit)
            {
                case MeasurementUnit.Centimeter:
                    {
                        return new int[] { 2, 5 };
                    }

                case MeasurementUnit.Inch:
                    {
                        return new int[] { 2 };
                    }

                default:
                    {
                        return null;
                    }
            }
        }
Example #45
0
        public static double ConvertMeasurement(
            double sourceLength, 
            MeasurementUnit sourceUnits, 
            MeasurementUnit basisDpuUnits, 
            double basisDpu, 
            MeasurementUnit resultDpuUnits)
        {
            // Validation
            if (!IsValidMeasurementUnit(sourceUnits))
            {
                throw new InvalidEnumArgumentException("sourceUnits", (int)sourceUnits, typeof(MeasurementUnit));
            }

            if (!IsValidMeasurementUnit(basisDpuUnits))
            {
                throw new InvalidEnumArgumentException("basisDpuUnits", (int)basisDpuUnits, typeof(MeasurementUnit));
            }

            if (!IsValidMeasurementUnit(resultDpuUnits))
            {
                throw new InvalidEnumArgumentException("resultDpuUnits", (int)resultDpuUnits, typeof(MeasurementUnit));
            }

            if (basisDpuUnits == MeasurementUnit.Pixel && basisDpu != 1.0)
            {
                throw new ArgumentOutOfRangeException("basisDpuUnits, basisDpu", "if basisDpuUnits is Pixel, then basisDpu must equal 1.0");
            }

            // Case 1. No conversion is necessary if they want the same units out.
            if (sourceUnits == resultDpuUnits)
            {
                return sourceLength;
            }

            // Case 2. Simple inches -> centimeters
            if (sourceUnits == MeasurementUnit.Inch && resultDpuUnits == MeasurementUnit.Centimeter)
            {
                return InchesToCentimeters(sourceLength);
            }

            // Case 3. Simple centimeters -> inches.
            if (sourceUnits == MeasurementUnit.Centimeter && resultDpuUnits == MeasurementUnit.Inch)
            {
                return CentimetersToInches(sourceLength);
            }

            // At this point we know we are converting from non-pixels to pixels, or from pixels
            // to non-pixels. 
            // Cases 4 through 8 cover conversion from non-pixels to pixels. 
            // Cases 9 through 11 cover conversion from pixels to non-pixels.

            // Case 4. Conversion from pixels to inches/centimeters when basis is in pixels too. 
            // This means we must use the default DPU for the desired result measurement.
            // No need to compare lengthUnits != resultDpuUnits, since we already know this to 
            // be true from case 1.
            if (sourceUnits == MeasurementUnit.Pixel && basisDpuUnits == MeasurementUnit.Pixel)
            {
                double dpu = GetDefaultDpu(resultDpuUnits);
                double lengthInOrCm = sourceLength / dpu;
                return lengthInOrCm;
            }

            // Case 5. Conversion from inches/centimeters to pixels when basis is in pixels too.
            // This means we must use the default DPU for the given input measurement.
            if (sourceUnits != MeasurementUnit.Pixel && basisDpuUnits == MeasurementUnit.Pixel)
            {
                double dpu = GetDefaultDpu(sourceUnits);
                double resultPx = sourceLength * dpu;
                return resultPx;
            }

            // Case 6. Conversion from inches/centimeters to pixels, when basis is in same units as input.
            if (sourceUnits == basisDpuUnits && resultDpuUnits == MeasurementUnit.Pixel)
            {
                double resultPx = sourceLength * basisDpu;
                return resultPx;
            }

            // Case 7. Conversion from inches to pixels, when basis is in centimeters.
            if (sourceUnits == MeasurementUnit.Inch && basisDpuUnits == MeasurementUnit.Centimeter)
            {
                double dpi = DotsPerCmToDotsPerInch(basisDpu);
                double resultPx = sourceLength * dpi;
                return resultPx;
            }

            // Case 8. Conversion from centimeters to pixels, when basis is in inches.
            if (sourceUnits == MeasurementUnit.Centimeter && basisDpuUnits == MeasurementUnit.Inch)
            {
                double dpcm = DotsPerInchToDotsPerCm(basisDpu);
                double resultPx = sourceLength * dpcm;
                return resultPx;
            }

            // Case 9. Converting from pixels to inches/centimeters, when the basis and result
            // units are the same.
            if (basisDpuUnits == resultDpuUnits)
            {
                double resultInOrCm = sourceLength / basisDpu;
                return resultInOrCm;
            }
            
            // Case 10. Converting from pixels to centimeters, when the basis is in inches.
            if (resultDpuUnits == MeasurementUnit.Centimeter && basisDpuUnits == MeasurementUnit.Inch)
            {
                double dpcm = DotsPerInchToDotsPerCm(basisDpu);
                double resultCm = sourceLength / dpcm;
                return resultCm;
            }

            // Case 11. Converting from pixels to inches, when the basis is in centimeters.
            if (resultDpuUnits == MeasurementUnit.Inch && basisDpuUnits == MeasurementUnit.Centimeter)
            {
                double dpi = DotsPerCmToDotsPerInch(basisDpu);
                double resultIn = sourceLength / dpi;
                return resultIn;
            }

            // Should not be possible to get here, but must appease the compiler.
            throw new InvalidOperationException();
        }
Example #46
0
        private static bool IsValidMeasurementUnit(MeasurementUnit unit)
        {
            switch (unit)
            {
                case MeasurementUnit.Pixel:
                case MeasurementUnit.Centimeter:
                case MeasurementUnit.Inch:
                    return true;

                default:
                    return false;
            }
        }
Example #47
0
 public void AddUnit(MeasurementUnit addMe)
 {
     this.comboBoxHandler.AddUnit(addMe);
 }
Example #48
0
 public ResizeConstrainer(Size originalPixelSize)
 {
     this.constrainToAspect = false;
     this.originalPixelSize = originalPixelSize;
     this.units = Document.DefaultDpuUnit;
     this.resolution = Document.GetDefaultDpu(this.units);
     this.newWidth = (double)this.originalPixelSize.Width / this.resolution;
     this.newHeight = (double)this.originalPixelSize.Height / this.resolution;
 }
Example #49
0
        public double PixelAreaToPhysicalArea(double area, MeasurementUnit resultUnit)
        {
            double xScale = PixelToPhysicalX(1.0, resultUnit);
            double yScale = PixelToPhysicalY(1.0, resultUnit);

            return area * xScale * yScale;
        }
Example #50
0
 private void OnConstrainerUnitsChanged(object sender, EventArgs e)
 {
     this.unitsComboBox1.Units = constrainer.Units;
     this.unitsComboBox2.Units = constrainer.Units;
     UpdateSizeText();
     TryToEnableOkButton();
 }
Example #51
0
        public double PixelToPhysicalY(double pixel, MeasurementUnit resultUnit)
        {
            double result;

            if (resultUnit == MeasurementUnit.Pixel)
            {
                result = pixel;
            }
            else
            {
                MeasurementUnit dpuUnit = this.DpuUnit;

                if (resultUnit == dpuUnit)
                {
                    result = pixel / this.DpuY;
                }
                else if (dpuUnit == MeasurementUnit.Pixel)
                {
                    double defaultDpuY = GetDefaultDpu(dpuUnit);
                    result = pixel / defaultDpuY;
                }
                else if (dpuUnit == MeasurementUnit.Centimeter && resultUnit == MeasurementUnit.Inch)
                {
                    result = pixel / (CmPerInch * this.DpuY);
                }
                else //if (dpuUnit == MeasurementUnit.Inch && resultUnit == MeasurementUnit.Centimeter)
                {
                    result = (pixel * CmPerInch) / this.DpuY;
                }
            }

            return result;
        }
Example #52
0
 private void OnUnitsComboBox2UnitsChanged(object sender, System.EventArgs e)
 {
     this.unitsComboBox1.Units = this.unitsComboBox2.Units;
     UpdateSizeText();
     TryToEnableOkButton();
 }
Example #53
0
        private static string GetUnitsAbbreviation(MeasurementUnit units)
        {
            string result;

            switch (units)
            {
                case MeasurementUnit.Pixel:
                    result = string.Empty;
                    break;

                case MeasurementUnit.Centimeter:
                    result = PdnResources.GetString("MeasurementUnit.Centimeter.Abbreviation");
                    break;

                case MeasurementUnit.Inch:
                    result = PdnResources.GetString("MeasurementUnit.Inch.Abbreviation");
                    break;

                default:
                    throw new InvalidEnumArgumentException("MeasurementUnit was invalid");
            }

            return result;
        }
 public Measurement(double value, MeasurementUnit unit)
 {
     mvarValue = value;
     mvarUnit = unit;
 }
 public void RemoveUnit(MeasurementUnit removeMe)
 {
     InitMeasurementItems();
     this.measurementItems[removeMe] = false;
     ReloadItems();
 }
        public Measurement ConvertTo(MeasurementUnit unit)
        {
            double multiplier = 1.0;

            switch (mvarUnit)
            {
                case MeasurementUnit.Decimal:
                {
                    switch (unit)
                    {
                        case MeasurementUnit.Percentage:
                        {
                            multiplier = 100.0;
                            break;
                        }
                    }
                    break;
                }
                case MeasurementUnit.Percentage:
                {
                    switch (unit)
                    {
                        case MeasurementUnit.Decimal:
                        {
                            multiplier = 0.01;
                            break;
                        }
                    }
                    break;
                }
                case MeasurementUnit.Pixel:
                {
                    switch (unit)
                    {
                        case MeasurementUnit.Pixel:
                        {
                            multiplier = 1.0;
                            break;
                        }
                    }
                    break;
                }
            }

            return new Measurement(mvarValue * multiplier, unit);
        }
 public void AddUnit(MeasurementUnit addMe)
 {
     InitMeasurementItems();
     this.measurementItems[addMe] = true;
     ReloadItems();
 }