139 lines
3.6 KiB
C#
139 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace JRCookbookBusiness
|
|
{
|
|
public enum MeasureType
|
|
{
|
|
Mass,
|
|
Volume,
|
|
Unit
|
|
}
|
|
public class Measure
|
|
{
|
|
public Guid? measureID = null;
|
|
public String description = String.Empty;
|
|
public MeasureType measureType = MeasureType.Mass;
|
|
|
|
|
|
public Measure()
|
|
{
|
|
}
|
|
|
|
public Measure(Guid measureID)
|
|
{
|
|
PopulateByID(measureID);
|
|
}
|
|
|
|
public static Measure GetMeasureByID(Guid measureID)
|
|
{
|
|
return new Measure(measureID);
|
|
}
|
|
|
|
private void PopulateByID(Guid measureID)
|
|
{
|
|
DataSet recordSet;
|
|
|
|
recordSet = clsDatabaseLayer.GetDatabaseLayer().GetMeasureByID(measureID);
|
|
|
|
if (recordSet.Tables[0].Rows.Count > 0)
|
|
{
|
|
DataRow ldbrwRow;
|
|
ldbrwRow = recordSet.Tables[0].Rows[0];
|
|
|
|
PopulateFromDataRow(ldbrwRow);
|
|
}
|
|
|
|
}
|
|
|
|
private void PopulateFromDataRow(DataRow dataRow)
|
|
{
|
|
InitializeAllFields();
|
|
|
|
if (dataRow.IsNull("measureID"))
|
|
measureID = null;
|
|
else
|
|
measureID = (Guid)dataRow["measureID"];
|
|
|
|
if (dataRow.IsNull("description"))
|
|
description = String.Empty;
|
|
else
|
|
description = (String)dataRow["description"];
|
|
|
|
if (dataRow.IsNull("Type"))
|
|
measureType = MeasureType.Mass;
|
|
else
|
|
measureType = MeasureTypeByString((String)dataRow["Type"]);
|
|
|
|
}
|
|
|
|
private void InitializeAllFields()
|
|
{
|
|
measureID = null;
|
|
description = String.Empty;
|
|
measureType = MeasureType.Mass;
|
|
}
|
|
|
|
public static Measure GetMeasureByDataRow(DataRow dataRow)
|
|
{
|
|
var newMeasure = new Measure();
|
|
newMeasure.PopulateFromDataRow(dataRow);
|
|
|
|
return newMeasure;
|
|
}
|
|
|
|
public static List<Measure> GetMeasuresByIngredientID(Guid ingredientID)
|
|
{
|
|
var returnValue = new List<Measure>();
|
|
|
|
DataSet recordSet;
|
|
|
|
recordSet = clsDatabaseLayer.GetDatabaseLayer().GetMeasuresByIngredientID(ingredientID);
|
|
|
|
foreach (DataRow dataRow in recordSet.Tables[0].Rows)
|
|
{
|
|
var newMeasure = Measure.GetMeasureByDataRow(dataRow);
|
|
returnValue.Add(newMeasure);
|
|
}
|
|
|
|
return returnValue;
|
|
}
|
|
|
|
|
|
public static MeasureType MeasureTypeByString(String value)
|
|
{
|
|
switch (value)
|
|
{
|
|
case "Mass": return MeasureType.Mass;
|
|
case "Volume": return MeasureType.Volume;
|
|
case "Unit": return MeasureType.Unit;
|
|
default:
|
|
throw new ApplicationException("Invalid MeasureType");
|
|
}
|
|
}
|
|
|
|
public static String ConvertMeasureTypeToString(MeasureType value)
|
|
{
|
|
switch (value)
|
|
{
|
|
case MeasureType.Mass: return "Mass";
|
|
case MeasureType.Volume: return "Volume";
|
|
case MeasureType.Unit: return "Unit";
|
|
default:
|
|
throw new ApplicationException("Invalid MeasureType");
|
|
}
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return this.description;
|
|
}
|
|
|
|
}
|
|
}
|