示例#1
0
        public void Write(CoachFile File, string FileName)
        {
            using (StreamWriter stream = new StreamWriter(FileName + ".exp", false, Encoding.UTF8))
            {
                foreach (var instruction in File.Instructions)
                {
                    stream.WriteLine(instruction.Id);
                    stream.WriteLine(instruction.Subject);
                    stream.WriteLine(instruction.Place);
                    stream.WriteLine(instruction.Effect);
                    stream.WriteLine(instruction.Value);
                    stream.WriteLine(instruction.Unit);
                    stream.WriteLine(instruction.Instr);

                    if (instruction.Group != "NULL")
                    {
                        stream.WriteLine(instruction.Group);
                    }

                    if (instruction.Clast != "NULL")
                    {
                        stream.WriteLine(instruction.Clast);
                    }
                }
            }
        }
示例#2
0
        public void Write(CoachFile File, string FileName)
        {
            //Рабочая книга Excel
            XSSFWorkbook wb;
            //Лист в книге Excel
            XSSFSheet sh;

            //Создаем рабочую книгу
            wb = new XSSFWorkbook();
            //Создаём лист в книге
            sh = (XSSFSheet)wb.CreateSheet("Лист 1");

            //Количество заполняемых строк
            int countRow = File.Instructions.Count;

            //Запускаем цыкл по строка
            for (int i = 0; i < countRow; i++)
            {
                //Создаем строку
                var currentRow = sh.CreateRow(i);

                //в строке создаём ячеёку с указанием столбца
                currentRow.CreateCell(0).SetCellValue(File.Instructions[i].Subject.ToString());
                //в строке создаём ячеёку с указанием столбца
                currentRow.CreateCell(1).SetCellValue(File.Instructions[i].Place.ToString());
                //в строке создаём ячеёку с указанием столбца
                currentRow.CreateCell(2).SetCellValue(File.Instructions[i].Effect.ToString());
                //в строке создаём ячеёку с указанием столбца
                currentRow.CreateCell(3).SetCellValue(File.Instructions[i].Value.ToString());
                //в строке создаём ячеёку с указанием столбца
                currentRow.CreateCell(4).SetCellValue(File.Instructions[i].Unit.ToString());

                //Выравним размер столбца по содержимому
                sh.AutoSizeColumn(0);
                //Выравним размер столбца по содержимому
                sh.AutoSizeColumn(1);
                //Выравним размер столбца по содержимому
                sh.AutoSizeColumn(2);
                //Выравним размер столбца по содержимому
                sh.AutoSizeColumn(3);
                //Выравним размер столбца по содержимому
                sh.AutoSizeColumn(4);
            }

            //запишем всё в файл
            using (var fs = new FileStream(FileName, FileMode.Create, FileAccess.Write))
            {
                wb.Write(fs);
            }

            wb.Close();

            //Откроем файл
            Process.Start(FileName);
        }
示例#3
0
        public static CoachFile Create()
        {
            CoachFile f = new CoachFile();

            List <string> Subjects = ReadFile("Subjects.txt");
            List <string> Places   = ReadFile("Places.txt");
            List <string> Effects  = ReadFile("Effects.txt");
            List <string> Values   = ReadFile("Values.txt");
            List <string> Units    = ReadFile("Units.txt");

            Check(Subjects);
            Check(Places);
            Check(Effects);
            Check(Values);
            Check(Units);

            if (Subjects.Count != Places.Count ||
                Subjects.Count != Effects.Count ||
                Subjects.Count != Values.Count ||
                Subjects.Count != Units.Count)
            {
                throw new Exception();
            }

            for (int i = 0; i < Subjects.Count; i++)
            {
                Instruction instruct = new Instruction()
                {
                    Id      = (i + 1).ToString(),
                    Subject = Subjects[i],
                    Place   = Places[i],
                    Effect  = Effects[i] + " ",
                    Value   = Values[i],
                    Unit    = Units[i],
                    Instr   = "*****instr" + i.ToString(),
                    Group   = "*****group" + i.ToString(),
                    Clast   = "*****clast" + i.ToString()
                };

                if (instruct.Effect == "задать уставку ")
                {
                    instruct.Unit = " " + Units[i];
                }

                if (instruct.Effect == "нажать кнопку ")
                {
                    instruct.Value = " ";
                    instruct.Unit  = " ";
                }

                f.Instructions.Add(instruct);
            }

            return(f);
        }
