public async Task <ActionResult> ChangeSet(int floor, int ceil, int max, bool isActiveSearch, string searchString, int requestedChange) { ActionResult actionResult = null; Json311 dataHandler = null; HomeViewModel model = new HomeViewModel() { rowHandler = new RowHandler() { Curr_min = floor, Curr_max = ceil, total = max } }; try { dataHandler = new Json311(); if (isActiveSearch) { string[] search; DateTime?start, end; string agency = null; if (searchString.Contains("-")) { search = searchString.Split('-'); start = DateTime.Parse(search[0]); if (search[1].Contains("|")) { search = search[1].Split('|'); end = DateTime.Parse(search[0]); agency = search[1]; //Create date + agency search } else { if (requestedChange > 0) { model.rowHandler.UpdateValuesUp(); } else { model.rowHandler.UpdateValuesDown(); } end = DateTime.Parse(search[1]); model.JsonData = dataHandler.GetDateFilteredList(model.rowHandler.Curr_min, model.rowHandler.Curr_max, start.Value, end.Value); } } } else { return(await ChangeSetWithoutFilter(floor, ceil, max, requestedChange)); } } catch (Exception ex) { actionResult = Json(new { Reroute = false, error = $"Error retrieving new DataSet: {ex.GetType()}" }); } return(await Task.FromResult(actionResult)); }
/// <summary> /// fill a list of our custom varible for us to display to the user /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns>Returns the data to populate the table</returns> private List <Json311> GetData(RowNumbers rows) { SqlConnect getConnection = new SqlConnect(); List <Json311> displayData; Json311 retrieve = new Json311(); rows.total = getConnection.GetRows(); displayData = retrieve.GetFullDataset(rows.Curr_min, rows.rowsRemaining); return(displayData); }
/// <summary> /// used to parse our data into our user created type instead of the dictionary that the API /// call returns /// </summary> /// <param name="dataset"> recieves out dataset, formatted in getData into an array of Dictionary objects</param> /// <returns>The data parsed into our user created class /// </returns> public List <Json311> parseData(Dictionary <string, object>[] dataset) { List <Json311> dataList = new List <Json311>(); for (int i = 0; i < dataset.Length; i++) { Json311 dItem = new Json311(dataset[i]); dataList.Add(dItem); } return(dataList); }
/// <summary> /// used to parse our data into our user created type instead of the dictionary that the API /// call returns /// </summary> /// <param name="dataset"> recieves out dataset, formatted in getData into an array of Dictionary objects</param> /// <returns>The data parsed into our user created class /// </returns> public List <Json311> ParseData(Dictionary <string, object>[] dataset) { List <Json311> dataList = new List <Json311>(); DateTime date = DateTime.Today.Date.AddDays(-1); for (int i = 0; i < dataset.Length; i++) { Json311 dItem = new Json311(dataset[i]); if (dItem.Created_date < date) { dataList.Add(dItem); } } return(dataList); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Display_dates(object sender, RoutedEventArgs e) { DateTime? start = Start.SelectedDate; DateTime? end = Start.SelectedDate; RowNumbers rows = Application.Current.Resources["RowNumbers"] as RowNumbers; SqlConnect dbconnect = new SqlConnect(); Json311 get_data = new Json311(); List <Json311> show_data = new List <Json311>(); if (!start.HasValue) { MessageBox.Show("Select a date on the left"); } else if (start.HasValue && !end.HasValue) { DateTime new_start = (DateTime)start; int year = new_start.Year; int month = new_start.Month; int date = new_start.Day; DateTime date1 = new DateTime(year, month, date, 0, 0, 0); DateTime date2 = new DateTime(year, month, date, 23, 59, 59); int num_rows = dbconnect.GetRows(date1, date2); if (num_rows == 0) { MessageBox.Show("There are no values for the selected dates"); } else { rows.filter_min = 0; if (num_rows > 500) { rows.filter_max = 500; } else { rows.filter_max = num_rows; } rows.filter_total = num_rows; rows.is_filter = true; show_data = get_data.GetDateFilteredList(0, 0, date1, date2); DBDataBinding.ItemsSource = show_data; this.NavigationService.Refresh(); } } Application.Current.Resources["RowNumbers"] = rows; }
public void JsonNull() { /// <remarks> /// Since data is often missing all fields are initialized to null if they do not have another value; /// </remarks> Json311 test = new Json311(); List <Json311> JList = new List <Json311>(); JList.Add(test); SqlConnect DBTest = new SqlConnect(); /// <remarks> /// Uses a test user who has only insert and select privelege in testtable /// </remarks> String connString = DBTest.Connect("test", "test", false); NpgsqlConnection conn = new NpgsqlConnection(connString); conn.Open(); /// <remarks> /// Check The connection /// </remarks> Assert.AreEqual(conn.State, System.Data.ConnectionState.Open); /// <remarks> /// Test the import, making sure the data is added to the right table /// and our date is not updated /// </remarks> DBTest.Import(JList, connString, "testtable", false); using (NpgsqlCommand checkValue = new NpgsqlCommand("SELECT * FROM testtable", conn)) using (NpgsqlDataReader reader = checkValue.ExecuteReader()) { while (reader.Read()) { /// <remarks> /// Since the column is empty, it will throw an invalid cast exception when /// attemption to convert it to a string /// </remarks> Assert.Throws <System.InvalidCastException>(() => { reader.GetString(0); }); } } conn.Close(); }
public async Task <ActionResult> ChangeSetWithoutFilter(int floor, int ceil, int max, int change) { ActionResult actionResult = null; Json311 dataHandler = null; HomeViewModel model = new HomeViewModel() { rowHandler = new RowHandler() { Curr_min = floor, Curr_max = ceil, total = max } }; try { dataHandler = new Json311(); if (change > 0) { model.rowHandler.UpdateValuesUp(); } else { model.rowHandler.UpdateValuesDown(); } model.JsonData = dataHandler.GetFullDataset(model.rowHandler.Curr_min, model.rowHandler.Curr_max); model.CurrentFloor = model.rowHandler.Curr_min; model.CurrentCeil = model.rowHandler.Curr_max; model.CurrentMax = max; model.ChangeDown = -500; model.ChangeUp = 500; model.ActiveSearch = false; actionResult = View("Index", model); } catch (Exception ex) { actionResult = Json(new { Reroute = false, error = $"Error retrieving new DataSet: {ex.GetType()}" }); } return(await Task.FromResult(actionResult)); }
public async Task <ActionResult> Index(HomeViewModel model) { Json311 json = new Json311(); ActionResult actionResult = null; if (model.StartDate.HasValue) { model.rowHandler = new RowHandler() { Curr_min = model.CurrentFloor, Curr_max = model.CurrentCeil, total = model.CurrentMax }; try { DateTime?start, end; start = model.StartDate; if (model.EndDate.HasValue) { end = model.EndDate.Value; } else { end = DateTime.Now; } int offset = 0; if (model.NextSet) { offset = model.CurrentCeil; } else if (model.PreviousSet) { if ((offset - 500) < 0) { offset = 0; } else { offset -= 500; } } if (offset > model.CurrentMax) { offset = 0; } model.JsonData = json.GetDateFilteredList(500, offset, start.Value, end.Value); model.CurrentFloor = offset; model.StartDate = start; model.EndDate = end; model.CurrentCeil = model.CurrentFloor + model.JsonData.Count(); model.CurrentMax = json.GetCount(start.Value, end.Value); actionResult = View(model); } catch (Exception ex) { } } else { model.JsonData = json.GetFullDataset(0, 500); model.CurrentFloor = 0; model.CurrentCeil = model.JsonData.Count(); model.CurrentMax = json.GetCount(); model.ChangeUp = 500; model.ChangeDown = -500; model.ActiveSearch = false; actionResult = View(model); } return(await Task.FromResult(actionResult)); }