コード例 #1
0
        //Sessions
        private void endSessionButton_Click(object sender, EventArgs e)
        {
            if (dataGridView2.SelectedCells.Count <= 0)
            {
                return;
            }
            int rowindex = dataGridView2.SelectedCells[0].RowIndex;

            if (dataGridView2.Rows[rowindex].Cells["End_Date"].Value.ToString() == "Active Session")
            {
                setDate end = new setDate(DateTime.Now);
                end.set_Message("Enter End Date");
                end.ShowDialog();
                if (end.values_set == false)
                {
                    return;
                }
                Console.WriteLine(Convert.ToDateTime(dataGridView2.Rows[rowindex].Cells["Begin_Date"].Value.ToString()));
                Console.WriteLine(end.result);
                if (Convert.ToDateTime(dataGridView2.Rows[rowindex].Cells["Begin_Date"].Value.ToString()).Date >= end.result.Date)
                {
                    a.ErrorBox("End date should be greater than start date of the session");
                    endSessionButton.PerformClick();
                    return;
                }
                dataGridView2.Rows[rowindex].Cells["End_Date"].Value             = end.result;
                dataGridView2.Rows[rowindex].DefaultCellStyle.BackColor          = Color.Coral;
                dataGridView2.Rows[rowindex].DefaultCellStyle.SelectionBackColor = Color.Orange;
            }
        }
コード例 #2
0
        private void startSessionButton_Click(object sender, EventArgs e)
        {
            setDate start = new setDate(DateTime.Now);

            start.set_Message("Enter Start Date");
            start.ShowDialog();
            if (start.values_set == false)
            {
                Console.WriteLine("ret");
                return;
            }

            //check if start date is in between any previous start and end dates
            int open_session_index = -1;

            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                DateTime s_i = Convert.ToDateTime(dataGridView2.Rows[i].Cells["Begin_Date"].Value.ToString());
                DateTime e_i;
                try
                {
                    e_i = Convert.ToDateTime(dataGridView2.Rows[i].Cells["End_Date"].Value.ToString());
                }
                catch
                {
                    open_session_index = i;
                    continue;
                }
                if (start.result.Date >= s_i.Date && start.result.Date <= e_i.Date)
                {
                    a.ErrorBox("Start Date is in between Begin and End Dates of Session ID: " + dataGridView2.Rows[i].Cells["Session_ID"].Value.ToString());
                    this.startSessionButton.PerformClick();
                    return;
                }
            }

            Console.WriteLine("Open session index = " + open_session_index);
            if (open_session_index == -1)
            {
                DateTime last_end_date = Convert.ToDateTime(Convert.ToDateTime(dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["End_Date"].Value.ToString()));
                if (start.result.Date > last_end_date.Date)
                {
                    Console.WriteLine("Case 1a");
                    dataGridView2.Rows.Add("Session Added", start.result, "Active Session");
                    dataGridView2.Rows[dataGridView2.Rows.Count - 1].DefaultCellStyle.BackColor          = Color.LawnGreen;
                    dataGridView2.Rows[dataGridView2.Rows.Count - 1].DefaultCellStyle.SelectionBackColor = Color.Green;
                    return;
                }
                else
                {
                    while (true)
                    {
                        setDate end = new setDate(DateTime.Now);
                        end.set_Message("Enter End Date (Start Date: " + start.result.ToString().Substring(0, 10).Replace('/', '-') + ")");
                        end.ShowDialog();
                        if (end.values_set == false)
                        {
                            return;
                        }
                        if (end.result.Date <= start.result.Date)
                        {
                            a.ErrorBox("End Date should greater than start date");
                        }
                        for (int i = 0; i < dataGridView2.Rows.Count; i++)
                        {
                            DateTime s_this = Convert.ToDateTime(dataGridView2.Rows[i].Cells["Begin_Date"].Value.ToString());
                            if (s_this.Date >= start.result.Date && s_this.Date <= end.result.Date)
                            {
                                a.ErrorBox("End date should be between entered start date and start date of next session");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Case 2c");
                                dataGridView2.Rows.Add("Session Added", start.result, end.result);
                                this.dataGridView2.Sort(this.dataGridView2.Columns["Begin_Date"], ListSortDirection.Ascending);
                                return;
                            }
                        }
                    }
                }
            }
            else
            {
                DateTime last_start_date = Convert.ToDateTime(Convert.ToDateTime(dataGridView2.Rows[open_session_index].Cells["Begin_Date"].Value.ToString()));
                if (start.result.Date == last_start_date.Date)
                {
                    Console.WriteLine("Case 2a");
                    a.ErrorBox("Start Date cannot be equal to the Begin Date of the open session (Session ID: " + dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["Session_ID"].Value.ToString() + ")");
                    this.startSessionButton.PerformClick();
                    return;
                }
                else if (start.result.Date > last_start_date.Date)
                {
                    Console.WriteLine("Case 2b");
                    a.ErrorBox("Please close the last session before opening a new one after that");
                    this.startSessionButton.PerformClick();
                    return;
                }
                else
                {
                    while (true)
                    {
                        setDate end = new setDate(DateTime.Now);
                        end.set_Message("Enter End Date (Start Date: " + start.result.ToString().Substring(0, 10).Replace('/', '-') + ")");
                        end.ShowDialog();
                        if (end.values_set == false)
                        {
                            return;
                        }
                        if (end.result.Date <= start.result.Date)
                        {
                            a.ErrorBox("End Date should greater than start date");
                        }
                        for (int i = 0; i < dataGridView2.Rows.Count; i++)
                        {
                            DateTime s_this = Convert.ToDateTime(dataGridView2.Rows[i].Cells["Begin_Date"].Value.ToString());
                            if (s_this.Date >= start.result.Date && s_this.Date <= end.result.Date)
                            {
                                a.ErrorBox("End date should be between entered start date and start date of next session");
                                break;
                            }
                            else
                            {
                                Console.WriteLine("Case 2c");
                                dataGridView2.Rows.Add("Session Added", start.result, end.result);
                                this.dataGridView2.Sort(this.dataGridView2.Columns["Begin_Date"], ListSortDirection.Ascending);
                                return;
                            }
                        }
                    }
                }
            }
        }