private void dispatch( ) { ArrayList prayers = new ArrayList(); bool allPrayers = false; DateTime fromdate = this.dateTimePicker1.Value; DateTime todate = this.dateTimePicker2.Value; string city = string.Empty; string country = string.Empty; LocDataElement location = LocDataElement.Zero; if ( this.listView1.SelectedIndices.Count == 0 ) { MessageBox.Show("Please select a location first !!", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.listView1.SelectedIndices.Count > 10) { DialogResult response = MessageBox.Show("You have selected too many locations. It may take a long time. Are you sure you want to continue?", Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (response == DialogResult.No) { return; } } if (this.checkedListBox1.CheckedIndices.Count == 0) { MessageBox.Show("Please select the prayer times to calculate !!", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } prayers = getSelectedPrayers(); allPrayers = this.checkedListBox1.CheckedItems.Count >= this.checkedListBox1.Items.Count - 1; Prayers [] p = (Prayers[])prayers.ToArray ( typeof(Prayers) ); switch ( this.comboBox1.SelectedIndex ) { case 0: fromdate = new DateTime (this.dateTimePicker1.Value.Year,1,1); todate = fromdate.AddYears(1); todate = todate.Subtract ( new TimeSpan(1,0,0,0) ); break; case 1: fromdate = new DateTime ( this.dateTimePicker1.Value.Year, this.dateTimePicker1.Value.Month, 1); todate = fromdate.AddMonths ( 1 ); todate = todate.Subtract ( new TimeSpan ( 1, 0 , 0, 0 ) ); break; case 3: todate = fromdate; break; } TimeCalculatorAdapter adapter = new TimeCalculatorAdapter (); BugReportDialog reporter = new BugReportDialog(); WaitDialog dlg = new WaitDialog(); dlg.DisplayMessage = "Please Wait..."; dlg.ProgressType = 0; dlg.Owner = this; dlg.Left = this.Left + (this.Width - dlg.Width) / 2; dlg.Top = this.Top + (this.Height - dlg.Height) / 2; dlg.Show(); Application.DoEvents(); ProgressCallback pcb = delegate ( int progress ) { if ( progress - dlg.Progress > 10 ) dlg.Progress = progress; }; foreach (ListViewItem item in listView1.SelectedItems) { location = locdata[(int)item.Tag]; ArrayList data; try { data = adapter.GetTime(p, allPrayers, this.checkBox1.Checked, (int)this.numericUpDown1.Value, fromdate, todate, location, pcb); addPage(location.City + "-" + location.Country, data); dlg.Progress = 0; } catch ( Exception ex ) { MessageBox.Show(ex.Message); reporter.AddBugReport(location, fromdate, todate, p); } Application.DoEvents(); } dlg.Close(); if (reporter.ReportCount > 0) { MessageBox.Show("A critical error has prevented the application from performing some of the required operations.", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); reporter.ShowDialog(); reporter.Dispose(); } }
private void MainForm_Shown(object sender, EventArgs e) { if (_isLocDataLoaded) return; WaitDialog dlg = new WaitDialog(); dlg.Owner = this; dlg.DisplayMessage = "Loading location data..."; dlg.ProgressType = 1; dlg.Left = this.Left + (this.Width - dlg.Width) / 2; dlg.Top = this.Top + (this.Height - dlg.Height) / 2; dlg.Show(); Application.DoEvents(); try { locdatalist.AllowEdit = false; locdatalist.AllowNew = false; locdatalist.AllowRemove = false; locdatalist.RaiseListChangedEvents = true; string datafilepath = string.Empty; if (ApplicationDeployment.IsNetworkDeployed) datafilepath = ApplicationDeployment.CurrentDeployment.DataDirectory + "\\locdata.xml"; else datafilepath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\locdata.xml"; LoadLocationData(datafilepath); _isLocDataLoaded = true; Application.DoEvents(); comboBox1.SelectedIndex = 0; listView1.ListViewItemSorter = new LocationItemComparer(0, SortOrder.Ascending); float progressstep = 100 / (float)locdata.Count; float progress = 0; for (int i = 0; i < locdata.Count; i++) { LocDataElement elt = locdata[i]; ListViewItem item = new ListViewItem(); item.Tag = i; item.Text = elt.City; item.SubItems.Add(elt.Country); string temp = string.Empty; if (elt.latitude >= 0) temp = elt.Latitude.ToString() + "N"; else temp = (-elt.Latitude).ToString() + "S"; item.SubItems.Add(temp); if (elt.Longitude >= 0) temp = elt.Longitude.ToString() + "E"; else temp = (-elt.Longitude).ToString() + "W"; item.SubItems.Add(temp); TimeSpan tempgmt = TimeSpan.FromHours(elt.GMTDiff); item.SubItems.Add(tempgmt.ToString()); listView1.Items.Add(item); progress += progressstep ; dlg.Progress = (int)progress; } } catch (Exception ex) { MessageBox.Show(ex.Message); Environment.Exit(-1); } dlg.Close(); }