Exemplo n.º 1
0
        public System.Collections.Generic.List <ExamComponent> ExamsComponentsFromBaseData(Exam_Board eb, string season, string year)
        {
            System.Collections.Generic.List <ExamComponent> temp = new List <ExamComponent>();
            while (year.Length > 2)
            {
                year = year.Substring(1, year.Length - 1);
            }
            string search = "C" + season + "?" + year + "_" + eb.m_LegacyExamBdId + ".X??";

            string[] filelist = System.IO.Directory.GetFiles(path, search);
            foreach (string f in filelist)
            {
                Stream myStream;
                string line;
                int    JCQ_Version = 0;
                if ((myStream = File.Open(f, FileMode.Open)) != null)
                {
                    using (StreamReader sr = new StreamReader(myStream))
                    {
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Substring(0, 2) == "C1")
                            {
                                JCQ_Version = System.Convert.ToInt32(line.Substring(24, 2));
                            }
                            if (line.Substring(0, 2) == "C5")
                            {
                                ExamComponent eco1 = new ExamComponent();
                                eco1.LoadFromBaseData(line, JCQ_Version, eb.m_ExamBoardId.ToString());
                                temp.Add(eco1);
                            }
                        }
                    }
                }
            }
            temp.Sort();

            return(temp);
        }
Exemplo n.º 2
0
        public Guid Find_Component(string c_file, string component, string ExamBoard, string season, string year, bool forceupdate)
        {
            ExamComponent com1   = new ExamComponent();
            Guid          com1ID = new Guid(); com1ID = Guid.Empty;
            Stream        myStream;
            string        line        = "";
            int           JCQ_Version = 0;

            //try to find in db
            com1ID = com1.Find_ComponentID(component, ExamBoard, season, year);
            if ((com1ID != Guid.Empty) && !forceupdate)
            {
                return(com1ID);
            }
            //so not in db... find in c_file and make...
            try
            {
                if ((myStream = File.Open(c_file, FileMode.Open)) != null)
                {
                    using (StreamReader sr = new StreamReader(myStream))
                    {
                        ExamComponent examcom1 = new ExamComponent();
                        ExamComponent examcom2 = new ExamComponent();//used for forced update
                        while ((line = sr.ReadLine()) != null)
                        {
                            if (line.Substring(0, 2) == "C1")
                            {
                                JCQ_Version = System.Convert.ToInt32(line.Substring(24, 2));
                            }
                            if ((line.Substring(0, 2) == "C5") && (line.Substring(2, 12) == component))
                            {
                                examcom1.m_ComponentCode = component;
                                examcom1.LoadFromBaseData(line, JCQ_Version, ExamBoard);
                                examcom1.m_season = season; examcom1.m_year = year;
                                if (com1ID != Guid.Empty)
                                {
                                    // we are doing a forced update..... and already know the ID....
                                    examcom2.Load(com1ID);//has current db version.....
                                    //now if any significant changes need to delete current scheduled components...
                                    examcom1.m_ComponentID = com1ID;
                                    if (!examcom1.EqualTo(examcom2))
                                    {
                                        ScheduledComponentList scl1 = new ScheduledComponentList();
                                        scl1.LoadList(com1ID);
                                        foreach (ScheduledComponent sc1 in scl1.m_List)
                                        {
                                            sc1.Delete();
                                        }
                                    }
                                    examcom1.Save();
                                }
                                else
                                {
                                    examcom1.Create();
                                }
                                return(Find_Component("", component, ExamBoard, season, year, false));
                            }
                        }
                    }
                }
            }
            catch (Exception e1)
            {
                System.Windows.Forms.MessageBox.Show("Error writing the component file... " + e1.Message, "File Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            }
            //not found - this could be a poblem
            System.Windows.Forms.MessageBox.Show("Warning.... Can't find a component: " + component, "Warning", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
            return(com1ID);
        }