Ejemplo n.º 1
0
        public static List <HS> GetDataByPdf(string path, List <string> type, params string[] stringAppearing)
        {
            PdfReader     reader     = new PdfReader(@path);
            int           intPageNum = reader.NumberOfPages;
            List <string> lstLine    = new List <string>();
            string        text;
            List <HS>     lst  = new List <HS>();
            List <object> lstS = new List <object>();

            lstS.AddRange(stringAppearing);
            List <object> lstType = new List <object>();

            for (int i = 1; i <= intPageNum; i++)
            {
                Rules r = new Rules();
                r.RName = "Rules Check string Appearing";
                text    = PdfTextExtractor.GetTextFromPage(reader, i);
                lstLine = text.Split('\n').ToList();
                string data = "";
                foreach (string s in lstLine)
                {
                    data = data + s;
                }
                r.AddRuleParam(text);
                stringAppearing.ToList().ForEach(u => r.AddRuleParam(u));

                r.AddCheckingMethod(new StringAppearing());
                bool b = r.IsValid;
                if (b)
                {
                    Rules r2 = new Rules();
                    r2.RName = "Rules Check string Appearing";
                    HS hs1 = new HS();
                    hs1 = (ChietXuatDuLieu.GetData(lstLine, stringAppearing));
                    r2.AddCheckingMethod(new TypeData());
                    r2.AddRuleParam(type, hs1.name, hs1.Place, hs1.Result, hs1.Score, hs1.Level);
                    bool br2 = r2.IsValid;
                    if (br2)
                    {
                        hs1.name   = hs1.name.Remove(0, 2);
                        hs1.Place  = hs1.Place.Remove(0, 2);
                        hs1.Result = hs1.Result.Remove(0, 2);
                        hs1.Score  = hs1.Score.Remove(0, 2);
                        hs1.Level  = hs1.Level.Remove(0, 2);
                        lst.Add(hs1);
                    }
                }
            }

            return(lst);
        }
Ejemplo n.º 2
0
        public static HS GetData(List <string> lstLine, string[] DataAppearing)
        {
            HS     hsrs = new HS();
            string rsS  = (DataAppearing[2] + " " + DataAppearing[3] + " " + DataAppearing[4]);

            for (int i = 0; i < lstLine.Count; i++)
            {
                if (lstLine[i].Contains(DataAppearing[0].ToString()))
                {
                    hsrs.name = "S:" + lstLine[i + 1];
                }
                if (lstLine[i].Contains(DataAppearing[1].ToString()))
                {
                    hsrs.Place = "S:" + lstLine[i + 1];
                }
                if (lstLine[i].Contains(rsS))
                {
                    if (lstLine[i + 3].Contains("Level A2"))
                    {
                        hsrs.Result = "S:" + lstLine[i + 1] + " " + lstLine[i + 3];
                        string[] rs = lstLine[i + 2].Split(' ');
                        hsrs.Level = "S:" + rs[rs.Length - 1];
                        int  score;
                        bool ok = int.TryParse(rs[rs.Length - 2], out score);
                        if (ok)
                        {
                            hsrs.Score = "I:" + score.ToString();
                        }
                        else
                        {
                            hsrs.Score = "I:";
                        }
                        break;
                    }
                    else
                    {
                        string[] rs = lstLine[i + 1].Split(' ');
                        int      l  = rs.Length;
                        if (l == 1)
                        {
                            hsrs.Result = "S:" + lstLine[i + 1];
                            hsrs.Level  = "S:";
                            hsrs.Score  = "I:";
                            break;
                        }
                        hsrs.Level = "S:" + rs[l - 1]; l--;

                        int  score;
                        bool ok = int.TryParse(rs[l - 1], out score);
                        if (ok)
                        {
                            hsrs.Score = "I:" + score.ToString();
                        }
                        else
                        {
                            hsrs.Score = "I:";
                        }
                        l--;
                        for (int j = 0; j < l; j++)
                        {
                            if (l == 1)
                            {
                                hsrs.Result = rs[j];
                            }
                            else
                            {
                                hsrs.Result += rs[j] + " ";
                            }
                        }

                        hsrs.Result = "S:" + hsrs.Result;
                        break;
                    }
                }
            }
            // tách chuỗi theo type đã đưa vào
            return(hsrs);
        }