private void cellTimerLevel1(Border inputBorder, Label inputlbl, int[] inProgressionID, char inRow, int inColumn, int RecipeKey) { int row = Conversions.charToInt(inRow); if (Icolbl[row, inColumn].Children.Count == 3) { Icolbl[row, inColumn].Children.RemoveAt(2); Icons myIcons = new Icons(); Icolbl[row, inColumn].Children.Add(myIcons.getGreen()); } inputBorder.Background = Brushes.Green; }
public void Click(bool autoFromRead) { DateTime startTime = Server.getStartTime(ovenName, row, column); if (startTime.Equals(Server.nullity)) { DateTime curr = new DateTime(); curr = DateTime.Now; int placeHolder = Server.UpdateOven(this.ovenName, this.row, this.column, curr, RecipeKey, this.ProgressionID); if (placeHolder != -1) { disTimer = new DispatcherTimer(); disTimer.Interval = secSpan; disTimer.Tick += DisTimer_Tick; currBorder.Background = System.Windows.Media.Brushes.Blue; if (currGrid.Children.Count == 2) { Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getBlue()); } else if (currGrid.Children.Count == 3) { currGrid.Children.RemoveAt(2); Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getBlue()); } currlbl.Content = Conversions.StripMiliSec(spanTimer).ToString(); //currlbl.Content = string.Format("{0}:{1}:{2}:{3}", (int)spanTimer.Days, (int)spanTimer.Hours, (int)spanTimer.Minutes, (int)spanTimer.Seconds); disTimer.Start(); } else { MainWindow.connect.Close(); System.Windows.MessageBox.Show("Database Entry has Failed, Please Contact System Admin."); } Server.readAllFromDataBase(ovenName); } else { DateTime curr = DateTime.Now; //The entire calculation below is f****d but it works TimeSpan tempSpans1 = totalTimer; TimeSpan tempSpans2 = curr.Subtract(startTime); TimeSpan remSpan = tempSpans1.Subtract(tempSpans2); double sec = tempSpans2.TotalSeconds; TimeSpan currStime = curr.Subtract(startTime); TimeSpan timeTest = totalTimer.Subtract(currStime); double totSec = timeTest.TotalSeconds; if (totSec <= -0.5) //-500 mili seconds as a buffer for timer threading issues { if (autoFromRead) { currBorder.Background = System.Windows.Media.Brushes.Red; currlbl.Content = currlbl.Content = "00:00:00:00"; if (currGrid.Children.Count == 2) { Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getRed()); } } else { this.ProgressionID = Conversions.UpdateProgressionID(this.ProgressionID); int placeHolder = Server.UpdateOven(this.ovenName, this.row, this.column, Server.nullity, RecipeKey, this.ProgressionID); if (placeHolder != -1) { timerLevelReset(this.currBorder, this.currlbl, ProgressionID, this.row, this.column, this.RecipeKey); } else { System.Windows.MessageBox.Show("Database nullified has Failed, Please Contact System Admin."); } } } else { if (autoFromRead) //need to fix this { disTimer = new DispatcherTimer(); disTimer.Interval = new TimeSpan(0, 0, 0, 1, 0); //current timer increments in 1 seconds disTimer.Tick += DisTimer_Tick; this.timer = (int)sec; spanTimer = remSpan; if (timer >= Limit2 && timer < Limit3) //Instead of equals to try using less than in order to incorporate all the possible time frames. { currBorder.Background = System.Windows.Media.Brushes.Yellow; if (currGrid.Children.Count == 2) { Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getYellow()); } } else if (timer >= Limit1 && timer < Limit2) { currBorder.Background = System.Windows.Media.Brushes.Green; if (currGrid.Children.Count == 2) { Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getGreen()); } } else { currBorder.Background = System.Windows.Media.Brushes.Blue; if (currGrid.Children.Count == 2) { Icons myIcons = new Icons(); currGrid.Children.Add(myIcons.getBlue()); } } currlbl.Content = Conversions.StripMiliSec(spanTimer).ToString(); disTimer.Start(); } else if (singleCounter[0]) { disTimer.Stop(); if (currGrid.Children.Count == 3) { currGrid.Children.RemoveAt(2); } this.ProgressionID = Conversions.UpdateProgressionID(this.ProgressionID); int placeHolder = Server.UpdateOven(this.ovenName, this.row, this.column, Server.nullity, RecipeKey, this.ProgressionID); if (placeHolder != -1) { timerLevelReset(this.currBorder, this.currlbl, ProgressionID, this.row, this.column, this.RecipeKey); } else { System.Windows.MessageBox.Show("Database nullified has Failed, Please Contact System Admin."); } } } } Server.readAllFromDataBase(ovenName); }