示例#4
0
        public CoachFile Read(string FileName)
        {
            CoachFile file = new CoachFile();

            //Книга Excel
            XSSFWorkbook xssfwb;

            //Открываем файл
            using (FileStream f = new FileStream(FileName, FileMode.Open, FileAccess.Read))
            {
                xssfwb = new XSSFWorkbook(f);
            }

            //Получаем первый лист книги
            ISheet sheet = xssfwb.GetSheetAt(0);

            //запускаем цикл по строкам
            for (int row = 0; row < 3000; row++)
            {
                //получаем строку
                var         currentRow  = sheet.GetRow(row);
                Instruction instruction = new Instruction();

                if (currentRow != null) //null когда строка содержит только пустые ячейки
                {
                    //Получаем значение ячейки
                    instruction.Id = (row + 1).ToString();

                    if (currentRow.GetCell(0).CellType == CellType.String)
                    {
                        instruction.Subject = currentRow.GetCell(0).StringCellValue.ToString();
                    }
                    else
                    {
                        instruction.Subject = currentRow.GetCell(0).NumericCellValue.ToString();
                    }

                    if (currentRow.GetCell(1).CellType == CellType.String)
                    {
                        instruction.Place = currentRow.GetCell(1).StringCellValue.ToString();
                    }
                    else
                    {
                        instruction.Place = currentRow.GetCell(1).NumericCellValue.ToString();
                    }

                    if (currentRow.GetCell(2).CellType == CellType.String)
                    {
                        instruction.Effect = currentRow.GetCell(2).StringCellValue.ToString() + " ";
                    }
                    else
                    {
                        instruction.Effect = currentRow.GetCell(2).NumericCellValue.ToString() + " ";
                    }

                    if (currentRow.GetCell(3).CellType == CellType.String)
                    {
                        string str = currentRow.GetCell(3).StringCellValue.ToString();

                        if (str.Contains("-"))
                        {
                            instruction.Value = " ";
                        }
                        else
                        {
                            instruction.Value = str;
                        }
                    }
                    else
                    {
                        string str = currentRow.GetCell(3).NumericCellValue.ToString();

                        if (str.Contains("-"))
                        {
                            instruction.Value = " ";
                        }
                        else
                        {
                            instruction.Value = str;
                        }
                    }

                    if (currentRow.GetCell(4).CellType == CellType.String)
                    {
                        string str = currentRow.GetCell(4).StringCellValue.ToString();

                        if (str.Contains("-"))
                        {
                            instruction.Unit = " ";
                        }
                        else
                        {
                            instruction.Unit = str;
                        }
                    }
                    else
                    {
                        string str = currentRow.GetCell(4).NumericCellValue.ToString();

                        if (str.Contains("-"))
                        {
                            instruction.Unit = " ";
                        }
                        else
                        {
                            instruction.Unit = str;
                        }
                    }

                    instruction.Instr = "*****instr" + row.ToString();
                    instruction.Group = "*****group" + row.ToString();
                    instruction.Clast = "*****clast" + row.ToString();

                    file.Instructions.Add(instruction);
                }
                else
                {
                    break;
                }
            }


            xssfwb.Close();

            return(file);
        }
示例#5
0
        public CoachFile Read(string FileName)
        {
            CoachFile file = new CoachFile();

            using (StreamReader stream = new StreamReader(FileName))
            {
                List <string> buffer = new List <string>();

                while (!stream.EndOfStream)
                {
                    Instruction instruct = new Instruction();


                    switch (buffer.Count)
                    {
                    case 0:
                        instruct.Id      = stream.ReadLine();
                        instruct.Subject = stream.ReadLine();
                        instruct.Place   = stream.ReadLine();
                        instruct.Effect  = stream.ReadLine();
                        instruct.Value   = stream.ReadLine();
                        instruct.Unit    = stream.ReadLine();
                        instruct.Instr   = stream.ReadLine();
                        break;

                    case 1:
                        instruct.Id      = buffer[0];
                        instruct.Subject = stream.ReadLine();
                        instruct.Place   = stream.ReadLine();
                        instruct.Effect  = stream.ReadLine();
                        instruct.Value   = stream.ReadLine();
                        instruct.Unit    = stream.ReadLine();
                        instruct.Instr   = stream.ReadLine();
                        break;

                    case 2:
                        instruct.Id      = buffer[0];
                        instruct.Subject = buffer[1];
                        instruct.Place   = stream.ReadLine();
                        instruct.Effect  = stream.ReadLine();
                        instruct.Value   = stream.ReadLine();
                        instruct.Unit    = stream.ReadLine();
                        instruct.Instr   = stream.ReadLine();
                        break;
                    }

                    buffer.Clear();

                    string g = stream.ReadLine();
                    if (g == null)
                    {
                        break;
                    }

                    if (g.Contains("group"))
                    {
                        instruct.Group = g;
                    }
                    else
                    {
                        instruct.Group = "NULL";
                        buffer.Add(g);
                    }

                    string c = stream.ReadLine();
                    if (c == null)
                    {
                        break;
                    }

                    if (c.Contains("clast"))
                    {
                        instruct.Clast = c;
                    }
                    else
                    {
                        instruct.Clast = "NULL";
                        buffer.Add(c);
                    }

                    file.Instructions.Add(instruct);
                }
            }

            return(file);
        }