Exemple #1
0
        public Report GetForms(Report report)
        {
            try
            {
                MySqlDataReader reader = null;
                conn.Open();

                string       sqlStatement = "SELECT * FROM forms WHERE report_id=@report_id";
                MySqlCommand command      = new MySqlCommand(sqlStatement, conn);
                command.Prepare();
                command.Parameters.AddWithValue("@report_id", report.reportID);

                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    String        formID    = reader["form_id"].ToString();
                    String        fieldsXML = reader["fields_xml"].ToString();
                    Form          tempForm  = new Form("");
                    XmlSerializer ser       = new XmlSerializer(tempForm.GetType());
                    using (TextReader tReader = new StringReader(fieldsXML))
                    {
                        tempForm = (Form)ser.Deserialize(tReader);
                    }

                    report.AddForm(tempForm);
                }
                conn.Close();
                return(report);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Gets all reports under a casefile.
        /// </summary>
        /// <param name="caseFile"></param>
        /// <returns></returns>
        public List <Report> GetReports(CaseFile caseFile)
        {
            List <Report> reports = new List <Report>();

            try
            {
                WebRequest request = WebRequest.Create(reportSyncAddress + "?case_id=" + caseFile.caseID);
                request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                request.Method      = "GET";
                using (WebResponse response = request.GetResponse())
                {
                    using (StreamReader stream = new StreamReader(response.GetResponseStream()))
                    {
                        string pagesource = stream.ReadToEnd();
                        if (pagesource == "")
                        {
                            return(null);
                        }
                        else
                        {
                            string[] result = pagesource.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            foreach (string reportLine in result)
                            {
                                string[] reportResult = reportLine.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries);
                                Report   temp         = new Report(reportResult[2] + "_Report", reportResult[2], reportResult[2], caseFile);
                                temp.reportID     = reportResult[0].ToString();
                                temp.lastModified = DateTime.Parse(reportResult[3]).ToLocalTime();
                                FormSyncer formSyncer = new FormSyncer();
                                foreach (Form form in formSyncer.GetForms(temp))
                                {
                                    temp.AddForm(form);
                                }
                                reports.Add(temp);
                            }

                            return(reports);
                        }
                    }
                }
            } catch (WebException e)
            {
                Console.WriteLine(e.Message);
                UserPrefs.isOnline = false;
                return(reports);
            }
        }
Exemple #3
0
        private static void TestForm()
        {
            CaseFile caseFile = new CaseFile("case00001", "Steve's assisted living", 00004);
            Report   report   = caseFile.AddReport("kenny00001", "kenny");
            Form     form     = report.AddForm(new Form("formA"));
            User     testUser;


            Console.WriteLine(caseFile);

            Console.WriteLine("Testing users");
            UserSyncer userSyncer = new UserSyncer();

            userSyncer.CreateUser("tester", "tpassword", "Bob", false);
            Console.WriteLine("Testing valid login info");
            testUser = userSyncer.Login("tester", "tpassword");
            Console.WriteLine("Testing invalid login info");
            userSyncer.Login("tester", "asd");
            Console.WriteLine("Testing colliding usernames user creation");
            userSyncer.CreateUser("tester", "tPassword", "Bill", true);

            CaseFileSyncer syncer = new CaseFileSyncer();

            Console.WriteLine("Testing inserting case file into database");
            //syncer.SyncCaseFile(caseFile, testUser);
            caseFile.Sync(testUser);
            Console.WriteLine("Testing updating case file already in database");
            CaseFile caseFile2 = new CaseFile("case00001", "Bob's assisted living", 00004);

            //syncer.SyncCaseFile(caseFile2, testUser);
            caseFile2.Sync(testUser);
            CaseFile caseFile3 = new CaseFile(caseFile2.caseID, "Bob's existing living", 00004);

            syncer.UpdateCaseFile(caseFile3);

            CaseFile databaseCaseFile = new CaseFile("14", "invalid", -1);

            //databaseCaseFile = syncer.SyncCaseFile(databaseCaseFile, testUser);
            databaseCaseFile.Sync(testUser);
            Console.WriteLine(databaseCaseFile);



            string dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "testXML");

            XmlSerializer ser = new XmlSerializer(caseFile.GetType());

            using (TextWriter writer = new StreamWriter(dir + @"\groupTest.xml"))
            {
                ser.Serialize(writer, caseFile);
            }


            Console.WriteLine("\n    >done!");
            Console.WriteLine("    >Now reading from file!");


            CaseFile readField;

            using (TextReader reader = new StreamReader(dir + @"\groupTest.xml"))
            {
                readField = (CaseFile)ser.Deserialize(reader);
            }

            Console.WriteLine(readField);
        }