Example #1
0
        private void CalendarNode_Click(object sender, EventArgs e)
        {
            CalendarNode nodeClicked = (CalendarNode)sender;

            if (nodeClicked.numDates == 4)
            {
                return;
            }

            DateTime dueDate = nodeClicked.date;

            Tuple <Label, int> tag = GetSelectedTagInfo();

            Label l = tag.Item1;

            l.Location = new Point(10, 20 * ++nodeClicked.numDates);

            DueDateTextBox t = new DueDateTextBox(l, l.Width, nodeClicked, nodeClicked.numDates);

            t.BackColor = c6;
            t.ForeColor = Color.White;

            if (tag.Item2 != -1)
            {
                t.Text        = "HW #1";
                t.Location    = new Point(l.Width + 10, 20 * nodeClicked.numDates);
                t.Size        = new Size(110, 18);
                t.BorderStyle = BorderStyle.None;
                t.LostFocus  += DueDateBox_Leave;

                nodeClicked.Controls.Add(t.InitDotLabel(5, 20 * nodeClicked.numDates + 5, l.ForeColor));
            }
            else
            {
                t.Text        = "HW #1";
                t.Location    = new Point(13, 20 * nodeClicked.numDates);
                t.Size        = new Size(110, 18);
                t.BorderStyle = BorderStyle.None;
                t.LostFocus  += DueDateBox_Leave;

                nodeClicked.Controls.Add(t.InitDotLabel(5, 20 * nodeClicked.numDates + 5, Color.Black));
            }

            nodeClicked.Controls.Add(l);
            nodeClicked.Controls.Add(t);

            using (SQLiteCommand cmd = new SQLiteCommand("INSERT INTO " + sched_table + " (name, tag_id, date) VALUES (@name, @tag_id, @date)", SQLCon))
            {
                cmd.Parameters.AddWithValue("@name", "HW #1");
                cmd.Parameters.AddWithValue("@tag_id", tag.Item2);
                cmd.Parameters.AddWithValue("@date", dueDate);
                cmd.ExecuteNonQuery();
            }

            t.rowid = Convert.ToInt32(SQLCon.LastInsertRowId);
        }
Example #2
0
        public DueDateTextBox(Label l, int _spaceBetween, CalendarNode _parent, int _rowIndex)
        {
            spaceBetween = _spaceBetween;

            if (_spaceBetween != -1)
            {
                tagLabel = l;
            }
            else
            {
                tagLabel = null;
            }

            parent   = _parent;
            rowIndex = _rowIndex;
        }
