HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_Batch.cpp
Go to the documentation of this file.
1 /******************************************************************/
8 #include "../headers/Batch.h"
9 
12 
14 HK_Batch::HK_Batch(int ID, string Name, string Type,
15  string Breed, string Group, string Comments,string Incubator,
16  int Eggs, int Fertile, int Chicks,
17  HK_Date Start, HK_Date Candle, HK_Date Lockdown, HK_Date Hatch,
18  int Remind, int Adv ){
19 
20  Set( ID, Name, Type, Breed, Group, Comments, Incubator, Eggs,
21  Fertile, Chicks, Start, Candle, Lockdown, Hatch, Remind, Adv);
22 }
23 
26 
28 HK_KeyValue HK_Batch::Search(string Value, bool SearchBatch, bool SearchAdv)
29 {
30  HK_KeyValue Results;
31 
32  if(SearchBatch) {
33  string Name = HK_BatchName;
34  string Breed = HK_BatchBreed;
35  string Type = HK_BatchType;
36  string Group = HK_BatchGroup;
37  string Incubator = HK_BatchIncubator;
38  string Comments = HK_BatchComments;
39 
40  transform(Value.begin(),Value.end(),Value.begin(), ::tolower);
41  transform(Name.begin(),Name.end(),Name.begin(), ::tolower);
42  transform(Breed.begin(),Breed.end(),Breed.begin(), ::tolower);
43  transform(Type.begin(),Type.end(),Type.begin(), ::tolower);
44  transform(Group.begin(),Group.end(),Group.begin(), ::tolower);
45  transform(Incubator.begin(),Incubator.end(),Incubator.begin(), ::tolower);
46  transform(Comments.begin(),Comments.end(),Comments.begin(), ::tolower);
47 
48  if(Name.find(Value) != string::npos)
49  Results.Add("Batch " + HK_BatchName + "'s Name", HK_BatchName);
50 
51  if(Breed.find(Value) != string::npos)
52  Results.Add("Batch " + HK_BatchName + "'s Breed", HK_BatchBreed);
53 
54  if(Type.find(Value) != string::npos)
55  Results.Add("Batch " + HK_BatchName + "'s Type", HK_BatchType);
56 
57  if(Group.find(Value) != string::npos)
58  Results.Add("Batch " + HK_BatchName + "'s Group", HK_BatchGroup);
59 
60  if(Incubator.find(Value) != string::npos)
61  Results.Add("Batch " + HK_BatchName + "'s Incubator", HK_BatchIncubator);
62 
63  if(Comments.find(Value) != string::npos)
64  Results.Add("Batch " + HK_BatchName + "'s Comments", HK_BatchComments);
65  }
66 
67  if(SearchAdv)
68  Results.Add(HK_BatchAdvanced.Search(Value,HK_BatchName));
69 
70  return Results;
71 
72 }
73 
75 void HK_Batch::Set(int ID, string Name, string Type,
76  string Breed, string Group, string Comments, string Incubator,
77  int Eggs, int Fertile, int Chicks,
78  HK_Date Start, HK_Date Candle, HK_Date Lockdown, HK_Date Hatch,
79  int Remind, int Adv
80 ){
81  HK_BatchID = ID;
82  HK_BatchName = Name;
83  HK_BatchType = Type;
84  HK_BatchBreed = Breed;
85  HK_BatchGroup = Group;
86  HK_BatchComments = Comments;
87  HK_BatchIncubator = Incubator;
88  HK_BatchEggs = Eggs;
89  HK_BatchFertile = Fertile;
90  HK_BatchChicks = Chicks;
91  HK_BatchStart = Start;
92  HK_BatchCandle = Candle;
93  HK_BatchLockdown = Lockdown;
94  HK_BatchHatch = Hatch;
96  HK_BatchAdv = Adv;
97 }
98 
100 void HK_Batch::SetID(int ID){HK_BatchID = ID;}
102 void HK_Batch::SetName(string Name){HK_BatchName = Name;}
104 void HK_Batch::SetType(string Type){HK_BatchType = Type;}
106 void HK_Batch::SetBreed(string Breed){HK_BatchBreed = Breed;}
108 void HK_Batch::SetGroup(string Group){HK_BatchGroup = Group;}
110 void HK_Batch::SetComments(string Comments){HK_BatchComments = Comments;}
112 void HK_Batch::SetIncubator(string Incubator){HK_BatchIncubator = Incubator;}
114 void HK_Batch::SetEggs(int Eggs){HK_BatchEggs = Eggs;}
116 void HK_Batch::SetFertile(int Fertile){HK_BatchFertile = Fertile;}
118 void HK_Batch::SetChicks(int Chicks){HK_BatchChicks = Chicks;}
124 void HK_Batch::SetLockdown(HK_Date Lockdown){HK_BatchLockdown = Lockdown;}
130 void HK_Batch::SetAdv(int Adv){HK_BatchAdv = Adv;}
134 void HK_Batch::SetAdvEgg(HK_Egg Egg, int Select){HK_BatchAdvanced.SetEgg(Egg,Select);}
137 
138 
144 string HK_Batch::GetType(){return HK_BatchType ;}
155 
158 {
159  if(GetAdv() == 0)
160  return HK_BatchFertile;
161  else
162  return HK_BatchAdvanced.GetFertile();
163 }
164 
167 {
168  if(GetAdv() == 0)
169  return HK_BatchChicks;
170  else
171  return HK_BatchAdvanced.GetChicks();
172 }
173 
188 
190 vector<string> HK_Batch::GetSQL(){return GetSQL(HK_BatchID);}
191 
193 vector<string> HK_Batch::GetSQL(int ID)
194 {
195  vector<string> SQL;
196  SQL.push_back("INSERT INTO Batches VALUES(" + to_string(ID) + ", '" + \
197  HK_BatchName + "'," + to_string(HK_BatchEggs) + ", '" + HK_BatchType + \
198  "', '" + GetStart().ToSortable("/") + "','" + GetCandle().ToSortable("/") + \
199  "','" + GetLockdown().ToSortable("/") + "','" + GetHatch().ToSortable("/") + \
200  "'," + to_string(HK_BatchFertile) + "," + to_string(HK_BatchChicks) + \
201  ",'" + HK_BatchComments + "','" + HK_BatchBreed + "','" + \
202  HK_BatchGroup + "','" + HK_BatchIncubator + "'," + \
203  to_string(HK_BatchRemind) + "," + to_string(HK_BatchAdv) + ");");
204 
205  if(GetAdv() == 1)
206  SQL.push_back(GetAdvanced().GetSQL());
207  return SQL;
208 }
210 vector<string> HK_Batch::GetUpdate()
211 {
212  vector<string> Result;
213 
214  if(HK_BatchAdv == 1)
215  Result = HK_BatchAdvanced.GetUpdate();
216 
217  string SQL = "UPDATE Batches SET ";
218  SQL += "BatchName = '" + HK_BatchName + "',";
219  SQL += "BatchType = '" + HK_BatchType + "',";
220  SQL += "BatchBreed = '" + HK_BatchBreed + "',";
221  SQL += "BatchGroup = '" + HK_BatchGroup + "',";
222  SQL += "Incubator = '" + HK_BatchIncubator + "',";
223  SQL += "BatchComments = '" + HK_BatchComments + "',";
224  SQL += "BatchSDate = '" + GetStart().ToSortable("/") + "',";
225  SQL += "BatchC1Date = '" + GetCandle().ToSortable("/") + "',";
226  SQL += "BatchTDate = '" + GetLockdown().ToSortable("/") + "',";
227  SQL += "BatchHDate = '" + GetHatch().ToSortable("/") + "',";
228  SQL += "BatchEggs = " + to_string(HK_BatchEggs) + ",";
229  SQL += "FertileEggs = " + to_string(HK_BatchFertile) + ",";
230  SQL += "ChicksHatched = " + to_string(HK_BatchChicks) + ",";
231  SQL += "IsReminded = " + to_string(HK_BatchRemind) + ",";
232  SQL += "AdvEnabled = " + to_string(HK_BatchAdv);
233  SQL += " WHERE ID = " + to_string(HK_BatchID) + ";";
234 
235  Result.push_back(SQL);
236  return Result;
237 }
238 
239 
241 int HK_Batch::CalculatePercent(int First, int Second)
242 {
243  if (First == 0 || Second == 0)
244  return 0;
245 
246  float Float1 = First;
247  float Float2 = Second;
248  float Float3 = Float1 / Float2;
249  return Float3 * 100;
250 }
251 
253 
255  HK_Date d;
256 
257  if(HK_BatchStart.IsBefore(d))
259  else if (HK_BatchHatch.IsAfter(d))
260  return 0;
261  else
262  return d.Difference(HK_BatchHatch);
263 }
264 
267  HK_Date d;
268 
269  if(HK_BatchStart.IsBefore(d))
270  return 0;
271  else if (HK_BatchHatch.IsAfter(d))
273  else
274  return d.Difference(HK_BatchStart);
275 }
276 
279 {
280  return CalculatePercent(GetFertile(),GetEggs());
281 }
282 
285 {
287 }
288 
291 {
292  return CalculatePercent(GetChicks(),GetEggs());
293 }
294 
297 {
298  return (GetEggs() - GetChicks()) - (GetEggs() - GetFertile());
299 }
300 
303 {
304  return CalculatePercent(GetEggs() - GetChicks(), GetEggs());
305 }
HK_Storage Remind
Definition: Declare.h:40
A Class For Managing Multiple HK_Egg Instances.
Definition: Advanced.h:20
void SetUpdate(bool Status)
Sets Update Status For This HK_Advanced.
HK_KeyValue Search(string Value, string BatchName)
Searches Eggs For Matches To Value.
vector< string > GetUpdate()
Returns An Array Of SQL Strings To Update Database.
int GetChicks()
Returns The Number Of Eggs That Hatched Based On HK_Egg Data.
Definition: HK_Advanced.cpp:65
void SetEgg(HK_Egg Egg, int Select)
Sets Selected Egg.
int GetFertile()
Returns The Number Of Eggs That Are Fertile Based On HK_Egg Data.
Definition: HK_Advanced.cpp:55
int PercentOfTotal()
Returns The Percentage Of Total Eggs That Hatched.
Definition: HK_Batch.cpp:290
void SetAdv(int Adv)
Sets Batch Advanced Status.
Definition: HK_Batch.cpp:130
int PercentFertile()
Returns The Percentage Of Eggs That Were Fertile.
Definition: HK_Batch.cpp:278
void SetID(int ID)
Sets Batch ID.
Definition: HK_Batch.cpp:100
void SetAdvanced(HK_Advanced Adv)
Sets Batch Advanced Data.
Definition: HK_Batch.cpp:132
int HK_BatchFertile
Definition: Batch.h:33
void SetCandle(HK_Date Candle)
Sets Batch Candle Date.
Definition: HK_Batch.cpp:122
int GetChicks()
Returns Number Of Hatched Eggs In Batch, If Advanced Is Enabled It Returns HK_Advanced::GetChicks()
Definition: HK_Batch.cpp:166
string HK_BatchBreed
Definition: Batch.h:27
HK_Date GetCandle()
Returns Batch Candle Date.
Definition: HK_Batch.cpp:177
HK_Date HK_BatchLockdown
Definition: Batch.h:38
int HK_BatchChicks
Definition: Batch.h:34
HK_Advanced HK_BatchAdvanced
Definition: Batch.h:43
vector< string > GetSQL()
Returns An SQL String To Set Batch In Database.
Definition: HK_Batch.cpp:190
string GetName()
Returns Batch Name.
Definition: HK_Batch.cpp:142
int GetFertile()
Returns Number Of Fertile Eggs In Batch, If Advanced Is Enabled It Returns HK_Advanced::GetFertile()
Definition: HK_Batch.cpp:157
void Set(int ID, string Name, string Type, string Breed, string Group, string Comments, string Incubator, int Eggs, int Fertile, int Chicks, HK_Date Start, HK_Date Candle, HK_Date Lockdown, HK_Date Hatch, int Remind, int Adv)
Sets All Batch Data In One Function.
Definition: HK_Batch.cpp:75
void SetFertile(int Fertile)
Sets Batch Fertile Eggs.
Definition: HK_Batch.cpp:116
HK_Batch()
Default Constructor.
Definition: HK_Batch.cpp:11
void SetName(string Name)
Sets Batch Name.
Definition: HK_Batch.cpp:102
HK_Date GetStart()
Returns Batch Start Date.
Definition: HK_Batch.cpp:175
string GetIncubator()
Returns The Incubator As A String.
Definition: HK_Batch.cpp:152
vector< string > GetUpdate()
Returns A String That Updates This Batch In Database.
Definition: HK_Batch.cpp:210
string GetGroup()
Returns Batch Group.
Definition: HK_Batch.cpp:148
void SetRemind(int Remind)
Sets Batch Remind Status For Notifications.
Definition: HK_Batch.cpp:128
int OnDay()
Returns The Number Of Days Left In Incubation Period.
Definition: HK_Batch.cpp:266
int GetEggs()
Returns Number Of Eggs In Batch.
Definition: HK_Batch.cpp:154
void SetType(string Type)
Sets Batch Type.
Definition: HK_Batch.cpp:104
void SetIncubator(string Incubator)
Sets Batch Incubator.
Definition: HK_Batch.cpp:112
HK_Date GetLockdown()
Returns Batch Lockdown Date.
Definition: HK_Batch.cpp:179
void SetAdvEgg(HK_Egg Egg, int Select)
Sets The Selected Egg For HK_Advanced.
Definition: HK_Batch.cpp:134
string HK_BatchComments
Definition: Batch.h:29
void SetChicks(int Chicks)
Sets Batch Hatched Eggs.
Definition: HK_Batch.cpp:118
void SetComments(string Comments)
Sets Batch Comments.
Definition: HK_Batch.cpp:110
int HK_BatchRemind
Definition: Batch.h:41
string GetComments()
Returns Batch Comments.
Definition: HK_Batch.cpp:150
int GetRemind()
Returns Batch Remind Status.
Definition: HK_Batch.cpp:183
HK_Date HK_BatchHatch
Definition: Batch.h:39
void SetBreed(string Breed)
Sets Batch Breed.
Definition: HK_Batch.cpp:106
int GetDaysLeft()
Returns The Number Of Days Left In Incubation Period.
Definition: HK_Batch.cpp:254
~HK_Batch()
Destructor.
Definition: HK_Batch.cpp:25
int FertileUnhatched()
Returns The Number Of Fertile Eggs That Didn't Hatch.
Definition: HK_Batch.cpp:296
HK_Date HK_BatchStart
Definition: Batch.h:36
int HK_BatchAdv
Definition: Batch.h:42
string GetBreed()
Returns Batch Breed.
Definition: HK_Batch.cpp:146
void SetHatch(HK_Date Hatch)
Sets Batch Hatch Date.
Definition: HK_Batch.cpp:126
string HK_BatchName
Definition: Batch.h:25
void SetEggs(int Eggs)
Sets Batch Eggs.
Definition: HK_Batch.cpp:114
int PercentOfTotalUnhatched()
Returns The Percentage Of Total Eggs That Didn't Hatch.
Definition: HK_Batch.cpp:302
int PercentOfFertile()
Returns The Percentage Of Fertile Eggs That Hatched.
Definition: HK_Batch.cpp:284
void SetAdvUpdate(bool Status)
Sets The Update Status HK_Advanced.
Definition: HK_Batch.cpp:136
string HK_BatchType
Definition: Batch.h:26
void SetStart(HK_Date Start)
Sets Batch Start Date.
Definition: HK_Batch.cpp:120
int GetID()
Returns Batch ID.
Definition: HK_Batch.cpp:140
HK_Advanced GetAdvanced()
Returns Batch Advanced Egg Data.
Definition: HK_Batch.cpp:187
int GetAdv()
Returns Batch Advanced Status.
Definition: HK_Batch.cpp:185
string GetType()
Returns Batch Type.
Definition: HK_Batch.cpp:144
void SetLockdown(HK_Date Lockdown)
Sets Batch Lockdown Date.
Definition: HK_Batch.cpp:124
HK_KeyValue Search(string Value, bool SearchBatches, bool SearchAdv)
Searches For Value And Returns HK_KeyValue With Data.
Definition: HK_Batch.cpp:28
string HK_BatchGroup
Definition: Batch.h:28
void SetGroup(string Group)
Sets Batch Group.
Definition: HK_Batch.cpp:108
HK_Date GetHatch()
Returns Batch Hatch Date.
Definition: HK_Batch.cpp:181
int CalculatePercent(int First, int Second)
Returns The Percentage Of Two Ints.
Definition: HK_Batch.cpp:241
int HK_BatchEggs
Definition: Batch.h:32
HK_Date HK_BatchCandle
Definition: Batch.h:37
int HK_BatchID
Definition: Batch.h:24
string HK_BatchIncubator
Definition: Batch.h:30
A Class For Managing Dates.
Definition: Date.h:25
int Difference(HK_Date Date)
Returns The Number Of Days Difference Between This HK_Date And The Supplied Date.
Definition: HK_Date.cpp:84
std::string ToSortable(std::string Separator)
Generate A Sortable String For Database.
Definition: HK_Date.cpp:163
bool IsBefore(HK_Date Date)
Checks To See If The Input Date Is Before The Stored Date.
Definition: HK_Date.cpp:289
bool IsAfter(HK_Date Date)
Checks To See If The Input Date Is After The Stored Date.
Definition: HK_Date.cpp:253
A Class For Storing And Retieving Data For One Egg.
Definition: Egg.h:24
A Key and Value Type Storage.
Definition: KeyValue.h:25
void Add(string Key, string Value)
Adds A Key And Value;.
Definition: HK_KeyValue.cpp:33