public DashboardView() { InitializeComponent(); AndonManager = new AndonManager(StationList, null, Andonmanager.AndonManager.MODE.MASTER); AndonManager.start(); StationList = new Queue<int>(); Plans = new Plans(); PlanGrid.DataContext = Plans; Actuals = new Models.Actuals(); ActualGrid.DataContext = Actuals; AppTimer = new Timer(1000); AppTimer.AutoReset = false; AppTimer.Elapsed += AppTimer_Elapsed; EfficiencyWatch = new Stopwatch(); using (PSBContext DBContext = new PSBContext()) { Shifts = DBContext.Shifts.ToList(); foreach (Shift s in Shifts) { s.Update(); } } AppTimer.Start(); }
private void ActivateButton_Click(object sender, RoutedEventArgs e) { if (Plans.Count <= 0) return; if (PlanGrid.SelectedIndex == -1) { MessageBox.Show("Please Select Plan", "Application Message", MessageBoxButton.OK, MessageBoxImage.Information); return; } using (PSBContext DB = new PSBContext()) { int planIndex = PlanGrid.SelectedIndex; if (Plans[planIndex].Active == true) { MessageBox.Show("Plan Already Activated", "Application Info", MessageBoxButton.OK, MessageBoxImage.Information); return; } int planid = Plans[planIndex].PlanID; var newActivePlan = DB.Plans.Include("Actuals").Single(p => p.PlanID == planid); if (ActivePlan != null) { ActivePlan = DB.Plans.Include("Actuals").Single(p => p.PlanID == ActivePlan.PlanID); ActivePlan.Active = false; DB.SaveChanges(); } ActivePlan = newActivePlan; ActivePlan.Active = true; ActivePlan.StartTimestamp = DateTime.Now; Actual newActual = new Actual("", ActivePlan.Reference, DateTime.Now, ActivePlan.PlanID); DB.Actuals.Add(newActual); DB.SaveChanges(); } UpdatePlansActuals(); UpdateReference(); }
void UpdatePlansActuals() { if (PlansList != null) { PlansList.Clear(); } if (ActualsList != null) { ActualsList.Clear(); } this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { Plans.Clear(); Actuals.Clear(); })); using (PSBContext DBContext = new PSBContext()) { PlansList = DBContext.Plans.Include("Actuals") .Where(p => p.ShiftID == CurrentShift.ShiftID && (p.CreatedTimestamp >= CurrentShift.Start) && (p.CreatedTimestamp < CurrentShift.End)) .ToList(); foreach (Plan p in PlansList) { this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { Plans.Add(p); })); if (p.Active == true) { ActivePlan = p; } } ActualsList = DBContext.Actuals .Where(a => (a.EndTimestamp >= CurrentShift.Start) && (a.EndTimestamp < CurrentShift.End)) .OrderBy(b => b.EndTimestamp) .ToList(); foreach (Actual a in ActualsList) { this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { Actuals.Add(a); })); } this.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { PlanGrid.DataContext = Plans; ActualGrid.DataContext = Actuals; })); } }
private void SerialNoTextBox_TextChanged(object sender, TextChangedEventArgs e) { if (SerialNoTextBox.Text.Length == 12) { using (PSBContext db = new PSBContext()) { foreach (Plan p in Plans) { if (p.Reference == ActualReferenceTextBox.Text) { var actual = db.Actuals.Single(a => a.Reference == p.Reference && (a.PlanID == p.PlanID) && (a.EndTimestamp == null) && (a.SerialNo == String.Empty ) && (a.StartTimestamp >= CurrentShift.Start) && a.StartTimestamp <= CurrentShift.End); actual.SerialNo = SerialNoTextBox.Text; actual.EndTimestamp = DateTime.Now; Actual newActual = new Actual("", p.Reference, actual.EndTimestamp.Value, p.PlanID); db.Actuals.Add(newActual); db.SaveChanges(); break; } } } UpdatePlansActuals(); UpdateQuantity(); SerialNoTextBox.Clear(); ActualReferenceTextBox.Clear(); } }
void Initialize() { using (PSBContext DBContext = new PSBContext()) { Breaks = DBContext.Breaks.Where(b => b.ShiftID == CurrentShift.ShiftID).ToList(); foreach (Break b in Breaks) { b.Update(); } } UpdatePlansActuals(); UpdateReference(); UpdateQuantity(); }
double CalculateEfficiency(DateTime StartReference, DateTime EndReference) { double Efficiency = 0.0; double TotalUnitTime = 0.0; double ActualUnitTime = 0.0; double ActualTime = 0.0; double DesignTime = 0.0; List<Actual> orderedActualList; using (PSBContext db = new PSBContext()) { orderedActualList = db.Actuals .Where(a => (a.EndTimestamp >= StartReference) && (a.EndTimestamp < EndReference)) .OrderBy(b => b.EndTimestamp) .ToList(); } foreach (Actual a in orderedActualList) { TotalUnitTime = GetUsefulTime(a.StartTimestamp, a.EndTimestamp.Value); if (a.StartTimestamp < StartReference) { ActualUnitTime += GetUsefulTime(StartReference, a.EndTimestamp.Value); } else ActualUnitTime = TotalUnitTime; foreach (Plan p in Plans) { if (a.PlanID == p.PlanID) { DesignTime += p.DT * (ActualUnitTime / TotalUnitTime); break; } } } ActualTime = GetUsefulTime(StartReference, EndReference); Efficiency = (DesignTime / ActualTime) * 100; return Efficiency; }
private void AddPlanButton_Click(object sender, RoutedEventArgs e) { String reference = ReferenceTextBox.Text; int operators = Convert.ToInt32(OperatorTextBox.Text); int quantity = Convert.ToInt32(TargetQtyTextBox.Text); using (PSBContext db = new PSBContext()) { var p = db.ProductModels.SingleOrDefault(pm => pm.Reference == ReferenceTextBox.Text); if (p == null) { MessageBox.Show("Reference Not Found. Please Verify", "Application Message", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } Plan newPlan = new Plan(reference, quantity, operators); newPlan.CreatedTimestamp = DateTime.Now; newPlan.ShiftID = CurrentShift.ShiftID; newPlan.DT = p.DT / (0.75 * operators); db.Plans.Add(newPlan); db.SaveChanges(); Plans.Add(newPlan); } }
private void ActualReferenceTextBox_TextChanged(object sender, TextChangedEventArgs e) { if (ActualReferenceTextBox.Text.Length < 10) return; using (PSBContext db = new PSBContext()) { var plan = db.Plans.SingleOrDefault(p => p.Reference == ActualReferenceTextBox.Text && (p.CreatedTimestamp >= CurrentShift.Start) && (p.CreatedTimestamp < CurrentShift.End)); if (plan == null) return; else SerialNoTextBox.Focus(); } }