Example #1
0
        private void ProcessCategory(int column, int row)
        {
            COLUMN_STATUS CStatus = new COLUMN_STATUS(column, row);
            GetCategory_Status(column, row, out CStatus);

            row = CStatus.row;

            bool is_label_open = CStatus.is_label_open;
            bool is_unlocked = CStatus.is_unlocked;

            string end_label = CStatus.end_label;
            string start_label = CStatus.start_label;

            int open_row = CStatus.open_row;
            int close_row = CStatus.close_row;

            string tlabel = CStatus.tlabel;
            string status_tlabel = CStatus.status_tlabel;

            if (is_label_open == false)
            {

                #region label not opened

                if (end_label.CompareTo(" ") == 0) //end label blank
                {
                    if (tlabel.CompareTo(" ") == 1) //current label no blank
                    {
                        dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "start";
                        dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                        dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = "Start";

                        dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = close_row;

                        // set type combo to state 4 == do not change
                        // before 1
                        if (set_status_forward(open_row, close_row, tlabel, 4, true, open_row) == -1)
                        {
                            System.Console.WriteLine("Error, end label was found before");
                        }

                    }
                    else //blank
                    {
                        dataGridView1.Rows[row].Cells[CINDEX.Status].Value = " ";
                        dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = -1;
                        dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = " ";

                        dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = -1;

                        // cleanup
                        // set type combo to state 4 == do not change
                        // before 3
                        if (set_status_forward(open_row, close_row, tlabel, 3, false, open_row) == -1)
                        { System.Console.WriteLine("Error, end label was found before"); }

                    }
                }
                else //end_label not blank
                {
                    if (status_tlabel.CompareTo("start") == 0)
                    {
                        if (tlabel.CompareTo(" ") == 1) //no blank
                        {
                            dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "start";

                            dataGridView1.Rows[close_row].Cells[CINDEX.Status].Value = "end";
                            dataGridView1.Rows[close_row].Cells[CINDEX.category_label].Value = tlabel;

                            // set type combo to state 4 == do not change
                            // before 1
                            if (set_status_forward(open_row, close_row, tlabel, 4, true, open_row) == -1)
                            { System.Console.WriteLine("Error, end label was found before"); }

                        }
                        else //blank
                        {

                            dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = " ";
                            dataGridView1.Rows[row].Cells[CINDEX.category_label].Value = " ";

                            if (row != open_row)
                            {
                                dataGridView1.Rows[open_row].Cells[CINDEX.StartEnd].Value = " ";
                                dataGridView1.Rows[open_row].Cells[CINDEX.category_label].Value = " ";
                            }

                            dataGridView1.Rows[close_row].Cells[CINDEX.StartEnd].Value = " ";
                            dataGridView1.Rows[close_row].Cells[CINDEX.category_label].Value = " ";

                            // cleanup
                            // set type combo to state 4 == do not change
                            // before 3
                            if (set_status_forward(open_row, close_row, tlabel, 3, false, open_row) == -1)
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }

                        }

                    }
                    else
                    {

                        // this start needs to stop with other start
                        // end label is incorrect, should be " "
                        // System.Console.WriteLine("This case needs to be considered");

                        if (tlabel.CompareTo(" ") != 0) //no blank
                        {
                            dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "start";

                            dataGridView1.Rows[close_row].Cells[CINDEX.Status].Value = "end";
                            dataGridView1.Rows[close_row].Cells[CINDEX.category_label].Value = tlabel;

                            // set type combo to state 4 == do not change
                            // before 1
                            //if (set_status_forward(open_row, close_row, tlabel, 4, true, open_row) == -1)
                            if (set_status_forward(row, close_row, tlabel, 4, true, open_row) == -1)
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }
                        }
                        else //blank
                        {

                            dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = " ";
                            dataGridView1.Rows[row].Cells[CINDEX.category_label].Value = " ";

                            if (row != open_row)
                            {
                                dataGridView1.Rows[open_row].Cells[CINDEX.StartEnd].Value = " ";
                                dataGridView1.Rows[open_row].Cells[CINDEX.category_label].Value = " ";
                            }

                            dataGridView1.Rows[close_row].Cells[CINDEX.StartEnd].Value = " ";
                            dataGridView1.Rows[close_row].Cells[CINDEX.category_label].Value = " ";

                            // cleanup
                            // set type combo to state 4 == do not change
                            // before 3
                            if (set_status_forward(open_row, close_row, tlabel, 3, false, open_row) == -1)
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }

                        }

                    }
                }

                #endregion

            }
            else //is_label_open == 1
            {

                #region label opened

                if (end_label.CompareTo(" ") == 0)
                {
                    if (tlabel.CompareTo(" ") == 0) // blank
                    {
                        dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "start_on";
                        dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                        dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = " ";
                        dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = -1;

                        if (dataGridView1.Rows[row + 1].Cells[CINDEX.Status].Value.ToString().CompareTo("start") != 0) //start is not next
                        {
                            //close_row = search_close_row_forward(row, nrows);
                            start_label = dataGridView1.Rows[open_row].Cells[CINDEX.category_label].Value.ToString();

                            // set type combo to state 4 == do not change
                            //before 1
                            if (set_status_forward(row + 1, close_row, start_label, 4, false, open_row) == -1)
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }
                        }

                    }
                    else
                    {
                        start_label = dataGridView1.Rows[open_row].Cells[CINDEX.category_label].Value.ToString();

                        if (start_label.CompareTo(tlabel) == 0)
                        {

                            if (status_tlabel.CompareTo("start") != 0) //different to start
                            {
                                // set the end
                                dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "end";
                                dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                                dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = "End";
                                dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = row;

                                // set type combo to state 4 == do not change
                                // before 3
                                if (set_status_forward(row + 1, close_row, "", 3, false, row + 1) == -1)
                                {
                                    System.Console.WriteLine("Error, end label was found before");
                                }

                            }
                            else
                            {
                                // This needs to be considered !!!!
                                System.Console.WriteLine("This case needs to be considered");
                            }
                        }
                        else
                        {
                            //set the right labels in the combo
                            // set type combo to state 4 == do not change
                            // before 1
                            if (set_status_forward(open_row, close_row, start_label, 4, true, open_row) == -1)
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }
                        }
                    }// ends tlabel "no blank" endlabel " "
                } // ends end label " "
                else
                {
                    if (tlabel.CompareTo(" ") == 0) // blank
                    {
                        dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "start_on";
                        dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                        dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = " ";
                        dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = close_row;
                    }
                    else // if no blank
                    {
                        //set end
                        start_label = dataGridView1.Rows[open_row].Cells[CINDEX.category_label].Value.ToString();

                        if (start_label.CompareTo(tlabel) == 0)
                        {
                            if (row == close_row) //is this the end?
                            {
                                dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "end";
                                dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                                dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = "End";
                                dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = row;
                            }
                            else if (row < close_row)
                            {
                                dataGridView1.Rows[row].Cells[CINDEX.Status].Value = "end";
                                dataGridView1.Rows[row].Cells[CINDEX.StartID].Value = open_row;
                                dataGridView1.Rows[row].Cells[CINDEX.StartEnd].Value = "End";
                                dataGridView1.Rows[row].Cells[CINDEX.EndID].Value = row;

                                //cleanup the rest
                                // if row label == close label, clean the close label
                                // if labels are different, clomplete
                                dataGridView1.Rows[row + 1].Cells[CINDEX.Status].Value = "start";
                                dataGridView1.Rows[close_row].Cells[CINDEX.Status].Value = "end";

                                // set type combo to state 4 == do not change
                                // before 3
                                if (set_status_forward(row + 1, close_row, "", 3, false, row + 1) == -1)
                                {
                                    System.Console.WriteLine("Error, end label was found before");
                                }
                            }
                            else
                            {
                                System.Console.WriteLine("Error, end label was found before");
                            }
                        }
                    }
                }

                #endregion

            }// ends "is label open == 1"

            //is_busy = 0;
            //tlabel = " ";
            //status_tlabel = " ";
        }
