private Models.Scale CreateScale(int?copyScaleID = null) { //Create a new Scale and assign entered values var scale = new Models.Scale { Metric = (eMetric)int.Parse(cboMetric.SelectedValue), Description = txtScaleDescription.Text, IsEnabled = true, }; using (var uow = DIContainer.CreateUnitOfWork()) { var repo = DIContainer.CreateRepository <Repositories.IScaleRepository>(uow); repo.Add(scale); //Save changes to database uow.SaveChanges(); //Copy the Scale Values if (copyScaleID.HasValue) { repo.CopyScaleValues(copyScaleID.Value, scale.ScaleID); } } //and return the new Scale with its assigned ScaleID return(scale); }
private void LoadScaleValues(Models.Scale scale) { var inputSetting = (NumericTextBoxSetting)rimScaleValues.GetSettingByBehaviorID("ScaleValues"); switch (scale.Metric) { case eMetric.PalletSpaces: inputSetting.Type = NumericType.Number; inputSetting.DecimalDigits = 2; break; case eMetric.Weight: inputSetting.Type = NumericType.Number; inputSetting.DecimalDigits = 0; break; } //Reset the hidden field that holds the selected cellIds hidValueChanges.Value = string.Empty; HtmlTableRow tr = null; HtmlTableCell td = null; var scaleValues = scale.ScaleValues.OrderBy(sv => sv.Value).Select(sv => new { sv.ScaleValueID, sv.Value }).ToList(); //For each Scale Value foreach (var scaleValue in scaleValues) { tr = new HtmlTableRow(); tr.Attributes.Add("class", "GridRow_Orchestrator"); grdValues.Rows.Add(tr); //Add a cell for the Value td = new HtmlTableCell(); tr.Cells.Add(td); //Create a new input box and add it to the cell var input = new TextBox { ID = string.Format("cell:{0}", scaleValue.ScaleValueID), Text = scaleValue.Value.ToString(), }; td.Controls.Add(input); //Each input box will call a function when its value is changed so that //the cell colour can be changed and the id of th input recorded in the hidden field input.Attributes.Add("onchange", "Value_onchange(this);"); } int newValues = 10 - scaleValues.Count; if (newValues <= 0) { newValues = 3; } for (var i = 0; i < newValues; i++) { tr = new HtmlTableRow(); tr.Attributes.Add("class", "GridRow_Orchestrator"); grdValues.Rows.Add(tr); //Add a cell for the Scale Value td = new HtmlTableCell(); tr.Cells.Add(td); //Create a new input box and add it to the cell //Set the cells id so that it indicates to Zone and Pallets var input = new TextBox { ID = string.Format("new:{0}", i) }; td.Controls.Add(input); //Each input box will call a function when its value is chnaged so that //the cell colour can be changed and the id of th input recorded in the hidden field input.Attributes.Add("onchange", "Value_onchange(this);"); } }