|
Sorry, looks like my answer was wrong.
The sample you pasted is using the separate PdfSharp.Charting assembly, which is why I couldn't see the Chart type in the PdfSharp assembly. It looks like it comes from this example[^], which demonstrates how to add the chart to a PDF file using a ChartFrame :
PdfPage page = document.AddPage();
page.Size = PageSize.A4;
Chart chart = CombinationChart();
ChartFrame = new ChartFrame();
chartFrame.Location = new XPoint(30, 30);
chartFrame.Size = new XSize(500, 600);
chartFrame.Add(chart);
XGraphics gfx = XGraphics.FromPdfPage(page);
chartFrame.Draw(gfx);
document.Close();
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
Create a bitmap from the chart. If you're using WPF, you can create a bitmap (RenderTargetBitmap) from the chart's visual.
Use PdfSharp to convert the bmp to an XImage and draw it on the page using .DrawImage.
|
|
|
|
|
Yes, for me it is difficult too) I will try to make so, will search sample in internet, i am not similar with this method too...
thank you...
|
|
|
|
|
Yes; Google is your friend.
Once you have a bmp from your chart, it's easy.
Give it a try (making a bmp) and if you get stuck, come back here (with what you've tried).
|
|
|
|
|
I am trying to write a small search functionality in LINQ-to-SQL (with Sharp Repository and Entity Framework) where given a string value, I should be able to search it through all properties and return the entities which have the input string value "Contained" (as in someString.Contains ) in any of their properties (with "searchable" types like int, long, etc since search by ID should be possible).
I have written a method which does this for a "single" string property (which was the requirement earlier ) and returns an Expression predicate which I pass to my SharpRepository instance as the selector.
public static Expression<Func<T, bool>> ContainsExpression<T>(string propertyName, string propertyValue)
{
var parameterExpression = Expression.Parameter(typeof(T), typeof(T).Name);
var propertyExpression = Expression.PropertyOrField(parameterExpression, propertyName);
var stringTypeArray = new[] { typeof(String) };
var containsMethod = typeof(String).GetMethod("Contains", stringTypeArray);
var valueToBeChecked = Expression.Constant(propertyValue, typeof(String));
var finalContainsExpression = Expression.Call(propertyExpression, containsMethod, valueToBeChecked);
return Expression.Lambda<Func<T, bool>>(finalContainsExpression, parameterExpression);
}
I have even tried overriding ToString() method in my entity (simple Employee type at the moment) as:
public override string ToString()
{
string instance = String.Concat(Id, ",", Name, ",", Department, ",", DateOfJoining.ToString("dd-MMM-yyyy"), ",", Salary);
return instance;
} and then generate an Expression as:
Employee => Employee.ToString().Contains(ValueToBeSearched)
But needless to say, the first one won't work for the types other than String (since I will need to do someTypeOtherThanString.ToString().Contains(..) which is not supported in LINQ-to-SQL and the later one also won't work due to the similar reason!
I do know that I can simply write an SP for this functionality, I want to know if there's a way to achieve this using LINQ-to-SQL. Also, I need to pass the Expression as the selector to my SharpRepository instance so although I am not sure if a .ToList<T>() on all entities followed by a filter expression will work, unfortunately I am not open to that, I would rather write an SP.
[EDIT]
Just came across SqlFunctions[^].StringConvert() method overloads. Unfortunately they only support numeric types. But I think I have the necessary things to go ahead with string and numeric types. Will see what could be done for rest of the types, if they exist at all and should be search-enabled.
[/EDIT]
Any pointers will be appreciated. Thanks!
Your time will come, if you let it be right.
modified 28-Oct-14 1:58am.
|
|
|
|
|
Agent__007 wrote: I do know that I can simply write an SP for this functionality, I want to know
if there's a way to achieve this using LINQ-to-SQL Even if it is possible, the SP is still the recommended way. That way the server would search for the data, as opposed to having the server blow all tables over the network to each client and have each client search their own in-memory-copies.
Look into reflection and recursion, that should do the trick. You'd iterate every property, and if it isn't an interface or a class, you'd convert it to a string and search the string-represenation. This way you should be able to search most items, as an enum, a long and a boolean would all convert nicely. If the property represents a class, interface or struct, then you call the method again, but now passing the value of that property and not the object you're looking at. That'd be the recursive part.
Should work for POCO's, can't say with certainty that it will work nicely on entities.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your reply, Sir. I always like your answers.
Fortunately they are now okay with my initial suggestion of using an SP.
Your time will come, if you let it be right.
|
|
|
|
|
Ehr, thanks
|
|
|
|
|
Any time you have an application send SQL to a database that identifies the data tables, you are doing it *so* wrong§. You should treat the data model as an implementation detail and the stored procedures and Table Valued Functions (if MSSQL) as your data services. It would be much, much nicer if the SQL Server team had followed through on their rhetoric that table valued parameters would be able to be OUTPUT parameters "in the next release of SQL Server" (which should have been 2008R2...that would allow the DataTransferObject to be registered directly with the DBMS) but an ADO.NET bridging layer that performs your data transfer into the application domain is *ridiculously simple*
§...and that's why Entity Framework is pure, unadulterated evil; It's the ADO.NET DataSet 2.0
"I need build Skynet. Plz send code"
|
|
|
|
|
Thanks for your reply. An SP is the way now!
Your time will come, if you let it be right.
|
|
|
|
|
Anyway, now that I have managed to get it working for string and numeric properties (which are going to be "most" of them), I have been "suggested" to go with the SP approach - which was my suggestion to them in the first place.
If anyone is interested how I implemented the property-search (for string and numeric types only), here are the methods (please don't point out the refactoring/coding conventions, etc needed, this was just a quick one):
private static Expression<Func<T, bool>> ContainsInStringTypeExpression<T>(string propertyName, string propertyValue)
{
var parameterExpression = Expression.Parameter(typeof(T), typeof(T).Name);
var propertyExpression = Expression.PropertyOrField(parameterExpression, propertyName);
var stringTypeArray = new[] { typeof(String) };
var containsMethod = typeof(String).GetMethod("Contains", stringTypeArray);
var valueToBeChecked = Expression.Constant(propertyValue, typeof(String));
var finalContainsExpression = Expression.Call(propertyExpression, containsMethod, valueToBeChecked);
return Expression.Lambda<Func<T, bool>>(finalContainsExpression, parameterExpression);
}
private static Expression<Func<T, bool>> ContainsInNumericTypeExpression<T>(string propertyName, string propertyValue)
{
var parameterExpression = Expression.Parameter(typeof(T), typeof(T).Name);
var propertyExpression = Expression.PropertyOrField(parameterExpression, propertyName);
var decimalPropertyExpression = Expression.Convert(propertyExpression, typeof(System.Nullable<Decimal>));
var nullableDecimalType = new[] { typeof(System.Nullable<Decimal>) };
var stringConvertExp = Expression.Call(null, typeof(SqlFunctions).GetMethod("StringConvert", nullableDecimalType), decimalPropertyExpression);
var stringTypeArray = new[] { typeof(String) };
var containsMethod = typeof(String).GetMethod("Contains", stringTypeArray);
var valueToBeChecked = Expression.Constant(propertyValue, typeof(String));
var finalContainsExpression = Expression.Call(stringConvertExp, containsMethod, valueToBeChecked);
return Expression.Lambda<Func<T, bool>>(finalContainsExpression, parameterExpression);
}
And finally,
public static Expression<Func<T, bool>> ContainsExpression<T>(string value)
{
var properties = typeof(T).GetProperties();
Expression<Func<T, bool>> finalExpression = PredicateBuilder.False<T>();
var parameterExpression = Expression.Parameter(typeof(T), typeof(T).Name);
string propertyName = String.Empty;
foreach (var property in properties)
{
var propertyType = property.PropertyType.Name;
if (propertyType == "String")
{
var propContainsExpression = ContainsInStringTypeExpression<T>(property.Name, value);
finalExpression = finalExpression.Or(propContainsExpression);
}
else if (IsNumericType(propertyType))
{
var propContainsExpression = ContainsInNumericTypeExpression<T>(property.Name, value);
finalExpression = finalExpression.Or(propContainsExpression);
}
else
{
}
}
return finalExpression;
}
Where, I have ORed the generated Expression using Universal Predicate Builder[^].
As always, thank you all for your suggestions.
Your time will come, if you let it be right.
modified 28-Oct-14 23:40pm.
|
|
|
|
|
I want to inherit a observablecollection<t>,
class Student : INotifyPropertyChanged
{
private string _IDstudent;
private string _nameStudent;
private string _familyStudent;
private double _avg;
public ObservableCollection<grade> Grades { get; set; }
public Student()
{
Grades = new ObservableCollection<grade>();
}
}
class StudentList : ObservableCollection<student>, INotifyPropertyChanged
{
private ObservableCollection<student> _students = new ObservableCollection<student>();
public ObservableCollection<student> Students
{
get { return _students; }
set { _students = value;
NotifyPropertyChanged("Students");
}
}
public StudentList()
{
_students.Add(new Student());
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
are i use notify in Studentlist correctly .
|
|
|
|
|
Edit #1: I wonder if what you are really after is a way to encapsulate PropertyChanged Events within an ObservableCollection: so that you could assign one Delegate to the ObservableCollection that would route all PropertyChanged notifications to one EventHandler you defined ? I can't say I understand your code, since it is not clear to me what your goal is in mixing and matching ObservableCollection and INotifyPropertyChanged: note you never implement a CollectionChanged Event. And, you have another ObservableCollection, 'Grades, inside your 'Student Class which promises to implement INotifyPropertyChanged.
I strongly suggest you study implementing INotifyPropertyChanged first, and, when you understand it, move on to using ObservableCollection. When you know how to use both, then make a list of exactly what events you wish to be notified of ... which notifications you want to use from the ObservableCollection (Add, Remove, Move, Replace, Reset). Of course, INotifyPropertyChanged even handling is only going to give you one thing: the PropertyName (string) of the changed Property.
But, I can try to help you understand inheriting from ObservableCollection to some degree (I hope):
There should be a "good reason" to inherit from something like ObservableCollection<T>: "good reasons" are usually because:
1. you need to extend the inherited-from object: i.e., add functionality
2. you want to over-ride behavior (methods) in the inherited-from object.
Assume I have a class 'Student which has a constructor like this: note that only one parameter is required to be specified to create a new instance:
public Student(DateTime admissionDate, string stuName = "", string stuClass = "", string stuAddress = "")
{
AdmissionDate = admissionDate;
StuName = stuName;
StuClass = stuClass;
StuAddress = stuAddress;
} If I inherit from ObservableCollection<Student> and extend it by adding my own 'Add method:
public class Students : ObservableCollection<Student>
{
internal void Add(string admDate, string name)
{
base.Add(new Student(Convert.ToDateTime(admDate), name));
}
} I can enable easy in-line syntax entry of new Items in the ObservableCollection:
Students StudentsCollection = new Students
{
{"02/05/2012", "Moe"},
{"11/05/2013", "Curly"},
{"02/05/2014", "Larry"},
{"01/05/2010", "Mutt"},
{"02/05/2010", "Jeff"},
{"01/05/2009", "Dagwood"}
}; So, assuming you wanted to use the functionality in ObservableCollection to observe something
StudentsCollection.CollectionChanged += StudentsCollection_CollectionChanged;
private void StudentsCollection_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
break;
case NotifyCollectionChangedAction.Remove:
break;
}
}
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
modified 27-Oct-14 9:24am.
|
|
|
|
|
Extraction of data from excel to databae
|
|
|
|
|
First of all, welcome to CodeProject. I see from your profile that this is your first day on the site, so you might not be aware of some of the finer points of site etiquette.
The first rule that you need to be aware of is that your question needs to be as specific as possible. Tell us what the problem is you're trying to solve, what you've done so far and where you're stuck. Showing us relevant code snippets is a definite plus.
The second rule is, don't post the same question in multiple forums. Pick one place and stick with it. You stand a much better chance of getting an answer that helps you if you do that.
|
|
|
|
|
Thanks i did not know
|
|
|
|
|
I need the code for Game "2048" so that always number 2 added.
Simple UI without graphic and program play not user.
Can anyone help me.
Thanks.
|
|
|
|
|
Please read the "How to get an answer to your question" pinned post on this forum:
"2. Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with."
« There is only one difference between a madman and me. The madman thinks he is sane. I know I am mad. » Salvador Dali
|
|
|
|
|
Wrong site - try rendacoder or freelancer or one of the I want codz sites. You will need to pay a minimal amount.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
When you think about it what you're trying to create is, effectively, just some minor manipulation inside a grid. Now, what you want to consider is how could you represent a grid? Perhaps with a 2-D array. Then, you need to think about what the rules are. What you're trying to do is move tiles vertically or horizontally each time - that simplifies the code you have to write because you know that each operation affects only the rows or the columns.
So, you have rows and columns being manipulated. Let's consider the case where the user has swiped down so you're moving the rows down. Starting at the top row, when you move down this is always the way you'll work, start at the first element of that line of the array, and see if the first element of the line of the array below is the same number - if it is, you can increment it and blank out the current cell. You'll have to mark the cell that you just incremented so that you don't try to use it again - it's one increment per turn.
There, you have all the logic you need to get started. You should be able to extend this for swipe up and swipe left/right.
|
|
|
|
|
The game was (briefly) very popular, so predictably, it has lots of clones, in almost every language.
There is a C# version[^] with source code available too. It has a GUI (using System.Console), but I'm sure you can separate that out from the game logic.
I literally googled this in a couple of seconds, then browsed the source in maybe a minute. Writing this post took longer.
|
|
|
|
|
Hi,
I have a list as below
-Branch
Branchname = AB
BranchCode = 01
-Counters
-Countername = AB-1
Countercode = 101
countername = AB-2
countercode = 102
Branchname = CD
BranchCode = 02
-Counter
-Countername = CD-1
Countercode = 201
countername = CD-2
countercode = 202
i have 2 listboxes in UI, first list box should load all the branches and the second list box should have the corresponding counters for the selected branch.
Can anyone help me in binding the nested listbox to 2 listbox.
Thanks,
Rajeeva
|
|
|
|
|
There may be a way to do this with purely xaml but I would put the filtering in the viewmodel.
Assuming you know how to bind the collections to the listbox and get the selecteditem (bound twoway on the branch listbox)
In the selected item of the branch apply the branch filter to the counter collection and the UI will be updated!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi all, I have a web page that allows users to drag an image from their desktop on to a box that had been designated as a droppable box. Once the image is dropped it will be sent to a web service to be saved in a folder on the server. The following is the Javascript I'm using to send the image from the frontend to the webservice.
function ImageUpload(file) {
xhr = new XMLHttpRequest();
xhr.open('post', 'SaveImageService.asmx', true);
xhr.setRequestHeader('Content-Type', "multipart/form-Data");
xhr.setRequestHeader('X-File-Name', file.fileName);
xhr.setRequestHeader('X-File-Size', file.fileSize);
xhr.setRequestHeader('X-File-type', file.fileType);
xhr.send(file);
};
I am using the following code in my web service to save the posted image in a folder called Images. I'm not certain if the project folder name should be included as part of the folder path when I specify where to save the uploaded images. I tried including and excluding the project folder name but it didn't help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
namespace ImageUpload
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class SaveImageService : System.Web.Services.WebService
{
[WebMethod]
public void SaveImage()
{
var httpRequest = HttpContext.Current.Request;
foreach (string file in httpRequest.Files)
{
var postedFile = httpRequest.Files[file];
var filePath = HttpContext.Current.Server.MapPath("~/Images/" + postedFile.FileName);
postedFile.SaveAs(filePath);
}
}
}
}
I am getting response status of 500 internal server error. Please look at the code above and point out any problem you see. Thanks in advance for your help.
modified 25-Oct-14 9:21am.
|
|
|
|
|