Esempio n. 1
0
        /// <summary>
        /// Checks if imported row is valid: Name, Department,
        /// HomeworkHours exist and are of correct types
        /// </summary>
        /// <param name="row">Row to be checked</param>
        /// <returns>True if row is valid</returns>
        public static bool IsValidRow(RowNoHeader row)
        {
            //Check if crucial cells are empty
            //1 being name, 2 being department and 9 being homework hours
            if (row[1] == "" || row[2] == "" || row[9] == "")
            {
                return(false);
            }
            //Check if a credit, not just some row
            int    parseInt;
            string name          = row[1].ToString().Trim();
            string department    = row[2].ToString().Trim();
            string homeworkHours = row[9].ToString().Trim();

            //homeworkHours must be a number, whereas name and department should not
            if (int.TryParse(name, out parseInt) ||
                int.TryParse(department, out parseInt) ||
                !int.TryParse(homeworkHours, out parseInt) ||
                !isValidDepartment(department))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 2
0
        private void btnSelectFile_Click(object sender, EventArgs e)
        {
            var dialog = new OpenFileDialog
            {
                Filter = Constants.FileExt
            };

            dialog.ShowDialog();

            if (dialog.FileName != "")
            {
                this.txtAllMember.Text = dialog.FileName;
            }
            WinnerInfo  = GetWinnerFormExcel(this.txtAllMember.Text);
            ExcelHeader = GetExcelHeader(this.txtAllMember.Text);
            if (WinnerInfo != null && WinnerInfo.Count != 0)
            {
                this.lblPageSize.Text = WinnerInfo.Count.ToString();
                this.lblRemain.Text   = WinnerInfo.Distinct(new MyComparer()).Count().ToString();
                this.lblWon.Text      = WinnerInfo.Count(x => WinnerHistory.Select(y => y[Constants.KeyName].Value).ToList()
                                                         .Contains(x[Constants.KeyName].Value)
                                                         ).ToString();
            }
            else
            {
                this.txtLog.Text = CustomMessage.FileNotCorrect;
            }
        }
Esempio n. 3
0
 private void _initNewObjects(RowNoHeader row)
 {
     var objectsCount = row.Count(cell => cell != null && !String.IsNullOrEmpty(cell)) - 1;
     for (int i = 0; i < objectsCount; ++i)
     {
         _currentSentenceErrors.Add(i, new ClasterizedSentenceError());
     }
 }
Esempio n. 4
0
        private Item toItem(RowNoHeader row)
        {
            var type     = row[1].ToString();
            var content  = row[2].ToString();
            var isPassed = row[3] != "-" ? true : false;
            var comment  = row[4].ToString();

            return(new Item(type, content, isPassed, comment));
        }
Esempio n. 5
0
        public Group ImportGroup(RowNoHeader courseRow,
                                 RowNoHeader titleRow,
                                 int offset)
        {
            Group group = new Group();

            parseTitle(group, titleRow[offset]);
            group.Course = courseRow[offset];
            group.Year   = 2015;
            return(group);
        }
Esempio n. 6
0
 private void _processRow(RowNoHeader row)
 {
     switch (_currentIndex)
     {
         case 0:
             _initNewObjects(row);
             ++_currentIndex;
             break;
         case ClasterIndex:
             _setSentenceIdAndErrorType(row);
             ++_currentIndex;
             break;
         case SampleWordsCountIndex:
             _readSentenceErrorInfo(
                 (sentenceError, index) => sentenceError.SampleWordsCount = Int32.Parse(row[index + 2]));
             ++_currentIndex;
             break;
         case SampleWordsIndex:
             _readSentenceErrorInfo(
                 (sentenceError, index) =>
                 {
                     var cell = (row[index + 2].Value as String);
                     sentenceError.SampleWords = !String.IsNullOrEmpty(cell)
                         ? cell.Split(',').Select(s => s.Trim()).ToArray()
                         : new string[]{};
                 });
             ++_currentIndex;
             break;
         case DetectedWordsCountIndex:
             _readSentenceErrorInfo(
                 (sentenceError, index) => sentenceError.DetectedWordsCount = Int32.Parse(row[index + 2]));
             ++_currentIndex;
             break;
         case DetectedWordsIndex:
             _readSentenceErrorInfo(
                 (sentenceError, index) =>
                 {
                     var cell = (row[index + 2].Value as String);
                     sentenceError.DetectedWords = !String.IsNullOrEmpty(cell)
                         ? cell.Split(',').Select(s => s.Trim()).ToArray()
                         : new string[]{};
                 });
             ++_currentIndex;
             break;
         case PrecisionIndex:
             _readSentenceErrorInfo(
                 (sentenceError, index) => sentenceError.Precision = Double.Parse(row[index + 2].ToString().Replace("%", "")));
             _onSentenceEnd();
             break;
         default:
             ++_currentIndex;
             break;
     }
 }
Esempio n. 7
0
 public Credit(RowNoHeader row)
 {
     if (row == null)
     {
         return;
     }
     Id                = cellToInt(row[0]);
     CreditName        = row[1];
     Department        = row[2];
     ETCSCreditCount   = cellToInt(row[3]);
     LectionHourCount  = cellToInt(row[6]);
     SeminarHourCount  = cellToInt(row[7]);
     LabHourCount      = cellToInt(row[8]);
     HomeworkHourCount = cellToInt(row[9]);
 }
Esempio n. 8
0
        //TODO: bad approach, need to use mapper composition, refactor
        private static object ToPaymentrecordsList(RowNoHeader row, IMapper mapper)
        {
            List <PaymentRecord> mapped = new List <PaymentRecord>();
            int baseIndex = 3;
            int shift     = 4;
            int currentPaymentRecordPointer = baseIndex;

            for (int i = 0; currentPaymentRecordPointer + 3 < row.Count; i++)
            {
                string[] paymentRecordSource = new string[4];
                for (int j = 0; j < 4; j++)
                {
                    paymentRecordSource[j] = row[currentPaymentRecordPointer + j];
                }
                var currentPaymentRecord = mapper.Map <string[], PaymentRecord>(paymentRecordSource);
                mapped.Add(currentPaymentRecord);
                currentPaymentRecordPointer += shift;
            }
            return(mapped);
        }
Esempio n. 9
0
        public void AddRow(RowNoHeader row)
        {
            if(_isClosed) return;

            if (_currentIndex == -1)
            {
                var maker = row[0].ToString().Trim();
                if (maker == RecordStartMarker)
                {
                    _currentIndex = 0;
                    _currentSentenceErrors = new Dictionary<int, ClasterizedSentenceError>();
                }
                else if (maker == EndOfDataMarker)
                {
                    _isClosed = true;
                }
            }
            else
            {
                _processRow(row);
            }
        }
Esempio n. 10
0
        public Module ParseModule(RowNoHeader row)
        {
            if (row == null || !IsValidRow(row))
            {
                return(null);
            }
            var module = new Module();

            module.Title     = row[Offset.Title];
            module.Credits   = double.Parse(row[Offset.Credits]); // Guaranteed to be an double
            module.Lections  = cellToInt(row[Offset.Lections]);
            module.Practices = cellToInt(row[Offset.Practices]);
            module.Labs      = cellToInt(row[Offset.Labs]);
            //module.Self = cellToInt(row[Offset.Self]);
            module.Exam           = cellToInt(row[Offset.Exam]);
            module.ZALIK          = row[Offset.Zalik];
            module.Module_tests   = cellToInt(row[Offset.Module_tests]);
            module.Course_project = cellToInt(row[Offset.Course_project]);
            module.Course_work    = cellToInt(row[Offset.Course_work]);
            module.RGR            = cellToInt(row[Offset.RGR]);
            module.DKR            = cellToInt(row[Offset.DKR]);
            module.Referat        = cellToInt(row[Offset.Referat]);
            return(module);
        }
Esempio n. 11
0
 public ModuleStudyActionImport(TeachersModelContainer context,
                                RowNoHeader row)
 {
     this.context = context;
     this.row     = row;
 }
Esempio n. 12
0
 private void _setSentenceIdAndErrorType(RowNoHeader row)
 {
     _currentSentenceErrors.ForEach(pair =>
     {
         pair.Value.SentenceId = Int32.Parse(row[0]);
         pair.Value.ErrorClass = Int32.Parse(row[pair.Key + 2]);
     });
 }
Esempio n. 13
0
File: Parser.cs Progetto: Ogonik/LWS
        private static List<int> getChainReferences(RowNoHeader row)
        {
            var result = new List<int>();

            var nextChainRefPos = row.FindIndex(LinkedChainsStartCell, LinkedChainsCellCount, isVluableCell);

            while (nextChainRefPos != -1)
            {
                result.Add(nextChainRefPos);

                nextChainRefPos = row.FindIndex(nextChainRefPos + 1, LinkedChainsCellCount - (nextChainRefPos - LinkedChainsStartCell + 1), isVluableCell);
            }

            return result.Select(i => i - LinkedChainsStartCell).ToList();
        }