public ScheduleItemWindow(ScheduleItem si_, DateTime dtClicked_) : base(Gtk.WindowType.Toplevel) { this.Build (); _dtClicked = dtClicked_; if ( si_ != null ) { _si = si_; MySqlConnection conn = new MySqlConnection(Globals.ConnectionString); MySqlCommand cmd = new MySqlCommand("select * from tasks where t_id = @t_id;", conn); cmd.Parameters.Add( new MySqlParameter("t_id", MySqlDbType.VarChar)).Value = _si.TaskId; conn.Open(); MySqlDataReader rdr = cmd.ExecuteReader(); _task = new Task(); if (rdr.Read()) { _task.Id = rdr.GetInt32(rdr.GetOrdinal("t_id")); _task.Name = rdr.GetString(rdr.GetOrdinal("t_title")); _task.TimeRequired = rdr.GetInt32(rdr.GetOrdinal("t_time_req")); if (rdr.IsDBNull(rdr.GetOrdinal("t_depends"))) _task.Depends = 0; else _task.Depends = rdr.GetInt32(rdr.GetOrdinal("t_depends")); _task.TaskType = rdr.GetInt32(rdr.GetOrdinal("t_type")); } conn.Close(); PopulateResources(_task.TaskType); _update = true; } else { _si = new ScheduleItem(); if ( _dtClicked != DateTime.MinValue ) { txtStart.Text = _dtClicked.ToString(); } } if (_update) { FillDetails(); } else { btnDelete.Visible = false; } }
private void UpdateGraph() { DateTime dtWeekStart = Utils.GetWeekStart(dtCurrent); DateTime dtWeekEnd = Utils.GetWeekEnd(dtCurrent); lblCurrentWeek.Text = "<b>" + dtWeekStart.ToShortDateString() + " - " + dtWeekEnd.ToShortDateString() + "</b>"; lblCurrentWeek.UseMarkup = true; MySqlConnection conn = new MySqlConnection(Globals.ConnectionString); MySqlCommand cmd = new MySqlCommand( "select s.s_id, s.t_id, s.t_start, s.t_finish, s.r_id, t.t_title, t.t_time_req, t.t_depends, r.r_name, y.tt_name " + "from schedule s, tasks t, resources r, tasktypes y " + "where s.t_id = t.t_id and s.r_id = r.r_id and t.t_type = y.tt_id and s.t_start between @week_start and @week_end" , conn); cmd.Parameters.Add(new MySqlParameter("week_start", MySqlDbType.DateTime)).Value = dtWeekStart; cmd.Parameters.Add(new MySqlParameter("week_end", MySqlDbType.DateTime)).Value = dtWeekEnd; conn.Open(); MySqlDataReader rdr = cmd.ExecuteReader(); List<ScheduleItem> items = new List<ScheduleItem>(); while(rdr.Read()) { int s_id = rdr.GetInt32(rdr.GetOrdinal("s_id")); int t_id = rdr.GetInt32(rdr.GetOrdinal("t_id")); DateTime t_start = DateTime.MinValue; DateTime t_finish = DateTime.MinValue; if (!rdr.IsDBNull(rdr.GetOrdinal("t_start"))) t_start = rdr.GetDateTime(rdr.GetOrdinal("t_start")); if (!rdr.IsDBNull(rdr.GetOrdinal("t_finish"))) t_finish = rdr.GetDateTime(rdr.GetOrdinal("t_finish")); int r_id = rdr.GetInt32(rdr.GetOrdinal("r_id")); string t_title = rdr.GetString( rdr.GetOrdinal( "t_title" ) ); int t_time_req = rdr.GetInt32( rdr.GetOrdinal( "t_time_req" ) ); string rname = rdr.GetString( rdr.GetOrdinal( "r_name" ) ); string ttype = rdr.GetString( rdr.GetOrdinal( "tt_name" ) ); ScheduleItem si = new ScheduleItem(s_id, t_id, r_id, t_start, t_finish, t_title, t_time_req, rname, ttype); items.Add(si); } conn.Close(); sg.Items.Clear(); sg.Items.AddRange(items); sg.WeekStart = dtWeekStart; sg.QueueDraw(); }