void updateOverzight()
        {
            if (!_NoConnectionMode)
            {
                try
                {
                    _TimerReloadOverzicht.Stop();
                    NetCom.ServerRequestOverzightFromOneDate request = new NetCom.ServerRequestOverzightFromOneDate();
                    request.useToday = true;

                    NetCom.ServerResponse response;

                    try
                    {
                        Stopwatch sw = new Stopwatch();
                        sw.Start();

                        response = webbbbrrrrrry(request);

                        label2.Text = sw.ElapsedMilliseconds.ToString();
                    }
                    catch
                    { // als server down is (als school in brand staat...)
                      // if (MessageBox.Show("Kan Niet Verbinden Met Server", "Ga Naar Alarm Modus?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)==DialogResult.Yes) {
                        enableNoConnectionMode();
                        //} else {
                        //this.BackColor=Color.Yellow;
                        //}
                        _TimerReloadOverzicht.Start();
                        return;
                    }

                    this.BackColor = SystemColors.Control; // all OK color

                    NetCom.ServerResponseOverzightFromOneDate returnedValue;
                    if (response.IsErrorOccurred)
                    {
                        throw new Exception(response.ErrorInfo.ErrorMessage);
                    }
                    else
                    {
                        //--
                        int _SelectedRowNummber = 0;
                        if (dataGridView1.CurrentCell != null)
                        {
                            _SelectedRowNummber = dataGridView1.CurrentCell.RowIndex;
                        }
                        ListSortDirection  _oldSortOrder;
                        DataGridViewColumn _oldSortCol;
                        _oldSortOrder = dataGridView1.SortOrder == SortOrder.Ascending ?
                                        ListSortDirection.Ascending : ListSortDirection.Descending;
                        _oldSortCol = dataGridView1.SortedColumn;
                        ///--
                        ///
                        returnedValue            = JsonConvert.DeserializeObject <NetCom.ServerResponseOverzightFromOneDate>(JsonConvert.SerializeObject(response.Response));
                        dataGridView1.DataSource = FormHelp.UserInfoListToDataTableForDataGridDisplay(returnedValue.EtList, returnedValue.SQlDateTime);
                        dataGridView1.Refresh();
                        _LastRecivedOverzight = returnedValue.EtList;

                        //--
                        if (_oldSortCol != null)
                        {
                            DataGridViewColumn newCol = dataGridView1.Columns[_oldSortCol.Name];
                            dataGridView1.Sort(newCol, _oldSortOrder);
                        }
                        try
                        {// voor als row[x] er niet (meer) is
                            if (dataGridView1.CurrentCell != null)
                            {
                                dataGridView1.CurrentCell = dataGridView1[1, _SelectedRowNummber];
                            }
                        }
                        catch
                        {
                            dataGridView1.ClearSelection();
                        }
                        ///--

                        dataGridView1.Columns[0].Width = 130;
                        dataGridView1.Columns[1].Width = 158;
                        dataGridView1.Columns[4].Width = dataGridView1.Width - dataGridView1.Columns[0].Width - dataGridView1.Columns[1].Width - dataGridView1.Columns[2].Width - dataGridView1.Columns[3].Width - 3 - 20;
                        _TimerReloadOverzicht.Start();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    _TimerReloadOverzicht.Start();
                }
            }
            else
            {
                if (FormHelp.CanConnectToServer(_ApiAddres))
                {
                    disableNoConnectionMode();
                    this.BackColor = Color.Yellow;//still outdated
                }
            }
        }
示例#2
0
        private void ReloadOverzight(bool reloadFromServer)
        {
            if (!_NoConnectionMode)
            {
                _TimerReloadOverzicht.Stop();
                NetCom.ServerRequestOverzightFromOneDate request = new NetCom.ServerRequestOverzightFromOneDate();
                if (checkBoxSeUserTodayAsDate.Checked)
                {
                    request.useToday = true;
                }
                else
                {
                    request.useToday = false;
                    request.dateToGetOverzightFrom = dateTimePickerSeDateToListTo.Value.Date;
                    _LastRecivedOverzightDate      = dateTimePickerSeDateToListTo.Value.Date;
                }
                _LastRecivedOverzightDateIsToday = checkBoxSeUserTodayAsDate.Checked;
                if (checkBoxSeShowExUsers.Checked)
                {
                    request.alsoReturnExUsers = true;
                }
                NetCom.ServerResponse response;
                try
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    response    = webbbbrrrrrry(request);
                    label2.Text = sw.ElapsedMilliseconds.ToString();
                }
                catch
                { // als server down is (als school in brand staat...)
                  //   if (MessageBox.Show("Kan Niet Verbinden Met Server", "Ga Naar Alarm Modus?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) {
                    enableNoConnectionMode();
                    //   } else {
                    //       this.BackColor = Color.Yellow;//times are outdated
                    //       panel2.BackColor = Color.Yellow;
                    //   }
                    _TimerReloadOverzicht.Start();
                    return;
                }
                NetCom.ServerResponseOverzightFromOneDate returnedValue;
                if (response.IsErrorOccurred)
                {
                    throw new Exception(response.ErrorInfo.ErrorMessage);
                }
                else
                {
                    //--
                    int _SelectedRowNummber = 0;
                    if (dataGridView1.CurrentCell != null)
                    {
                        _SelectedRowNummber = dataGridView1.CurrentCell.RowIndex;
                    }
                    ListSortDirection  _oldSortOrder;
                    DataGridViewColumn _oldSortCol;
                    _oldSortOrder = dataGridView1.SortOrder == SortOrder.Ascending ?
                                    ListSortDirection.Ascending : ListSortDirection.Descending;
                    _oldSortCol = dataGridView1.SortedColumn;
                    ///--
                    if (reloadFromServer)
                    {
                        returnedValue = JsonConvert.DeserializeObject <NetCom.ServerResponseOverzightFromOneDate>(JsonConvert.SerializeObject(response.Response));

                        _ALLOWCLEARINPUTSONRELOAD = false;

                        if (_LastRecivedOverzight != null && _CurrentlySelectedUser.UsE != null && _CurrentlySelectedUser.RegE != null && ((_LastRecivedOverzightDateIsToday == checkBoxSeUserTodayAsDate.Checked && _LastRecivedOverzightDateIsToday == true) || _LastRecivedOverzightDate == dateTimePickerSeDateToListTo.Value.Date))
                        {
                            #region try 2015/2016?

                            /*
                             * try
                             * {
                             *  foreach (var entry in returnedValue.EtList)
                             *  {
                             *      if (entry.UsE.ID == _CurrentlySelectedUser.UsE.ID)
                             *      {
                             *          if (entry.hasTodayRegEntry == _CurrentlySelectedUser.hasTodayRegEntry)
                             *          {
                             *              if (entry.RegE.ID == _CurrentlySelectedUser.RegE.ID &&
                             *                  entry.RegE.HeeftIngetekend == _CurrentlySelectedUser.RegE.HeeftIngetekend &&
                             *                  entry.RegE.IsAanwezig == _CurrentlySelectedUser.RegE.IsAanwezig &&
                             *                  entry.RegE.IsExcurtie == _CurrentlySelectedUser.RegE.IsExcurtie &&
                             *                  entry.RegE.IsFlexiebelverlof == _CurrentlySelectedUser.RegE.IsStudieverlof &&
                             *                  entry.RegE.IsStudieverlof == _CurrentlySelectedUser.RegE.IsStudieverlof &&
                             *                  entry.RegE.IsLaat == _CurrentlySelectedUser.RegE.IsLaat &&
                             *                  entry.RegE.IsZiek == _CurrentlySelectedUser.RegE.IsZiek &&
                             *                  entry.RegE.Opmerking == _CurrentlySelectedUser.RegE.Opmerking)
                             *              {
                             *                  if (entry.RegE.HeeftIngetekend)
                             *                  {
                             *                      if (entry.RegE.TimeInteken == _CurrentlySelectedUser.RegE.TimeInteken)
                             *                      {
                             *                          if (entry.RegE.IsAanwezig == false)
                             *                          {
                             *                              if (entry.RegE.TimeUitteken == _CurrentlySelectedUser.RegE.TimeUitteken)
                             *                              {
                             *                                  if (entry.RegE.IsLaat)
                             *                                  {
                             *                                      if (entry.RegE.Verwachtetijdvanaanwezighijd == _CurrentlySelectedUser.RegE.Verwachtetijdvanaanwezighijd)
                             *                                      {
                             *                                          _ALLOWCLEARINPUTSONRELOAD = false;
                             *                                      }
                             *                                      break;
                             *                                  }
                             *                                  _ALLOWCLEARINPUTSONRELOAD = false;
                             *                              }
                             *                              break;
                             *                          }
                             *                          _ALLOWCLEARINPUTSONRELOAD = false;
                             *                      }
                             *                      break;
                             *                  }
                             *                  _ALLOWCLEARINPUTSONRELOAD = false;
                             *              }
                             *              break;
                             *          }
                             *          break;
                             *      }
                             *  }
                             * }
                             * catch (Exception ex) { string kanker = ex.Message; _ALLOWCLEARINPUTSONRELOAD = true; }
                             */
                            #endregion


                            #region try 2017
                            try
                            {
                                DBDingus.CombUserAfwEntry entry = returnedValue.EtList.First(x => x.UsE.ID == _CurrentlySelectedUser.UsE.ID);
                                if (entry.RegE != null)
                                {
                                    if (entry.RegE.ID == _CurrentlySelectedUser.RegE.ID &&
                                        entry.RegE.HeeftIngetekend == _CurrentlySelectedUser.RegE.HeeftIngetekend &&
                                        entry.RegE.IsAanwezig == _CurrentlySelectedUser.RegE.IsAanwezig &&
                                        entry.RegE.IsExcurtie == _CurrentlySelectedUser.RegE.IsExcurtie &&
                                        entry.RegE.IsFlexiebelverlof == _CurrentlySelectedUser.RegE.IsStudieverlof &&
                                        entry.RegE.IsStudieverlof == _CurrentlySelectedUser.RegE.IsStudieverlof &&
                                        entry.RegE.IsLaat == _CurrentlySelectedUser.RegE.IsLaat &&
                                        entry.RegE.IsZiek == _CurrentlySelectedUser.RegE.IsZiek &&
                                        entry.RegE.Opmerking == _CurrentlySelectedUser.RegE.Opmerking)
                                    {
                                        _ALLOWCLEARINPUTSONRELOAD = false;
                                    }
                                    else
                                    {
                                        _ALLOWCLEARINPUTSONRELOAD = true;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                _ALLOWCLEARINPUTSONRELOAD = true;
                            }
                            #endregion
                        }

                        _LastRecivedOverzight = returnedValue.EtList;
                    }
                    else
                    {
                        returnedValue        = new NetCom.ServerResponseOverzightFromOneDate();
                        returnedValue.EtList = _LastRecivedOverzight;
                    }
                    if (textBoxZoekOp.Text.Trim() == "")
                    {
                        dataGridView1.SelectionChanged -= dataGridView1_SelectionChanged;
                        dataGridView1.DataSource        = FormHelp.UserInfoListToDataTableForDataGridDisplay(returnedValue.EtList, returnedValue.SQlDateTime);
                        dataGridView1.SelectionChanged += new EventHandler(dataGridView1_SelectionChanged);
                        dataGridView1.Refresh();
                    }
                    else
                    { //zoek op
                        List <DBDingus.CombUserAfwEntry> sortedList = new List <DBDingus.CombUserAfwEntry>();
                        foreach (DBDingus.CombUserAfwEntry perso in returnedValue.EtList)
                        {
                            if (perso.UsE.VoorNaam.Contains(textBoxZoekOp.Text.Trim()) || perso.UsE.AchterNaam.Contains(textBoxZoekOp.Text.Trim()))
                            {
                                sortedList.Add(perso);
                            }
                        }
                        dataGridView1.SelectionChanged -= dataGridView1_SelectionChanged;
                        dataGridView1.DataSource        = FormHelp.UserInfoListToDataTableForDataGridDisplay(sortedList, returnedValue.SQlDateTime);
                        dataGridView1.SelectionChanged += new EventHandler(dataGridView1_SelectionChanged);
                        dataGridView1.Refresh();
                    }
                    this.BackColor   = SystemColors.Control; // times are uptodate
                    panel2.BackColor = SystemColors.Control;
                    //--
                    if (_oldSortCol != null)
                    {
                        DataGridViewColumn newCol = dataGridView1.Columns[_oldSortCol.Name];
                        dataGridView1.Sort(newCol, _oldSortOrder);
                    }
                    try
                    {// voor als row[x] er niet (meer) is
                        if (dataGridView1.CurrentCell != null)
                        {
                            dataGridView1.CurrentCell = dataGridView1[1, _SelectedRowNummber];
                        }
                    }
                    catch
                    {
                        dataGridView1.ClearSelection();
                    }
                    ///--
                    dataGridView1.Columns[0].Width = 130;
                    dataGridView1.Columns[1].Width = 140;
                    dataGridView1.Columns[2].Width = 130;
                    dataGridView1.Columns[3].Width = 130;
                    dataGridView1.Columns[4].Width = dataGridView1.Width - dataGridView1.Columns[0].Width - dataGridView1.Columns[1].Width - dataGridView1.Columns[2].Width - dataGridView1.Columns[3].Width - 3 - 20;
                    _TimerReloadOverzicht.Start();
                }
            }

            else
            {
                if (FormHelp.CanConnectToServer(_ApiAddres))
                {
                    disableNoConnectionMode();
                    this.BackColor   = Color.Yellow; //still outdated
                    panel2.BackColor = Color.Yellow; //why?
                }
            }
        }