|
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.
|
|
|
|
|
As you are calling this using AJAX, then do you have the SaveImageService registered in the ScriptManager control on your ASPX page?
Christopher Reed
"The oxen are slow, but the earth is patient."
|
|
|
|
|
Hi, thanks for responding. The web service is not registered in the Scriptmanager control and there is no ASXP page.
|
|
|
|
|
I think your issue is in your loop. Try:
foreach (string file in httpRequest.Files.AllKeys)
|
|
|
|
|
Hello,
I am getting an error 0xC0000006 when starting program that normally starts up and runs fine. It is being
executed from a network drive. I am working with .NET 2.0, however some machines that I am using have
the .NET 3.5 or .NET 4.0 runtime installed. The machines that are giving the errors are running Windows 7
Professional.
Any help or advice is appreciated.
|
|
|
|
|
You MUST have .NET 2.0 installed and, by default, code running from network sources is not trusted. Your code is running in a very restricted sandbox.
So, either you have to tell the machine to trust the network source, or move the .EXE to the local hard drive and run it from there. Running from a network source isn't the greatest idea if you're going to be replacing the .EXE since the file is locked when the code is running on any machine.
|
|
|
|
|
Dave,
Thank you for your response.
How do I go about telling the machine to trust the network source? Is this procedure common for all versions of Windows? (XP, Win7, Win8, Win10, etc). I don't think putting the EXE on a local drive is a good option in our case. For updates, I would have to go to every machine and update. Another vendor, which we interface with their software, they put everything on the network with no problems.
Mike
|
|
|
|
|
look for instruction/how to use 'CasPol.exe' and see if that gives you the options
Control Panel->Administrative Tools->.NET Framework Configuration ?.?->Runtime Security Policy->Adjust Zone Security might also be of some use
|
|
|
|
|
Is there something I'm misisng? I tried this and it still does not correct the problem. I had to use the caspol from the cmd line, using the guidelines seen here:
<a href="https://julianscorner.com/wiki/programming/caspol_network_share">
</a>[<a href="https://julianscorner.com/wiki/programming/caspol_network_share" target="_blank" title="New Window">^</a>]
Any other hints?
Thanks
Mike
|
|
|
|
|