示例#1
0
 public static void Draw(this IRow self, int begin = 0, int end = 0x7fffffff, GUILayoutOption[] guiOpts = null, bool newRow = true)
 {
     #if UNITY_EDITOR
     if (newRow)
     {
         EditorGUILayout.BeginHorizontal();
     }
     {
         var width = 30;
         if (newRow)
         {
             EditorGUILayout.LabelField((self.Cell(0).RowIndex + 1).ToString(), new GUILayoutOption[]
             {
                 GUILayout.Width(width),
                 GUILayout.ExpandWidth(false),
             });
         }
         for (var i = begin; i < end; ++i)
         {
             self.Cell(i).Draw(null, guiOpts);
         }
     }
     if (newRow)
     {
         EditorGUILayout.EndHorizontal();
     }
     #endif
 }
示例#2
0
 public void It_has_9_cells_with_value_unknown()
 {
     Assert.That(_row1.Cell(1).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(2).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(3).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(4).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(5).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(6).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(7).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(8).Value, Is.EqualTo(Solver.CellValue.Unknown));
     Assert.That(_row1.Cell(9).Value, Is.EqualTo(Solver.CellValue.Unknown));
 }
示例#3
0
        public List <TimeSpan> GetCurrentColumn()
        {
            List <TimeSpan> res = new List <TimeSpan>();

            if (Data.Instance.ChangeCallsMatrix != null)
            {
                IRow DatesChangeRow = Data.Instance.ChangeCallsMatrix.GetRow(0);
                if (DatesChangeRow != null)
                {
                    DateTime DateTimeNow = DateTime.Now;
                    int      len         = DatesChangeRow.LastCellNum;
                    for (int i = 0; i <= len; i++)
                    {
                        if (ContainsDate(DatesChangeRow.Cell(i), DateTimeNow))
                        {
                            len = Data.Instance.ChangeCallsMatrix.LastRowNum;

                            for (int j = 1; j <= len; j++)
                            {
                                string s = Data.Instance.ChangeCallsMatrix.Cell(j, i);
                                if (s == "")
                                {
                                    continue;
                                }
                                res.AddRange(Times(s));
                            }

                            return(res);
                        }
                    }
                }
            }

            return(GetCurrentColumnWithoutChanges());
        }
示例#4
0
        public Col(int oneBasedColumnIndex, IRow row1, IRow row2, IRow row3, IRow row4, IRow row5, IRow row6, IRow row7, IRow row8, IRow row9)
        {
            Id = oneBasedColumnIndex;

            Add(row1.Cell(oneBasedColumnIndex));
            Add(row2.Cell(oneBasedColumnIndex));
            Add(row3.Cell(oneBasedColumnIndex));
            Add(row4.Cell(oneBasedColumnIndex));
            Add(row5.Cell(oneBasedColumnIndex));
            Add(row6.Cell(oneBasedColumnIndex));
            Add(row7.Cell(oneBasedColumnIndex));
            Add(row8.Cell(oneBasedColumnIndex));
            Add(row9.Cell(oneBasedColumnIndex));
        }
示例#5
0
 public ExcelHead(IRow hrow)
 {
     hidx = new int[(int)HeadIdx.Count];
     for (int i = 0; i < hrow.LastCellNum; ++i)
     {
         var v = hrow.Cell(i);
         for (int j = 0; j < (int)HeadIdx.Count; ++j)
         {
             if (v.StringCellValue == ((HeadIdx)j).ToString())
             {
                 hidx[j] = i;
                 break;
             }
         }
     }
 }
示例#6
0
        public List <(DateRange date, List <TimeSpan> times)> GetListChangesCalls()
        {
            var res = new List <(DateRange date, List <TimeSpan> times)>();

            if (Data.Instance.ChangeCallsMatrix == null)
            {
                return(res);
            }

            IRow DatesRow = Data.Instance.ChangeCallsMatrix.GetRow(0);
            int  LastCell = DatesRow.LastCellNum;
            int  len      = Data.Instance.ChangeCallsMatrix.LastRowNum;

            for (int i = 0; i <= LastCell; i++)
            {
                string DatesVal = DatesRow.Cell(i);
                if (DatesVal == "")
                {
                    continue;
                }
                List <DateRange> dates = DatesRange(DatesVal);
                List <TimeSpan>  calls = new List <TimeSpan>();
                for (int j = 1; j <= len; j++)
                {
                    string s = Data.Instance.ChangeCallsMatrix.Cell(j, i);
                    if (s == "")
                    {
                        continue;
                    }
                    calls.AddRange(Times(s));
                }

                foreach (DateRange item in dates)
                {
                    res.Add((item, calls));
                }
            }

            return(res);
        }
