/// <summary>
        /// Invokes specified invoker inside a loop with try-catch/everything and retries until reaches timeout or until each of the following is true:
        /// - The invoker does not throw exception.
        /// - If the additional condition delegate is specified, it must return true.
        /// </summary>
        /// <param name="invoker">The method to invoke</param>
        /// <param name="stopCondition">If specified, to break from the loop, it must be true. The condition delegate must not throw.</param>
        /// <param name="timeout">Timeout to stop retries after.</param>
        /// <returns>True on success, false on timeout.</returns>
        private bool InvokeWithRetry(MethodInvoker invoker, BoolMethodInvoker stopCondition, TimeSpan timeout)
        {
            Debug.Assert(invoker != null);

            Stopwatch timer = Stopwatch.StartNew();
            bool hasTimedOut = true;
            try
            {
                do
                {
                    bool isExceptionThrown = false;
                    try
                    {
                        invoker.Invoke();
                    }
                    catch
                    {
                        isExceptionThrown = true;
                    }

                    // If there was no exception, also check for stop condition.
                    // Note: condition.Invoke() must not throw. If it throws, we also throw from here.
                    if (!isExceptionThrown &&
                        (stopCondition == null || stopCondition.Invoke()))
                    {
                        hasTimedOut = false;
                        break;
                    }

                    Thread.Sleep(RegistrySettings.BaseSleepDuration);   // This is to prevent 100% CPU consumption.
                } while (timer.Elapsed < timeout);
            }
            finally
            {
                timer.Stop();
            }

            return !hasTimedOut;
        }
Example #2
0
 // Thread-safe operations from event handlers
 // I love StackOverflow: http://stackoverflow.com/q/782274
 public void ThreadSafeDelegate(MethodInvoker method)
 {
     if (InvokeRequired)
         BeginInvoke(method);
     else
         method.Invoke();
 }
Example #3
0
        // process frame
        private void OnFrameUpdate(object sender, EventArgs e)
        {
            DateTime updateTime = DateTime.Now;
            double   elapsed;

            if (Duration == 0)
            {
                elapsed = 1.0;
            }
            else
            {
                elapsed = (updateTime - _lastUpdateTime).TotalMilliseconds / Duration;
            }

            _lastUpdateTime = updateTime;
            Alpha           = Math.Max(0.0, Math.Min(Alpha + (_reverse ? -elapsed : elapsed), 1.0));

            Update?.Invoke(Value);

            if (Alpha == 0.0 || Alpha == 1.0)
            {
                Pause();
                Complete?.Invoke();
            }
        }
Example #4
0
 private void ActualizaProgressBar()
 {
     while (true)
     {
         MethodInvoker m = new MethodInvoker(() =>
         {
             int valor = progressBar.Value;
             if (valor == 100)
             {
                 valor = 0;
             }
             else
             {
                 ++valor;
             }
             progressBar.Value = valor;
             Thread.Sleep(milisegundos);
         });
         if (progressBar.InvokeRequired)
         {
             progressBar.Invoke(m);
         }
         else
         {
             m.Invoke();
         }
     }
 }
        public static Thread SlideVertically(this Control c, double pixelsPerMss, int position2, int step = 1, MethodInvoker finished = null)
        {
            lock (c)
            {
                Thread t = null;
                //if (controls2sliding_thread.TryGetValue(c, out t) && t.IsAlive)
                //    return t;

                step = c.Top > position2 ? -step : step;
                double total_mss = Math.Abs(position2 - c.Top) / pixelsPerMss;
                int sleep = (int)(total_mss / ((position2 - c.Top) / step));
                t = ThreadRoutines.Start(() =>
                {
                    try
                    {
                        while (c.Visible && !(bool)ControlRoutines.Invoke(c, () =>
                            {
                                c.Top = c.Top + step;
                                return step < 0 ? c.Top <= position2 : c.Top >= position2;
                            })
                        )
                            System.Threading.Thread.Sleep(sleep);
                        ControlRoutines.Invoke(c, () =>
                            {
                                finished?.Invoke();
                            });
                    }
                    catch(Exception e)//control disposed
                    {
                    }
                });
                //controls2sliding_thread[c] = t;
                return t;
            }
        }
Example #6
0
 public static Thread StartTry(MethodInvoker code, ErrorHandler on_error = null, MethodInvoker on_finally = null, bool background = true)
 {
     Thread t = new Thread(
         () => {
             try
             {
                 code.Invoke();
             }
             catch (ThreadAbortException e)
             {
                 Thread.ResetAbort();
             }
             catch (Exception e)
             {
                 if (on_error != null)
                     on_error.Invoke(e);
                 else
                     Message.Error(e);
             }
             finally
             {
                 on_finally?.Invoke();
             }
         }
     );
     t.IsBackground = background;
     t.Start();
     return t;
 }
Example #7
0
        public static Thread StartTry(MethodInvoker code, ErrorHandler on_error = null, MethodInvoker on_finally = null, bool background = true)
        {
            Thread t = new Thread(
                () => {
                try
                {
                    code.Invoke();
                }
                catch (ThreadAbortException)
                {
                }
                catch (Exception e)
                {
                    if (on_error != null)
                    {
                        on_error.Invoke(e);
                    }
                    else
                    {
                        Message.Error(e);
                    }
                }
                finally
                {
                    on_finally?.Invoke();
                }
            }
                );

            t.IsBackground = background;
            t.Start();
            return(t);
        }
 private void UpdateState()
 {
     MethodInvoker invoker = new MethodInvoker(delegate()
                 {
                     if ((File.GetAttributes(m_originalSolutionFullPath) & FileAttributes.ReadOnly) != 0)
                     {
                         m_labelState.ForeColor = Color.Red;
                         m_labelState.Text = "ReadOnly";
                         m_labelStateDescription.Visible = true;
                         m_buttonYes.Enabled = false;
                     }
                     else
                     {
                         m_labelState.ForeColor = Color.Black;
                         m_labelState.Text = "Writable";
                         m_labelStateDescription.Visible = false;
                         m_buttonYes.Enabled = true;
                     }
                 });
     if (m_labelState.InvokeRequired)
     {
         this.Invoke(invoker);
     }
     else
     {
         invoker.Invoke();
     }
 }
        //static readonly  Dictionary<Control, Thread> controls2sliding_thread = new Dictionary<Control, Thread>();

        public static Thread Condense(this Form f, double opacityPerMss, double opacity2, double step = 0.05, MethodInvoker finished = null)
        {
            lock (f)
            {
                Thread t = null;
                //if (controls2condensing_thread.TryGetValue(f, out t) && t.IsAlive)
                //    return t;

                step = f.Opacity < opacity2 ? step : -step;
                double total_mss = Math.Abs(opacity2 - f.Opacity) / opacityPerMss;
                int sleep = (int)(total_mss / ((opacity2 - f.Opacity) / step));
                t = ThreadRoutines.Start(() =>
                {
                    try
                    {
                        while (!(bool)ControlRoutines.Invoke(f, () =>
                            {
                                f.Opacity = f.Opacity + step;
                                return step > 0 ? f.Opacity >= opacity2 : f.Opacity <= opacity2;
                            })
                        )
                            System.Threading.Thread.Sleep(sleep);
                        ControlRoutines.Invoke(f, () =>
                        {
                            finished?.Invoke();
                        });
                    }
                    catch (Exception e)//control disposed
                    {
                    }
                });
                //controls2condensing_thread[f] = t;
                return t;
            }
        }
Example #10
0
 public static void BeginInvoke(this Control c, MethodInvoker code)
 {
     //c.BeginInvoke(code);
     if (c.InvokeRequired)
         c.BeginInvoke(code);
     else
         code.Invoke();
 }
        public void Test_MethodInvoker_Basic()
        {
            var viewModel5 = new TestViewModel5();

            var canMethodInvoker = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "CanAddAge", null);
            var methodInvoker = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "AddAge", null);

            bool value = canMethodInvoker.CanInvoke();
            Assert.IsFalse(value);
            methodInvoker.Invoke();

            viewModel5.TestViewModel = new TestViewModel();
            value = canMethodInvoker.CanInvoke();
            Assert.IsTrue(value);
            methodInvoker.Invoke();

            Assert.AreEqual(1, viewModel5.TestViewModel.Age);

            var canMethodInvoker2 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "AddAge", null);

            MissingMemberException exception = null;
            try
            {
                canMethodInvoker2.CanInvoke();
            }
            catch (MissingMemberException e)
            {
                exception = e;
            }
            Assert.IsNotNull(exception);

            var vm = new TestViewModel();

            var canMethodInvoker3 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "CanSetAge",
                new[] { new BindContext(vm, "Age") });
            var methodInvoker2 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "SetAge",
                new[] { new BindContext(vm, "Age") });

            Assert.IsTrue(canMethodInvoker3.CanInvoke());
            vm.Age = 6;
            Assert.AreNotEqual(6, viewModel5.TestViewModel.Age);

            methodInvoker2.Invoke();
            Assert.AreEqual(6, viewModel5.TestViewModel.Age);
        }
