|
gibsray wrote: but I got an error when I passed the location of the file
I tried the XmlDocument and it's function SelectSingleNode("n1") but I got another error. We can't read your mind. What errors did you receive?
/ravi
|
|
|
|
|
I very much doubt that your file is in the root of the Document and Settings folder. Perhaps you should double check that your path is valid.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
You need a root. You did not provide the error, so so not know what the exact issue is, but can only have one root node.
<items>
<*n1>random number here </*n1>
<*n2>random number here </*n2>
</items>
Of course this is not good xml either. XML will object to the *, and there is no * before the backslash.
|
|
|
|
|
|
I have this code:
public static IQueryable<T> OrderBy<T>(
this IQueryable<T> source, string propertyName, string order)
{
var type = typeof(T);
var asc = order == "asc" ? true:false;
string methodName = asc ? "OrderBy" : "OrderByDescending";
var parameter = Expression.Parameter(type, "p");
var property = type.GetProperty(propertyName);
var propertyAccess = Expression.MakeMemberAccess(parameter, property);
var orderByExp = Expression.Lambda(propertyAccess, parameter);
MethodCallExpression resultExp = Expression.Call(typeof(Queryable), methodName,
new Type[] { type, property.PropertyType },
source.Expression, Expression.Quote(orderByExp));
return source.Provider.CreateQuery<T>(resultExp);
}
And i would like to extend it to allow child properties, like "Address.Street"
if i pass just a simple property it works nice... but i want to make it better and accept child object property to make order by.
Anyone knows how to modify it?
I tryed but no success... i don't know how to make it to find the child object property and create the MemberAccess with it
Thanks!!
|
|
|
|
|
There you go, sorts on properties of properties... not quite sure if it works with methods. The logic is there, but it's not fully tested
public static IEnumerable<T> SortObject<T>(this IEnumerable<T> ObjectToSort, string SortBy)
{
if (ObjectToSort == null)
return null;
if (string.IsNullOrEmpty(SortBy) == true)
return null;
string[] tempSorts = SortBy.Split(',');
List<string> SortList = new List<string>();
bool inParanthese = false;
string addString = string.Empty;
foreach (string tempSort in tempSorts)
{
if ((tempSort.Contains("(") == true) && (tempSort.Contains(")") == false))
{
inParanthese = true;
}
else if (tempSort.Contains(")") == true)
{
inParanthese = false;
}
if (inParanthese == false)
{
if (string.IsNullOrEmpty(addString) == false)
{
SortList.Add(addString + "," + tempSort.Trim());
}
else
{
SortList.Add(tempSort);
}
addString = string.Empty;
}
else
{
if (string.IsNullOrEmpty(addString) == false)
addString += ",";
addString += tempSort.Trim();
}
}
string[] Sorts = SortList.ToArray();
bool Sorted = false;
foreach (string FieldSort in Sorts)
{
string[] SubSort = FieldSort.Trim().Split(' ');
string[] props = SubSort[0].Split('.');
Type type = typeof(T);
ParameterExpression arg = Expression.Parameter(type, "x");
Expression expr = arg;
foreach (string prop in props)
{
System.Reflection.PropertyInfo pi = type.GetProperty(prop);
if (pi != null)
{
Sorted = true;
expr = Expression.MakeMemberAccess(expr, pi);
type = pi.PropertyType;
}
else
{
string wholeMethod = prop;
if ((wholeMethod.Contains("(") == false) && (wholeMethod.Contains(")") == false))
{
wholeMethod += "()";
}
int firstParans = wholeMethod.IndexOf('(');
int lastParans = wholeMethod.LastIndexOf(')');
if ((firstParans > -1) && (lastParans > firstParans))
{
string methodname = wholeMethod.Substring(0, firstParans).Trim();
string paramList = wholeMethod.Substring(firstParans + 1, lastParans - (firstParans + 1));
System.Reflection.MethodInfo mi = null;
List<string> indParams = null;
if (paramList.Length > 0)
{
bool inDoubleQuotes = false;
bool inSingleQuotes = false;
string currParam = string.Empty;
indParams = new List<string>();
foreach (char c in paramList)
{
if (c == '\"')
{
if (inSingleQuotes == false)
{
inDoubleQuotes = !inDoubleQuotes;
}
currParam += c;
}
else if (c == '\'')
{
if (inDoubleQuotes == false)
{
inSingleQuotes = !inSingleQuotes;
}
currParam += c;
}
else if ((c == ',') && (inDoubleQuotes == false) && (inSingleQuotes == false))
{
if (string.IsNullOrEmpty(currParam) == false)
{
indParams.Add(currParam);
currParam = string.Empty;
}
}
else
{
currParam += c;
}
}
if ((string.IsNullOrEmpty(currParam) == false) && (inDoubleQuotes == false) &&
(inSingleQuotes == false))
{
indParams.Add(currParam);
}
Type[] methodTypes = new Type[indParams.Count];
Expression[] methodParams = new Expression[indParams.Count];
int paramTypeIndex = 0;
int intResult;
foreach (string indParam in indParams)
{
if (indParam[0] == '\'')
{
if ((indParam.Length == 3) && (indParam[2] == '\''))
{
methodTypes[paramTypeIndex] = typeof(char);
methodParams[paramTypeIndex] = Expression.Constant(indParam[1], typeof(char));
}
else
{
methodTypes[paramTypeIndex] = typeof(string);
methodParams[paramTypeIndex] = Expression.Constant(indParam, typeof(string));
}
}
else if (indParam[0] == '"')
{
methodTypes[paramTypeIndex] = typeof(string);
methodParams[paramTypeIndex] = Expression.Constant(indParam, typeof(string));
}
else if (int.TryParse(indParam, out intResult) == true)
{
methodTypes[paramTypeIndex] = typeof(int);
methodParams[paramTypeIndex] = Expression.Constant(intResult, typeof(int));
}
else
{
methodTypes[paramTypeIndex] = typeof(object);
methodParams[paramTypeIndex] = Expression.Constant(indParam);
}
paramTypeIndex++;
}
mi = type.GetMethod(methodname, methodTypes);
if (mi != null)
{
expr = Expression.Call(expr, mi, methodParams);
}
}
else
{
mi = type.GetMethod(methodname, System.Type.EmptyTypes);
if (mi != null)
{
expr = Expression.Call(expr, mi);
}
}
}
}
}
LambdaExpression lambda = Expression.Lambda(expr, arg);
if (Sorted == true)
{
IQueryable<T> queryableData = ObjectToSort.AsQueryable<T>();
if ((SubSort.Count() > 1) && (string.Compare(SubSort[1].Trim(), "desc", true) == 0))
{
MethodCallExpression MyExpr = Expression.Call(
typeof(Queryable), "OrderByDescending",
new Type[] { typeof(T), type },
queryableData.Expression, lambda);
IQueryable<T> results = queryableData.Provider.CreateQuery<T>(MyExpr);
try
{
results.Count();
ObjectToSort = results;
}
catch (Exception exc){}
}
else
{
MethodCallExpression MyExpr = Expression.Call(
typeof(Queryable), "OrderBy",
new Type[] { typeof(T), type },
queryableData.Expression, Expression.Quote(lambda));
IQueryable<T> results = queryableData.Provider.CreateQuery<T>(MyExpr);
try
{
results.Count();
ObjectToSort = results;
}
catch (Exception exc){}
}
}
}
if (Sorted == true)
{
return ObjectToSort;
}
else
{
return null;
}
}
|
|
|
|
|
So my current project here at work will soon involve a parts ordering process. All is well with that. I'm just looking for all possible solutions for one portion of that process. Here is the gist of how it will work:
Worker #1: "Oh, I need to order this part."
------ * Select the part(s) using a CheckBox
------ * Click 'Place Order'
Worker #2 (picker) is in his station in some other work area. What needs to happen is when Worker #1 clicks 'Place Order', a label will print out at Worker #2's station with the appropriate information. Now, the label format and such is not the problem. What I am looking for is the most efficient method for monitoring the orders and printing the label automatically. I hope that was explained clearly.
When an order is placed it will be inserted into a table in Microsoft SQL Server 2008. And this is a WinForms application (C#, .NET v4.0).
The first potential solution I have contemplated: A Windows Service on Worker #2's station which monitors the database for new orders, set to check every so often (fairly short intervals).
My second potential solution: Share Worker #2's printer on the local network and connect to it via each station which can place orders.
What can you all suggest that may help me along? If you need anymore information please feel free to ask. I will gladly provide further information.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: What I am looking for is the most efficient method for monitoring the orders and printing the label automatically. I hope that was explained clearly.
Depends on where your orders are stored.
Matt U. wrote: When an order is placed it will be inserted into a table in Microsoft SQL Server 2008.
Query Notification[^]
Matt U. wrote: The first potential solution I have contemplated: A Windows Service on Worker #2's station which monitors
I'd recommend a user-level application, not a service. It does not need to run when there's no user, since there's nowhere to display the notification and no-one to react.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Awesome, thanks a ton, Eddy! I'll be bookmarking the link and reading into it. I appreciate the help.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Also, I did forget to mention the fact that I am using LINQ To SQL. However, I found this article[^] which contains a basic explanation for using Query Notifications with LINQ To SQL. I had to make some modifications, as that article is several years old, but I got it working. Thanks again.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
|
I'm having a problem ...
<br />
DataTable GetSomeData()<br />
{<br />
DataTable dtResult = null;<br />
IDbCommand Cmd = new SqlCommand(SQL, OldSqlConn);<br />
DataAdapter da = new DataAdapter(Cmd);<br />
DataSet ResultSet = new DataSet();<br />
da.Fill(ResultSet);<br />
<br />
if(ResultSet!=null)<br />
{<br />
dtResult = ResultSet.Tables(0);<br />
foreach(DataRow rw in dtResult.Rows)<br />
{<br />
if(SomeConditionMet) {<br />
rw["SomeCol"] = xxxxx; << Blows up here saying Column 'SomeCol' does not belong to table ABC (But I'm quite confident SomeCol is a column which should be returned by the SQL query... wondering if it's any issue with ADO.NET SqlConn caching or if OldSqlConn has any stale data at one point during the night app loses database connection or something... confused as I can't reproduce this on debugger and it happens only once in a month)<br />
}<br />
}<br />
}<br />
<br />
return dtResult;<br />
}<br />
dev
|
|
|
|
|
Is there any reason you don't open your db connection before use and close just after?
Preferably with:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
}
--
"My software never has bugs. It just develops random features."
|
|
|
|
|
Put a breakpoint on the line that causes you a problem. Expand the DataRow in the watch window and inspect the values that are in there.
In other words, learn how to use the debugger. It would save you a lot of time coming up with random ideas about what the issue could be.
|
|
|
|
|
that's the problem - i ran it on debugger whole night just can't reproduce this problem. It only happens once in a full moon
dev
|
|
|
|
|
devvvy wrote: that's the problem - i ran it on debugger whole night just can't reproduce this problem. It only happens once in a full moon
Try logging all Sql statements that get executed.
I assume that you're not "keeping a connection open"? If yes, then you might want to try and see how the system reacts if the server goes to sleep.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
From the look of it it feels like someone is changing schema of referenced table or view - SQL is same/constant and doesn't change. I try to log columns returned from ResultSet when this sh*t happens again. No joy thus far!
dev
|
|
|
|
|
devvvy wrote: Column 'SomeCol' does not belong to table ABC
As others have stated you need to debug your code and I would suggest that you make sure that the query you are executing does return a column names that it is throwing an error on.
I would test this by executing your query in the database that you are using.
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Does anyone know how to send message to mobile(Windows phone 7) by using Web service (ASP.NET web service).
Now, I am doing a project about sending message automatically. I found for this, and I knew to API Google, but it only send message to one determine phone number. Can anyone help me?? I want to send message to multi person....Thank you so much!
|
|
|
|
|
You do realise that if you can send a message to one person there, you could just use the same call again to send the message to another person don't you?
|
|
|
|
|
I have downloaded the following code to work from for an app which requires login and registration.
http://code.msdn.microsoft.com/windowsdesktop/CCS-LABS-C-Creating-a-9ba05613/view/Discussions[^]
When I run the code and wish to register I enter my registration details and when I Click on register the MessageBox appear with note "Username can not be empty."
But there is text in the box.
Any suggestions?
Below is the code for the registration form.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ccslabsLogIn.forms
{
public partial class frmRegister : Form
{
#region "Properties"
private bool _Registered = false;
public bool Registered
{
get { return _Registered; }
set { _Registered = value; }
}
private string _Username = "";
public string Username
{
get { return _Username; }
set { _Username = value; }
}
#endregion
public frmRegister()
{
InitializeComponent();
}
private void btnCancel_Click(object sender, EventArgs e)
{
Registered = false;
this.Close();
}
private void btnRegister_Click(object sender, EventArgs e)
{
RegisterUser();
}
private void RegisterUser()
{
if (tbUsername.Text.Length > 0)
{
if (tbPassword.Text != tbRepeatPassword.Text) { MessageBox.Show("Passwords do not match"); RegisterUser(); }
if (tbPassword.Text.Length == 0) { MessageBox.Show("Passwords can not be empty"); RegisterUser(); }
usersTableAdapter.Insert(tbUsername.Text, tbPassword.Text);
Registered = true;
this.Close();
}
MessageBox.Show("Username can not be empty");
RegisterUser();
}
private void usersBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.usersBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.applicationDataSet);
}
private void frmRegister_Load(object sender, EventArgs e)
{
this.usersTableAdapter.Fill(this.applicationDataSet.Users);
}
}
}
Thank you very much.
|
|
|
|
|
Should be something like this, I reckon;
private void RegisterUser()
{
if (tbUsername.Text.Length > 0)
{
if (tbPassword.Text != tbRepeatPassword.Text) { MessageBox.Show("Passwords do not match"); RegisterUser(); }
if (tbPassword.Text.Length == 0) { MessageBox.Show("Passwords can not be empty"); RegisterUser(); }
usersTableAdapter.Insert(tbUsername.Text, tbPassword.Text);
Registered = true;
RegisterUser();
this.Close();
}
else
MessageBox.Show("Username can not be empty");
}
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks a lot that did the trick.
|
|
|
|
|
My vote of one:
What use is this recursive call of RegisterUser() ?
I'd really like to see an explanation for that. In case there is some information missing/empty there will be a recursive call to method RegisterUser which will bring absolutely nothing except locking up the application.
More interesting still is that OP thinks this is a solution (Silent SP alarm goes off!).
Strange!
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Didn't notice the call was recursive; it's original location looked flaky too
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|