Beispiel #1
0
        private void readFromFile()
        {
            // Read data from file
            string       path = Server.MapPath("../App_Data/res.txt");
            StreamReader res  = new StreamReader(path);

            while (!res.EndOfStream)
            {
                string   line   = res.ReadLine();
                string[] values = line.Split('\t');
                int      ncol   = ColDay(values[0]);
                int      nrow   = RowHour(values[1]);

                if ((ncol > 0) && (nrow > 0))
                {
                    Button btn = (Button)Court1.FindControl(string.Format("c{0}{1}", nrow.ToString("D2"), ncol));
                    btn.Text = values[2];
                }
            }
        }
Beispiel #2
0
        private void LoadPlanning()
        {
            // Clean current values
            for (int r = 1; r < Court1.Rows.Count; r++)              // start at 1 to avoid header row
            {
                for (int c = 1; c < Court1.Rows[r].Cells.Count; c++) // start at 1 to avoid header column
                {
                    TableCell cell = (TableCell)Court1.FindControl(string.Format("cell{0}{1}", r.ToString("D2"), c.ToString("D2")));
                    cell.BackColor = System.Drawing.Color.Transparent;
                    Button btn = (Button)Court1.FindControl(string.Format("c{0}{1}", r.ToString("D2"), c));
                    btn.Text = "";
                }
            }

            // Load new values
            SqlConnection cnx = new SqlConnection(ConfigurationManager.ConnectionStrings["TCCXCLConnection"].ConnectionString);

            cnx.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "SELECT courtName, moment, MadeBy.LastName, Partner.LastName, guest " +
                              "FROM ((booking INNER JOIN court ON fkCourt = idcourt) LEFT JOIN Users AS MadeBy ON fkMadeBy = MadeBy.UserId) LEFT JOIN Users AS Partner ON fkPartner = Partner.UserId " +
                              "WHERE idcourt = " + dpdCourtSelect.SelectedValue + " AND moment > GETDATE() and moment < DATEADD(WEEK,1,GETDATE());";
            cmd.Connection = cnx;
            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read()) // found details
            {
                try
                {
                    int    row = 0, col = 0; // cell to fill
                    string madeBy  = null;
                    string partner = null;
                    string guest   = null;

                    // Get data from reader
                    DateTime moment = rdr.GetDateTime(1);
                    if (!rdr.IsDBNull(2))
                    {
                        madeBy = rdr.GetString(2);
                    }
                    if (!rdr.IsDBNull(3))
                    {
                        partner = rdr.GetString(3);
                    }
                    if (!rdr.IsDBNull(4))
                    {
                        guest = rdr.GetString(4);
                    }

                    // Compute cell coordinates
                    switch (moment.DayOfWeek)
                    {
                    case DayOfWeek.Monday: col = 1; break;

                    case DayOfWeek.Tuesday: col = 2; break;

                    case DayOfWeek.Wednesday: col = 3; break;

                    case DayOfWeek.Thursday: col = 4; break;

                    case DayOfWeek.Friday: col = 5; break;

                    case DayOfWeek.Saturday: col = 6; break;

                    case DayOfWeek.Sunday: col = 7; break;
                    }
                    row = moment.Hour - 7; // row 1 is for 8:00AM

                    // Compute cell attributes
                    string name = null;
                    System.Drawing.Color bcolor = System.Drawing.Color.Transparent;

                    if (madeBy != null)
                    {
                        name = madeBy;
                        if (partner != null)
                        {
                            bcolor = System.Drawing.Color.DarkOliveGreen;
                        }
                        else
                        {
                            bcolor = System.Drawing.Color.ForestGreen;
                        }
                    }
                    else
                    {
                        name   = guest;
                        bcolor = System.Drawing.Color.LemonChiffon;
                    }

                    // Set cell attributes
                    TableCell cell = (TableCell)Court1.FindControl(string.Format("cell{0}{1}", row.ToString("D2"), col.ToString("D2")));
                    cell.BackColor = bcolor;
                    Button btn = (Button)Court1.FindControl(string.Format("c{0}{1}", row.ToString("D2"), col));
                    btn.Text = name;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.Write("Error reading bookings from database. " + ex.Message);
                }
            }
        }