Example #12
0
 public static void UIThread(this System.Windows.Forms.Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #13
0
 public static void InvokeInControlThread(Control c, MethodInvoker code)
 {
     if (c.InvokeRequired)
     {
         c.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #14
0
 /// <summary>
 /// Ensure code is run on the UI thread.
 /// </summary>
 internal static void UIThread(Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #15
0
 protected void invoke_in_hosting_thread(MethodInvoker code)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(code);
         return;
     }
     code.Invoke();
 }
Example #16
0
        public static void RunInAnotherThread(MethodInvoker inv, bool join = false)
        {
            var th = new Thread(() => inv?.Invoke());

            th.Start();
            if (join)
            {
                th.Join();
            }
        }
Example #17
0
 public void MultiThreadSafe(Control main, MethodInvoker action)
 {
     if (main.InvokeRequired)
     {
         main.Invoke(action);
     }
     else
     {
         action?.Invoke();
     }
 }
Example #18
0
 /// <summary>
 /// Invokes a method on the main window thread
 /// </summary>
 /// <param name="aInvoker">the method to invoke</param>
 /// <param name="aAsync">set to true to invoke asynchronously</param>
 private void InvokeMainWindow(MethodInvoker aInvoker, bool aAsync)
 {
     if (this.mPluginHost.MainWindow.InvokeRequired) {
     if (aAsync) {
       mPluginHost.MainWindow.BeginInvoke(aInvoker);
     } else {
       mPluginHost.MainWindow.Invoke(aInvoker);
     }
       } else {
     aInvoker.Invoke();
       }
 }
Example #19
0
 /// <summary>
 /// Executes a delegate and show exception window on exception
 /// </summary>
 private static void guardedOp(MethodInvoker mi)
 {
     try
     {
         mi.Invoke();
     }
     catch (Exception ex)
     {
         log.Error(ex);
         ExceptionDialog.showException(ex, "Dirigent Exception", "");
     }
 }
Example #20
0
		private void FormAutoAnswer_Load(object sender, EventArgs e)
		{
			refresh = () =>
			{
				lsv.Items.Clear();
				foreach (var item in aa)
				{
					lsv.Items.Add(new ListViewItem(new string[]{
						item.Description,
						item.Prefix,
						item.Identify
					}));
				}
			};
			refresh.Invoke();
		}
Example #21
0
        /// <summary>
        /// Runs the action on the form or component thread on a per-needed basis.
        /// </summary>
        /// <param name="obj">The form or component instance</param>
        /// <param name="action">The action to be performed</param>
        public static void InvokeIfRequired(this ISynchronizeInvoke obj, MethodInvoker action)
        {
            if (obj == null)
            {
                throw new System.ArgumentNullException(nameof(obj));
            }

            if (obj.InvokeRequired)
            {
                var args = new object[0];
                obj.Invoke(action, args);
            }
            else
            {
                action?.Invoke();
            }
        }
Example #22
0
        public static Thread StartTry(MethodInvoker code, ErrorHandler onError = null, MethodInvoker finallyCode = null, bool background = true, ApartmentState state = ApartmentState.Unknown)
        {
            Thread t = new Thread(
                () =>
            {
                try
                {
                    code.Invoke();
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
                catch (Exception e)
                {
                    try
                    {
                        if (onError == null)
                        {
                            throw;
                        }
                        onError.Invoke(e);
                    }
                    catch (ThreadAbortException)
                    {
                        Thread.ResetAbort();
                    }
                }
                finally
                {
                    finallyCode?.Invoke();
                }
            }
                );

            if (state != ApartmentState.Unknown)
            {
                t.SetApartmentState(state);
            }
            t.IsBackground = background;
            t.Start();
            return(t);
        }
Example #23
0
        private void OnSaveInfo()
        {
            try
            {
                XetNghiem_CellDyn3200 xetNghiem = new XetNghiem_CellDyn3200();
                xetNghiem.XetNghiemGUID = Guid.Parse(_row["XetNghiemGUID"].ToString());
                xetNghiem.UpdatedDate   = DateTime.Now;
                xetNghiem.UpdatedBy     = Guid.Parse(Global.UserGUID);

                MethodInvoker method = delegate
                {
                    xetNghiem.TenXetNghiem = _tenXetNghiem;
                    xetNghiem.FullName     = _tenXetNghiem;

                    if (chkFromValue_Normal.Checked)
                    {
                        xetNghiem.FromValue = (double)numFromValue_Normal.Value;
                    }

                    if (chkToValue_Normal.Checked)
                    {
                        xetNghiem.ToValue = (double)numToValue_Normal.Value;
                    }

                    //if (chkFromValue_NormalPercent.Enabled && chkFromValue_NormalPercent.Checked)
                    //    xetNghiem.FromPercent = (double)numFromValue_NormalPercent.Value;

                    //if (chkToValue_NormalPercent.Enabled && chkToValue_NormalPercent.Checked)
                    //    xetNghiem.ToPercent = (double)numToValue_NormalPercent.Value;

                    Result result = XetNghiem_CellDyn3200Bus.UpdateXetNghiem(xetNghiem);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(Application.ProductName, result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdateXetNghiem"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("XetNghiem_CellDyn3200Bus.UpdateXetNghiem"));
                    }
                    else
                    {
                        DataRow row = GetDataRow(xetNghiem.XetNghiemGUID.ToString());
                        if (row != null)
                        {
                            if (chkFromValue_Normal.Checked)
                            {
                                row["FromValue"] = xetNghiem.FromValue.Value;
                            }
                            else
                            {
                                row["FromValue"] = DBNull.Value;
                            }

                            if (chkToValue_Normal.Checked)
                            {
                                row["ToValue"] = xetNghiem.ToValue.Value;
                            }
                            else
                            {
                                row["ToValue"] = DBNull.Value;
                            }

                            //if (chkFromValue_NormalPercent.Enabled && chkFromValue_NormalPercent.Checked)
                            //    row["FromPercent"] = xetNghiem.FromPercent.Value;
                            //else
                            //    row["FromPercent"] = DBNull.Value;

                            //if (chkToValue_NormalPercent.Enabled && chkToValue_NormalPercent.Checked)
                            //    row["ToPercent"] = xetNghiem.ToPercent.Value;
                            //else
                            //    row["ToPercent"] = DBNull.Value;

                            MsgBox.Show(Application.ProductName, "Lưu chỉ số xét nghiệm thành công.", IconType.Information);
                        }
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            catch (Exception e)
            {
                MsgBox.Show(Application.ProductName, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }
Example #24
0
        void UpdateTimerCountdown()
        {
            MethodInvoker invokeFromUI = new MethodInvoker(
               () =>
               {
                   this.lblCountdown.Text = string.Format(
                         "Next Tracker Popup: {0}",
                         TimeSpan
                             .FromSeconds(Convert.ToDouble(this._secondsRemaining))
                             .ToString(@"hh\:mm\:ss")
                         );

                   this._secondsRemaining -= 1;
               }
               );

            if (this.InvokeRequired)
                this.Invoke(invokeFromUI);
            else
                invokeFromUI.Invoke();
        }
Example #25
0
        void SafeOpenTimeEntryDialog()
        {
            MethodInvoker invokeFromUI = new MethodInvoker(this.PromptMonitoring);

            if (this.InvokeRequired)
                this.Invoke(invokeFromUI);
            else
                invokeFromUI.Invoke();
        }
Example #26
0
        protected void InvokeDelayed(MethodInvoker method, int delayInterval)
        {
            if (delayInterval <= 0) { method.Invoke(); return; }

            Timer delayedInvokeTimer = new Timer();
            delayedInvokeTimer = new Timer();
            delayedInvokeTimer.Tag = method;
            delayedInvokeTimer.Interval = delayInterval;
            delayedInvokeTimer.Tick += new EventHandler(DelayedInvokeTimerTick);
            delayedInvokeTimer.Start();
        }
Example #27
0
        /// <summary>
        /// Special Invoke for framework callbacks from the render process.
        /// Maintains the thread within the context of the calling remote thread.
        /// Use this instead of invoke when the following conditions are meat:
        /// 1) The current thread is executing in the scope of a framework
        ///    callback event from the render process (ex. CfrTask.Execute).
        /// 2) You need to Invoke on the webbrowser control and
        /// 3) The invoked code needs to call into the render process.
        /// </summary>
        public void RenderThreadInvoke(MethodInvoker method)
        {
            if (!CfxRemoteCallContext.IsInContext)
            {
                throw new HtmlUIException("Can't use RenderThreadInvoke without being in the scope of a render process callback.");
            }

            if (!InvokeRequired)
            {
                method.Invoke();
                return;
            }

            var context = CfxRemoteCallContext.CurrentContext;

            // Use BeginInvoke and Wait instead of Invoke.
            // Invoke marshals exceptions back to the calling thread.
            // We want exceptions to be thrown in place.

            var waitLock = new object();
            lock (waitLock)
            {
                BeginInvoke((MethodInvoker)(() => {
                    context.Enter();
                    try
                    {
                        method.Invoke();
                    }
                    finally
                    {
                        context.Exit();
                        lock (waitLock)
                        {
                            Monitor.PulseAll(waitLock);
                        }
                    }
                }));
                Monitor.Wait(waitLock);
            }
        }
Example #28
0
        void Instance_OnSlideLayoutChanged(SlideLayout NewSlideLayout)
        {
            SaveWindows();

            MethodInvoker i = new MethodInvoker(() =>
                {
                    if (NewSlideLayout != null)
                        _slideLocked = PresentationController.Instance.CanUnlockSlide(NewSlideLayout.Slide);
                    bool _isEmpty = NewSlideLayout == null || NewSlideLayout.IsEmpty;
                    if (CanEdit)
                        _view.ReadOnly = _isEmpty;
                    else
                        _view.ReadOnly = true;

                    LoadLayout(NewSlideLayout);
                    CurrentLayout = NewSlideLayout;
                });

            if (_view.IsHandleCreated)
            {
                _view.Invoke(i);
            }
            else
            {
                i.Invoke();
            }
        }
        /// <summary>
        /// Loads the data for the specifc KPI
        /// </summary>
        /// <param name="Overall.SelectedCountry"></param>
        public void LoadData()
        {
            try
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PO Release vs PR Delivery Date
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    strPoLineFirstRelDate = (dr["PO Line 1st Rel Dt"].ToString()).Split('/');
                    int poLineFirstRelYear  = int.Parse(strPoLineFirstRelDate[2]);
                    int poLineFirstRelMonth = int.Parse(strPoLineFirstRelDate[0]);
                    int poLineFirstRelDay   = int.Parse(strPoLineFirstRelDate[1]);

                    if (poLineFirstRelYear == 0 && poLineFirstRelMonth == 0 && poLineFirstRelDay == 0)
                    {
                        continue;
                    }
                    else
                    {
                        poRelVsPRDelDate.data.Total++;
                        poLineFirstRelYear  = int.Parse(strPoLineFirstRelDate[2]);
                        poLineFirstRelMonth = int.Parse(strPoLineFirstRelDate[0].TrimStart('0'));
                        poLineFirstRelDay   = int.Parse(strPoLineFirstRelDate[1].TrimStart('0'));
                    }

                    DateTime poLineFirstRelDate = new DateTime(poLineFirstRelYear, poLineFirstRelMonth, poLineFirstRelDay);

                    string[] strPRDelDate = (dr["PR Delivery Date"].ToString()).Split('/');
                    int      prDelYear    = int.Parse(strPRDelDate[2]);
                    int      prDelMonth   = int.Parse(strPRDelDate[0].TrimStart('0'));
                    int      prDelDay     = int.Parse(strPRDelDate[1].TrimStart('0'));

                    DateTime prDelDate   = new DateTime(prDelYear, prDelMonth, prDelDay);
                    double   elapsedDays = (prDelDate - poLineFirstRelDate).TotalDays;
                    totalDays  += elapsedDays;
                    elapsedDays = (int)elapsedDays;

                    if (elapsedDays <= 0)
                    {
                        poRelVsPRDelDate.data.LessThanZero++;
                    }
                    else if (elapsedDays >= 1 && elapsedDays <= 3)
                    {
                        poRelVsPRDelDate.data.One_Three++;
                    }
                    else if (elapsedDays >= 4 && elapsedDays <= 7)
                    {
                        poRelVsPRDelDate.data.Four_Seven++;
                    }
                    else if (elapsedDays >= 8 && elapsedDays <= 14)
                    {
                        poRelVsPRDelDate.data.Eight_Fourteen++;
                    }
                    else if (elapsedDays >= 15 && elapsedDays <= 21)
                    {
                        poRelVsPRDelDate.data.Fifteen_TwentyOne++;
                    }
                    else if (elapsedDays >= 22 && elapsedDays <= 28)
                    {
                        poRelVsPRDelDate.data.TwentyTwo_TwentyEight++;
                    }
                    else if (elapsedDays >= 29 && elapsedDays <= 35)
                    {
                        poRelVsPRDelDate.data.TwentyNine_ThirtyFive++;
                    }
                    else if (elapsedDays >= 36 && elapsedDays <= 42)
                    {
                        poRelVsPRDelDate.data.ThirtySix_FourtyTwo++;
                    }
                    else if (elapsedDays >= 43 && elapsedDays <= 49)
                    {
                        poRelVsPRDelDate.data.FourtyThree_FourtyNine++;
                    }
                    else if (elapsedDays >= 50)
                    {
                        poRelVsPRDelDate.data.greaterThanEqualFifty++;
                    }
                }


                try
                {
                    poRelVsPRDelDate.data.Average = Math.Round(totalDays / poRelVsPRDelDate.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    poRelVsPRDelDate.data.Average = 0;
                }

                totalDays = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PR 2nd Lvl Release to Original Planned Delivery Date
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                foreach (DataRow dr in Overall.pr2ndLvlRelDateDt.Rows)
                {
                    string[] strPR2ndLvlRelDate = (dr["PR 2° Rel# Date"].ToString()).Split('/');
                    int      pr2ndLvlRelYear    = int.Parse(strPR2ndLvlRelDate[2]);
                    int      pr2ndLvlRelMonth   = int.Parse(strPR2ndLvlRelDate[0]);
                    int      pr2ndLvlRelDay     = int.Parse(strPR2ndLvlRelDate[1]);

                    if (pr2ndLvlRelYear == 0 && pr2ndLvlRelMonth == 0 && pr2ndLvlRelDay == 0)
                    {
                        continue;
                    }
                    else
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.Total++;
                        pr2ndLvlRelYear  = int.Parse(strPR2ndLvlRelDate[2]);
                        pr2ndLvlRelMonth = int.Parse(strPR2ndLvlRelDate[0].TrimStart('0'));
                        pr2ndLvlRelDay   = int.Parse(strPR2ndLvlRelDate[1].TrimStart('0'));
                    }
                    DateTime pr2ndLvlRelDate = new DateTime(pr2ndLvlRelYear, pr2ndLvlRelMonth, pr2ndLvlRelDay);

                    string[] strPRDelDate = (dr["PR Delivery Date"].ToString()).Split('/');
                    int      prDelYear    = int.Parse(strPRDelDate[2]);
                    int      prDelMonth   = int.Parse(strPRDelDate[0].TrimStart('0'));
                    int      prDelDay     = int.Parse(strPRDelDate[1].TrimStart('0'));

                    DateTime prDelDate   = new DateTime(prDelYear, prDelMonth, prDelDay);
                    double   elapsedDays = (prDelDate - pr2ndLvlRelDate).TotalDays;
                    totalDays  += elapsedDays;
                    elapsedDays = (int)elapsedDays;

                    if (elapsedDays <= 0)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.LessThanZero++;
                    }
                    else if (elapsedDays >= 1 && elapsedDays <= 3)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.One_Three++;
                    }
                    else if (elapsedDays >= 4 && elapsedDays <= 7)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.Four_Seven++;
                    }
                    else if (elapsedDays >= 8 && elapsedDays <= 14)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.Eight_Fourteen++;
                    }
                    else if (elapsedDays >= 15 && elapsedDays <= 21)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.Fifteen_TwentyOne++;
                    }
                    else if (elapsedDays >= 22 && elapsedDays <= 28)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.TwentyTwo_TwentyEight++;
                    }
                    else if (elapsedDays >= 29 && elapsedDays <= 35)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.TwentyNine_ThirtyFive++;
                    }
                    else if (elapsedDays >= 36 && elapsedDays <= 42)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.ThirtySix_FourtyTwo++;
                    }
                    else if (elapsedDays >= 43 && elapsedDays <= 49)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.FourtyThree_FourtyNine++;
                    }
                    else if (elapsedDays >= 50)
                    {
                        pr2ndLvlRelOrigPlanDelDate.data.greaterThanEqualFifty++;
                    }
                }

                try
                {
                    pr2ndLvlRelOrigPlanDelDate.data.Average = Math.Round(totalDays / pr2ndLvlRelOrigPlanDelDate.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    pr2ndLvlRelOrigPlanDelDate.data.Average = 0;
                }
                totalDays = 0;

                PRPO_DB_Utils.CompletedDataLoads++;
                MethodInvoker del = delegate
                {
                    PRPO_DB_Utils.UpdateDataLoadProgress();
                };
                del.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "KPI -> Purch Plan Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #30
0
        /// <summary>
        /// Loads the data of the specific KPA.
        /// </summary>
        /// <param name="Overall.SelectedCountry"></param>
        public void LoadData()
        {
            try
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // Current Planned Date vs Current Confirmation Date (Open POs)
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                DataTable    dt = new DataTable();
                OleDbCommand cmd;
                if (Overall.SelectedCountry == AccessInfo.MainTables.US_PRPO)
                {
                    cmd = new OleDbCommand(PRPOCommands.Queries[(int)PRPOCommands.DatabaseTables.TableNames.KPA_CurrPlanActual_CurrPlanDateCurrConfDateOpenPO] + Filters.FilterQuery, PRPO_DB_Utils.DatabaseConnection);
                }
                else
                {
                    cmd = new OleDbCommand(PRPOCommands.Queries[(int)PRPOCommands.DatabaseTables.TableNames.KPA_CurrPlanActual_CurrPlanDateCurrConfDateOpenPO] + Filters.FilterQuery, PRPO_DB_Utils.DatabaseConnection);
                }

                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(dt);

                currPlanDateCurrConfDate.data.Total = dt.Rows.Count;

                foreach (DataRow dr in dt.Rows)
                {
                    string[] strDate = (dr["Del#Conf#Date"].ToString()).Split('/');
                    int      year    = int.Parse(strDate[2]);
                    int      month   = int.Parse(strDate[0].TrimStart('0'));
                    int      day     = int.Parse(strDate[1].TrimStart('0'));

                    DateTime confDate = new DateTime(year, month, day);


                    string[] strCurrPlanDate = (dr["Rescheduling date"].ToString()).Split('/');
                    int      currConfYear    = int.Parse(strCurrPlanDate[2]);
                    int      currConfMonth   = int.Parse(strCurrPlanDate[0]);
                    int      currConfDay     = int.Parse(strCurrPlanDate[1]);

                    if (currConfYear == 0 && currConfMonth == 0 && currConfDay == 0)
                    {
                        string[] strNewCurrConfDate = (dr["Delivery Date"].ToString()).Split('/');
                        currConfYear  = int.Parse(strNewCurrConfDate[2]);
                        currConfMonth = int.Parse(strNewCurrConfDate[0].TrimStart('0'));
                        currConfDay   = int.Parse(strNewCurrConfDate[1].TrimStart('0'));
                    }
                    else
                    {
                        currConfYear  = int.Parse(strCurrPlanDate[2]);
                        currConfMonth = int.Parse(strCurrPlanDate[0].TrimStart('0'));
                        currConfDay   = int.Parse(strCurrPlanDate[1].TrimStart('0'));
                    }

                    DateTime currPlanDate = new DateTime(currConfYear, currConfMonth, currConfDay);
                    double   elapsedDays  = (confDate - currPlanDate).TotalDays; // keep this a double so we can calculate an accurate average
                    totalWeeks += elapsedDays / 7;
                    elapsedDays = (int)elapsedDays;                              // we can now convert to a whole number

                    int weeks = 0;
                    if (elapsedDays < 0)
                    {
                        weeks = (int)Math.Floor(elapsedDays / 7);
                    }
                    else
                    {
                        weeks = (int)Math.Ceiling(elapsedDays / 7);
                    }


                    if (weeks <= (-4))
                    {
                        currPlanDateCurrConfDate.data.LessThanMinusFourWeeks++;
                    }
                    else if (weeks > (-4) && weeks <= (-3))
                    {
                        currPlanDateCurrConfDate.data.LessThanMinusThreeWeeks++;
                    }
                    else if (weeks > (-3) && weeks <= (-2))
                    {
                        currPlanDateCurrConfDate.data.LessThanMinusTwoWeeks++;
                    }
                    else if (weeks > (-2) && weeks <= (-1))
                    {
                        currPlanDateCurrConfDate.data.LessThanMinusOneWeeks++;
                    }
                    else if (weeks == 0)
                    {
                        currPlanDateCurrConfDate.data.ZeroWeeks++;
                    }
                    else if (weeks > 0 && weeks <= 1)
                    {
                        currPlanDateCurrConfDate.data.OneWeek++;
                    }
                    else if (weeks > 1 && weeks <= 2)
                    {
                        currPlanDateCurrConfDate.data.TwoWeeks++;
                    }
                    else if (weeks > 2 && weeks <= 3)
                    {
                        currPlanDateCurrConfDate.data.ThreeWeeks++;
                    }
                    else // 4 Weeks+
                    {
                        currPlanDateCurrConfDate.data.FourWeeksPlus++;
                    }
                }

                try
                {
                    currPlanDateCurrConfDate.data.Average = Math.Round(totalWeeks / currPlanDateCurrConfDate.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    currPlanDateCurrConfDate.data.Average = 0;
                }

                totalWeeks = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // Current Planned Date vs Current Confirmation Date (Open POs)
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                dt = new DataTable();
                if (Overall.SelectedCountry == AccessInfo.MainTables.US_PRPO)
                {
                    cmd = new OleDbCommand(PRPOCommands.Queries[(int)PRPOCommands.DatabaseTables.TableNames.KPA_CurrPlanActual_CurrPlanDateCurrConfDateOpenPOHotJobs] + Filters.FilterQuery, PRPO_DB_Utils.DatabaseConnection);
                }
                else
                {
                    cmd = new OleDbCommand(PRPOCommands.Queries[(int)PRPOCommands.DatabaseTables.TableNames.KPA_CurrPlanActual_CurrPlanDateCurrConfDateOpenPOHotJobs] + Filters.FilterQuery, PRPO_DB_Utils.DatabaseConnection);
                }

                da = new OleDbDataAdapter(cmd);
                da.Fill(dt);

                currPlanDateCurrConfDateHotJobs.data.Total = dt.Rows.Count;

                foreach (DataRow dr in dt.Rows)
                {
                    string[] strDate = (dr["Del#Conf#Date"].ToString()).Split('/');
                    int      year    = int.Parse(strDate[2]);
                    int      month   = int.Parse(strDate[0].TrimStart('0'));
                    int      day     = int.Parse(strDate[1].TrimStart('0'));

                    DateTime confDate = new DateTime(year, month, day);

                    string[] strCurrPlanDate = (dr["Rescheduling date"].ToString()).Split('/');
                    int      currConfYear    = int.Parse(strCurrPlanDate[2]);
                    int      currConfMonth   = int.Parse(strCurrPlanDate[0]);
                    int      currConfDay     = int.Parse(strCurrPlanDate[1]);

                    if (currConfYear == 0 && currConfMonth == 0 && currConfDay == 0)
                    {
                        string[] strNewCurrConfDate = (dr["Delivery Date"].ToString()).Split('/');
                        currConfYear  = int.Parse(strNewCurrConfDate[2]);
                        currConfMonth = int.Parse(strNewCurrConfDate[0].TrimStart('0'));
                        currConfDay   = int.Parse(strNewCurrConfDate[1].TrimStart('0'));
                    }
                    else
                    {
                        currConfYear  = int.Parse(strCurrPlanDate[2]);
                        currConfMonth = int.Parse(strCurrPlanDate[0].TrimStart('0'));
                        currConfDay   = int.Parse(strCurrPlanDate[1].TrimStart('0'));
                    }

                    DateTime currPlanDate = new DateTime(currConfYear, currConfMonth, currConfDay);
                    double   elapsedDays  = (confDate - currPlanDate).TotalDays; // keep this a double so we can calculate an acccurate average
                    totalWeeks += elapsedDays / 7;
                    elapsedDays = (int)elapsedDays;                              // we can now convert this to a whole number.

                    int weeks = 0;
                    if (elapsedDays < 0)
                    {
                        weeks = (int)Math.Floor(elapsedDays / 7);
                    }
                    else
                    {
                        weeks = (int)Math.Ceiling(elapsedDays / 7);
                    }


                    if (weeks <= (-4))
                    {
                        currPlanDateCurrConfDateHotJobs.data.LessThanMinusFourWeeks++;
                    }
                    else if (weeks > (-4) && weeks <= (-3))
                    {
                        currPlanDateCurrConfDateHotJobs.data.LessThanMinusThreeWeeks++;
                    }
                    else if (weeks > (-3) && weeks <= (-2))
                    {
                        currPlanDateCurrConfDateHotJobs.data.LessThanMinusTwoWeeks++;
                    }
                    else if (weeks > (-2) && weeks <= (-1))
                    {
                        currPlanDateCurrConfDateHotJobs.data.LessThanMinusOneWeeks++;
                    }
                    else if (weeks == 0)
                    {
                        currPlanDateCurrConfDateHotJobs.data.ZeroWeeks++;
                    }
                    else if (weeks > 0 && weeks <= 1)
                    {
                        currPlanDateCurrConfDateHotJobs.data.OneWeek++;
                    }
                    else if (weeks > 1 && weeks <= 2)
                    {
                        currPlanDateCurrConfDateHotJobs.data.TwoWeeks++;
                    }
                    else if (weeks > 2 && weeks <= 3)
                    {
                        currPlanDateCurrConfDateHotJobs.data.ThreeWeeks++;
                    }
                    else // 4 Weeks+
                    {
                        currPlanDateCurrConfDateHotJobs.data.FourWeeksPlus++;
                    }
                }

                try
                {
                    currPlanDateCurrConfDateHotJobs.data.Average = Math.Round(totalWeeks / currPlanDateCurrConfDateHotJobs.data.Total);
                }
                catch (DivideByZeroException)
                {
                    currPlanDateCurrConfDateHotJobs.data.Average = 0;
                }

                PRPO_DB_Utils.CompletedDataLoads++;
                MethodInvoker del = delegate
                {
                    PRPO_DB_Utils.UpdateDataLoadProgress();
                };
                del.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "KPA -> Follow Up Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void SafeThreadMethod(Control ctrl, MethodInvoker method)
 {
     if (ctrl != null)
     {
         if (ctrl.InvokeRequired)
         {
             if (method != null)
             {
                 ctrl.Invoke(method);
             }
         }
         else
         {
             if (method != null)
             {
                 method.Invoke();
             }
         }
     }
 }
Example #32
0
        /// <summary>
        /// Loads the data of a specific KPI
        /// </summary>
        /// <param name="Overall.SelectedCountry"></param>
        public void LoadData()
        {
            try
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PR Created
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.AllDt.Rows)
                {
                    string[] strReqDate   = (dr["Requisn Date"].ToString()).Split('/');
                    int      reqDateYear  = int.Parse(strReqDate[2]);
                    int      reqDateMonth = int.Parse(strReqDate[0].TrimStart('0'));
                    int      reqDateDay   = int.Parse(strReqDate[1].TrimStart('0'));

                    DateTime requiDate = new DateTime(reqDateYear, reqDateMonth, reqDateDay);

                    totalValue += decimal.Parse(dr["PR Pos#Value"].ToString());

                    DateTime today       = DateTime.Now.Date;
                    double   elapsedDays = (requiDate - today).TotalDays;
                    double   weeks       = Math.Floor(elapsedDays / 7);

                    if (weeks == 0)
                    {
                        prsCreated.data.Zero++;
                    }
                    else if (weeks < 0 && weeks >= (-1))
                    {
                        prsCreated.data.LessOneWeek++;
                    }
                    else if (weeks < (-1) && weeks >= (-2))
                    {
                        prsCreated.data.LessTwoWeeks++;
                    }
                    else if (weeks < (-2) && weeks >= (-3))
                    {
                        prsCreated.data.LessThreeWeeks++;
                    }
                    else if (weeks < (-3) && weeks >= (-4))
                    {
                        prsCreated.data.LessFourWeeks++;
                    }
                    else if (weeks < (-4) && weeks >= (-5))
                    {
                        prsCreated.data.LessFiveWeeks++;
                    }
                    else if (weeks < (-5) && weeks >= (-6))
                    {
                        prsCreated.data.LessSixWeeks++;
                    }
                    else if (weeks < (-6) && weeks >= (-7))
                    {
                        prsCreated.data.LessSevenWeeks++;
                    }
                    else if (weeks < (-7) && weeks >= (-8))
                    {
                        prsCreated.data.LessEightWeeks++;
                    }
                    else if (weeks <= (-9))
                    {
                        prsCreated.data.LessNinePlusWeeks++;
                    }
                }

                prsCreated.data.TotalValue = totalValue;
                prsCreated.data.Total      = Overall.AllDt.Rows.Count;
                totalValue = 0;


                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PRs Released
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.pr2ndLvlRelDateDt.Rows)
                {
                    string[] strPr2ndLvlRelDt   = (dr["PR 2° Rel# Date"].ToString()).Split('/');
                    int      pr2ndLvlRelDtYear  = int.Parse(strPr2ndLvlRelDt[2]);
                    int      pr2ndLvlRelDtMonth = int.Parse(strPr2ndLvlRelDt[0].TrimStart('0'));
                    int      pr2ndLvlRelDtDay   = int.Parse(strPr2ndLvlRelDt[1].TrimStart('0'));

                    DateTime pr2ndLvlRelDt = new DateTime(pr2ndLvlRelDtYear, pr2ndLvlRelDtMonth, pr2ndLvlRelDtDay);

                    totalValue += decimal.Parse(dr["PR Pos#Value"].ToString());

                    DateTime today       = DateTime.Now.Date;
                    double   elapsedDays = (pr2ndLvlRelDt - today).TotalDays;
                    double   weeks       = Math.Floor(elapsedDays / 7);


                    if (weeks == 0)
                    {
                        prsReleased.data.Zero++;
                    }
                    else if (weeks < 0 && weeks >= (-1))
                    {
                        prsReleased.data.LessOneWeek++;
                    }
                    else if (weeks < (-1) && weeks >= (-2))
                    {
                        prsReleased.data.LessTwoWeeks++;
                    }
                    else if (weeks < (-2) && weeks >= (-3))
                    {
                        prsReleased.data.LessThreeWeeks++;
                    }
                    else if (weeks < (-3) && weeks >= (-4))
                    {
                        prsReleased.data.LessFourWeeks++;
                    }
                    else if (weeks < (-4) && weeks >= (-5))
                    {
                        prsReleased.data.LessFiveWeeks++;
                    }
                    else if (weeks < (-5) && weeks >= (-6))
                    {
                        prsReleased.data.LessSixWeeks++;
                    }
                    else if (weeks < (-6) && weeks >= (-7))
                    {
                        prsReleased.data.LessSevenWeeks++;
                    }
                    else if (weeks < (-7) && weeks >= (-8))
                    {
                        prsReleased.data.LessEightWeeks++;
                    }
                    else if (weeks <= (-9))
                    {
                        prsReleased.data.LessNinePlusWeeks++;
                    }
                }

                prsReleased.data.TotalValue = totalValue;
                prsReleased.data.Total      = Overall.pr2ndLvlRelDateDt.Rows.Count;
                totalValue = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // Total Spend
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    string[] strPoCreateDt   = (dr["PO Line Creat#DT"].ToString()).Split('/');
                    int      poCreateDtYear  = int.Parse(strPoCreateDt[2]);
                    int      poCreateDtMonth = int.Parse(strPoCreateDt[0].TrimStart('0'));
                    int      poCreateDtDay   = int.Parse(strPoCreateDt[1].TrimStart('0'));

                    DateTime poCreateDate = new DateTime(poCreateDtYear, poCreateDtMonth, poCreateDtDay);

                    totalValue += decimal.Parse(dr["PO Value"].ToString());
                    DateTime today       = DateTime.Now.Date;
                    double   elapsedDays = (poCreateDate - today).TotalDays;
                    double   weeks       = Math.Floor(elapsedDays / 7);


                    if (weeks == 0)
                    {
                        totalSpend.data.Zero++;
                    }
                    else if (weeks < 0 && weeks >= (-1))
                    {
                        totalSpend.data.LessOneWeek++;
                    }
                    else if (weeks < (-1) && weeks >= (-2))
                    {
                        totalSpend.data.LessTwoWeeks++;
                    }
                    else if (weeks < (-2) && weeks >= (-3))
                    {
                        totalSpend.data.LessThreeWeeks++;
                    }
                    else if (weeks < (-3) && weeks >= (-4))
                    {
                        totalSpend.data.LessFourWeeks++;
                    }
                    else if (weeks < (-4) && weeks >= (-5))
                    {
                        totalSpend.data.LessFiveWeeks++;
                    }
                    else if (weeks < (-5) && weeks >= (-6))
                    {
                        totalSpend.data.LessSixWeeks++;
                    }
                    else if (weeks < (-6) && weeks >= (-7))
                    {
                        totalSpend.data.LessSevenWeeks++;
                    }
                    else if (weeks < (-7) && weeks >= (-8))
                    {
                        totalSpend.data.LessEightWeeks++;
                    }
                    else if (weeks <= (-9))
                    {
                        totalSpend.data.LessNinePlusWeeks++;
                    }
                }

                totalSpend.data.TotalValue = totalValue;
                totalSpend.data.Total      = Overall.prsOnPOsDt.Rows.Count;
                totalValue = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PR vs PO Value
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    string[] strPoCreateDt   = (dr["PO Line Creat#DT"].ToString()).Split('/');
                    int      poCreateDtYear  = int.Parse(strPoCreateDt[2]);
                    int      poCreateDtMonth = int.Parse(strPoCreateDt[0].TrimStart('0'));
                    int      poCreateDtDay   = int.Parse(strPoCreateDt[1].TrimStart('0'));

                    DateTime poCreateDate = new DateTime(poCreateDtYear, poCreateDtMonth, poCreateDtDay);

                    totalValue += decimal.Parse(dr["PO Value"].ToString()) - decimal.Parse(dr["PR Pos#Value"].ToString());

                    DateTime today       = DateTime.Now.Date;
                    double   elapsedDays = (poCreateDate - today).TotalDays;
                    double   weeks       = Math.Floor(elapsedDays / 7);


                    if (weeks == 0)
                    {
                        prVsPOValue.data.Zero++;
                    }
                    else if (weeks < 0 && weeks >= (-1))
                    {
                        prVsPOValue.data.LessOneWeek++;
                    }
                    else if (weeks < (-1) && weeks >= (-2))
                    {
                        prVsPOValue.data.LessTwoWeeks++;
                    }
                    else if (weeks < (-2) && weeks >= (-3))
                    {
                        prVsPOValue.data.LessThreeWeeks++;
                    }
                    else if (weeks < (-3) && weeks >= (-4))
                    {
                        prVsPOValue.data.LessFourWeeks++;
                    }
                    else if (weeks < (-4) && weeks >= (-5))
                    {
                        prVsPOValue.data.LessFiveWeeks++;
                    }
                    else if (weeks < (-5) && weeks >= (-6))
                    {
                        prVsPOValue.data.LessSixWeeks++;
                    }
                    else if (weeks < (-6) && weeks >= (-7))
                    {
                        prVsPOValue.data.LessSevenWeeks++;
                    }
                    else if (weeks < (-7) && weeks >= (-8))
                    {
                        prVsPOValue.data.LessEightWeeks++;
                    }
                    else if (weeks <= (-9))
                    {
                        prVsPOValue.data.LessNinePlusWeeks++;
                    }
                }
                totalValue = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // Hot Job PRs
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.AllDt.Rows)
                {
                    if (dr["Purch# Group"].ToString() != "UHJ")
                    {
                        continue;
                    }

                    string[] strPrReqDt   = (dr["Requisn Date"].ToString()).Split('/');
                    int      reqDateYear  = int.Parse(strPrReqDt[2]);
                    int      reqDateMonth = int.Parse(strPrReqDt[0].TrimStart('0'));
                    int      reqDateDay   = int.Parse(strPrReqDt[1].TrimStart('0'));

                    DateTime prReqDate = new DateTime(reqDateYear, reqDateMonth, reqDateDay);

                    totalValue += decimal.Parse(dr["PR Pos#Value"].ToString());

                    DateTime today       = DateTime.Now.Date;
                    double   elapsedDays = (prReqDate - today).TotalDays;
                    double   weeks       = Math.Floor(elapsedDays / 7);


                    if (weeks == 0)
                    {
                        hotJobPrs.data.Zero++;
                    }
                    else if (weeks < 0 && weeks >= (-1))
                    {
                        hotJobPrs.data.LessOneWeek++;
                    }
                    else if (weeks < (-1) && weeks >= (-2))
                    {
                        hotJobPrs.data.LessTwoWeeks++;
                    }
                    else if (weeks < (-2) && weeks >= (-3))
                    {
                        hotJobPrs.data.LessThreeWeeks++;
                    }
                    else if (weeks < (-3) && weeks >= (-4))
                    {
                        hotJobPrs.data.LessFourWeeks++;
                    }
                    else if (weeks < (-4) && weeks >= (-5))
                    {
                        hotJobPrs.data.LessFiveWeeks++;
                    }
                    else if (weeks < (-5) && weeks >= (-6))
                    {
                        hotJobPrs.data.LessSixWeeks++;
                    }
                    else if (weeks < (-6) && weeks >= (-7))
                    {
                        hotJobPrs.data.LessSevenWeeks++;
                    }
                    else if (weeks < (-7) && weeks >= (-8))
                    {
                        hotJobPrs.data.LessEightWeeks++;
                    }
                    else if (weeks <= (-9))
                    {
                        hotJobPrs.data.LessNinePlusWeeks++;
                    }
                }
                totalValue = 0;


                PRPO_DB_Utils.CompletedDataLoads++;
                MethodInvoker del = delegate
                {
                    PRPO_DB_Utils.UpdateDataLoadProgress();
                };
                del.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "KPI -> Other Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #33
