// TODO: Make sorting disabled while updating public void ReplaceDataPoint(int deviceID) { DataGridViewRow dataGridItem = null; int dataGridSelectedIndex = -1; // Find row with matching ID foreach (DataGridViewRow item in dataGridView2.Rows) { dataGridSelectedIndex = Convert.ToInt32(item.Cells[1].Value); if (dataGridSelectedIndex == deviceID) { dataGridItem = item; break; } } if (dataGridItem == null) { throw new Exception("Item in DataGrid with that deviceID doesn't exist"); } // Find matching ID in allData var tuple = GetInstanceFromAllDataByDeviceID(deviceID); if (tuple == null) { throw new Exception("Data item in allData with that deviceID doesn't exist"); } // Extract information from data object DataClass data = tuple.Item1; DateTime dateStart = data.startDate; DateTime dateEnd = data.endDate; string oracleDateStart = HelperClass.ConvertToOracleTime(data.startDate); string oracleDateEnd = HelperClass.ConvertToOracleTime(data.endDate); // Generate oracle time selection string string result = ""; //int currentRow = _index; string querryCommand = "SELECT VALID,IPAA,IPBA,IPCA,VABA,VBCA,VCAA, READ_TIME, ID FROM DATA_HISTORY WHERE DEVICE_ID=" + dataGridSelectedIndex + " AND READ_TIME >= " + oracleDateStart + " AND READ_TIME < " + oracleDateEnd + "AND ROWNUM <= " + ConfigClass.MAX_ROWS_GET.ToString(); char delim = '|'; try { result = DatabaseControllerClass.FetchValuesFromDatabase(DatabaseSettingsClass.ReadConnectionString(), querryCommand, delim); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } finally { //fw.Close(); } // Instantiate dataclass for current row //data = new DataClass(dateEnd.Subtract(dateStart).Days, dataGridItem.Index, dateStart, dateEnd); var newData = new DataClass(dateEnd.Subtract(dateStart).Days, tuple.Item2, dateStart, dateEnd); // Fill it with values from database newData.FillDataRow(result, dataGridSelectedIndex, delim); // Process data row for: null values, zero values, duplicate values and generaly some way of corrupted data newData.ProcessData(); newData.RunAnalysis(); // This will calculate all needed info string tempSummary = newData.GenerateSummary(); string[] summary = tempSummary.Split(delim); // Fill cells dataGridItem.Cells[4].Value = summary[0]; // valid dataGridItem.Cells[5].Value = summary[1]; // flag status dataGridItem.Cells[6].Value = dateStart.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); dataGridItem.Cells[7].Value = dateEnd.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); dataGridItem.Cells[8].Value = "Ready"; dataGridItem.Cells[8].Style.BackColor = Color.Lavender; // Finaly replace data instance in allData array ReplaceDataPoint(newData); }
private void ProcessDataIntegrity(ICancelableForm fw) { string sysFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern; string sysUIFormat = CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern; FormCustomConsole.WriteLine("CurrentCulture: " + sysFormat); FormCustomConsole.WriteLine("CurrentUICulture: " + sysUIFormat); DateTime dateStart = GetDateFiltered(dateTimePickerStartDataIntegrity); DateTime dateEnd = GetDateFiltered(dateTimePickerEndDataIntegrity); // Check if day selection is valid TimeSpan dayDiff = dateEnd.Subtract(dateStart); // It will hold days difference if (dayDiff.Days <= 0) { MessageBox.Show("Select valid time!"); return; } string oracleDateStart; string oracleDateEnd; string querryCommand; string result = ""; int currentRow = -1; // If row is enabled, process it foreach (DataGridViewRow item in dataGridView2.Rows) { currentRow++; // Start from -1 so it is 0 at first iteration if (Convert.ToBoolean(item.Cells[0].Value) == true) { // Selected element is enabled // Create oracle time selection string oracleDateStart = HelperClass.ConvertToOracleTime(dateStart); oracleDateEnd = HelperClass.ConvertToOracleTime(dateEnd); // Create command querryCommand = "SELECT VALID,IPAA,IPBA,IPCA,VABA,VBCA,VCAA, READ_TIME, ID FROM DATA_HISTORY WHERE DEVICE_ID=" + item.Cells[1].Value + " AND READ_TIME >= " + oracleDateStart + " AND READ_TIME < " + oracleDateEnd + "AND ROWNUM <= " + ConfigClass.MAX_ROWS_GET.ToString(); char delim = '|'; try { result = DatabaseControllerClass.FetchValuesFromDatabase(DatabaseSettingsClass.ReadConnectionString(), querryCommand, delim); } catch (Exception) { Task.Run(() => MessageBox.Show("Timeout for device ID:" + item.Cells[1].Value)); return; } // Instantiate dataclass for current row allData[currentRow] = new DataClass(dayDiff.Days, currentRow, dateStart, dateEnd); // Fill it with values from database allData[currentRow].FillDataRow(result, Convert.ToInt32(item.Cells[1].Value), delim); // Process data row for: null values, zero values, duplicate values and generaly some way of corrupted data allData[currentRow].ProcessData(); allData[currentRow].RunAnalysis(); // This will calculate all needed info string tempSummary = allData[currentRow].GenerateSummary(); string[] summary = tempSummary.Split(delim); // Fill cells item.Cells[4].Value = summary[0]; // valid item.Cells[5].Value = summary[1]; // flag status item.Cells[6].Value = dateStart.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); item.Cells[7].Value = dateEnd.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture); item.Cells[8].Value = "Ready"; item.Cells[8].Style.BackColor = Color.Lavender; // Update percentage bar and check if aborted fw.ProgresStep(); // Update progress bar if (fw.AlreadyClosed) { return; } } else // Cell is not selected { } } }