Esempio n. 1
0
        private void btnPrintRaceOrder_Click(object sender, EventArgs e)
        {
            // Print starting lists
            try
            {
                // Call DatabaseConnection Class
                // first create new object
                objConnect = new DatabaseConnection();
                // then give SQL as a parameter
                // Classes
                objConnect.Sql = "select * from class WHERE EventID = '" + EventID + "' ORDER BY Name";
                ds             = objConnect.GetConnection;
                DataTable RaceClasses = new DataTable();
                RaceClasses = ds.Tables["Table"];

                // Attendees with more details
                objConnect.Sql = "SELECT d.ClassID, d.RaceOrder Lähtönumero, p.Lastname, p.Firstname, d.Vehicle Ajoneuvo, d.Vehicle_info Ajoneuvon_Tiedot, p.City Kunta, p.Club Seura FROM Device d JOIN Person p ON p.PersonID = d.PersonID WHERE p.EventID = '" + EventID + "' ORDER BY d.RaceOrder";
                ds             = objConnect.GetConnection;
                dt             = new DataTable();
                dt             = ds.Tables["Table"];

                // Warn about actions
                MessageBox.Show("Tulostetaan lähtölistat. Sinulle avautuu jokainen luokka erikseen tulostettavaksi, kun suljet ikkunan aukeaa seuraava luokka.", "Luokkien tulostaminen");

                foreach (DataRow dr in RaceClasses.Rows)
                {
                    var FilteredAttendees = dt.Select("ClassID = '" + dr["ClassID"].ToString() + "'").CopyToDataTable();
                    if (FilteredAttendees.Rows.Count > 0)
                    {
                        DataGridView dgvAttendees = new DataGridView();
                        dgvAttendees.Rows.Clear();
                        dgvAttendees.Columns.Add("StartingNumber", "Lähtönumero");
                        dgvAttendees.Columns.Add("Person", "Henkilö");
                        dgvAttendees.Columns.Add("Vehicle", "Ajoneuvo");
                        dgvAttendees.Columns.Add("VehicleInfo", "Ajoneuvon lisätiedot");
                        dgvAttendees.Columns.Add("City", "Kunta");
                        dgvAttendees.Columns.Add("Club", "Seura");

                        string Class = "";
                        foreach (DataRow d in FilteredAttendees.Rows)
                        {
                            Class = dr["Name"].ToString();
                            string Henkilö = d["Lastname"].ToString() + ", " + d["Firstname"].ToString();
                            dgvAttendees.Rows.Add(d["Lähtönumero"].ToString(), Henkilö, d["Ajoneuvo"].ToString(), d["Ajoneuvon_Tiedot"].ToString(), d["Kunta"].ToString(), d["Seura"].ToString());
                        }
                        // Then print it
                        ClsPrint _ClsPrint = new ClsPrint(dgvAttendees, Class);
                        _ClsPrint.PrintForm();
                    }
                    else
                    {
                        // Nothing to print here
                    }
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message);
            }
        }
