Пример #1
0
        void loadButton_Click(object sender, EventArgs e)
        {
            Button btn = (Button)sender;

            // Set the pagesize of the lookup table loader...
            if (ux_radiobuttonHighDemand.Checked)
            {
                _sharedUtils.LookupTablesLoadingPageSize = 100000;
            }
            else if (ux_radiobuttonMediumDemand.Checked)
            {
                _sharedUtils.LookupTablesLoadingPageSize = 10000;
            }
            else
            {
                _sharedUtils.LookupTablesLoadingPageSize = 1000;
            }

            if (btn.Tag.ToString() == "_LOADALL_")
            {
                for (int i = 1; i < tableLayoutPanel1.RowCount; i++)
                {
                    // Get the next rows start loading button...
                    Control ctrl = tableLayoutPanel1.GetControlFromPosition(2, i);
                    // If the row is empty - ignore it...
                    if (ctrl != null)
                    {
                        // Now disable it...
                        ctrl.Enabled = false;
                        // Enable the marquee progress bar...
                        ((ProgressBar)tableLayoutPanel1.GetControlFromPosition((int)CtrlPosition.activityProgressBar, i)).Style = ProgressBarStyle.Marquee;
                        ((ProgressBar)tableLayoutPanel1.GetControlFromPosition((int)CtrlPosition.activityProgressBar, i)).MarqueeAnimationSpeed = 3000000 / _sharedUtils.LookupTablesLoadingPageSize;

                        // If this table has been completely loaded, clear it and reload from Empty...
                        if (_sharedUtils.LookupTablesIsUpdated(ctrl.Tag.ToString().Trim()))
                        {
                            _sharedUtils.LookupTablesClearLookupTable(ctrl.Tag.ToString().Trim());
                        }

                        // Background thread the loading of the lookup table...
                        //_lookupTables.LoadTableFromDatabase(ctrl.Tag.ToString());
                        new System.Threading.Thread(_sharedUtils.LookupTablesLoadTableFromDatabase).Start(ctrl.Tag.ToString());
                        DateTime start = DateTime.Now;
                        // Wait 1/2 second before processing the next row (lookup table)...
                        while (DateTime.Now < start.AddSeconds(0.5))
                        {
                            // Let messages get processed...
                            Application.DoEvents();
                        }
                    }
                }
            }
            else
            {
                // Disable the start loading button...
                btn.Enabled = false;
                // Enable the marquee progress bar...
                TableLayoutPanelCellPosition progressBarPosition = tableLayoutPanel1.GetCellPosition(btn);
                ((ProgressBar)tableLayoutPanel1.GetControlFromPosition((int)CtrlPosition.activityProgressBar, progressBarPosition.Row)).Style = ProgressBarStyle.Marquee;
                ((ProgressBar)tableLayoutPanel1.GetControlFromPosition((int)CtrlPosition.activityProgressBar, progressBarPosition.Row)).MarqueeAnimationSpeed = 3000000 / _sharedUtils.LookupTablesLoadingPageSize;

                // If this table has been completely loaded, clear it and reload from Empty...
                if (_sharedUtils.LookupTablesIsUpdated(btn.Tag.ToString().Trim()))
                {
                    _sharedUtils.LookupTablesClearLookupTable(btn.Tag.ToString().Trim());
                }

                // Now thread the LU table load...
                new System.Threading.Thread(_sharedUtils.LookupTablesLoadTableFromDatabase).Start(btn.Tag.ToString());
            }
        }