Beispiel #1
0
        private void btnShowAllMachines_Click(object sender, EventArgs e)
        {
            List <string> demonumbers = new List <string>();

            try
            {
                if (cbModel.SelectedItem.ToString() == "")
                {
                    demonumbers = CC.GetAllDemoNumbers();
                }
                else
                {
                    try
                    {
                        if (cbType.SelectedItem.ToString() == "")
                        {
                            demonumbers = CC.GetDemoNumbersByModel(cbModel.SelectedItem.ToString());
                        }
                        else
                        {
                            demonumbers = CC.GetDemoNumbersByModelAndNumber(cbModel.SelectedItem.ToString(), cbType.SelectedItem.ToString());
                        }
                    }
                    catch (Exception)
                    {
                        demonumbers = CC.GetDemoNumbersByModel(cbModel.SelectedItem.ToString());
                    }
                }
            }
            catch (Exception)
            {
                try
                {
                    demonumbers = CC.GetAllDemoNumbers();
                }
                catch (Exception)
                {
                    MessageBox.Show("Connection error");
                }
            }


            try
            {
                DateTime  startdate = dtpStart.Value;
                DateTime  enddate   = dtpEnd.Value;
                DataTable dt        = new DataTable();
                dt.Columns.Add("Machine", typeof(string));

                double days = (enddate - startdate).TotalDays;
                int    i    = 0;
                while (i < days)
                {
                    dt.Columns.Add(startdate.AddDays(i).ToString().Substring(0, 10), typeof(string));
                    i++;
                }

                gvBookings.DataSource = dt;
                int columnsInt = dt.Columns.Count;
                i = 0;
                foreach (string s in demonumbers)
                {
                    dt.Rows.Add(s);

                    List <string> bookedDates = CC.GetBookedDates(s);

                    foreach (string st in bookedDates)
                    {
                        for (int k = 1; k < columnsInt; k++)
                        {
                            if (st == dt.Columns[k].ToString())
                            {
                                dt.Rows[i].SetColumnError(k, "Booked");
                            }
                        }
                    }
                    i++;
                }

                for (int l = 0; l < columnsInt; l++)
                {
                    gvBookings.Columns[l].Width = 70;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Connection error");
            }
        }