Esempio n. 2
0
        private void FillTab()
        {
            try
            {
                // So far, remove first (Summary) tab
                tabControl.TabPages.RemoveByKey("tab1");
                // But only after some page has been clicked

                string TabName = tabControl.TabPages[this.tabControl.SelectedIndex].Text;

                // Create DataGridView
                DataGridView dgvTime = new DataGridView();
                dgvTime.Name = "dgv" + TabName;
                dgvTime.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                // dgvTime.Parent = this;
                dgvTime.Location                = new System.Drawing.Point(20, 40);
                dgvTime.Size                    = new System.Drawing.Size(1200, 970);
                dgvTime.ReadOnly                = true;
                dgvTime.Enabled                 = true;
                dgvTime.AllowUserToAddRows      = false;
                dgvTime.AllowUserToDeleteRows   = true;
                dgvTime.AllowUserToOrderColumns = true;
                dgvTime.AllowUserToResizeRows   = true;
                dgvTime.AllowUserToResizeRows   = true;
                dgvTime.ClipboardCopyMode       = DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText;
                //dgvTime.Allow = true;

                // Add DataGridView to Tab
                TabPage ntb = tabControl.TabPages[this.tabControl.SelectedIndex];
                // Add to Tab
                ntb.Controls.Add(dgvTime);

                // Get distinct users of class results
                GetAttendees(TabName);
                GetMaxLapNumberPerClass(TabName);

                string LapsMax = "0";
                foreach (DataRow dr in dtMaxLaps.Rows)
                {
                    LapsMax = dr["Kierroksia"].ToString();
                }

                DataTable Results = new DataTable();
                Results.Columns.Add("SukuNimi");
                Results.Columns.Add("Etunimi");
                Results.Columns.Add("Laite");

                int r = 0;
                foreach (DataRow dr in dtAttendees.Rows)
                {
                    string VehicleID = dr["VehicleID"].ToString();
                    GetLaps(VehicleID);

                    // Now we got results in dtResults data table
                    if (r == 0)
                    {
                        dgvTime.Columns.Add("LastName", "Sukunimi");
                        dgvTime.Columns.Add("FirstName", "Etunimi");
                        dgvTime.Columns.Add("Device", "Laite");

                        for (int ii = 1; ii <= Int32.Parse(LapsMax); ii++)
                        {
                            dgvTime.Columns.Add("Lap" + ii, "Kierros" + ii);
                        }

                        dgvTime.Columns.Add("TotalTime", "Yhteistulos");
                    }

                    dgvTime.Rows.Add();


                    string LastName  = dr["Sukunimi"].ToString();
                    string FirstName = dr["Etunimi"].ToString();
                    string Device    = dr["Laite"].ToString();
                    dgvTime.Rows[r].Cells[0].Value = LastName;
                    dgvTime.Rows[r].Cells[1].Value = FirstName;
                    dgvTime.Rows[r].Cells[2].Value = Device;

                    TimeSpan TotalTime = new TimeSpan();

                    int f = 3;
                    for (int j = 0; j < dtResults.Rows.Count; j++)
                    {
                        string LapTimeString = dtResults.Rows[j][1].ToString();
                        // Single LapTime to string
                        TimeSpan LapTime = TimeSpan.Parse(LapTimeString);
                        // Put it to datagridview with formatting
                        dgvTime.Rows[r].Cells[f].Value = LapTime.ToString(@"mm\:ss\.ff");
                        // Also put same LapTime to TotalTimeString
                        TotalTime = TotalTime + TimeSpan.Parse(LapTimeString);
                        f++;
                    }
                    // Add Total time of laps as a last one to datagridview
                    dgvTime.Rows[r].Cells[dgvTime.Columns.Count - 1].Value = TotalTime.ToString(@"mm\:ss\.ff");

                    //

                    r++;
                }

                // Sort results

                if (dgvTime.Rows.Count > 0)
                {
                    dgvTime.Sort(dgvTime.Columns["TotalTime"], ListSortDirection.Ascending);
                }

                dgvTime.Columns.Add("Difference", "Ero 1:een");

                for (int i = 1; i < dgvTime.Rows.Count; i++)
                {
                    String   var1       = dgvTime.Rows[0].Cells["TotalTime"].Value.ToString();
                    TimeSpan var1TS     = TimeSpan.ParseExact(var1, @"mm\:ss\.ff", System.Globalization.CultureInfo.InvariantCulture);
                    String   var2       = dgvTime.Rows[i].Cells["TotalTime"].Value.ToString();
                    TimeSpan var2TS     = TimeSpan.ParseExact(var2, @"mm\:ss\.ff", System.Globalization.CultureInfo.InvariantCulture);
                    TimeSpan Difference = var2TS - var1TS;
                    dgvTime.Rows[i].Cells["Difference"].Value = Difference.ToString(@"mm\:ss\.ff");
                }


                // Create Print button
                Button Print = new Button();
                Print.Text     = "Tulosta";
                Print.Name     = "btnPrint";
                Print.Location = new System.Drawing.Point(1098, 667);

                this.Controls.Add(Print);

                Print.Click += delegate
                {
                    ClsPrint _ClsPrint = new ClsPrint(dgvTime, TabName);
                    _ClsPrint.PrintForm();
                };
            }
            catch (Exception exc) { MessageBox.Show(exc.Message); }
        }