Пример #1
0
 public override object[,] ObjInfo(object column, object row)
 {
     if (column.GetType() == typeof(ExcelMissing) && row.GetType() == typeof(ExcelMissing))
     {
         var result = new MatrixBuilder();
         result.Add(ColumnHeaders, false, true, true);
         result.Add(Content, false, true, false);
         return(result.Deliver());
     }
     if (row.GetType() != typeof(ExcelMissing) && Convert.ToInt32(row) == -1)
     {
         var result = new MatrixBuilder();
         result.Add(ColumnHeaders, false, true, true);
         return(result.Deliver());
     }
     return(base.ObjInfo(FindHeader(column, ColumnHeaders, "Column"), row));
 }
Пример #2
0
        public object[,] DisplayObject()
        {
            FieldInfo[]   keyList = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
            MatrixBuilder result  = new MatrixBuilder();

            foreach (var key in keyList)
            {
                if (key.GetValue(this) != null)
                {
                    result.Add(new[] { key.Name }, false, true, false);
                    if (typeof(IIMatrix).IsAssignableFrom(key.FieldType))
                    {
                        result.Add(((IIMatrix)key.GetValue(this)).ObjInfo(ExcelMissing.Value, ExcelMissing.Value), true, true, false);
                    }
                    else
                    {
                        result.Add(new[] { key.GetValue(this) }, true, false, false);
                    }
                }
            }
            return(result.Deliver());
        }
Пример #3
0
        public object[,] ObjInfo(object column, object row)
        {
            int iCol;
            var keyList = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
            var nCol    = keyList.Length;

            if (column.GetType() == typeof(ExcelMissing) && row.GetType() == typeof(ExcelMissing))
            {
                var header = new string[nCol];
                for (iCol = 0; iCol < nCol; iCol++)
                {
                    header[iCol] = keyList[iCol].Name;
                }
                var resi = new MatrixBuilder();
                resi.Add(header, false, true, true);
                resi.Add((Array)keyList[0].GetValue(this), false, true, false);
                for (iCol = 1; iCol < nCol; iCol++)
                {
                    resi.Add((Array)keyList[iCol].GetValue(this), true, false, false);
                }
                return(resi.Deliver());
            }
            if (column.GetType() == typeof(ExcelMissing) && Convert.ToInt32(row) == -1)
            {
                var result2 = new object[1, nCol];
                for (iCol = 0; iCol < nCol; iCol++)
                {
                    result2[0, iCol] = keyList[iCol].Name;
                }
                return(result2);
            }
            for (iCol = 0; iCol < nCol; iCol++)
            {
                if (keyList[iCol].Name.Equals(column))
                {
                    break;
                }
            }
            if (iCol == nCol)
            {
                return new object[, ] {
                           { "Column " + column + " not found!" }
                }
            }
            ;
            var b = (Array)keyList[iCol].GetValue(this);

            if (b.Length == 0)
            {
                return new object[, ] {
                           { "Column " + column + " has not been initialized!" }
                }
            }
            ;
            if (row.GetType() != typeof(ExcelMissing))
            {
                return new[, ] {
                           { b.GetValue(Convert.ToInt32(row)) }
                }
            }
            ;
            var result = new object[b.Length, 1];

            for (int iRow = 0; iRow < b.Length; iRow++)
            {
                result[iRow, 0] = b.GetValue(iRow);
            }
            return(result);
        }
    }
}
Пример #4
0
        public static object[,] mmLoadObjs(string location)
        {
            if (!File.Exists(location))
            {
                return new object[, ] {
                           { "File not found." }
                }
            }
            ;
            string[]      fileText = File.ReadAllLines(location);
            string        name = "", type = "";
            List <string> loadedObjs = new List <string>();

            for (int iLine = 0; iLine < fileText.Length; iLine++)
            {
                int           iObjLine;
                MatrixBuilder mRange = new MatrixBuilder();
                for (iObjLine = iLine; iObjLine < fileText.Length; iObjLine++)
                {
                    string[] lineFields = fileText[iObjLine].Split('\t');
                    if (iObjLine == iLine)
                    {
                        if (!lineFields[0].StartsWith("NEW"))
                        {
                            return new object[, ] {
                                       { "File not in correct format at line " + iObjLine }
                            }
                        }
                        ;
                        type = lineFields[0].Substring(3);
                    }
                    else if (iObjLine == iLine + 1)
                    {
                        if (lineFields[0] != "name")
                        {
                            return new object[, ] {
                                       { "File not in correct format at line " + iObjLine }
                            }
                        }
                        ;
                        name = lineFields[1];
                    }
                    else if (lineFields.Length < 2)
                    {
                        break;
                    }
                    else
                    {
                        mRange.Add(lineFields, false, true, true);
                    }
                }
                try
                {
                    loadedObjs.Add(ObjectHandler.CreateObject(name, type, mRange.Deliver(false)).GetNameCounter());
                }
                catch (Exception e)
                {
                    return(new object[, ] {
                        { "Error when generating object " + name + " of type " + type + ". " + e.Message }
                    });
                }
                iLine = iObjLine;
            }
            object[,] vLoadedObjs = new object[loadedObjs.Count, 1];
            for (int i = 0; i < loadedObjs.Count; i++)
            {
                vLoadedObjs[i, 0] = loadedObjs.ElementAt(i);
            }

            return(vLoadedObjs);
        }