0
 /// <summary>
 /// 线程安全方法调用。
 /// </summary>
 /// <param name="ctrl"></param>
 /// <param name="method"></param>
 private void ThreadSafeMethod(Control ctrl, MethodInvoker method)
 {
     if (ctrl != null && method != null)
     {
         if (ctrl.InvokeRequired)
             ctrl.Invoke(method);
         else
             method.Invoke();
     }
 }
Example #34
0
        private void OnSaveInfo()
        {
            try
            {
                _yKienKhachHang.Status = (byte)Status.Actived;

                if (_isNew)
                {
                    _yKienKhachHang.ContactDate = DateTime.Now;
                    _yKienKhachHang.ContactBy   = Guid.Parse(Global.UserGUID);
                }
                else
                {
                    _yKienKhachHang.UpdatedDate = DateTime.Now;
                    _yKienKhachHang.UpdatedBy   = Guid.Parse(Global.UserGUID);
                }

                MethodInvoker method = delegate
                {
                    if (txtTenKhachHang.Tag != null)
                    {
                        _yKienKhachHang.PatientGUID = Guid.Parse(txtTenKhachHang.Tag.ToString());
                    }
                    else
                    {
                        _yKienKhachHang.PatientGUID = null;
                    }

                    _yKienKhachHang.TenCongTy    = txtTenCongTy.Text;
                    _yKienKhachHang.MaKhachHang  = txtMaKhachHang.Text;
                    _yKienKhachHang.MucDich      = txtMucDich.Text;
                    _yKienKhachHang.TenKhachHang = txtTenKhachHang.Text;
                    _yKienKhachHang.SoDienThoai  = txtSoDienThoai.Text;
                    _yKienKhachHang.DiaChi       = txtDiaChi.Text;
                    _yKienKhachHang.YeuCau       = txtYeuCau.Text;
                    _yKienKhachHang.Nguon        = cboNguon.Text;
                    _yKienKhachHang.Note         = string.Empty;
                    _yKienKhachHang.IsIN         = raIN.Checked;
                    _yKienKhachHang.SoTongDai    = txtSoTongDai.Text;

                    if (cboDocStaff.SelectedValue != null && cboDocStaff.Text.Trim() != string.Empty)
                    {
                        _yKienKhachHang.BacSiPhuTrachGUID = Guid.Parse(cboDocStaff.SelectedValue.ToString());
                    }
                    else
                    {
                        _yKienKhachHang.BacSiPhuTrachGUID = null;
                    }

                    _yKienKhachHang.DaXong  = chkDaXong.Checked;
                    _yKienKhachHang.KetLuan = txtHuongGiaiQuyet.Text;

                    Result result = YKienKhachHangBus.InsertYKienKhachHang(_yKienKhachHang);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("YKienKhachHangBus.InsertYKienKhachHang"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("YKienKhachHangBus.InsertYKienKhachHang"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            catch (Exception e)
            {
                MsgBox.Show(this.Text, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }
Example #35
0
 /// <summary>
 /// Run action on UI thread
 /// </summary>
 /// <param name="action"></param>
 public static void RunAsync(MethodInvoker action)
 {
     Form ui = MainForm as Form;
     if (ui != null && ui.InvokeRequired) ui.BeginInvoke(action);
     else action.Invoke();
 }
 /// <summary>
 /// 主线程更新UI
 /// </summary>
 /// <param name="control"></param>
 /// <param name="action"></param>
 public void RunOnUIThread(Control control, MethodInvoker action)
 {
     UISync.Init(control);
     UISync.Execute(() => { action?.Invoke(); });
 }
        private IMethodReturnMessage ForwardCall(IMethodCallMessage call)
        {
            var ret = MethodInvoker.Invoke(_queryLanguage, _queryLanguageType, (System.Reflection.MethodInfo)call.MethodBase, call.InArgs);

            return(new ReturnMessage(ret, null, 0, null, call));
        }
Example #38
0
        private void UpdateLevel(WaterTankPosition tank, int level)
        {
            PictureBox picWaterTank = tank == WaterTankPosition.Tank1 ? picWaterTank1 : picWaterTank2;
            TextBox    txtLevel     = tank == WaterTankPosition.Tank1 ? txtLevel1 : txtLevel2;

            MethodInvoker mth = (MethodInvoker) delegate()
            {
                try
                {
                    txtLevel.Text = string.Format("{0:F0}%", level);

                    if (level < 10)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_0;
                    }
                    else if (level < 20)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_10;
                    }
                    else if (level < 30)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_20;
                    }
                    else if (level < 40)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_30;
                    }
                    else if (level < 50)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_40;
                    }
                    else if (level < 60)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_50;
                    }
                    else if (level < 70)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_60;
                    }
                    else if (level < 80)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_70;
                    }
                    else if (level < 90)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_80;
                    }
                    else if (level < 100)
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_90;
                    }
                    else
                    {
                        picWaterTank.Image = Properties.Resources.water_tank_level_100;
                    }
                }
                catch (Exception e)
                {
                    txtMsg.Text = e.Message;
                }
            };

            if (!this.IsHandleCreated)
            {
                mth.Invoke();
            }
            else
            {
                this.BeginInvoke(mth);
            }
        }
