예제 #1
0
        /// <summary>
        /// Displays in the control the table "tableToPut" and returns the tuple in which the first element
        /// contains the table given by the user and the second one the dialog result.
        /// Throws an exception if the number of rows within the table "tableToPut"
        /// </summary>
        /// <param name="tableToPut"></param>
        /// <returns></returns>
        public Tuple <MyTable, DialogResult> GetTableWithHeader(MyTable tableToPut, bool dialog = true, System.Windows.Forms.Form myForm = null)
        {
            if (tableToPut.Content.Count() <= 1)
            {
                throw new ArgumentException("A table with 0 or 1 row passed to GetTableWithHeader");
            }

            for (int Iterator = 1; Iterator <= tableToPut.ColumnsInFirstRow(); Iterator++)
            {
                MyGridView2.Columns.Add(tableToPut.Content[0][Iterator - 1], tableToPut.Content[0][Iterator - 1]);
            }
            MyGridView2.RowCount = tableToPut.RowCount() - 1;
            foreach (int RowIterator in tableToPut.NonHeaderRowNumbers())
            {
                // if (MyGridView2[0, RowIterator - 1 - 1].Value is null) continue;
                for (int ColumnIterator = 1; ColumnIterator <= tableToPut[RowIterator - 1].Count(); ColumnIterator++)
                {
                    MyGridView2[ColumnIterator - 1, RowIterator - 1 - 1].Value = tableToPut.Content[RowIterator - 1][ColumnIterator - 1];
                }
            }


            DialogResult MyOutcome = DialogResult.OK;

            if (dialog)
            {
                MyOutcome = ShowDialog();
            }
            else
            {
                Show(myForm);
            }


            // 000000000000000000
            // DialogResult MyOutcome = modal? ShowDialog():Show(this);
            List <List <string> > MyContent = new List <List <string> >();

            MyContent.Add(tableToPut.Content[0]);
            if (MyOutcome == DialogResult.OK)
            {
                for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++)
                {
                    if (MyGridView2[0, Iterator - 1].Value is null)
                    {
                        continue;
                    }
                    List <string> MyRowItem = new List <string>();
                    for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++)
                    {
                        string ValueToAdd = (MyGridView2[ColumnIterator - 1, Iterator - 1].Value is null) ? "" : MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString();
                        MyRowItem.Add(ValueToAdd);
                    }
                    MyContent.Add(MyRowItem);
                }
            }
            MyTable MyOutput = new MyTable(MyContent);

            return(new Tuple <MyTable, DialogResult>(MyOutput, MyOutcome));
        }
예제 #2
0
        /// <summary>
        /// Fills the control  with the content of the argument "tableToPut" and displays it modally.
        /// The user is able to edit the content of the table, add rows to it. Returns the content created by him.
        /// </summary>
        /// <param name="tableToPut">The table which will be placed in the control MyGridView2</param>
        /// <param name="myHeader">The header placed in the first row of the control MyGridView2</param>
        /// <returns></returns>
        public MyTable GetTable(MyTable tableToPut, List <string> myHeader)
        {
            int MaxCount = tableToPut.Content.Select(Element => Element.Count()).ToList().Max();

            if (MaxCount > myHeader.Count())
            {
                throw new ArgumentException("Wrong arguments passed to the function DisplayGrid");
            }
            for (int Iterator = 1; Iterator <= myHeader.Count(); Iterator++)
            {
                MyGridView2.Columns.Add(myHeader[Iterator - 1], myHeader[Iterator - 1]);
            }
            MyGridView2.RowCount = tableToPut.RowCount();


            for (int RowIterator = 1; RowIterator <= tableToPut.RowCount(); RowIterator++)
            {
                for (int ColumnIterator = 1; ColumnIterator <= tableToPut[RowIterator - 1].Count(); ColumnIterator++)
                {
                    MyGridView2[ColumnIterator - 1, RowIterator - 1].Value = tableToPut.Content[RowIterator - 1][ColumnIterator - 1];
                }
            }

            DialogResult MyOutcome = ShowDialog();

            List <List <string> > MyContent = new List <List <string> >();

            if (MyOutcome == DialogResult.OK)
            {
                for (int Iterator = 1; Iterator <= MyGridView2.RowCount; Iterator++)
                {
                    List <string> MyRowItem = new List <string>();
                    for (int ColumnIterator = 1; ColumnIterator <= MyGridView2.ColumnCount; ColumnIterator++)
                    {
                        MyRowItem.Add(MyGridView2[ColumnIterator - 1, Iterator - 1].Value.ToString());
                    }
                    MyContent.Add(MyRowItem);
                }
            }
            MyTable MyOutput = new MyTable(MyContent);

            return(MyOutput);
        }
