Why is my report not showing data in devExpress XtraReport? - c#

I'm creating a report in VS2013 C# winform application using devExpress XtraReport. I'm trying to use a table in the entity framework as the datasource. I tried this using a binding source, but the data does not show.
From my dataProvider class:
public static List<vwInventoryRequestReport> GetView(int docNo)
{
var items = new List<vwInventoryRequestReport>();
using (var context = new Sage300Entities())
{
var query = from i in context.vwInventoryRequestReports
where i.InventoryRequestHeaderId == docNo
select i;
items = query.ToList();
}
return items;
}
From my main class:
var docNo = Convert.ToInt32(teDocumentNumber.Text);
var items = DataProvider.GetView(docNo);
this.bindingSource2.DataSource = items;
InventoryRequestReport report = new InventoryRequestReport();
report.DataSource = items;
ReportPrintTool tool = new ReportPrintTool(report);

Related

Reading DataCollection<Entity> from Dynamics CRM using C#

I am trying to pull and read the entity from Dynamics CRM using C#. I am using retrieveMultiple method and all I am getting is Microsoft.Xrm.Sdk.OptionSetValue. When I debug I see 1000 records but every record is showing the same text Microsoft.Xrm.Sdk.OptionSetValue. What am I doing wrong here?
QueryExpression bookQuery = new QueryExpression("new_res")
{
ColumnSet = new ColumnSet("new_book"),
Criteria =
{
Conditions =
{
new ConditionExpression()
{
AttributeName="new_bookid",
Operator = ConditionOperator.NotNull
}
}
}
};
DataCollection<Entity> bookList = service.RetrieveMultiple(bookeQuery).Entities;
foreach (var c in bookList)
{
Console.WriteLine(c.Attributes["new_bookid"]);
}
I just needed to use an EntityCollection:
EntityCollection bookList = (EntityCollection)service.RetrieveMultiple(bookQuery);
if (bookList.Entities.Count > 0)
{
var record = bookList.Entities[0];
var recordNumberString = string.Empty;
}

Could not load file or assembly 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

I am trying to develop a web application that displays some charts based on different data that is stored in a database. I found on different tutorials online that I should transfer the data from the controller to the view using a model and then to use Json.Encode for the data to be read correctly by my chart.
First it didn't recognize Json.Encode method, so I had to use NuGet Packet Manager to install Microsoft.AspNet.WebPages and when I try to run the app, this error pops up.
I am using .NET Core 5.0
This is where the error comes in:
<script type="text/javascript">
var chart = document.getElementById('pie').getContext('2d');
var myChart = new Chart(chart, {
type: 'pie',
data : #Html.Raw(System.Web.Helpers.Json.Encode(Model.PieChartData)),
});
</script>
This is how I build the model that is given to the view:
public PieChartVM GetPieChartData()
{
var model = new PieChartVM();
var labels = new List<string>();
labels.Add("Green");
labels.Add("Blue");
labels.Add("Gray");
labels.Add("Purple");
model.labels = labels;
var dataset = new List<PieChartChildVM>();
var childModel = new PieChartChildVM();
var backgroundColorList = new List<string>();
var dataList = new List<int>();
foreach(var label in labels)
{
if (label == "Green")
{
backgroundColorList.Add("#2ecc71");
dataList.Add(12);
}
if (label == "Blue")
{
backgroundColorList.Add("#3498db");
dataList.Add(20);
}
if (label == "Gray")
{
backgroundColorList.Add("#95a5a6");
dataList.Add(18);
}
if (label == "Purple")
{
backgroundColorList.Add("#9b59b6");
dataList.Add(50);
}
}
childModel.backgroundColor = backgroundColorList;
childModel.data = dataList;
dataset.Add(childModel);
model.datasets = dataset;
return model;
}
Have you tried this:
using System.Text.Json.Serialization;
string jsonString = JsonSerializer.Serialize(yourModel);
OR
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
var jsonModel = serializer.Serialize(YOURMODEL);

Generate PDF with Telerik Reporting with .NET Core