Example #39
0
 public override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
 => _invoker.Invoke(this, null, parameters, null, invokeAttr, binder, culture);
Example #40
0
 public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
 {
     return(_invoker.Invoke(this, obj, parameters, null, invokeAttr, binder, culture));
 }
Example #41
0
        void SafeEditEntry(int primaryKey, string category, string description, bool rememberSetting,
                           DateTime createdDate, DateTime systemCreatedDate, DateTime rememberedCreatedDateTime,
                           Double hoursRendered
                           )
        {
            this.StopTimer();

            MethodInvoker invokeFromUI = new MethodInvoker(
                () =>
            {
                try
                {
                    if (this._promptingInProgress)
                    {
                        return;
                    }

                    this._promptingInProgress = true;

                    this.View_GetObjectiveData(createdDate);

                    using (frmTaskMonitoringEntry monitoring = new frmTaskMonitoringEntry(
                               this.View_GetCategories()
                               .Select(x => x.Name),
                               primaryKey, category, description, rememberSetting, createdDate, systemCreatedDate,
                               this.txtObjectives.Text, hoursRendered
                               ))
                    {
                        DialogResult result = monitoring.ShowDialog(this);

                        if (result != System.Windows.Forms.DialogResult.OK)
                        {
                            return;
                        }

                        this.SaveLogDetail(monitoring);

                        monitoring.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    this._promptingInProgress = false;
                }
            }
                );

            if (this.InvokeRequired)
            {
                this.Invoke(invokeFromUI);
            }
            else
            {
                invokeFromUI.Invoke();
            }

            this.RestartTimer();
        }
Example #42
0
        private void InvokeCallback(MethodInvoker method)
        {
            if (!InvokeRequired)
            {
                method.Invoke();
                return;
            }

            // Use BeginInvoke and Wait instead of Invoke.
            // Invoke marshals exceptions back to the calling thread.
            // We want exceptions to be thrown in place.

            var waitLock = new object();
            lock (waitLock)
            {
                BeginInvoke((MethodInvoker)(() => {
                    try
                    {
                        method.Invoke();
                    }
                    finally
                    {
                        lock (waitLock)
                        {
                            Monitor.PulseAll(waitLock);
                        }
                    }
                }));
                Monitor.Wait(waitLock);
            }
        }
Example #43
0
        void SafeEditEntry(int primaryKey, string category, string description, bool rememberSetting,
            DateTime createdDate, DateTime systemCreatedDate, DateTime rememberedCreatedDateTime,
            Double hoursRendered
            )
        {
            this.StopTimer();

            MethodInvoker invokeFromUI = new MethodInvoker(
                () =>
                {
                    try
                    {
                        if (this._promptingInProgress)
                            return;

                        this._promptingInProgress = true;

                        this.View_GetObjectiveData(createdDate);

                        using (frmTaskMonitoringEntry monitoring = new frmTaskMonitoringEntry(
                            this.View_GetCategories()
                                .Select(x => x.Name),
                            primaryKey, category, description, rememberSetting, createdDate, systemCreatedDate,
                            this.txtObjectives.Text, hoursRendered
                            ))
                        {
                            DialogResult result = monitoring.ShowDialog(this);

                            if (result != System.Windows.Forms.DialogResult.OK)
                                return;

                            this.SaveLogDetail(monitoring);

                            monitoring.Dispose();
                        }
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        this._promptingInProgress = false;
                    }
                }
            );

            if (this.InvokeRequired)
                this.Invoke(invokeFromUI);
            else
                invokeFromUI.Invoke();

            this.RestartTimer();
        }
Example #44
0
        public void InvokeTest()
        {
            MethodInfo[] myMethodInfo;
            Type myType = typeof(MyClass);
            // Get the type and fields of FieldInfoClass.
            myMethodInfo = myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance
                | BindingFlags.Public);

            MethodInfo methodInfo = myMethodInfo[0];

            IMethodInvoker target = new MethodInvoker(methodInfo);
            object instance = new MyClass("S001", "司法署");

            object expected = "S001";
            object actual;
            actual = target.Invoke(instance, null);
            Assert.AreEqual(expected, actual);
        }
