164 lines
4.6 KiB
C#
164 lines
4.6 KiB
C#
using System;
|
|
using System.Data;
|
|
|
|
namespace JRCookbookBusiness
|
|
{
|
|
public class RecipeIngredientItem: RecipeIngredient
|
|
{
|
|
public Guid? ingredientID = null;
|
|
public String quantityText = String.Empty;
|
|
public String unitText = String.Empty;
|
|
|
|
public String measureName = String.Empty;
|
|
private Guid? _measureID = null;
|
|
private bool isMeasureLoaded = false;
|
|
private Measure _measure = null;
|
|
|
|
public Single measureQuantity = 0;
|
|
public Int16 linkQuality = 1;
|
|
|
|
public RecipeIngredientItem()
|
|
{
|
|
linkQuality = 0;
|
|
}
|
|
|
|
public RecipeIngredientItem(Recipe parentRecipe)
|
|
{
|
|
recipeID = parentRecipe.recipeID;
|
|
linkQuality = 0;
|
|
}
|
|
|
|
public Measure measure {
|
|
get {
|
|
if (_measureID == null)
|
|
{
|
|
return null;
|
|
}
|
|
if (!isMeasureLoaded)
|
|
{
|
|
Measure.GetMeasureByID(_measureID.Value);
|
|
isMeasureLoaded = true;
|
|
}
|
|
return _measure;
|
|
}
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
measureName = String.Empty;
|
|
_measureID = null;
|
|
isMeasureLoaded = false;
|
|
_measure = null;
|
|
}
|
|
else
|
|
{
|
|
_measure = value;
|
|
measureName = _measure.description;
|
|
_measureID = _measure.measureID;
|
|
isMeasureLoaded = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
public Guid? measureID
|
|
{
|
|
get
|
|
{
|
|
return _measureID;
|
|
}
|
|
set
|
|
{
|
|
if (value == null)
|
|
{
|
|
measureName = String.Empty;
|
|
_measureID = null;
|
|
isMeasureLoaded = false;
|
|
_measure = null;
|
|
}
|
|
_measureID = value;
|
|
_measure = Measure.GetMeasureByID(_measureID.Value);
|
|
isMeasureLoaded = true;
|
|
measureName = _measure.description;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override void PopulateFromDataRow(DataRow dataRow)
|
|
{
|
|
InitializeAllFields();
|
|
|
|
base.PopulateFromDataRow(dataRow);
|
|
|
|
if (dataRow.IsNull("ingredientID"))
|
|
ingredientID = null;
|
|
else
|
|
ingredientID = (Guid)dataRow["ingredientID"];
|
|
|
|
if (dataRow.IsNull("quantityText"))
|
|
quantityText = String.Empty;
|
|
else
|
|
quantityText = (String)dataRow["quantityText"];
|
|
|
|
if (dataRow.IsNull("unitText"))
|
|
unitText = String.Empty;
|
|
else
|
|
unitText = (String)dataRow["unitText"];
|
|
|
|
if (dataRow.IsNull("measureQuantity"))
|
|
measureQuantity = 0;
|
|
else
|
|
measureQuantity = (Single)dataRow["measureQuantity"];
|
|
|
|
if (dataRow.IsNull("linkQuality"))
|
|
linkQuality = 0;
|
|
else
|
|
linkQuality = (Int16)dataRow["linkQuality"];
|
|
|
|
|
|
|
|
if (dataRow.IsNull("measureID"))
|
|
_measureID = null;
|
|
else
|
|
_measureID = (Guid)dataRow["measureID"];
|
|
|
|
measureName = String.Empty;
|
|
isMeasureLoaded = false;
|
|
_measure = null;
|
|
|
|
if (dataRow.Table.Columns.Contains("measureName") && !dataRow.IsNull("measureName") && !String.IsNullOrEmpty(dataRow[measureName].ToString()))
|
|
{
|
|
measureName = (String)dataRow[measureName];
|
|
}
|
|
else
|
|
{
|
|
if (_measureID != null)
|
|
{
|
|
measure = Measure.GetMeasureByID(_measureID.Value);
|
|
isMeasureLoaded = true;
|
|
measureName = measure.description;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected override void InitializeAllFields()
|
|
{
|
|
base.InitializeAllFields();
|
|
|
|
ingredientID = null;
|
|
quantityText = String.Empty;
|
|
unitText = String.Empty;
|
|
|
|
measureName = String.Empty;
|
|
_measureID = null;
|
|
isMeasureLoaded = false;
|
|
_measure = null;
|
|
|
|
measureQuantity = 0;
|
|
linkQuality = 0;
|
|
}
|
|
|
|
}
|
|
}
|