Example #3
0
        private void LoadWeek(DateTime firstDay, int rowIndex)
        {
            //this week has already been loaded
            if (days.ContainsKey(firstDay))
            {
                for (int i = 0; i < 7; i++)
                {
                    days[firstDay.AddDays(i)].SetLocation(i * width + x_offset, rowIndex * height + y_offset);
                    calendar.Controls.Add(days[firstDay.AddDays(i)]);
                }
            }
            else
            {
                //this week has not been loaded yet
                for (int i = 0; i < 7; i++)
                {
                    CalendarNode cNode = new CalendarNode(i * width + x_offset, rowIndex * height + y_offset);
                    cNode.BorderStyle = BorderStyle.FixedSingle;

                    Label l = new Label();
                    l.Text      = firstDay.AddDays(i).ToString("MMM") + " " + firstDay.AddDays(i).Day.ToString();
                    l.Visible   = true;
                    l.Size      = new Size(90, 18);
                    l.Location  = new Point(10, 0);
                    l.BackColor = Color.Transparent;
                    //l.ForeColor = c2;
                    l.ForeColor = Color.FromArgb(249, 38, 89);
                    l.Font      = new Font(l.Font, FontStyle.Bold);
                    cNode.date  = firstDay.AddDays(i);

                    cNode.BackColor = c6;

                    if (cNode.date == new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day))
                    {
                        Label ll = new Label();
                        //ll.BackColor = c2;
                        ll.BackColor = Color.FromArgb(166, 226, 46);
                        ll.AutoSize  = false;
                        ll.Size      = new Size(160, 6);
                        ll.Location  = new Point(0, 114);
                        cNode.Controls.Add(ll);
                    }

                    RemoveLabel r = new RemoveLabel();
                    r.Location = new Point(32, 95);
                    r.Visible  = false;

                    r.DragDrop += (o, e) => {
                        e.Effect = DragDropEffects.Copy;
                        r.SendToBack();
                        r.Font   = new Font(r.Font, FontStyle.Regular);
                        r.Text   = r.Text.Substring(3);
                        r.Width -= 5;

                        int rowid = (int)e.Data.GetData(typeof(int));

                        CalendarNode parent = (CalendarNode)r.Parent;

                        DueDateTextBox d = null;

                        foreach (Control c in parent.Controls)
                        {
                            if (c is DueDateTextBox)
                            {
                                if (((DueDateTextBox)c).rowid == rowid)
                                {
                                    d = (DueDateTextBox)c;
                                }
                            }
                        }

                        if (MessageBox.Show("Are you sure you want to delete \"" + d.Text + "\"?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            using (SQLiteCommand cmd = new SQLiteCommand("DELETE FROM " + sched_table + " WHERE rowid = @rowid", SQLCon))
                            {
                                cmd.Parameters.AddWithValue("@rowid", rowid);
                                cmd.ExecuteNonQuery();
                            }

                            parent.Controls.Remove(d.dotLabel);

                            if (d.tagLabel != null)
                            {
                                parent.Controls.Remove(d.tagLabel);
                            }

                            parent.Controls.Remove(d);

                            if (d.rowIndex < parent.numDates)
                            {
                                foreach (Control c in parent.Controls)
                                {
                                    if (c is DueDateTextBox)
                                    {
                                        DueDateTextBox d1 = (DueDateTextBox)c;

                                        if (d1.rowIndex > d.rowIndex)
                                        {
                                            d1.Location          = new Point(d1.Location.X, d1.Location.Y - 20);
                                            d1.dotLabel.Location = new Point(d1.dotLabel.Location.X, d1.dotLabel.Location.Y - 20);
                                            if (d1.tagLabel != null)
                                            {
                                                d1.tagLabel.Location = new Point(d1.tagLabel.Location.X, d1.tagLabel.Location.Y - 20);
                                                d1.rowIndex--;
                                            }
                                        }
                                    }
                                }
                            }

                            parent.numDates--;
                        }

                        r.Visible = false;
                    };

                    r.DragEnter += (o, e) => {
                        e.Effect = DragDropEffects.Copy;
                        r.SendToBack();
                        r.Font   = new Font(r.Font, FontStyle.Bold);
                        r.Text   = "   " + r.Text;
                        r.Width += 5;
                    };

                    r.DragLeave += (o, e) => {
                        r.Font   = new Font(r.Font, FontStyle.Regular);
                        r.Text   = r.Text.Substring(3);
                        r.Width -= 5;
                    };

                    r.AllowDrop = true;

                    cNode.removeLabel = r;

                    cNode.Controls.Add(r);
                    cNode.Controls.Add(l);

                    cNode.Click += CalendarNode_Click;

                    calendar.Controls.Add(cNode);

                    days[cNode.date] = cNode;
                }

                //if (firstDay == DateTime.Now.StartOfWeek(DayOfWeek.Sunday))
                //{
                //	Label l = new Label();
                //	l.BackColor = Color.Green;
                //	l.AutoSize = false;
                //	l.Size = new Size(5, 120);
                //	l.Location = new Point(0, 0);
                //	days[firstDay].Controls.Add(l);
                //	//MessageBox.Show("?" + firstDay.ToString());
                //}

                using (SQLiteCommand cmd = new SQLiteCommand("SELECT *, rowid FROM " + sched_table + " WHERE date >= @fd AND date <= @ld", SQLCon))
                {
                    cmd.Parameters.AddWithValue("@fd", firstDay);
                    cmd.Parameters.AddWithValue("@ld", firstDay.AddDays(6));

                    using (SQLiteDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            DateTime date = (DateTime)reader[2];

                            Label l = new Label();
                            l.Location = new Point(10, 20 * ++days[date].numDates);

                            int tagid = (int)reader[1];

                            string dueDateName = (string)reader[0];

                            int rowid = Convert.ToInt32((Int64)reader[3]);

                            if (tagid != -1)
                            {
                                l.Text      = tags[(int)reader[1]].tagNameBox.Text;
                                l.ForeColor = tags[(int)reader[1]].color;
                                l.Size      = TextRenderer.MeasureText(l.Text, l.Font);
                                l.BackColor = Color.Transparent;

                                DueDateTextBox t = new DueDateTextBox(l, l.Width, days[date], days[date].numDates);                                 //???
                                t.Text        = dueDateName;
                                t.Location    = new Point(l.Width + 10, 20 * days[date].numDates);
                                t.Size        = new Size(100, 18);
                                t.BorderStyle = BorderStyle.None;
                                t.LostFocus  += DueDateBox_Leave;
                                t.rowid       = rowid;
                                t.BackColor   = c6;
                                t.ForeColor   = Color.White;

                                days[date].Controls.Add(t.InitDotLabel(5, 20 * days[date].numDates + 5, l.ForeColor));
                                days[date].Controls.Add(l);
                                days[date].Controls.Add(t);
                            }
                            else
                            {
                                DueDateTextBox t = new DueDateTextBox(l, -1, days[date], days[date].numDates);
                                t.Text        = dueDateName;
                                t.Location    = new Point(13, 20 * days[date].numDates);
                                t.Size        = new Size(100, 18);
                                t.BorderStyle = BorderStyle.None;
                                t.LostFocus  += DueDateBox_Leave;
                                t.rowid       = rowid;
                                t.BackColor   = c6;

                                days[date].Controls.Add(t.InitDotLabel(5, 20 * days[date].numDates + 5, Color.Black));
                                days[date].Controls.Add(t);
                            }
                        }
                    }
                }
            }
        }