Files
JRCookbook/JRCookbookBusiness/RecipeProcedure.cs
2026-03-07 19:22:22 -06:00

136 lines
3.8 KiB
C#

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JRCookbookBusiness
{
public class RecipeProcedure: ICloneable
{
public Guid? recipeProcedureID = null;
public Guid? recipeID = null;
public String procedureText = String.Empty;
public Int32 procedureIndex = 0;
public bool isHeading = false;
public RecipeProcedure()
{
}
public RecipeProcedure(Recipe parentRecipe)
{
recipeID = parentRecipe.recipeID;
}
public RecipeProcedure(Guid recipeProcedureID)
{
PopulateByID(recipeProcedureID);
}
public void PasteIntoChapter(Guid newRecipeID)
{
this.recipeProcedureID = null;
this.recipeID = newRecipeID;
}
public void Save()
{
if (this.recipeProcedureID == null)
{
this.recipeProcedureID = clsDatabaseLayer.GetDatabaseLayer().GetNewIDRecipeProcedure();
clsDatabaseLayer.GetDatabaseLayer().InsertRecipeProcedure(this);
}
else
{
clsDatabaseLayer.GetDatabaseLayer().UpdateRecipeProcedure(this);
}
}
public void Delete()
{
clsDatabaseLayer.GetDatabaseLayer().DeleteRecipeProcedureByID(recipeProcedureID.Value);
}
public static void DeleteAllByRecipeID(Guid recipeID)
{
clsDatabaseLayer.GetDatabaseLayer().DeleteRecipeProceduresByRecipeID(recipeID);
}
public static RecipeProcedure GetRecipeProcedureByID(Guid recipeProcedureID)
{
return new RecipeProcedure(recipeProcedureID);
}
public static RecipeProcedure GetRecipeProcedureByDataRow(DataRow row)
{
var newProcedure = new RecipeProcedure();
newProcedure.PopulateFromDataRow(row);
return newProcedure;
}
private void PopulateByID(Guid recipeProcedureID)
{
DataSet recordSet;
recordSet = clsDatabaseLayer.GetDatabaseLayer().GetRecipeProcedureByID(recipeProcedureID);
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("recipeProcedureID"))
recipeProcedureID = null;
else
recipeProcedureID = (Guid)dataRow["recipeProcedureID"];
if (dataRow.IsNull("recipeID"))
recipeID = null;
else
recipeID = (Guid)dataRow["recipeID"];
if (dataRow.IsNull("procedureText"))
procedureText = String.Empty;
else
procedureText = (String)dataRow["procedureText"];
if (dataRow.IsNull("procedureIndex"))
procedureIndex = 0;
else
procedureIndex = (Int32)dataRow["procedureIndex"];
if (dataRow.IsNull("Heading"))
isHeading = false;
else
isHeading = (((String)dataRow["Heading"]).ToUpper() == "Y");
}
private void InitializeAllFields()
{
recipeProcedureID = null;
recipeID = null;
procedureText = String.Empty;
procedureIndex = 0;
isHeading = false;
}
public object Clone()
{
return this.MemberwiseClone();
}
}
}