예제 #3
0
        /// <summary>
        /// Reads the table from the location "myInfo" assuming that there is a CSV file at this location with "mySeparator" as a separator.
        /// </summary>
        /// <param name="tableToSelect"></param>
        public MyGridEditor(System.IO.FileInfo myInfo, char mySeparator)
        {
            if (myInfo.Exists == false)
            {
                throw new ArgumentException("There is no file at the path " + myInfo.FullName);
            }

            FileNameBox.Text = myInfo.FullName;


            //    MyPath = new FileInfo(myInfo.FullName);
            InitializeComponent();
            throw new NotImplementedException();


            string MyInput = MyFileOperations.ReadFile(myInfo.FullName);

            // MyStringOperations.Dou
            MyTable TableToPut = new MyTable(MyInput, MyStringOperations.EndOfLine, mySeparator.ToString(), true);

            // MyTable tableToPut=new MyTable(myInfo.FullName)
            int           MaxCount = TableToPut.Content.Select(Element => Element.Count()).ToList().Max();///The length of the longest row
            List <string> myHeader = TableToPut.Content[0];

            if (MaxCount > myHeader.Count())
            {
                throw new ArgumentException("Wrong arguments passed to the function DisplayGrid");
            }
            for (int Iterator = 1; Iterator <= myHeader.Count(); Iterator++)
            {
                MyGridView2.Columns.Add(myHeader[Iterator - 1], myHeader[Iterator - 1]);
            }

            int GridRow  = 1;
            int TableRow = 1;

            MyGridView2.RowCount = TableToPut.RowCount();
            while
            (TableRow <= (TableToPut.Count()))
            {
                for (int ColumnIterator = 1; ColumnIterator <= TableToPut[TableRow - 1].Count(); ColumnIterator++)
                {
                    MyGridView2[ColumnIterator - 1, GridRow - 1].Value = TableToPut.Content[TableRow - 1][ColumnIterator - 1];
                }
                GridRow  += 1;
                TableRow += 1;
            }
        }
예제 #4
0
 /// <summary>
 /// Puts the table "toPut" into the grid
 /// </summary>
 /// <param name="toPut"></param>
 /// <returns></returns>
 public void DisplayTable(MyTable tableToPut)
 {
     for (int Iterator = 1; Iterator <= tableToPut.ColumnsInFirstRow(); Iterator++)
     {
         MyGridView2.Columns.Add(tableToPut.Content[0][Iterator - 1], tableToPut.Content[0][Iterator - 1]);
     }
     MyGridView2.RowCount = tableToPut.RowCount();
     foreach (int RowIterator in tableToPut.NonHeaderRowNumbers())
     {
         for (int ColumnIterator = 1; ColumnIterator <= tableToPut[RowIterator - 1].Count(); ColumnIterator++)
         {
             MyGridView2[ColumnIterator - 1, RowIterator - 1 - 1].Value = tableToPut.Content[RowIterator - 1][ColumnIterator - 1];
         }
     }
     Show();
 }
예제 #5
0
        /// <summary>
        /// Fills the control MyGridView2 with the content of the table tableToPut.
        /// The form is displayed modally.
        /// Throws an exception if any row of the table "tableToPut" contains larger number of elements than the
        /// argument "myHeader".
        /// The string "myTitle" is a title which is displayed at the form.
        /// </summary>
        /// <param name="tableToPut">The table which will be placed in the control MyGridView2</param>
        /// <param name="myHeader">The header placed in the first row of the control MyGridView2</param>
        /// <param name="omitHeader">determines if the header's display is omitted</param>
        public DialogResult DisplayGrid(MyTable tableToPut, List <string> myHeader, bool omitHeader = false, string myTitle = "")
        {
            int MaxCount = tableToPut.Content.Select(Element => Element.Count()).ToList().Max();

            if (MaxCount > myHeader.Count())
            {
                throw new ArgumentException("Wrong arguments passed to the function DisplayGrid");
            }
            for (int Iterator = 1; Iterator <= myHeader.Count(); Iterator++)
            {
                MyGridView2.Columns.Add(myHeader[Iterator - 1], myHeader[Iterator - 1]);
            }

            int GridRow  = 1;
            int TableRow = 1;

            if (omitHeader)
            {
                TableRow += 1;
            }
            MyGridView2.RowCount = tableToPut.RowCount();
            this.Text            = myTitle;
            while
            (TableRow <= (tableToPut.Count()))
            {
                for (int ColumnIterator = 1; ColumnIterator <= tableToPut[TableRow - 1].Count(); ColumnIterator++)
                {
                    MyGridView2[ColumnIterator - 1, GridRow - 1].Value = tableToPut.Content[TableRow - 1][ColumnIterator - 1];
                }
                GridRow  += 1;
                TableRow += 1;
            }
            //   CheckState();
            DialogResult MyOutcome = ShowDialog();

            return(MyOutcome);
        }