Currently, we want to implement a PDF generator with telerik reporting.
We would like to create the PDF with our own customized designer template and supply it with a data model.
The following code shows a route that will export a PDF file with the template: "confirmation.trdp" (see attachment).
It's a dummy file that I created for testing purpose.
Here is the source code I have:
public IActionResult Pdf()
{
// mock data
var dataModel = new MockData
{
Name = "Terence",
Amount = 1000
};
var dataSource = new Telerik.Reporting.ObjectDataSource
{
DataSource = dataModel
};
var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
var reportSource = new Telerik.Reporting.UriReportSource
{
Uri = "PDF/confirmation.trdp"
};
//reportSource.Parameters
var result = reportProcessor.RenderReport("PDF", reportSource, null);
var output = result.DocumentBytes;
return File(output, "application/pdf");
}
Here is the template I created from Telerik Report Designer
Here is my question:
How can I bind the text boxes with the data model in the pdf file? And how to configure the.trdp template for that?
You need to parse *.trdp file to Telerik Report object.
var reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
var deviceInfo = new System.Collections.Hashtable();
var reportPackager = new ReportPackager();
Report report;
InstanceReportSource instanceReportSource = new InstanceReportSource();
using (var sourceStream = System.IO.File.OpenRead(path))
{
report = (Report)reportPackager.UnpackageDocument(sourceStream);
}
After that you can change report datasource. For example (with JsonDataSource):
var ds = new JsonDataSource
{
DataSelector = "$",
Source = JsonConvert.SerializeObject(model,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
})
};
report.DataSource = ds;
instanceReportSource.ReportDocument = report;
Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", instanceReportSource, deviceInfo);
If you are using Telerik Reports in .NET Core don't forget to add all NuGet dependencies.
https://docs.telerik.com/reporting/use-reports-in-net-core-apps

Get Data from SQLite into ArrayAdapter / ListView - Android C# Xamarin

I am trying to get the data from my SQLite table into a List<string> and then into an ArrayAdapter<string> and into a ListView.
How would I get the data pulled from the below code, into a ListView using an ArrayAdapter?
DB Helper.cs:
public List<string> getNoteList()
{
List<string> noteList = new List<string>();
SQLiteDatabase db = this.ReadableDatabase;
ICursor cursor = db.Query(DB_TABLE, new string[] { DB_COLUMN}, null, null, null, null, null);
while (cursor.MoveToNext())
{
int index = cursor.GetColumnIndex(DB_COLUMN);
noteList.Add(cursor.GetString(index));
}
return noteList;
}
As you can see it is put into noteList, but how would I code an array adapter so that the noteList goes into a ListView?
UPDATE 1: MainActivity.cs
public void LoadNoteList()
{
List<string> noteList = dbHelper.getNoteList();
adapter = new ArrayAdapter<string>(this, Resource.Layout.list_black_text, noteList);
lvNotes.Adapter = adapter;
}
Error:
Change noteList's type to ArrayList and add follow line at the place after your ListView being initialization
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, noteList);
listview.setAdapter(adapter);
try this
here cards is my linked-list
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_single_choice);
for (MerchantCard card : cards) {
arrayAdapter.add(card.getName());
}
ListView listView = (ListView) mView.findViewById(R.id.listView);
listView.setAdapter(arrayAdapter);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectedCardTypeId = cards.get(position).getId();
Log.d("request", cards.get(position).getId() + " " + cards.get(position).getName());
}
});

Getting full contents of a Datagrid using UIAutomation

I have need to retrieve all of the items in a Datagrid from an external application using UIAutomation. Currently, I can only retrieve (and view in UISpy) the visible items. Is there a way to cache all of the items in the Datagrid and then pull them? Here's the code:
static public ObservableCollection<Login> GetLogins()
{
ObservableCollection<Login> returnLogins = new ObservableCollection<Login>();
var id = System.Diagnostics.Process.GetProcessesByName("<Name here>")[0].Id;
var desktop = AutomationElement.RootElement;
var bw = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ProcessIdProperty, id));
var datagrid = bw.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.AutomationIdProperty, "lv"));
var loginLines = datagrid.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.DataItem));
foreach (AutomationElement loginLine in loginLines)
{
var loginInstance = new Login { IP = new IP() };
var loginLinesDetails = loginLine.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Custom));
for (var i = 0; i < loginLinesDetails.Count; i++)
{
var cacheRequest = new CacheRequest
{
AutomationElementMode = AutomationElementMode.None,
TreeFilter = Automation.RawViewCondition
};
cacheRequest.Add(AutomationElement.NameProperty);
cacheRequest.Add(AutomationElement.AutomationIdProperty);
cacheRequest.Push();
var targetText = loginLinesDetails[i].FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TextBlock"));
cacheRequest.Pop();
var myString = targetText.Cached.Name;
#region Determine data and write to return object
//Removed private information
#endregion
}
}
returnLogins.Add(loginInstance);
}
return returnLogins;
}
You can only retrieve the visible cells because you have table virtualization on.
Try disabling the virtualization (not always possible in all application but perhaps you want to move it into configuration and change it before testing)
I am 99% sure that this is not possible. UI Automation doesn't know about the data structures which are represented by the currently visible portion of a grid. It only sees what is visible. I think that you will have to page through the grid to get all the data (that is what I do).

Categories