Example #2
0
        private void GetCategory_Status(int column, int row, out COLUMN_STATUS status)
        {
            bool is_unlocked = false;
            bool is_label_open = true;

            status.tlabel = dataGridView1.Rows[row].Cells[column].Value.ToString();

            if (column == (C1.category_label))
            { CINDEX.SetValues(1); }
            else if (column == (C2.category_label))
            { CINDEX.SetValues(2); }

            if (dataGridView1.Rows[row].Cells[CINDEX.Lock].Value != null)
            { is_unlocked = (bool)dataGridView1.Rows[row].Cells[CINDEX.Lock].Value; }

            status.status_tlabel = dataGridView1.Rows[row].Cells[CINDEX.Status].Value.ToString();

            status.open_row = search_open_row_backwards(row);

            if ((status.open_row == row) || (row == 0))
            { is_label_open = false; }

            status.start_label = dataGridView1.Rows[status.open_row].Cells[CINDEX.category_label].Value.ToString();

            if (is_unlocked == true)
            {

                int result = check_label_lock(is_unlocked, is_label_open, row, CINDEX.category_label,
                                               status.tlabel, status.open_row, status.start_label);

                if (result > -1)
                {
                    //Update open_row value
                    if (result == 0)
                    {
                        status.open_row = row;
                        is_label_open = false;
                        status.start_label = status.tlabel;
                    }
                    else if (result == 1)
                    {
                        status.open_row = row + 1;
                        is_label_open = false;
                        status.start_label = status.tlabel;

                        row = row + 1;
                        nrows = dataGridView1.Rows.Count;
                    }
                }
            }

            status.close_row = search_close_row_forward(row, nrows, status.open_row, is_label_open);

            if ((is_label_open == false) && (status.tlabel.CompareTo(" ") != 0))
            {
                if (status.close_row >= nrows)
                {
                    status.close_row = add_end_row(row + 1, out nrows, status.tlabel, CINDEX.category_label, status.open_row, false);
                }
                else if (status.close_row <= status.open_row)
                {
                    // if label needs to be closed, because "end" or "start_on"
                    // perhaps do not work when the end row is separated several lines from open row
                    status.close_row = add_end_row(row + 1, out nrows, status.tlabel, CINDEX.category_label, status.open_row, true);
                }
            }

            if (status.close_row >= nrows)
            {
                status.close_row = nrows - 1;
            }

            if (dataGridView1.Rows[status.close_row].Cells[CINDEX.Status].Value == null)
            {
                dataGridView1.Rows[status.close_row].Cells[CINDEX.Status].Value = " ";
            }
            else if ((status.close_row < nrows) &&
                     (dataGridView1.Rows[status.close_row].Cells[CINDEX.Status].Value.ToString().CompareTo("start") == 0))
            {
                status.close_row = add_end_row(row + 1, out nrows, status.tlabel, CINDEX.category_label, status.open_row, true);
            }

            if (dataGridView1.Rows[status.close_row].Cells[CINDEX.category_label].Value == null)
            { dataGridView1.Rows[status.close_row].Cells[CINDEX.category_label].Value = " "; }

            status.end_label = dataGridView1.Rows[status.close_row].Cells[CINDEX.category_label].Value.ToString();

            // update fields before going out
            status.column = column;
            status.row = row;

            status.is_unlocked = is_unlocked;
            status.is_label_open = is_label_open;
        }