示例#7
0
        private string GetFirstLineCurrentColumn()
        {
            DateTime DateTimeNow = DateTime.Now;
            int      len;

            if (Data.Instance.ChangeCallsMatrix != null)
            {
                IRow DatesChangeRow = Data.Instance.ChangeCallsMatrix.GetRow(0);
                if (DatesChangeRow != null)
                {
                    len = DatesChangeRow.LastCellNum;
                    for (int i = 0; i <= len; i++)
                    {
                        if (ContainsDate(DatesChangeRow.Cell(i), DateTimeNow))
                        {
                            len = Data.Instance.ChangeCallsMatrix.LastRowNum;

                            for (int j = 1; j <= len; j++)
                            {
                                string s = Data.Instance.ChangeCallsMatrix.Cell(j, i);
                                if (s == "")
                                {
                                    continue;
                                }
                                return(s);
                            }

                            return("");
                        }
                    }
                }
            }


            if (Data.Instance.CallsMatrix == null)
            {
                return("");
            }

            int index = 0;

            switch (DateTimeNow.DayOfWeek)
            {
            case DayOfWeek.Tuesday:
                index = 1;
                break;

            case DayOfWeek.Saturday:
                index = 2;
                break;
            }

            len = Data.Instance.CallsMatrix.LastRowNum;
            for (int j = 1; j <= len; j++)
            {
                string s = Data.Instance.CallsMatrix.Cell(j, index);
                if (s == "")
                {
                    continue;
                }
                return(s);
            }

            return("");
        }
        public TableLessons GetTableLessonsWithoutChanges(Class c, DayOfWeek d)
        {
            if (d == DayOfWeek.Sunday)
            {
                return(new TableLessons());
            }
            IRow ClassesRow = Data.Instance.LessonsMatrix?.GetRow(Data.Instance.CurrentManifest.LessonsMatrixOffsetY);

            if (ClassesRow == null)
            {
                return(new TableLessons());
            }

            int    len = ClassesRow.LastCellNum;
            string s   = c.ToString();

            List <string> Lesson  = new List <string>();
            List <string> Cabinet = new List <string>();

            for (int i = 0; i <= len; i++)
            {
                if (!ClassesRow.Cell(i).Contains(s))
                {
                    continue;
                }

                int d_Norm = d.Normalising();
                int StartLine = 0, EndLine = 0;
                int LastRow = Data.Instance.LessonsMatrix.LastRowNum;

                int  NumberCounter = 0;
                int  LastNum       = 0;
                int  j             = 0;
                bool LineSwitch    = false;
                if (d_Norm == 0)
                {
                    LineSwitch = true; StartLine = Data.Instance.CurrentManifest.LessonsMatrixOffsetY + 1;
                }
                if (d_Norm == 5)
                {
                    EndLine = LastRow;
                }

                while (NumberCounter < d_Norm + 1 && (j <= LastRow))
                {
                    string val = Data.Instance.LessonsMatrix.GetCell(
                        Data.Instance.CurrentManifest.LessonsMatrixOffsetY + j + 1,
                        Data.Instance.CurrentManifest.LessonsMatrixOffsetX
                        ) ?? "";
                    if (val == "")
                    {
                        j++; continue;
                    }

                    if (!int.TryParse(val, out int CurNum))
                    {
                        j++; continue;
                    }

                    if (CurNum < LastNum)
                    {
                        NumberCounter++;
                        if (NumberCounter > d_Norm - 1)
                        {
                            if (!LineSwitch)
                            {
                                LineSwitch = true;
                                StartLine  = Data.Instance.CurrentManifest.LessonsMatrixOffsetY + j + 1;
                            }
                            else
                            {
                                EndLine = Data.Instance.CurrentManifest.LessonsMatrixOffsetY + j;
                                break;
                            }
                        }
                    }
                    LastNum = CurNum;
                    j++;
                }

                int  MissCounter = 0;
                bool LessonFound = false;
                j = 0;
                while (true)
                {
                    if (MissCounter > 16 || (LessonFound && MissCounter > 2) || (StartLine + j > EndLine))
                    {
                        break;
                    }

                    if (Data.Instance.LessonsMatrix.GetCell(StartLine + j, i) == "")
                    {
                        MissCounter++;
                        if (!LessonFound)
                        {
                            Lesson.Add("--");
                            Cabinet.Add("--");
                        }
                        j++;
                        continue;
                    }
                    else
                    {
                        LessonFound = true;
                    }
                    MissCounter = 0;

                    Lesson.Add(Data.Instance.LessonsMatrix.GetCell(StartLine + j, i));

                    string Classrooms = Data.Instance.LessonsMatrix.GetCell(StartLine + j + 1, i + 1)
                                        + Data.Instance.LessonsMatrix.GetCell(StartLine + j, i + 2)
                                        + Data.Instance.LessonsMatrix.GetCell(StartLine + j + 1, i + 3);
                    Cabinet.Add(Classrooms);
                    j++;
                }

                break;
            }

            return(new TableLessons(Lesson, Cabinet));
        }
