Esempio n. 1
0
        private void buttonUpdate_Click(object sender, EventArgs e)
        {
            DisableUIControl();
            ICancelableForm fw     = new FormWait(this, GetDeliveredEnergyActiveRowNumber());
            Action          action = () =>
            {
                TaskUpdate(fw);
            };

            HelperInterruptibleWorker worker = new HelperInterruptibleWorker(this, fw);

            worker.ExecuteTask(action);
        }
Esempio n. 2
0
        private void buttonProcess_Click(object sender, EventArgs e)
        {
            DisableUIControl();
            ICancelableForm fw     = new FormWait(this, GetDataIntegrityActiveRowNumber());
            Action          action = () =>
            {
                TaskDataIntegrityProcess(fw);
            };

            HelperInterruptibleWorker worker = new HelperInterruptibleWorker(this, fw);

            worker.ExecuteTask(action);
        }
        /// <summary>
        /// Remove duplicates for all 15min periods, duplicates are removed if all measurment values are same
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void removeDuplicatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            #region OLD WAY
            //List<string> commands = new List<string>(); // List of database commands
            //// Loop thru every 15min point, and generate remove database queries for true duplicate data

            //foreach (Data15MinClass d15 in dataPtr.data)
            //{
            //    if (d15.numberOfPoints < 2)
            //    {
            //        continue; // If point have less than 2 values ignore
            //    }

            //    var uniqueValues = new List<FloatValues>(); // Create new list which will hold unique values
            //    var all15minValues = d15.GetAllValues(); // Some 15min point can have multiple values, duplicates

            //    // First value is always unique
            //    uniqueValues.Add(all15minValues[0]);

            //    // Generate remove command for each duplicated value, leave values that are different in float values
            //    for (int i = 1; i < d15.GetAllValues().Count; i++) // Skip first
            //    {
            //        bool equalFlag = false; // This will be set to true if any of data point is true duplicate
            //        foreach (var item2 in uniqueValues)
            //        {
            //            if (FloatHelper.CompareDuplicateValues(item2, all15minValues[i])) // Check if they are equal
            //            {
            //                equalFlag = true;
            //                // Generate command for row removal from database and add it to list of commands
            //                commands.Add(GenerateDatabaseRemoveCommand(all15minValues[i]));
            //            }

            //        }

            //        if (!equalFlag)
            //        {
            //            // This garantiues unique value
            //            uniqueValues.Add(all15minValues[i]);
            //        }
            //        equalFlag = false;
            //    }
            //}
            #endregion old way
            List <string> commands = CreateDBRemoveCommands();
            // Make dialog box, for connfirming deletion
            DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete: " + commands.Count + " items from database?", "Warning", MessageBoxButtons.YesNo);
            if (dialogResult == DialogResult.No)
            {
                return;
            }
            // Yes was selected

            Action action = () =>
            {
                //Console.WriteLine("Starting request");
                foreach (var item in commands)
                {
                    FormCustomConsole.WriteLine("Sending command: " + item);

                    try
                    {
#warning Deleteing items from database can be configured here
                        DatabaseControllerClass.SendCommandToDatabase(DatabaseSettingsClass.ReadConnectionString(), item);
                        FormCustomConsole.WriteLine("Successfully executed command:" + item);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            };

            ICancelableForm           cf     = new FormWaitMarquee(this);
            HelperInterruptibleWorker worker = new HelperInterruptibleWorker(this, cf);
            worker.ExecuteTask(action);
        }