Exemplo n.º 1
0
        /// <summary>
        /// Creates/Updates a casefile on the database and also adds the reports/forms.
        /// </summary>
        /// <param name="file"></param>
        public void InsertCaseFile(CaseFile file)
        {
            if (GetCaseInfo(file.caseID) == null)
            {
                try
                {
                    using (WebClient client = new WebClient())
                    {
                        NameValueCollection postData = new NameValueCollection()
                        {
                            { "facility_name", file.facilityName },
                            { "facility_license", file.facilitylicenseNumber.ToString() }
                        };
                        string pagesource = Encoding.UTF8.GetString(client.UploadValues(caseSyncAddress, postData));
                        file.caseID = pagesource;
                    }
                } catch (WebException e)
                {
                    Console.WriteLine(e.Message);
                    UserPrefs.isOnline = false;
                }
            }
            else
            {
                UpdateCaseFile(file);
            }

            ReportSyncer reportSyncer = new ReportSyncer();

            foreach (Report report in file.reports)
            {
                reportSyncer.InsertReport(report);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a casefile. Also gets all the reports and forms included with it.
        /// </summary>
        /// <param name="caseFileID"></param>
        /// <returns></returns>
        public CaseFile GetCaseFile(string caseFileID)
        {
            try
            {
                WebRequest request = WebRequest.Create(caseSyncAddress + "?case_id=" + caseFileID);
                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();
                        Console.WriteLine(pagesource);
                        if (pagesource == "invalid")
                        {
                            return(null);
                        }
                        else
                        {
                            string[] result = pagesource.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
                            CaseFile temp   = new CaseFile(result[0], result[0], int.Parse(result[1])); //changed this
                            temp.caseID = caseFileID;
                            if (int.Parse(result[2]) == 1)
                            {
                                temp.CloseCase();
                            }
                            foreach (string username in AssignedUsers(caseFileID))
                            {
                                temp.AssignUser(username);
                            }
                            List <Report> reports = new ReportSyncer().GetReports(temp);
                            foreach (Report report in reports)
                            {
                                temp.AddReport(report);
                            }

                            return(temp);
                        }
                    }
                }
            } catch (WebException e)
            {
                Console.WriteLine(e.Message);
                UserPrefs.isOnline = false;
                return(null);
            }
        }