DevExpress XtraReports - How to configure fields from custom datasource - asp.net-mvc-3

I'm starting using DevExpress XtraReports for the company project. My problem is the following:
I have a stored procedure that extracts the data, given three paramaters: startDay, endDay and developer ID, and this SP is inside a .dbml file.
Following this example http://www.devexpress.com/Support/Center/p/B223095.aspx, we have the this method:
static void report_DataSourceDemanded(object sender, System.EventArgs e)
{
Reports.WeeklyTimesheet report = (Reports.WeeklyTimesheet)sender;
DataClasses1DataContext context = new DataClasses1DataContext();
System.Data.Linq.ISingleResult<WeeklyTimesheetUserReportResult> res = >context.WeeklyTimesheetUserReport(Convert.ToDateTime("2012/01/16"), >Convert.ToDateTime("2012/01/20"), 52);
var result = from orderDetail in res select orderDetail;
report.DataSource = res.ToList();
}
Which is the only way i've found (that works) to pass parameters to the SP for the report.
What can i do so the report comes with the data i am sucessfully bringing but is not binding into the report? The attached images will illustrate this point better.
I have to point that when i made that report in the images, were originally formatted from a dataset using the wizard (hence why is ordered), but i have no idea how i can format it instead using the .dbml file.
Thanks in advance.
http://imgur.com/YQ7RE

