public FunctionResult_Models GetEntriesCSV(Options_Models Options) { using (var db = new BaseEntities()) { var FunctRes = new FunctionResult_Models(true); var Query = db.Schedules.Where(s => s.AppId == Options.AppId); //Filter Validity var query = Query.AsEnumerable(); var Excludes = ScheduleExclusionFields.ToList(); //Hide these 2 Excludes.Add("SchedulesId"); if (query.Count() == 0) { return(new FunctionResult_Models(false) { message = "No Entries Found!" }); } FunctRes.DataHeaders = ExcludeHeaders(query.FirstOrDefault(), Excludes); FunctRes.DataAsDictionary = query.OrderByDescending(s => s.CreatedOn).ThenByDescending(s => s.AppId).Select(s => ExcludeHeaders(s.GetType().GetProperties().Where(p => p.GetMethod.IsVirtual == false).ToDictionary(prop => prop.Name, prop => prop.GetValue(s, null)), Excludes, true). ToDictionary(prop => prop.Key, prop => prop.Value)).ToList(); return(FunctRes); } }
public void ExportToCsv_click(object sender, EventArgs e) { //Validate Input int integer; //Needs to Test if (Int32.TryParse(CurrentPage.Text, out integer) == false) { lblModal.Text = "Please select a proper page!"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } if (lblTotal.Text != "" && (Int32.TryParse(CurrentPage.Text, out integer) == false || Convert.ToInt32(CurrentPage.Text) < 1 || Convert.ToInt32(CurrentPage.Text) > repo.calculateLastPage(Convert.ToInt32(lblTotal.Text), PageSize))) { lblModal.Text = "Please select a proper page!"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } var Options = new Options_Models() { AppId = appId }; var Result = repo.GetEntriesCSV(Options); if (!Result.Valid) { lblModal.Text = Result.message; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } //json = SARepository.SerializerHelper(new Dictionary<string, object>() { // { "Count" , Query.Count() }, // { "Entries" , retblock}, // { "EntriesHeader" , headers} // }); var dt = repo.ListOfDictionaryToDataTable(Result.DataAsDictionary); string headers = string.Join(",", Result.DataHeaders.ToArray()); GeneralFunctions.ExportToCsv(dt, headers, "entries"); }
public FunctionResult_Models GetEntries(Options_Models Options) { using (var db = new BaseEntities()) { var FunctRes = new FunctionResult_Models(true); var Query = db.Schedules.Where(s => s.AppId == Options.AppId); Query = Options.isPast.ToUpper() == "True".ToUpper() ? Query.Where(s => s.EventDate < DateTime.UtcNow): Query.Where(s => s.EventDate >= DateTime.UtcNow); Query = Options.ValidOnly.ToUpper() == "Valid".ToUpper() ? Query.Where(s => (bool)s.IsValid == true) : Options.ValidOnly.ToUpper() == "Invalid".ToUpper() ? Query.Where(s => (bool)s.IsValid == false) : Query; Query = Options.isSent.ToUpper() == "True".ToUpper() ? Query.Where(s => (bool)s.IsSent == true) : Options.isSent.ToUpper() == "False".ToUpper() ? Query.Where(s => (bool)s.IsSent == false) : Query; //Other Filters? var query = Query.OrderByDescending(s => s.AppId).Skip((Options.Page - 1) * Options.PageSize).Take(Options.PageSize).AsEnumerable(); //var SAS = GetSASToken(); var count = query.Count(); FunctRes.TotalCount = Query.Count(); if (count == 0) { return(new FunctionResult_Models(false) { message = "No Entries Found!" }); } FunctRes.DataHeaders = ExcludeHeaders(query.FirstOrDefault(), ScheduleExclusionFields.ToList()); FunctRes.DataAsDictionary = ConvertEntriesToDictionary(query, ScheduleExclusionFields.ToList()); return(FunctRes); } }
//protected void Filter_Click(object sender, EventArgs e) //{ // //Validate Input // int integer; // //Needs to Test // if (Int32.TryParse(CurrentPage.Text, out integer) == false) // { // lblModal.Text = "Please select a proper page!"; // ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); // return; // } // if (lblTotal.Text != "" && // (Int32.TryParse(CurrentPage.Text, out integer) == false || // Convert.ToInt32(CurrentPage.Text) < 1 || // Convert.ToInt32(CurrentPage.Text) > repo.calculateLastPage(Convert.ToInt32(lblTotal.Text), PageSize))) // { // lblModal.Text = "Please select a proper page!"; // ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); // return; // } // var Options = new Options_Models() // { // isSent = ddlIsSent.SelectedValue, // Page = Convert.ToInt32(CurrentPage.Text), // PageSize = PageSize, // AppId = appId // }; // var Result = repo.GetEntries(Options); // if (!Result.Valid) // { // lblModal.Text = Result.message; // ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); // return; // } // //json = SARepository.SerializerHelper(new Dictionary<string, object>() { // // { "Count" , Query.Count() }, // // { "Entries" , retblock}, // // { "EntriesHeader" , headers} // // }); // lblTotal.Text = Result.TotalCount.ToString(); // lblTotalPages.Text = repo.calculateLastPage(Convert.ToInt32(lblTotal.Text), PageSize).ToString(); // var dt = repo.ListOfDictionaryToDataTable(Result.DataAsDictionary); // EntriesGV.DataSource = dt; // Paging? // EntriesGV.DataKeyNames = Result.DataHeaders.ToArray(); // EntriesGV.DataBind(); // if (User.Identity.IsAuthenticated && User.IsInRole("Superusers")) // { // PurgeDiv.Visible = true; // //PurgeSel.Visible = true; // } // else // { // PurgeDiv.Visible = false; // PurgeSel.Visible = true; // } // ExportDiv.Visible = true; // PagingDiv.Visible = true; // LoadedDiv.Visible = true; //} protected void ShowEntries() { //Validate Input int integer; //Needs to Test if (Int32.TryParse(CurrentPage.Text, out integer) == false) { lblModal.Text = "Please select a proper page!"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } var Options = new Options_Models() { ValidOnly = ddlValidity.SelectedValue, isSent = ddlIsSent.SelectedValue, isPast = radEvents.SelectedValue, Page = Convert.ToInt32(CurrentPage.Text), PageSize = PageSize, AppId = appId }; var Result = repo.GetEntries(Options); lblTotal.Text = Result.TotalCount.ToString(); if (lblTotal.Text != "" && (Int32.TryParse(CurrentPage.Text, out integer) == false || Convert.ToInt32(CurrentPage.Text) < 1 || Convert.ToInt32(CurrentPage.Text) > repo.calculateLastPage(Convert.ToInt32(lblTotal.Text), PageSize))) { lblModal.Text = "Please select a proper page!"; ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } if (!Result.Valid) { //lblModal.Text = Result.message; //ScriptManager.RegisterStartupScript(this, this.GetType(), "myModal", "$('#divPopUp').modal('show');", true); return; } //json = SARepository.SerializerHelper(new Dictionary<string, object>() { // { "Count" , Query.Count() }, // { "Entries" , retblock}, // { "EntriesHeader" , headers} // }); lblTotalPages.Text = repo.calculateLastPage(Convert.ToInt32(lblTotal.Text), PageSize).ToString(); var dt = repo.ListOfDictionaryToDataTable(Result.DataAsDictionary); EntriesGV.DataSource = dt; // Paging? EntriesGV.DataKeyNames = Result.DataHeaders.ToArray(); EntriesGV.DataBind(); if (User.Identity.IsAuthenticated && User.IsInRole("Superusers")) { PurgeDiv.Visible = true; //PurgeSel.Visible = true; } else { PurgeDiv.Visible = false; PurgeSel.Visible = true; } ExportDiv.Visible = true; PagingDiv.Visible = true; LoadedDiv.Visible = true; }