/// <summary> /// Adds question result to xml file. /// </summary> /// <param name="parent">Xml node that contains question data.</param> /// <returns>True if result was added successfully, in any other case false. </returns> public bool AddResult(XElement parent) { XElement child = new XElement("date"); DateOperations operationsOnDate = new DateOperations(); DateTime selectedDate = DateTime.Now; if (IsCorrectAnswer && !string.IsNullOrEmpty(Answer) && IsEnabled) { //selectedDate = DateTime.Parse(_answer, CultureInfo.CurrentCulture); selectedDate = DateTime.Parse(_answer, new CultureInfo("en-US")); } child.Value = operationsOnDate.DateTimeToMiliseconds(selectedDate).ToString(); parent.Add(child); return((IsCorrectAnswer && !string.IsNullOrEmpty(Answer)) || !IsEnabled); }
/// <summary> /// Method to prepare XML file based on information about filled out survey. /// </summary> /// <returns>Return result in proper XML format.</returns> public XDocument PrepareResultDocument() { _isResultCompleted = true; DateOperations operationsOnDate = new DateOperations(); XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); DateTime centuryBegin = new DateTime(2001, 1, 1); string userId = OperationsOnSettings.Instance.IMEI; string time = operationsOnDate.DateTimeToMiliseconds(DateTime.Now).ToString(); ResultInfo.Time = time; ResultInfo.ParentId = Id; string resultId; if (string.IsNullOrEmpty(ResultInfo.Id)) { ResultInfo.Id = GenerateUniqueID(); } resultId = ResultInfo.Id; XElement root = new XElement("result", new XAttribute("r_id", resultId), new XAttribute("s_id", Id), new XAttribute("u_id", userId), new XAttribute("time", time), new XAttribute("version", 2)); if (((ResultInfo.Latitude == null) || (ResultInfo.Longitude == null))) { if (OperationsOnSettings.Instance.GPS) { var position = GPSService.Instance.Location; if (position != null) { IsGpsSet = true; XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = position.Latitude.ToString(); longitude.Value = position.Longitude.ToString(); ResultInfo.Latitude = position.Latitude.ToString(); ResultInfo.Longitude = position.Longitude.ToString(); root.Add(latitude); root.Add(longitude); OperationsOnListOfResults listOperator = new OperationsOnListOfResults(Id); listOperator.UpdateLocation(ResultInfo.Id, position.Latitude.ToString(), position.Longitude.ToString()); } else { IsGpsSet = false; } } else { IsGpsSet = true; } } else { XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = ResultInfo.Latitude; longitude.Value = ResultInfo.Longitude; root.Add(latitude); root.Add(longitude); IsGpsSet = true; } XElement titleElement = new XElement("title"); if (!string.IsNullOrEmpty(ResultInfo.Title)) { titleElement.Value = ResultInfo.Title; } root.Add(titleElement); foreach (Category category in Categories) { XElement categoryXElement = new XElement("category", new XAttribute("name", category.Name), new XAttribute("id", category.Id)); if (!category.AddResult(categoryXElement)) { _isResultCompleted = false; } root.Add(categoryXElement); } resultDocument.AddFirst(root); ResultInfo.IsResultCompleted = _isResultCompleted; return(resultDocument); }
/// <summary> /// Method to prepare XML file based on information about filled out survey. /// </summary> /// <returns>Return result in proper XML format.</returns> public XDocument PrepareResultDocument() { _isResultCompleted = true; DateOperations operationsOnDate = new DateOperations(); XDocument resultDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes")); DateTime centuryBegin = new DateTime(2001, 1, 1); string userId = OperationsOnSettings.Instance.IMEI; string time = operationsOnDate.DateTimeToMiliseconds(DateTime.Now).ToString(); ResultInfo.Time = time; ResultInfo.ParentId = Id; string resultId; if (string.IsNullOrEmpty(ResultInfo.Id)) { ResultInfo.Id = GenerateUniqueID(); } resultId = ResultInfo.Id; XElement root = new XElement("result", new XAttribute("r_id", resultId), new XAttribute("s_id", Id), new XAttribute("u_id", userId), new XAttribute("time", time), new XAttribute("version", 2)); if (((ResultInfo.Latitude == null) || (ResultInfo.Longitude == null))) { if (OperationsOnSettings.Instance.GPS) { var position = GPSService.Instance.Location; if (position != null) { IsGpsSet = true; XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = position.Latitude.ToString(); longitude.Value = position.Longitude.ToString(); ResultInfo.Latitude = position.Latitude.ToString(); ResultInfo.Longitude = position.Longitude.ToString(); root.Add(latitude); root.Add(longitude); OperationsOnListOfResults listOperator = new OperationsOnListOfResults(Id); listOperator.UpdateLocation(ResultInfo.Id, position.Latitude.ToString(), position.Longitude.ToString()); } else { IsGpsSet = false; } } else { IsGpsSet = true; } } else { XElement latitude = new XElement("latitude"); XElement longitude = new XElement("longitude"); latitude.Value = ResultInfo.Latitude; longitude.Value = ResultInfo.Longitude; root.Add(latitude); root.Add(longitude); IsGpsSet = true; } XElement titleElement = new XElement("title"); if (!string.IsNullOrEmpty(ResultInfo.Title)) titleElement.Value = ResultInfo.Title; root.Add(titleElement); foreach (Category category in Categories) { XElement categoryXElement = new XElement("category", new XAttribute("name", category.Name), new XAttribute("id", category.Id)); if (!category.AddResult(categoryXElement)) { _isResultCompleted = false; } root.Add(categoryXElement); } resultDocument.AddFirst(root); ResultInfo.IsResultCompleted = _isResultCompleted; return resultDocument; }
/// <summary> /// Method to prepare new results with right date and GPS location. /// </summary> public void PreapreResultsForTests() { DateOperations operationsOnDate = new DateOperations(); // Wynik 1_1: Data utworzenia: 2/2/2010, szerokość: 52, długość: 21 (Warszawa) Survey survey = new Survey(); survey.Display(Convert.ToInt32(SurveyId)); survey.ResultInfo.Title = "test1"; survey.ResultInfo.Latitude = "52"; survey.ResultInfo.Longitude = "21"; XDocument documentXML = survey.PrepareResultDocument(); survey.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2010, 2, 2)).ToString(); SavetTestResult(survey, documentXML); // Wynik 1_2: Data utworzenia: 2/24/2010, bez GPS Survey survey1 = new Survey(); survey1.Display(Convert.ToInt32(SurveyId)); survey1.ResultInfo.Title = "test2"; XDocument documentXML1 = survey1.PrepareResultDocument(); survey1.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2010, 2, 24)).ToString(); if (documentXML1.Element("latitude") != null) { documentXML1.Element("latitude").Remove(); } if (documentXML1.Element("longitude") != null) { documentXML1.Element("longitude").Remove(); } SavetTestResult(survey1, documentXML1); // Wynik 1_3: Data utworzenia: 5/10/2010, szerokość: 50, długość: 20 (Kraków) Survey survey2 = new Survey(); survey2.Display(Convert.ToInt32(SurveyId)); survey2.ResultInfo.Title = "test3"; survey2.ResultInfo.Latitude = "50"; survey2.ResultInfo.Longitude = "20"; XDocument documentXML2 = survey2.PrepareResultDocument(); survey2.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2010, 5, 10)).ToString(); SavetTestResult(survey2, documentXML2); // Wynik 2_1: Data utworzenia: 2/2/2011, szerokość: 50, długość: 19 (Katowice) Survey survey3 = new Survey(); survey3.Display(Convert.ToInt32(SurveyId)); survey3.ResultInfo.Title = "test4"; survey3.ResultInfo.Latitude = "50"; survey3.ResultInfo.Longitude = "19"; XDocument documentXML3 = survey3.PrepareResultDocument(); survey3.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2011, 2, 2)).ToString(); SavetTestResult(survey3, documentXML3); // Wynik 2_2: Data utworzenia: 10/2/2011, szerokość: 50, długość: 20 (Kraków) Survey survey4 = new Survey(); survey4.Display(Convert.ToInt32(SurveyId)); survey4.ResultInfo.Title = "test5"; survey4.ResultInfo.Latitude = "50"; survey4.ResultInfo.Longitude = "20"; XDocument documentXML4 = survey4.PrepareResultDocument(); survey4.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2011, 10, 2)).ToString(); SavetTestResult(survey4, documentXML4); // Wynik 3_1: Data utworzenia: 10/2/2011, szerokość: 51, długość: 17 (Wrocław) Survey survey5 = new Survey(); survey5.Display(Convert.ToInt32(SurveyId)); survey5.ResultInfo.Title = "test6"; survey5.ResultInfo.Latitude = "51"; survey5.ResultInfo.Longitude = "17"; XDocument documentXML5 = survey5.PrepareResultDocument(); survey5.ResultInfo.Time = operationsOnDate.DateTimeToMiliseconds(new DateTime(2011, 10, 2)).ToString(); SavetTestResult(survey5, documentXML5); }
/// <summary> /// Adds question result to xml file. /// </summary> /// <param name="parent">Xml node that contains question data.</param> /// <returns>True if result was added successfully, in any other case false. </returns> public bool AddResult(XElement parent) { XElement child = new XElement("date"); DateOperations operationsOnDate = new DateOperations(); DateTime selectedDate = DateTime.Now; if (IsCorrectAnswer && !string.IsNullOrEmpty(Answer) && IsEnabled) { //selectedDate = DateTime.Parse(_answer, CultureInfo.CurrentCulture); selectedDate = DateTime.Parse(_answer, new CultureInfo("en-US")); } child.Value = operationsOnDate.DateTimeToMiliseconds(selectedDate).ToString(); parent.Add(child); return (IsCorrectAnswer && !string.IsNullOrEmpty(Answer)) || !IsEnabled; }