XtraReport have xrTables, xrLabel controls, they will let you to create custom report and after that you can bind those cell etc and modify the XRControl bindings of the report in the following manner:
[C#]
...
// Original
//this.xrTableCell14.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
// new DevExpress.XtraReports.UI.XRBinding("Text", null, "Symbols.Description")});
// Modified
this.xrTableCell14.DataBindings.AddRange(new DevExpress.XtraReports.UI.XRBinding[] {
new DevExpress.XtraReports.UI.XRBinding("Text", null, "Description")});
...
Refer these links and samples..
Binding a Report to an Entity Framework object at runtime
[ How to
use LINQ to SQL data source to create a Master-Detail report
example

Related

How to transfer Activities (mails, notes, etc) from one contact to another in Dynamics 365

Due to some bad practices from one of our internal users. We need to transfer all activities (mails, notes, etc) from one contact to another contact. I was trying to achieve this via UI and I could not find a way to do this.
Is this possible? I'm looking for any way to achieve this, wether is CRMTool, SSIS, UI or any other way. Only admins will do this so we do not need anything fancy as it will be done maybe 4 times a year to clean up some data.
Thanks a lot :)
Tried using UI but no success.
I can think of two ways to do these updates.
The first method is selecting a view on an activity where the owner is listed (i.e. All Phone Calls) and exporting to Excel. This downloads a XLSX with some hidden columns at the start where IDs for the records are kept. You then update the owner column with the new owner (take care of copying the exact fullname), and then importing the Excel spreadsheet again. You would need to repeat this export/import steps for each activity type (phone calls, email, etc.). So this might be impractical if you have a large volume of date, because of the need to repeat and because there are max numbers of records that you can export.
The other way to do this is using some .NET code. Of course, to do this you will need to use Visual Studio 2019.
If that's the case, this will do the trick:
using System;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using Microsoft.Xrm.Tooling.Connector;
namespace ChangeActivitiesOwner
{
class Program
{
static void Main(string[] args)
{
string connectionString = "AuthType=Office365;Url=<TODO:URL>;Username=<TODO:User>;Password=<TODO:Pass>;";
string oldUserFullname = ""; // TODO: place here fullname for the user you want to overwrite
string newUserFullname = ""; // TODO: place here fullname for the user you want to overwrite with
CrmServiceClient client = new CrmServiceClient(connectionString);
IOrganizationService service = client.OrganizationWebProxyClient != null ? client.OrganizationWebProxyClient : (IOrganizationService)client.OrganizationServiceProxy;
QueryByAttribute qbyaOldUser = new QueryByAttribute("systemuser");
qbyaOldUser.AddAttributeValue("fullname", oldUserFullname);
Guid olduserid = (Guid)service.RetrieveMultiple(qbyaOldUser)[0].Attributes["systemuserid"];
QueryByAttribute qbyaNewUser = new QueryByAttribute("systemuser");
qbyaNewUser.AddAttributeValue("fullname", newUserFullname);
Guid newuserid = (Guid)service.RetrieveMultiple(qbyaNewUser)[0].Attributes["systemuserid"];
foreach (string activity in new string[]{ "task", "phonecall", "email", "fax", "appointment", "letter", "campaignresponse", "campaignactivity" }) // TODO: Add other activities as needed!!!
{
QueryExpression query = new QueryExpression(activity)
{
ColumnSet = new ColumnSet("activityid", "ownerid")
};
query.Criteria.AddCondition(new ConditionExpression("ownerid", ConditionOperator.Equal, olduserid));
foreach (Entity e in service.RetrieveMultiple(query).Entities)
{
e.Attributes["ownerid"] = new EntityReference("systemuser", newuserid);
service.Update(e);
}
}
}
}
}
Please complete the lines marked with "TODO" with your info.
You will need to add the packages Microsoft.CrmSdk.CoreAssemblies, Microsoft.CrmSdk.Deployment, Microsoft.CrmSdk.Workflow, Microsoft.CrmSdk.XrmTooling.CoreAssembly, Microsoft.IdentityModel.Clients.ActiveDIrectory and Newtonsoft.Json to your solution, and use .NET Framework 4.6.2.
Hope this helps.

How to read columns of SQL Server tables in Visual Studio?

In Microsoft Access functions like DLookup - DMax or Dcount help the programmer to read a column from a table of a SQL Server database.
How do you do the same task in Visual Studio?
For example how can I find the ID of a user (John) in tblUsers table.
tblUsers columns: ID, Username, Password, .....
I've already added the SQL Server database to the Data Source.
Any kind of advice is much appreciated.
ow. Even in Access, that isn't proper.
Go read up on DAO, ADO, and, if you're using Visual Studio to write .Net applications, the system.data namespace.
in general, when accessing relational data via non-database program code, including the vba you're using in Access, you'd retrieve a reference to a Recordset object and query each record's fields as object properties.
If you want to visualize all of the data, click Database Explorer (see the tab at the bottom of the solution explorer), then expand your data connections and right click the name of the table, then click 'show table data'. If you want only the id's or names etc, I usually just create an SQL script to run, and run it when I want to browse certain data.
To simply create a script, while you're viewing all the data, click the script button above the table your viewing. Then you can execute your script
SELECT * FROM tblUsers WHERE User = 'John';
I hope I've understood your questions correctly.
I followed DougM and ended up with the following code. I will add it here just in case somebody else has the same question:
using System.Data.SqlClient; should be added to the reference section
private void button1_Click(object sender, EventArgs e)
{
string fltr = "UserName='Ando'";
MessageBox.Show(ReadOrderData(fltr));
}
public string ReadOrderData(string filter)
{
string connectionString = "Data Source=sqlServer-servername;Initial Catalog=database name;Integrated Security=True";
string queryString = "SELECT User_ID, UserName FROM tblUsers WHERE " + filter + ";";
using (SqlConnection connection = new SqlConnection(
connectionString))
{
SqlCommand command = new SqlCommand(
queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
while (reader.Read())
{
return reader[0].ToString();
//Console.WriteLine(String.Format("{0, {1",
// reader[0], reader[1]));
}
}
finally
{
// Always call Close when done reading.
reader.Close();
}
}
return "Null";

How to decrease margin programmatically on exported BIRT PDF reports?

Is there a way to decrease the margin of the PDF reports using the BIRT API?
I tried setting the PDF rendering options to:
PDFRenderOption renderOption = new PDFRenderOption();
renderOption.setOutputFormat(PDFRenderOption.OUTPUT_FORMAT_PDF);
renderOption.setOption(IPDFRenderOption.PDF_HYPHENATION, true);
renderOption.setOption(IPDFRenderOption.PDF_TEXT_WRAPPING, true);
renderOption.setOption(IPDFRenderOption.PAGE_OVERFLOW,
IPDFRenderOption.ENLARGE_PAGE_SIZE);
Basically the problem I have is that if I have a longer text in a column (from one of the tables) it will get it on the next line, but if I set the IPDFRenderOption.PDF_HYPHENATION to false I will get the text split right in the middle of the text (see below).
PDF with IPDFRenderOption.PDF_HYPHENATION set to true
PDF with IPDFRenderOption.PDF_HYPHENATION set to false
So, I was trying to set the margin of the PDF to be smaller to overcome this issue, but I don't find any documentation on how to do this with the BIRT API...
There is this suggestion of modifying the master page, but I have way too many reports to modify them by hand.
How should I approach the problem? Is this even possible using the BIRT API?
All I needed to do was to loop through all the handles, test which of them is a MasterPageHandle and call setProperty with these keys:
MasterPageHandle.BOTTOM_MARGIN_PROP
MasterPageHandle.LEFT_MARGIN_PROP
MasterPageHandle.RIGHT_MARGIN_PROP
MasterPageHandle.TOP_MARGIN_PROP
and the DimensionValue I needed.
Code sample
#SuppressWarnings("unchecked")
private void shrinkPageSizeForExport(IReportRunnable reportRunnable) {
DesignElementHandle designHandle = reportRunnable.getDesignHandle();
IElementDefn elementDefn = designHandle.getDefn();
for (int i = 0; i < elementDefn.getSlotCount(); i++) {
SlotHandle slotHandle = designHandle.getSlot(i);
for (DesignElementHandle elementHandle: (List<DesignElementHandle>)slotHandle.getContents()) {
if (!(elementHandle instanceof MasterPageHandle)) continue;
MasterPageHandle mph = (MasterPageHandle)elementHandle;
DimensionValue dv = new DimensionValue(0.1, "cm");
setAllMarginsTo(mph, dv);
}
}
}
private void setAllMarginsTo(MasterPageHandle mph, DimensionValue dv) {
try {
mph.setProperty(MasterPageHandle.BOTTOM_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.LEFT_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.RIGHT_MARGIN_PROP, dv);
mph.setProperty(MasterPageHandle.TOP_MARGIN_PROP, dv);
} catch (SemanticException se) {
throw new RuntimeException("Cannot set margins for report export!", se);
}
}
Alternate suggestion:
Build a MasterPage in your BIRT library, and use it on all reports. Then all reports it is used on can be updated at one time. If you did not start with library MasterPages, you can replace the report MasterPage with the library master page, quicker then trying to recode them all.
Things like DataSources, and MasterPages are almost always better as library items.

could not select subreport - .rdlc - VS 2010

I had created many reports with VS 2008. Now starting with VS 2010 for new requirement. Please note I am using .rdlc report
I could add subreport control to the report but could not select the available reports. There is no browse button or a dropdown to choose the available .rdlc report.
When I manually type the report name, the reportviewer doesnt show up any subreport. I dont see any error message on the 'Output' window either.
How do I use subreport with VS 2010? Am I missing anything? Any help is appreciated.
I have SQL 2005/2008 (report services installed), VS 2008, VS 2010 installed on the same PC.
First select sub report from Toolbox and put where you want to show.See the image bellow
Now right click on sub report properties and type your sub report name .
Now You have to create a sub report even handler in your .cs file from where you load your report like that:
public Ctor()
{
string path = HttpContext.Current.Server.MapPath("Your Report path");
ReportViewer1.Reset(); //important
ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
ReportViewer1.LocalReport.SubreportProcessing += Process_Subreport;
LocalReport objReport = ReportViewer1.LocalReport;
objReport.ReportPath = path;
// Add Parameter If you need
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("Name", Value));
ReportViewer1.LocalReport.SetParameters(parameters);
ReportViewer1.ShowParameterPrompts = false;
ReportViewer1.ShowPromptAreaButton = false;
ReportViewer1.LocalReport.Refresh();
//Add Datasourdce
ReportDataSource reportDataSource = new ReportDataSource();
reportDataSource.Name = "Datasource Name Used due to report design";
reportDataSource.Value = DataSourceValue;
objReport.DataSources.Add(reportDataSource);
objReport.Refresh();
}
Now Create Even Handler Method to load sub report details.
private void Process_Subreport(object sender, SubreportProcessingEventArgs e)
{
//You can get parameter from main report
int paramname = int.Parse(e.Parameters[0].Values[0].ToString());
//You can also add parameter in sub report if you need like main report
//Now add sub report data source
e.DataSources.Add(new ReportDataSource("DataSource Name",DataSourceValue)));
}
I think it will be works for you.Thank you.