Example #45
0
        private void OnSaveInfo()
        {
            try
            {
                if (_isNew)
                {
                    _ketQuaLamSang.CreatedDate = DateTime.Now;
                    _ketQuaLamSang.CreatedBy   = Guid.Parse(Global.UserGUID);
                }
                else
                {
                    _ketQuaLamSang.UpdatedDate = DateTime.Now;
                    _ketQuaLamSang.UpdatedBy   = Guid.Parse(Global.UserGUID);
                }

                _ketQuaLamSang.PatientGUID = Guid.Parse(_patientGUID);

                MethodInvoker method = delegate
                {
                    _ketQuaLamSang.NgayKham     = dtpkNgay.Value;
                    _ketQuaLamSang.DocStaffGUID = Guid.Parse(cboDocStaff.SelectedValue.ToString());

                    if (raMat.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.Mat;
                        _ketQuaLamSang.Normal   = chkNormal_Mat.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_Mat.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_Mat.Text;
                    }
                    else if (raTaiMuiHong.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.TaiMuiHong;
                        _ketQuaLamSang.Normal   = chkNormal_TaiMuiHong.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_TaiMuiHong.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_TaiMuiHong.Text;
                    }
                    else if (raRangHamMat.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.RangHamMat;
                        _ketQuaLamSang.Normal   = chkNormal_RangHamMat.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_RangHamMat.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_RangHamMat.Text;
                    }
                    else if (raHoHap.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.HoHap;
                        _ketQuaLamSang.Normal   = chkNormal_HoHap.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_HoHap.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_HoHap.Text;
                    }
                    else if (raTimMach.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.TimMach;
                        _ketQuaLamSang.Normal   = chkNormal_TimMach.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_TimMach.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_TimMach.Text;
                    }
                    else if (raTieuHoa.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.TieuHoa;
                        _ketQuaLamSang.Normal   = chkNormal_TieuHoa.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_TieuHoa.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_TieuHoa.Text;
                    }
                    else if (raTietNieuSinhDuc.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.TietNieuSinhDuc;
                        _ketQuaLamSang.Normal   = chkNormal_TietNieuSinhDuc.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_TietNieuSinhDuc.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_TietNieuSinhDuc.Text;
                    }
                    else if (raCoXuongKhop.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.CoXuongKhop;
                        _ketQuaLamSang.Normal   = chkNormal_CoXuongKhop.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_CoXuongKhop.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_CoXuongKhop.Text;
                    }
                    else if (raDaLieu.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.DaLieu;
                        _ketQuaLamSang.Normal   = chkNormal_DaLieu.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_DaLieu.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_DaLieu.Text;
                    }
                    else if (raThanKinh.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.ThanKinh;
                        _ketQuaLamSang.Normal   = chkNormal_ThanKinh.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_ThanKinh.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_ThanKinh.Text;
                    }
                    else if (raNoiTiet.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.NoiTiet;
                        _ketQuaLamSang.Normal   = chkNormal_NoiTiet.Checked;
                        _ketQuaLamSang.Abnormal = chkAbnormal_NoiTiet.Checked;
                        _ketQuaLamSang.Note     = txtNhanXet_NoiTiet.Text;
                    }
                    else if (raCacCoQuanKhac.Checked)
                    {
                        _ketQuaLamSang.CoQuan   = (byte)CoQuan.Khac;
                        _ketQuaLamSang.Normal   = false;
                        _ketQuaLamSang.Abnormal = false;
                        _ketQuaLamSang.Note     = txtNhanXet_CoQuanKhac.Text;
                    }
                    else if (raKhamPhuKhoa.Checked)
                    {
                        _ketQuaLamSang.CoQuan = (byte)CoQuan.KhamPhuKhoa;
                        _ketQuaLamSang.PARA   = txtPARA.Text;
                        if (chkKinhChot.Checked)
                        {
                            _ketQuaLamSang.NgayKinhChot = dtpkNgayKinhChot.Value;
                        }
                        else
                        {
                            _ketQuaLamSang.NgayKinhChot = null;
                        }

                        _ketQuaLamSang.Note        = txtKetQuaKhamPhuKhoa.Text;
                        _ketQuaLamSang.PhuKhoaNote = txtPhuKhoaNote.Text;
                        _ketQuaLamSang.Normal      = chkNormal_KhamPhuKhoa.Checked;
                        _ketQuaLamSang.Abnormal    = chkAbnormal_KhamPhuKhoa.Checked;
                    }

                    Result result = KetQuaLamSangBus.InsertKetQuaLamSang(_ketQuaLamSang);
                    if (!result.IsOK)
                    {
                        MsgBox.Show(this.Text, result.GetErrorAsString("KetQuaLamSangBus.InsertKetQuaLamSang"), IconType.Error);
                        Utility.WriteToTraceLog(result.GetErrorAsString("KetQuaLamSangBus.InsertKetQuaLamSang"));
                        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    }
                    else
                    {
                        InsertNhanXetKhamLamSang(txtNhanXet_TaiMuiHong.Text, (int)CoQuan.TaiMuiHong);
                        InsertNhanXetKhamLamSang(txtNhanXet_RangHamMat.Text, (int)CoQuan.RangHamMat);
                        InsertNhanXetKhamLamSang(txtNhanXet_Mat.Text, (int)CoQuan.Mat);
                        InsertNhanXetKhamLamSang(txtNhanXet_HoHap.Text, (int)CoQuan.HoHap);
                        InsertNhanXetKhamLamSang(txtNhanXet_TimMach.Text, (int)CoQuan.TimMach);
                        InsertNhanXetKhamLamSang(txtNhanXet_TieuHoa.Text, (int)CoQuan.TieuHoa);
                        InsertNhanXetKhamLamSang(txtNhanXet_TietNieuSinhDuc.Text, (int)CoQuan.TietNieuSinhDuc);
                        InsertNhanXetKhamLamSang(txtNhanXet_CoXuongKhop.Text, (int)CoQuan.CoXuongKhop);
                        InsertNhanXetKhamLamSang(txtNhanXet_DaLieu.Text, (int)CoQuan.DaLieu);
                        InsertNhanXetKhamLamSang(txtNhanXet_ThanKinh.Text, (int)CoQuan.ThanKinh);
                        InsertNhanXetKhamLamSang(txtNhanXet_NoiTiet.Text, (int)CoQuan.NoiTiet);
                        InsertNhanXetKhamLamSang(txtNhanXet_CoQuanKhac.Text, (int)CoQuan.Khac);
                        InsertNhanXetKhamLamSang(txtKetQuaKhamPhuKhoa.Text, (int)CoQuan.KhamPhuKhoa);
                    }
                };

                if (InvokeRequired)
                {
                    BeginInvoke(method);
                }
                else
                {
                    method.Invoke();
                }
            }
            catch (Exception e)
            {
                MsgBox.Show(this.Text, e.Message, IconType.Error);
                Utility.WriteToTraceLog(e.Message);
            }
        }
