public static double?ConvertValue(double value, Guid FromUoMID, Guid ToUoMID, Guid OrganizationId) { Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create(FromUoMID, OrganizationId); Micajah.Common.Bll.MeasureUnitCollection UoMs = mu.GetConvertUnits(); var cmu = UoMs.Where(u => u.MeasureUnitId == ToUoMID).ToList(); if (cmu.Count <= 0) { return(null); } return(cmu[0].ConversionFactor * value); }
public static List <Micajah.Common.Bll.MeasureUnit> GetConvertedUoMs(Guid?ParentUoMID, Guid OrganizationId) { Micajah.Common.Bll.MeasureUnitCollection UoMs = null; if (ParentUoMID == null) { UoMs = Micajah.Common.Bll.MeasureUnitCollection.GetUnits(OrganizationId); } else { Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create((Guid)ParentUoMID, OrganizationId); UoMs = mu.GetConvertUnits(); UoMs.Add(mu); UoMs.SortByName(); } return(UoMs.ToList()); }
private static string RunProcess() { Bll.Metric.CheckVariablesAndFormulas(); int maxgen = Bll.Metric.GenerationCount(); MathParser parser = new MathParser(); string er = String.Empty; string result = String.Empty; for (int i = 1; i <= maxgen; i++) { List <Bll.MetricValue.Extend> _CalcMetricValues = null; List <Bll.MetricValue.Extend> _InputMetricValues = Bll.MetricValue.MetricValuesForCalculation(i, out _CalcMetricValues); List <Bll.Mc_Instance> Instances = MetricTrac.Bll.Mc_Instance.List(); foreach (Bll.MetricValue.Extend mv in _CalcMetricValues) { Guid?CalcOutputUoM = mv.UnitOfMeasureID = mv.MetricUnitOfMeasureID; mv.InputUnitOfMeasureID = mv.MetricInputUnitOfMeasureID; Guid OrganizationId = Instances.Where(r => r.InstanceId == mv.InstanceId).SingleOrDefault().OrganizationId; List <Bll.MetricValue.Extend> ActualInputMetricValues = _InputMetricValues.Where(r => (r.RelatedFormulaID == mv.RelatedFormulaID) && (r.Date == mv.Date) && (r.OrgLocationID == mv.OrgLocationID)).ToList(); Hashtable h = new Hashtable(); /*bool IsMissedInputs = false; * bool IsConverted = true; * foreach (Bll.MetricValue.Extend mvi in ActualInputMetricValues) * { * Guid? CurOutputUoM = mvi.UnitOfMeasureID; * if (CalcOutputUoM != CurOutputUoM) * { * if (CalcOutputUoM != null && CurOutputUoM != null) * { * List<Micajah.Common.Bll.MeasureUnit> l = Bll.Mc_UnitsOfMeasure.GetConvertedUoMs(CalcOutputUoM, OrganizationId); * Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create((Guid)CurOutputUoM, OrganizationId); * if (!l.Contains(mu)) * IsConverted = false; * } * else * IsConverted = false; * } * if (IsConverted) * { * string var = mvi.Variable; * if (String.IsNullOrEmpty(var)) * var = Bll.Metric.GetGuidAsNumber(mvi.MetricID); * * string PreValue = "0"; * if (mvi.ConvertedValue != "-" && !String.IsNullOrEmpty(mvi.ConvertedValue)) * { * PreValue = mvi.ConvertedValue; * if (CalcOutputUoM != CurOutputUoM) * PreValue = Bll.Mc_UnitsOfMeasure.ConvertValue(PreValue, (Guid)CurOutputUoM, (Guid)CalcOutputUoM, OrganizationId); * } * else * IsMissedInputs = true; * h.Add("v" + var, PreValue); * if (mvi.MetricValueID == Guid.Empty) * IsMissedInputs = true; * } * }*/ bool IsInputsWithSubMissed = false; bool IsMissedInputs = false; bool IsConverted = true; foreach (Bll.MetricValue.Extend mvi in ActualInputMetricValues) { Guid?CurInputUoM = mvi.InputUnitOfMeasureID; if (CalcOutputUoM != CurInputUoM) { if (CalcOutputUoM != null && CurInputUoM != null) { List <Micajah.Common.Bll.MeasureUnit> l = Bll.Mc_UnitsOfMeasure.GetConvertedUoMs(CalcOutputUoM, OrganizationId); Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create((Guid)CurInputUoM, OrganizationId); if (!l.Contains(mu)) { IsConverted = false; } } else { IsConverted = false; } } if (IsConverted) { string var = mvi.Variable; if (String.IsNullOrEmpty(var)) { var = Bll.Metric.GetGuidAsNumber(mvi.MetricID); } string PreValue = "0"; if (mvi.Value != "-" && !String.IsNullOrEmpty(mvi.Value)) { PreValue = mvi.Value; if (CalcOutputUoM != CurInputUoM && CalcOutputUoM != null && CurInputUoM != null) { PreValue = Bll.Mc_UnitsOfMeasure.ConvertValue(PreValue, (Guid)CurInputUoM, (Guid)CalcOutputUoM, OrganizationId); } } else { IsMissedInputs = true; } h.Add("v" + var, PreValue); if (mvi.MetricValueID == Guid.Empty) { IsMissedInputs = true; } if (mvi.MissedCalc) { IsInputsWithSubMissed = true; } } } if (IsConverted) { string StartValue = null; try { StartValue = parser.Parse(mv.VariableFormula.ToLower().Trim(), h).ToString(); } catch (Exception e) { er += e.Message + "<br />"; StartValue = "-"; } mv.Value = StartValue == "Infinity" ? "-" : StartValue; mv.MissedCalc = IsMissedInputs || IsInputsWithSubMissed; } else { mv.Value = "-"; } } foreach (Bll.MetricValue.Extend mv in _CalcMetricValues) { result += "MetricName: " + mv.MetricName + " Date: " + mv.Date.ToShortDateString() + " CalcValue: " + mv.Value + "<br />"; } Bll.MetricValue.SaveCalcValues(_InputMetricValues, _CalcMetricValues); } Bll.MetricValue.ClearInputValues(maxgen); return(String.IsNullOrEmpty(result) && String.IsNullOrEmpty(er) ? String.Empty : (result + "<br /><br />" + er)); }
protected void mfMetricValue_PreRender(object sender, EventArgs e) { if (IsPostBack && String.IsNullOrEmpty(this.ErrorMessage)) { return; } mfMetricValue.Fields[3].Visible = mfMetricValue.Fields[4].Visible = (MVS.AllowMetricCustomNames && (Mode != DataMode.Approve)); if (Mode == DataMode.View) { flFiles.LocalObjectId = MVS.MetricValueID.ToString(); lblValueView.Text = MVS.Value; string PreValue = MVS.Value; bool IsConverted = true; Guid? CurInputUoM = MVS.InputUnitOfMeasureID; Guid? CalcOutputUoM = MVS.MetricUnitOfMeasureID; if (CalcOutputUoM != CurInputUoM) { if (CalcOutputUoM != null && CurInputUoM != null) { List <Micajah.Common.Bll.MeasureUnit> l = Bll.Mc_UnitsOfMeasure.GetConvertedUoMs(CalcOutputUoM); Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create((Guid)CurInputUoM, Bll.LinqMicajahDataContext.OrganizationId); if (!l.Contains(mu)) { IsConverted = false; } } else { IsConverted = false; } } if (IsConverted && PreValue != "-" && !String.IsNullOrEmpty(PreValue) && CalcOutputUoM != CurInputUoM && CalcOutputUoM != null && CurInputUoM != null) { PreValue = Bll.Mc_UnitsOfMeasure.ConvertValue(PreValue, (Guid)CurInputUoM, (Guid)CalcOutputUoM); } lblConvertedValue.Text = PreValue; //lblConvertedValue.Text = MVS.ConvertedValue; if (MVS.MetricDataTypeID == 1) { lblUoMView.Text = MVS.ValueInputUnitOfMeasureName + (String.IsNullOrEmpty(MVS.ValueInputUnitOfMeasureName) ? String.Empty : "(s)"); lblOutputUoMView.Text = MVS.MetricUnitOfMeasureName + (String.IsNullOrEmpty(MVS.MetricUnitOfMeasureName) ? String.Empty : "(s)");//MVS.ValueUnitOfMeasureName + (String.IsNullOrEmpty(MVS.ValueUnitOfMeasureName) ? String.Empty : "(s)"); } } else { ddlApprovalStatus.Enabled = Mode == DataMode.Approve; bool IsDataTypeChanged = false; bool IsNewRecord = false; if (MVS.MetricValueID == Guid.Empty) { lblOldValue.Visible = false; IsNewRecord = true; } else { if (MVS.MetricDataTypeID != MVS.ActualMetricDataTypeID) {// Data type was changed for this metric IsDataTypeChanged = true; string sOldValue = "Old value for this period is " + MVS.Value; if (MVS.MetricDataTypeID == 1) { sOldValue += " " + MVS.ValueInputUnitOfMeasureName; } lblOldValue.Text = sOldValue; lblOldValue.Visible = true; } } FilesUpload.LocalObjectId = MVS.MetricValueID == Guid.Empty ? null : MVS.MetricValueID.ToString(); switch (MVS.ActualMetricDataTypeID) { case 1: //Numeric rntValue.Visible = lblUoM.Visible = ddlInputUnitOfMeasure.Visible = true; if (MVS.IsCalculated == true) { mfMetricValue.Fields[8].HeaderText = "Calculated value"; rntValue.ReadOnly = true; rntValue.BorderStyle = BorderStyle.None; // } tbValue.Visible = chbValue.Visible = rdpDateValue.Visible = false; rntValue.Text = String.Empty; if (!IsDataTypeChanged) { if ((MVS.MetricUnitOfMeasureID != MVS.UnitOfMeasureID) && !IsNewRecord) { lblOldValue.Text = "Old value for this period is " + MVS.Value + " " + MVS.ValueInputUnitOfMeasureName; lblOldValue.Visible = true; } else { double _Value = double.NaN; if (double.TryParse(MVS.Value, out _Value)) { rntValue.Value = _Value; } } } // Range label if ((MVS.NOMinValue != null) || (MVS.NOMaxValue != null) || (MVS.NODecPlaces != null)) { //lblRange.Visible = true; lblRange.Text = String.Empty; int defPlaces = 2; if (MVS.NODecPlaces != null) { rntValue.NumberFormat.DecimalDigits = (int)MVS.NODecPlaces; defPlaces = (int)MVS.NODecPlaces; lblRange.Text += "DecPlaces = " + MVS.NODecPlaces.ToString() + ";"; } if (MVS.NOMinValue != null) { rntValue.MinValue = decimal.ToDouble((decimal)MVS.NOMinValue); lblRange.Text += "MinValue = " + ((decimal)MVS.NOMinValue).ToString("F" + defPlaces.ToString()) + "; "; // how many digits it may show ??? } if (MVS.NOMaxValue != null) { rntValue.MaxValue = decimal.ToDouble((decimal)MVS.NOMaxValue); lblRange.Text += "MaxValue = " + ((decimal)MVS.NOMaxValue).ToString("F" + defPlaces.ToString()) + "; "; } } else { lblRange.Visible = false; } break; case 2: //Text tbValue.Visible = true; rntValue.Visible = lblUoM.Visible = ddlInputUnitOfMeasure.Visible = lblRange.Visible = chbValue.Visible = rdpDateValue.Visible = false; tbValue.Text = String.Empty; if (!IsDataTypeChanged) { tbValue.Text = MVS.Value; } break; case 3: //Bool - checkbox chbValue.Visible = true; rntValue.Visible = lblUoM.Visible = ddlInputUnitOfMeasure.Visible = lblRange.Visible = tbValue.Visible = rdpDateValue.Visible = false; chbValue.Checked = false; if (!IsDataTypeChanged) { chbValue.Checked = MVS.Value == bool.TrueString; } break; case 4: //Date rdpDateValue.Visible = true; rntValue.Visible = lblUoM.Visible = ddlInputUnitOfMeasure.Visible = lblRange.Visible = tbValue.Visible = chbValue.Visible = false; rdpDateValue.SelectedDate = DateTime.Now; DateTime _dt = DateTime.Now; if (!IsDataTypeChanged) { if (DateTime.TryParse(MVS.Value, out _dt)) { rdpDateValue.SelectedDate = _dt; } } break; default: rntValue.Visible = lblUoM.Visible = ddlInputUnitOfMeasure.Visible = lblRange.Visible = tbValue.Visible = chbValue.Visible = rdpDateValue.Visible = false; break; } } }
public static string GetMeasureUnitPluralName(List <Micajah.Common.Bll.MeasureUnit> OrgUoMs, Guid?MeasureUnitID) { Micajah.Common.Bll.MeasureUnit mu = OrgUoMs.Find(u => u.MeasureUnitId == MeasureUnitID); return(mu == null ? String.Empty : mu.PluralFullName); }
public static string GetSingularAbbreviation(Guid UomID) { Micajah.Common.Bll.MeasureUnit mu = Micajah.Common.Bll.MeasureUnit.Create(UomID, LinqMicajahDataContext.OrganizationId); return(mu.SingularAbbreviation); }
public static string GetMeasureUnitAbbvr(List <Micajah.Common.Bll.MeasureUnit> OrgUoMs, Guid?MeasureUnitID) { Micajah.Common.Bll.MeasureUnit mu = OrgUoMs.Find(u => u.MeasureUnitId == MeasureUnitID); return(mu == null ? String.Empty : mu.SingularAbbreviation); }