Issue Retrieving a Screenshot from a database

I've got a bunch of screenshots and some screenshot meta data I'm trying to display in an ASP.NET MVC 3 web application, I'm trying to retrieve the data from my databse but I get this error:
LINQ to Entities does not recognize the method 'System.Drawing.Image
ByteArrayToImage(Byte[])' method, and this method cannot be translated
into a store expression.
Here's my code:
var screenshotData = (from screenshots in db.screenshots
where screenshots.projects_ID == projectID
select new ImageInformation
{
ID = screenshots.id,
Language = screenshots.language,
Screenshot = Utility.ByteArrayToImage(screenshots.screen_shot),
ProjectID = screenshots.projects_ID
});
foreach (ImageInformation info in screenshotData)
{
this.Add(info);
}
ImageInformation is just a simple class that contains the defintion the information stored (ID, Language, Screenshot, ProjectID).
Here's my ByteArrayToImage function:
public static Image ByteArrayToImage(byte[] byteArrayIn)
{
using (MemoryStream ms = new MemoryStream(byteArrayIn))
{
Image returnImage = Image.FromStream(ms);
return returnImage;
}
}
Can anybody tell me why I receive this error when this code runs?
Thanks.
I think it's because, with LINQ-to-Entities, the code is turned into server-side query and it can't do that in this case. I don't think you can mix client-side code like this directly with L2E.
I would suspect you will have to do the conversion from byte->image after you've retrieved the data from the database as a distinct step.
You can't do the function in a LINQ to Entities query... one option:
1) have a byte[] property on the object you are instantiating (ImageInformation) and copy the data in there along with another propery to read the image from this ImageInformation object.

Resources