Example #46
0
 /// <summary>
 /// 线程安全方法调用。
 /// </summary>
 /// <param name="ctrl"></param>
 /// <param name="method"></param>
 public virtual void ThreadSafeMethod(Control ctrl, MethodInvoker method)
 {
     if (ctrl != null && method != null)
     {
         if (ctrl.InvokeRequired)
         {
             ctrl.Invoke(method);
         }
         else
         {
             method.Invoke();
         }
     }
 }
Example #47
0
        /// <summary>
        /// Loads the data for the specific KPI
        /// </summary>
        /// <param name="Overall.SelectedCountry"></param>
        public void LoadData()
        {
            try
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // Initial Confirmation vs PR Planned Date
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    string[] strFirstConfDate = (dr["1st Conf Date"].ToString()).Split('/');
                    int      firstConfYear    = int.Parse(strFirstConfDate[2]);
                    int      firstConfMonth   = int.Parse(strFirstConfDate[0]);
                    int      firstConfDay     = int.Parse(strFirstConfDate[1]);

                    if (firstConfYear == 0 && firstConfMonth == 0 && firstConfDay == 0)
                    {
                        totalPOsUnconf++;
                        continue;
                    }
                    else
                    {
                        initConfVsPRPlanDate.data.Total++;
                        firstConfYear  = int.Parse(strFirstConfDate[2]);
                        firstConfMonth = int.Parse(strFirstConfDate[0].TrimStart('0'));
                        firstConfDay   = int.Parse(strFirstConfDate[1].TrimStart('0'));
                    }

                    DateTime firstConfDate = new DateTime(firstConfYear, firstConfMonth, firstConfDay);

                    string[] strPRPlanDate = (dr["PR Delivery Date"].ToString()).Split('/');
                    int      prDelYear     = int.Parse(strPRPlanDate[2]);
                    int      prDelMonth    = int.Parse(strPRPlanDate[0].TrimStart('0'));
                    int      prDelDay      = int.Parse(strPRPlanDate[1].TrimStart('0'));

                    DateTime prPlanDate  = new DateTime(prDelYear, prDelMonth, prDelDay);
                    double   elapsedDays = (firstConfDate - prPlanDate).TotalDays;
                    totalDays  += elapsedDays;
                    elapsedDays = (int)elapsedDays;

                    if (elapsedDays <= (-22))
                    {
                        initConfVsPRPlanDate.data.Minus_TwentyTwo++;
                    }
                    else if (elapsedDays > (-22) && elapsedDays <= (-15))
                    {
                        initConfVsPRPlanDate.data.Minus_Fifteen_TwentyOne++;
                    }
                    else if (elapsedDays > (-14) && elapsedDays <= (-8))
                    {
                        initConfVsPRPlanDate.data.Minus_Eight_Fourteen++;
                    }
                    else if (elapsedDays > (-7) && elapsedDays <= (-1))
                    {
                        initConfVsPRPlanDate.data.Minus_One_Seven++;
                    }
                    else if (elapsedDays == 0)
                    {
                        initConfVsPRPlanDate.data.Zero++;
                    }
                    else if (elapsedDays >= 1 && elapsedDays <= 7)
                    {
                        initConfVsPRPlanDate.data.One_Seven++;
                    }
                    else if (elapsedDays >= 8 && elapsedDays <= 14)
                    {
                        initConfVsPRPlanDate.data.Eight_Fourteen++;
                    }
                    else if (elapsedDays >= 15 && elapsedDays <= 21)
                    {
                        initConfVsPRPlanDate.data.Fifteen_TwentyOne++;
                    }
                    else // 22 Days or greater
                    {
                        initConfVsPRPlanDate.data.TwentyTwo++;
                    }
                }



                try
                {
                    initConfVsPRPlanDate.data.Average = Math.Round(totalDays / initConfVsPRPlanDate.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    initConfVsPRPlanDate.data.Average = 0;
                }



                try
                {
                    initConfVsPRPlanDate.data.PercentUnconf = (int)((totalPOsUnconf / initConfVsPRPlanDate.data.Total) * 100);
                }
                catch (DivideByZeroException)
                {
                    initConfVsPRPlanDate.data.PercentUnconf = 0;
                }



                initConfVsPRPlanDate.data.Total = Overall.prsOnPOsDt.Rows.Count - (int)totalPOsUnconf;

                totalDays = 0;

                PRPO_DB_Utils.CompletedDataLoads++;
                MethodInvoker del = delegate
                {
                    PRPO_DB_Utils.UpdateDataLoadProgress();
                };
                del.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "KPI -> Purch Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #48
0
        void Instance_OnHardwareStateChanged(EquipmentType arg1, bool? arg2)
        {
            foreach (var node in resourceNodes)
            {
                if (node.Key.ResourceInfo.IsHardware && node.Value.SourceType.Equals(arg1))//node.Key.ResourceInfo.Type == arg1.Type)
                {
                    MethodInvoker mi = new MethodInvoker(() =>
                    {
                        _view.OnHardwareStateChanged(node.Value, arg2);
                    });

                    if (_view.IsHandleCreated)
                        _view.Invoke(mi);
                    else
                        mi.Invoke();
                }
            }
        }
Example #49
0
        /// <summary>
        /// Loads the data for the specific KPI
        /// </summary>
        /// <param name="Overall.SelectedCountry"></param>
        public void LoadData()
        {
            try
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PR Release vs PO Release
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    string[] strPOLineFirstRelDate = (dr["PO Line 1st Rel Dt"].ToString()).Split('/');
                    int      poLineFirstRelYear    = int.Parse(strPOLineFirstRelDate[2]);
                    int      poLineFirstRelMonth   = int.Parse(strPOLineFirstRelDate[0]);
                    int      poLineFirstRelDay     = int.Parse(strPOLineFirstRelDate[1]);

                    if (poLineFirstRelYear == 0 && poLineFirstRelMonth == 0 && poLineFirstRelDay == 0)
                    {
                        continue;
                    }
                    else
                    {
                        prRelVsPORel.data.Total++;
                        poLineFirstRelYear  = int.Parse(strPOLineFirstRelDate[2]);
                        poLineFirstRelMonth = int.Parse(strPOLineFirstRelDate[0].TrimStart('0'));
                        poLineFirstRelDay   = int.Parse(strPOLineFirstRelDate[1].TrimStart('0'));
                    }

                    DateTime poLineFirstRelDate = new DateTime(poLineFirstRelYear, poLineFirstRelMonth, poLineFirstRelDay);

                    string[] strPR2ndLvlRelDate = (dr["PR 2° Rel# Date"].ToString()).Split('/');
                    int      secLvlRelYear      = int.Parse(strPR2ndLvlRelDate[2]);
                    int      secLvlRelMonth     = int.Parse(strPR2ndLvlRelDate[0].TrimStart('0'));
                    int      secLvlRelDay       = int.Parse(strPR2ndLvlRelDate[1].TrimStart('0'));

                    DateTime pr2ndLvlRelDate = new DateTime(secLvlRelYear, secLvlRelMonth, secLvlRelDay);
                    double   elapsedDays     = (poLineFirstRelDate - pr2ndLvlRelDate).TotalDays;
                    totalDays  += elapsedDays;
                    elapsedDays = (int)elapsedDays;

                    if (elapsedDays <= 0)
                    {
                        prRelVsPORel.data.LessThanZero++;
                    }
                    else if (elapsedDays >= 1 && elapsedDays <= 3)
                    {
                        prRelVsPORel.data.One_Three++;
                    }
                    else if (elapsedDays >= 4 && elapsedDays <= 7)
                    {
                        prRelVsPORel.data.Four_Seven++;
                    }
                    else if (elapsedDays >= 8 && elapsedDays <= 14)
                    {
                        prRelVsPORel.data.Eight_Fourteen++;
                    }
                    else if (elapsedDays >= 15 && elapsedDays <= 21)
                    {
                        prRelVsPORel.data.Fifteen_TwentyOne++;
                    }
                    else if (elapsedDays >= 22 && elapsedDays <= 28)
                    {
                        prRelVsPORel.data.TwentyTwo_TwentyEight++;
                    }
                    else if (elapsedDays >= 29 && elapsedDays <= 35)
                    {
                        prRelVsPORel.data.TwentyNine_ThirtyFive++;
                    }
                    else if (elapsedDays >= 36 && elapsedDays <= 42)
                    {
                        prRelVsPORel.data.ThirtySix_FourtyTwo++;
                    }
                    else if (elapsedDays >= 43 && elapsedDays <= 49)
                    {
                        prRelVsPORel.data.FourtyThree_FourtyNine++;
                    }
                    else if (elapsedDays >= 50)
                    {
                        prRelVsPORel.data.greaterThanEqualFifty++;
                    }
                }

                try
                {
                    prRelVsPORel.data.Average = Math.Round(totalDays / prRelVsPORel.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    prRelVsPORel.data.Average = 0;
                }
                totalDays = 0;



                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //
                // PO Creation vs Confirmation Entry
                //
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                poCreateVsConfEntry.data.Total = Overall.prsOnPOsDt.Rows.Count;

                foreach (DataRow dr in Overall.prsOnPOsDt.Rows)
                {
                    string[] strFirstConfCreationDt = (dr["1st Conf Creation Da"].ToString()).Split('/');
                    int      poLineFirstConfYear    = int.Parse(strFirstConfCreationDt[2]);
                    int      poLineFirstConfMonth   = int.Parse(strFirstConfCreationDt[0]);
                    int      poLineFirstConfDay     = int.Parse(strFirstConfCreationDt[1]);

                    if (poLineFirstConfYear == 0 && poLineFirstConfMonth == 0 && poLineFirstConfDay == 0)
                    {
                        totalUnconf++;
                        continue;
                    }
                    else
                    {
                        poLineFirstConfYear  = int.Parse(strFirstConfCreationDt[2]);
                        poLineFirstConfMonth = int.Parse(strFirstConfCreationDt[0]);
                        poLineFirstConfDay   = int.Parse(strFirstConfCreationDt[1]);
                    }


                    DateTime initialConfCreateDate = new DateTime(poLineFirstConfYear, poLineFirstConfMonth, poLineFirstConfDay);

                    string[] strPOLineCreateDt = (dr["PO Line Creat#DT"].ToString()).Split('/');
                    int      poLineCreateYear  = int.Parse(strPOLineCreateDt[2]);
                    int      poLineCreateMonth = int.Parse(strPOLineCreateDt[0].TrimStart('0'));
                    int      poLineCreateDay   = int.Parse(strPOLineCreateDt[1].TrimStart('0'));

                    DateTime poLineItemCreateDate = new DateTime(poLineCreateYear, poLineCreateMonth, poLineCreateDay);

                    double elapsedDays = (initialConfCreateDate - poLineItemCreateDate).TotalDays;
                    totalDays  += elapsedDays;
                    elapsedDays = (int)elapsedDays;

                    if (elapsedDays <= 0)
                    {
                        poCreateVsConfEntry.data.LessThanZero++;
                    }
                    else if (elapsedDays >= 1 && elapsedDays <= 3)
                    {
                        poCreateVsConfEntry.data.One_Three++;
                    }
                    else if (elapsedDays >= 4 && elapsedDays <= 7)
                    {
                        poCreateVsConfEntry.data.Four_Seven++;
                    }
                    else if (elapsedDays >= 8 && elapsedDays <= 14)
                    {
                        poCreateVsConfEntry.data.Eight_Fourteen++;
                    }
                    else if (elapsedDays >= 15 && elapsedDays <= 21)
                    {
                        poCreateVsConfEntry.data.Fifteen_TwentyOne++;
                    }
                    else if (elapsedDays >= 22 && elapsedDays <= 28)
                    {
                        poCreateVsConfEntry.data.TwentyTwo_TwentyEight++;
                    }
                    else if (elapsedDays >= 29 && elapsedDays <= 35)
                    {
                        poCreateVsConfEntry.data.TwentyNine_ThirtyFive++;
                    }
                    else if (elapsedDays >= 36 && elapsedDays <= 42)
                    {
                        poCreateVsConfEntry.data.ThirtySix_FourtyTwo++;
                    }
                    else if (elapsedDays >= 43 && elapsedDays <= 49)
                    {
                        poCreateVsConfEntry.data.FourtyThree_FourtyNine++;
                    }
                    else if (elapsedDays >= 50)
                    {
                        poCreateVsConfEntry.data.greaterThanEqualFifty++;
                    }
                }


                try
                {
                    poCreateVsConfEntry.data.Average = Math.Round(totalDays / poCreateVsConfEntry.data.Total, 2);
                }
                catch (DivideByZeroException)
                {
                    poCreateVsConfEntry.data.Average = 0;
                }


                try
                {
                    poCreateVsConfEntry.data.PercentUnconf = (int)((totalUnconf / poCreateVsConfEntry.data.Total) * 100);
                }
                catch (DivideByZeroException)
                {
                    poCreateVsConfEntry.data.PercentUnconf = 0;
                }


                totalDays = 0;

                PRPO_DB_Utils.CompletedDataLoads++;
                MethodInvoker del = delegate
                {
                    PRPO_DB_Utils.UpdateDataLoadProgress();
                };
                del.Invoke();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.StackTrace, "KPI -> Purch Sub Calculation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #50
0
 //Used to manipulate interface on multiple thread.
 public static void UIThread(this Form form, MethodInvoker code)
 {
     if (form.InvokeRequired) {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
        void OnShow()
        {
            MethodInvoker invokeFromUI = new MethodInvoker(
               () =>
               {
                   try
                   {
                       this.ShowDialog(this._parentForm);
                   }
                   catch (Exception ex)
                   {
                       throw ex;
                   }
               }
               );

            if (this.InvokeRequired)
                this.Invoke(invokeFromUI);
            else
                invokeFromUI.Invoke();
        }
 /// <summary>
 /// easy method to handle cross-thread calls on a windows form.
 /// </summary>
 /// <param name="task"></param>
 public void EasyInvoke(MethodInvoker task)
 {
     if (this.InvokeRequired)
         this.Invoke(task);
     else
         task.Invoke();
 }