Esempio n. 1
0
        public static bool ConnectToDB()
        {
            log.Info("Connecting to Access DB...");
            gui.UpdateStatus("Connecting to Access DB...");
            Cursor.Current = Cursors.WaitCursor;

            string connStr = Schools.GetPath(school);

            using (OleDbConnection conn = new OleDbConnection(connStr)) {
                OleDbCommand command = new OleDbCommand("SELECT * FROM CalPERS_ID_Dep", conn);
                log.Info("Conn String: " + connStr);

                try {
                    conn.Open();
                    using (OleDbDataReader reader = command.ExecuteReader()) {
                        Console.WriteLine("------------DATA--------------");
                        log.Info("CalPERS_ID_Dep data loaded");
                        while (reader.Read())
                        {
                            CIDEntry tempCIDE = new CIDEntry(
                                reader["EID"].ToString(),
                                reader["First Name"].ToString(),
                                reader["Last Name"].ToString(),
                                reader["Relationship"].ToString(),
                                reader["Birth Date"].ToString(),
                                reader["CalPERS ID"].ToString());
                            cidList.Add(tempCIDE);
                            log.Info(tempCIDE.ToString());
                        }
                    }

                    //load a list of people in calpers as unrepresent 007
                    try {
                        command = new OleDbCommand("SELECT * FROM CalPERS_HEInfo", conn);
                        using (OleDbDataReader reader = command.ExecuteReader()) {
                            Console.WriteLine("------------DATA--------------");
                            log.Info("CalPERS_HEInfo data loaded");
                            while (reader.Read())
                            {
                                HEInfo heiTemp = new HEInfo(
                                    reader["CalPERS_ID"].ToString(),
                                    reader["First Name"].ToString(),
                                    reader["Last Name"].ToString(),
                                    reader["HEZip"].ToString(),
                                    reader["HEType"].ToString(),
                                    reader["Medical Group"].ToString());
                                HEinfoList.Add(heiTemp);

                                //add to the unrepped list
                                if (heiTemp.MedicalGroup == "007 UNREPRESENTED")
                                {
                                    Unreped.Add(heiTemp.CalPERS_ID);
                                }
                            }
                            log.Info("Finished loading CalPERS_HEInfo: " + Unreped.Count);
                        }
                    } catch (Exception e1) {
                        Console.WriteLine(e1.Message);
                        log.Error(e1.Message);
                        gui.UpdateStatus(e1.Message);
                        return(false);
                    }
                } catch (Exception e) {
                    Console.WriteLine(e.Message);
                    log.Error(e.Message);
                    gui.UpdateStatus(e.Message);
                    return(false);
                }
            }
            log.Info("Connected to DB");
            gui.UpdateStatus("Connected to Access DB! Load File Next");
            Cursor.Current = Cursors.Default;
            return(true);
        }