Exemplo n.º 1
0
        public static void LoadSecondaryTable(string component, string secondaryPathAndFileName, ref List <string> warnings)
        {
            //Create new item in SecondaryGroups structure (if it is not
            //already there) with data from secondaryPathAndFileName.

            if (File.Exists(secondaryPathAndFileName))
            {
                if (SecondaryGroups.ContainsKey(secondaryPathAndFileName))
                {
                    SecondaryGroups.Remove(secondaryPathAndFileName);
                    //NOTE: the above comment is not valid. Keep it until debugging!!!!!:
                    //Do not load the data from this file since it is already in memory.
                    //In memory it could have been modified but we want to keep it as it
                    //is, just as Word and Excel does when a file is loaded again.
                }

                StreamReader secondaryFile;
                secondaryFile = File.OpenText(secondaryPathAndFileName);
                try
                {
                    var thisGroup = new SecondaryGroup();
                    thisGroup.Component = component;
                    thisGroup.FileName  = secondaryPathAndFileName;
                    thisGroup.NPoints   = Convert.ToInt64(secondaryFile.ReadLine());
                    var thisTable = new SecondaryTable[thisGroup.NPoints];

                    for (int j = 0; j <= thisGroup.NPoints - 1; ++j)
                    {
                        string   next     = secondaryFile.ReadLine();
                        string[] splt     = next.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        int      nColumns = splt.Length;
                        switch (nColumns)
                        {
                        case 1:
                            thisTable[j].Col0 = splt[0];
                            break;

                        case 2:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            break;

                        case 3:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            break;

                        case 4:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            break;

                        case 5:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            thisTable[j].Col4 = splt[4];
                            break;

                        case 6:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            thisTable[j].Col4 = splt[4];
                            thisTable[j].Col5 = splt[5];
                            break;

                        case 7:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            thisTable[j].Col4 = splt[4];
                            thisTable[j].Col5 = splt[5];
                            thisTable[j].Col6 = splt[6];
                            break;

                        case 8:
                            thisTable[j].Col0 = splt[0];
                            thisTable[j].Col1 = splt[1];
                            thisTable[j].Col2 = splt[2];
                            thisTable[j].Col3 = splt[3];
                            thisTable[j].Col4 = splt[4];
                            thisTable[j].Col5 = splt[5];
                            thisTable[j].Col6 = splt[6];
                            thisTable[j].Col7 = splt[7];
                            break;
                        }
                    }

                    secondaryFile.Close();

                    //Store bridge profile table:
                    thisGroup.Table = thisTable;

                    //Store this new group:
                    SecondaryGroups.Add(secondaryPathAndFileName, thisGroup);
                }
                catch (Exception ex)
                {
                    secondaryFile.Close();
                    MessageBox.Show(Idioma("ERROR 0605171628: error reading file ", "ERROR 0605171628: error leyendo archivo ") + "\n\n" + secondaryPathAndFileName + "\n\n" + ex.Message,
                                    "RiverFlow2D", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);

                    //Create a Default empty file.
                    CreateSecondaryDefaultFile(component, secondaryPathAndFileName, 5);
                    if (warnings.IndexOf(secondaryPathAndFileName) == -1)
                    {
                        warnings.Add(secondaryPathAndFileName);
                    }
                }
            }
            else
            {
                //secondaryPathAndFileName doesn't exist. Create a Default empty file.
                CreateSecondaryDefaultFile(component, secondaryPathAndFileName, 5);
                if (warnings.IndexOf(secondaryPathAndFileName) == -1)
                {
                    warnings.Add(secondaryPathAndFileName);
                }
            }
        }
Exemplo n.º 2
0
        public static int VisibleColumnsInSecondaryGroup(string fileName)
        {
            //How many additional columns are there in the SOURCES secondary group:
            int nCurrentVisibleColumns = 0;

            try
            {
                SecondaryGroup aSeries = SecondaryGroups[fileName];
                if (aSeries.Table[0].Col0 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col1 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col2 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col3 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col4 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col5 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col6 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col7 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col8 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col9 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col10 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col11 != null)
                {
                    nCurrentVisibleColumns++;
                }
                if (aSeries.Table[0].Col12 != null)
                {
                    nCurrentVisibleColumns++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(Universal.Idioma("ERROR 0909170615: error while computing visible columns. ", "ERROR 0909170615: error calculando columnas visibles. ") +
                                ex.Message, "RiverFlow2D", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }

            return(nCurrentVisibleColumns);
        }
Exemplo n.º 3
0
        public static void CreateSecondaryDefaultFile(string component, string fileName, int nValues)
        {
            var    aOneLineTable = new SecondaryTable[1];
            string aSingleLine   = "";

            switch (nValues)
            {
            case 1:
                aOneLineTable[0].Col0 = "0";
                aSingleLine           = "0";
                break;

            case 2:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aSingleLine           = "0 0";
                break;

            case 3:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aSingleLine           = "0 0 0";
                break;

            case 4:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aOneLineTable[0].Col3 = "0";
                aSingleLine           = "0 0 0 0";
                break;

            case 5:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aOneLineTable[0].Col3 = "0";
                aOneLineTable[0].Col4 = "0";
                aSingleLine           = "0 0 0 0 0";
                break;

            case 6:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aOneLineTable[0].Col3 = "0";
                aOneLineTable[0].Col4 = "0";
                aOneLineTable[0].Col5 = "0";
                aSingleLine           = "0 0 0 0 0 0";
                break;

            case 7:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aOneLineTable[0].Col3 = "0";
                aOneLineTable[0].Col4 = "0";
                aOneLineTable[0].Col5 = "0";
                aOneLineTable[0].Col6 = "0";
                aSingleLine           = "0 0 0 0 0 0 0";
                break;

            case 8:
                aOneLineTable[0].Col0 = "0";
                aOneLineTable[0].Col1 = "0";
                aOneLineTable[0].Col2 = "0";
                aOneLineTable[0].Col3 = "0";
                aOneLineTable[0].Col4 = "0";
                aOneLineTable[0].Col5 = "0";
                aOneLineTable[0].Col6 = "0";
                aOneLineTable[0].Col7 = "0";
                aSingleLine           = "0 0 0 0 0 0 0 0";
                break;
            }

            var data = new SecondaryGroup();

            data.Component = component;
            data.FileName  = fileName;
            data.NPoints   = 1;
            data.Table     = aOneLineTable;

            SecondaryGroups.Add(fileName, data);

            // Write data.
            TextWriter file = new StreamWriter(fileName);

            file.WriteLine("1");
            file.WriteLine(aSingleLine);
            file.Close();
        }