/// <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)); }
/// <summary> /// Fills the list "listToFill" basing on the header of the file "CSVPath" - the list is firstly cleared. Through the variable "tableId" the ID of the table is passed. Throws an exception if the file "cSVPath" is wrong. /// </summary> public static void FillList(ref List <TablesFields> listToFill, string cSVPath, int tableId) { try { MyFileOperations.CheckFile(cSVPath); } catch { throw new ArgumentException("The file cSVPath does not exist."); } listToFill.Clear(); MyTable CSVTable = new MyTable(cSVPath); for (int Iterator = 1; Iterator <= CSVTable.ColumnsInFirstRow(); Iterator++) { string NameOfField = CSVTable.Content[1 - 1][Iterator - 1]; TablesFields FieldToAdd = new TablesFields(); const string StringType = "3"; const string Description = @" id of table="; /// new List<string>() { "ID", "NameOfField", "IDType", "DefaultValue", "IfMandatory", "IfHidden", "IDTable", "IfDependent", "IDMasterField", "IfUnique", "IDConstraint", "Description" }; FieldToAdd.SetValues(Iterator.ToString(), NameOfField, StringType, "", "false", "false", tableId.ToString(), "false", "", "false", "", NameOfField + Description + tableId.ToString()); listToFill.Add(FieldToAdd); } }
/// <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(); }