示例#9
0
文件: Excel2Lua.cs 项目: MF-JIN/test
    public static bool writeLua(ISheet sheet, string path, int headerRowIdx = 0)
    {
        string        sheetname = sheet.SheetName.RReplace(PathUtils.PunctuationRegex + "+", "_").TrimEnd('_');
        StringBuilder luabuild  = new StringBuilder(2048000);

        luabuild.Append("-- usage: \n--\t" + sheetname + "[id][ColumnName] \n--\t" + sheetname + "[id].ColumnName\n");

        //columnIdxs
        IRow headerRow   = sheet.GetRow(headerRowIdx);
        int  columnCount = headerRow.LastCellNum;
        int  rowCount    = sheet.LastRowNum;

        luabuild.Append("\nlocal ColumnIdx={");
        for (int i = 0; i < columnCount; ++i)
        {
            var cell = headerRow.Cell(i);
            var v    = cell.SValue().RReplace(PathUtils.PunctuationRegex + "+", "_");
            // if(cell.CellType == CellType.String || (cell.CellType == CellType.Formula && cell.CachedFormulaResultType ==  CellType.String))
            v = "\"" + v + "\"";
            luabuild.Append("\n\t[" + v + "]=" + (i + 1) + ",");
        }
        luabuild.Append("\n}\n");

        // body
        luabuild.Append("\nlocal " + sheetname + "={");
        try
        {
            for (int i = headerRowIdx + 1; i < rowCount; ++i)
            {
                IRow row = sheet.GetRow(i);
                if (row == null)
                {
                    continue;
                }
                var cell0 = row.Cell(0);
                if (cell0.CellType == CellType.Blank ||
                    (cell0.CellType == CellType.String && cell0.StringCellValue == ""))
                {
                    continue;
                }

                var v0 = cell0.SValue();
                if (cell0.CellType == CellType.String ||
                    (cell0.CellType == CellType.Formula && cell0.CachedFormulaResultType == CellType.String))
                {
                    v0 = "\"" + v0 + "\"";
                }
                luabuild.Append("\n\t[" + v0 + "]" + "={" + v0);
                for (int j = 1; j < row.LastCellNum; ++j)
                {
                    var cell = row.Cell(j);
                    var v    = cell.SValueOneline();
                    if (cell.CellType == CellType.Blank)
                    {
                        v = "nil";
                    }
                    else if (cell.CellType == CellType.String ||
                             (cell.CellType == CellType.Formula && cell.CachedFormulaResultType == CellType.String))
                    {
                        v = "\"" + v + "\"";
                    }
                    luabuild.Append(",\t" + v);
                }
                luabuild.Append("},");
            }
        }
        catch (Exception e)
        {
            AppLog.e(Tag, e);
        }
        luabuild.Append("\n}\n");

        //tail
        luabuild.Append("\nfor k,v in pairs(" + sheetname + ") do")
        .Append("\n\tif type(v) == \"table\" then")
        .Append("\n\t\tsetmetatable(v,{")
        .Append("\n\t\t__newindex=function(t,kk) print(\"warning: attempte to change a readonly table\") end,")
        .Append("\n\t\t__index=function(t,kk)")
        .Append("\n\t\t\tif ColumnIdx[kk] ~= nil then")
        .Append("\n\t\t\t\treturn t[ColumnIdx[kk]]")
        .Append("\n\t\t\telse")
        .Append("\n\t\t\t\tprint(\"err: \\\"" + sheetname + "\\\" have no field [\"..kk..\"]\")")
        .Append("\n\t\t\t\treturn nil")
        .Append("\n\t\t\tend")
        .Append("\n\t\tend})")
        .Append("\n\tend")
        .Append("\nend");

        luabuild.Append("\nreturn " + sheetname + "\n");

        path += "/" + sheetname + ".lua";

        var dir = path.upath().Substring(0, path.LastIndexOf('/'));

        if (!Directory.Exists(dir))
        {
            Directory.CreateDirectory(dir);
        }
        File.WriteAllText(path, luabuild.ToString());
        AppLog.d(Tag, path);
        return(true);
    }