|
Odd. Did you try debug build running inside VS? release build running inside VS? debug build double-clicked in bin\debug folder? release build double-clicked in bin\release folder?
the difference would be optimizations (timing difference or bugs), and error handling (VS settings influence some).
Do you use time-outs? with sufficient value? and failures get logged? or is the client hanging, waiting on a reply?
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc:
There was one point where I was missing code in a catch statement. That was the exception that was getting thrown. After I added code to handle that exception, I discovered that the problem was stemming from a difference in the amount of data included in the message sent from my Test tier versus my local tier. Due to this size difference, a flaw in my received handler was being tripped. Fixed my code and everything works as expected.
Thanks for your question about exceptions. If forced me to go back and check all of my catch statements.
Tim
|
|
|
|
|
yep. catching and somehow showing all exceptions is a powerful technique.
whenever I see an empty catch statement (and that is quite frequently around here, some people think it is wise to skip or postpone error handling), I make sure the perpetrator will not forget about it any time soon ...
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hi, I'm creating an asp.net Pizza order form using c# for a night school course and I have a RadioButtonList for the Size of the pizza and a checkbox list for the Pizza Toppings. Both controls have autopostback enabled so that as a size is selected and a topping is added the Total Price label will automatically calculate the total price and size is selected and toppings added. I have a simple method that adds the ingredients price to the size price as selctions are made. The problem is that the value of the Total Price changes as selections are made to the size (2,4,6,8,10) but if a topping is selected then the value of the total price doesn't add the size price to the toppings price they are still calculated individually, can someone tell from my code how i can write and use my method to total the size price with the topping price? thanks in advance.
<br />
public partial class _Default : System.Web.UI.Page <br />
{<br />
decimal TotalPrice = 0;<br />
decimal IngredientsPrice = 0;<br />
decimal SizePrice = 0;<br />
<br />
private decimal MethodTotalPrice(decimal MethodIngredientsPrice,<br />
decimal MethodSizePrice)<br />
{<br />
decimal MethodTotalPrice;<br />
MethodTotalPrice = MethodIngredientsPrice + MethodSizePrice;<br />
return MethodTotalPrice;<br />
}<br />
<br />
protected void Page_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)<br />
{<br />
lblSize.Text = rblSize.SelectedItem.Text;<br />
<br />
if (rblSize.SelectedValue == "Slice")<br />
{<br />
lblSize.Font.Size = 8;<br />
SizePrice = 2;<br />
}<br />
if (rblSize.SelectedValue == "Small")<br />
{<br />
lblSize.Font.Size = 10;<br />
SizePrice = 4;<br />
}<br />
if (rblSize.SelectedValue == "Medium")<br />
{<br />
lblSize.Font.Size = 12;<br />
SizePrice = SizePrice + 6;<br />
}<br />
if (rblSize.SelectedValue == "Large")<br />
{<br />
lblSize.Font.Size = 14;<br />
SizePrice = 8;<br />
}<br />
if (rblSize.SelectedValue == "Xtra Large")<br />
{<br />
lblSize.Font.Size = 16;<br />
SizePrice = 10;<br />
}<br />
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);<br />
lblPriceTotal.Text = TotalPrice.ToString();<br />
}<br />
protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)<br />
{<br />
string Message;<br />
Message = "";<br />
for (int i = 0; i < cblIngredients.Items.Count; i++)<br />
{<br />
if (cblIngredients.Items[i].Selected)<br />
{<br />
Message = Message + cblIngredients.Items[i].Text + "<br>";<br />
IngredientsPrice = IngredientsPrice + 1;<br />
}<br />
}<br />
lblIngredients.Text = Convert.ToString(Message);<br />
TotalPrice = MethodTotalPrice(IngredientsPrice, SizePrice);<br />
lblPriceTotal.Text = TotalPrice.ToString();<br />
}<br />
}<br />
|
|
|
|
|
Marcus Farrugia wrote: SizePrice = SizePrice + 6;
Probably not intended
I mean, if you switch from Xtra large to medium, you're suddenly paying 16, right?
Marcus Farrugia wrote: IngredientsPrice = IngredientsPrice + 1;
AKA IngredientsPrice++ , just a style thing though. More important is that you don't reset it. It will just keep going up. That is not good.
Concatting "many" strings using the + operator is poor form, better use a StringBuilder , but that's not causing your problem.
Marcus Farrugia wrote: MethodTotalPrice = MethodIngredientsPrice + MethodSizePrice;
Surprising calculation, but if it's supposed to work that way...
edit: right ASP.NET. Ok ignore this post. Why do people just keep posting ASP.NET questions here instead of at the ASP.NET forum? Last modified: 45mins after originally posted --
|
|
|
|
|
harold aptroot wrote: Why do people just keep posting ASP.NET questions here
For the same reason they keep advertising ASP.net jobs as C# jobs.
|
|
|
|
|
Hi,
When one choice changes, how are you going to keep the result from another choice made earlier? The page reloads, doesn't it? With new variables, initialized at zero?
the easiest and safest way is to calculate total prize in a separate method that collects all required data;
then invoke that method from within all your Changed handlers. So every change recalculates the total price.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Well your code is a bit of a mess. As Luc has pointed out, ASP.NET will reset each of those class variables to zero on postback. There is the option of persisting values between postbacks but a more elegant solution would be to calculate the price whenever you need it.
I would approach this as follows, start with a method to do the actual proce calculation
private decimal CalculatePrice()
{
decimal sizePrice = 0;
switch(rblSize.SelectedValue)
{
case "Slice": sizePrice = 8;break;
case "Small": sizePrice = 10;break;
}
decimal ingredientsPrice = 0;
for (int i = 0; i < cblIngredients.Items.Count; i++)
{
if (cblIngredients.Items[i].Selected)
{
ingredientsPrice ++;
}
}
return sizePrice + ingredientsPrice ;
}
Next have this method called when either action is performed
protected void RadioButtonList1_SelectedIndexChanged1(object sender, EventArgs e)
{
decimal totalPrice = CalculatePrice();
lblPriceTotal.Text = totalPrice.ToString();
)
protected void cblIngredients_SelectedIndexChanged(object sender, EventArgs e)
{
decimal totalPrice = CalculatePrice();
lblPriceTotal.Text = totalPrice.ToString();
}
|
|
|
|
|
Marcus Farrugia wrote: I'm creating an asp.net Pizza order form using c# for a night school course
OK, I'm going to apologies in advance if the following is either to simple or too complicated. If you are going to use C# you should really look into object oriented design (lots of references around), but only when and if you are comfortable with control flow logic (loops and descision statements etc). Getting you head around this will save a lot of work in the long run, but it's daunting as you start out (or it was for me anyway )
You should condisder breaking some of your code down further into classes. A class is a way of gathering properties (e.g. Size) and methods (e.g. Add/Remove Toppings) into one logical place (often representing something in the real world). This is known as encapuslation and prevents any unwanted side-effects from other things happening if you do it correctly. e.g. in your example a mistake is causing the total to be incorrect.
For example:
If you create a class called Topping, you could create several of these. The topping might have a property called Description (e.g. Description = "Ham") and a set of prices for each size (there are several way to do this, e.g. have a property for each size, which is less good or consider using a Dictionary )
Now you could have Pizza class, this could have a List of Toppings, a Size (and a list of pizza-base prices for each size, just like the topping) an a calculate cost method. To calculate the cost, you take the pizza-base cost for the current size, and for each topping add it's cost according to the pizza size.
A good initial way to work out which classes, properties and methods you need is to write down what you want to achieve, nouns indicate classes or properties, verbs indicate a method is required.
e.g.
A pizza can come in different sizes and have several toppings added or removed as required. Calculate the cost of the pizza and show to the customer.
Note that you'll see the classes Pizza and Topping I sugested highlighted as well as the size property. Also highlighted are "Add[Topping]" and "Remove[Topping]", I haven't put these on the pizza class directly, though you could. I have suggested you create a property called Toppings which is a List of toppings (List<Topping> google up List<T> for more advice). The list itself has an Add & Remove methods, so you don't have to add them.
This seems like a chore, but 99% of the time it works easier. For example you could now add new types of topping easily or add stuff to save to a database. If you implement it well , new pizza sizes should be easy and the code you write should be more readable, robust & easy to adapt to new requirements (all of which are important when programming)!
Good luck with your course, and I hope you enjoy it. I'm jelous, I wish I could unlearn the stuff I have done, just so I could re-learn it! On the up side I suppose there are lots of cool new things being done in IT to find out about all the time. I am such a geek!
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|
Hi! Maxwell. I'm working with ASP C# and i'm trying to up pictures to the file. I have sample code:
string concatName = null, picname = null, strImageFolderPath = null, strImagePath = null;
DateTime now;
HttpPostedFile uploadedImage;
now = DateTime.Now;
concatName = Request.QueryString["||"].ToString() + now.Year.ToString() +
now.Month + now.Day + now.Hour + now.Minute + now.Second;
uploadedImage = FileUpload11.PostedFile;
picname = System.IO.Path.GetFileName("MAI" + concatName + ".jpg");
strImageFolderPath = Path.Combine
(Request.PhysicalApplicationPath, "pictures");
strImagePath = Path.Combine(strImageFolderPath, picname);
uploadedImage.SaveAs(strImagePath); //error "Object reference not set to an instance of an object."
Help me please
|
|
|
|
|
Mix Wheels wrote: uploadedImage.SaveAs(strImagePath); //error "Object reference not set to an instance of an object."
how many references are there in this line? I see 1.
hence uploadedImage is null. fix that.
Luc Pattyn
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Hello all,
How can I allow a user to type a letter on the keyboard and have a DataGridView (DGV) change current row to the first occurrence of the letter within a non-Primary Key column.
For example, LastName is a column in a DGV. Typing ‘S’ should change the current row of the DGV to the first Lastname that starts with an ‘S’. Note: LastName is not the primary key of the bound table.
I am using a DataGridView bound to a DataSet.Table[] without a binding source.
Here is a code snippet I tried, but it returns -1:
ds.Tables["Students"].DefaultView.Sort = "LastName";
int intRow = ds.Tables["Students"].DefaultView.Find("S%");
I have also tried this, but it returns zero rows:
ds.Tables["Students"].DefaultView.Sort = "LastName";
DataRowView[] drv = ds.Tables["Students"].DefaultView.FindRows("LastName LIKE 'S'");
Thanks in advance,
KCI
Live long and prosper.
|
|
|
|
|
Isn't the last one missing a wildcard?
JimSchor wrote: ds.Tables["Students"].DefaultView.Sort = "LastName";
DataRowView[] drv = ds.Tables["Students"].DefaultView.FindRows("LastName LIKE 'S*'");
I are Troll
|
|
|
|
|
Hello Troll,
Thanks for the advice.
I just tried it and no difference.
Any more thought anyone?
KCI
Live long and prosper.
|
|
|
|
|
Here is how I eventuall worked this out. I have not tested it deeply so take this only as an outline:
using System.Collections.Generic;
private string strKeyPreview = String.Empty
private List<string> strStudent_List = null;
private void dgv_KeyPress(object sender, KeyPressEventArgs e)
{
strKeyPreview = e.KeyChar.ToString();
int intRow = strStudent_List.FindIndex(StartsWithLetter);
if (intRow >= 0)
{
dgv[3, intRow].Selected = true;
dgv.FirstDisplayedScrollingRowIndex = intRow;
}
}
private bool StartsWithLetter(String s)
{
if (s.StartsWith(strKeyPreview.ToUpper()) == true)
{
return true;
}
else
{
return false;
}
}
strStudent_List = new List<string>();
foreach (DataRow dr in dt.Rows)
{
strStudent_List.Add(dr[2].ToString());
}
Feel free to post improvement ... I'm sure this is not bullet proof as it is untested.
Live long and prosper.
|
|
|
|
|
i have a treeView in splitterContainer, the treeview flickers when i try to resize the Form using mouse at any of the corner screen edges. the flickering will not happen if i try to increase the Forms Width, or the Lenght. it flickers only when i increase size of the Form at the corner edges. Can you help me with this i am using VS 2005.
|
|
|
|
|
Hi
I wish to remove installed program from control panel using C# . Can anyone suggest me something how to proceed?
|
|
|
|
|
To remove application from control panel, just go to C:\WINDOWS\system32 and rename the file with ".CPL" extension.
Just write a code to do that.
|
|
|
|
|
Ajithevn wrote: an anyone suggest me something how to proceed?
Yes. Try to reformulate your question.
* Do you want to remove an applet from the control panel (e.g., removing the "Mouse" icon from the folder "Configuration"), OR
* Do you want to uninstall an application (e.g., uninstall FireFox), OR
* Do you want to remove an entry in the list of installed applications (e.g., when an app is deinstalled, but still listed in the 'installed applications')
I are Troll
|
|
|
|
|
yes i want to uninstall an application. i.e i have created a setup of my application and intalled it and i want to uninstall that application from another c# application.
|
|
|
|
|
Take a look at the registry, under the key
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\ie8 It contains a key called UninstallString , with the value "C:\Windows\ie8\spuninst\spuninst.exe". If you execute that application, it will uninstall IE8. The key also contains the name of the app (e.g., "Windows Internet Explorer 8") and the InstallDate (e.g., 20090806). You'll also find service-packs and the likes if you browse further. Alternatively, you can search the registry for the key "uninst.exe".
Not every application will have such an entry. DOS-applications are usually copied, and thus don't register an uninstaller for the app. Also keep in mind that the current user might not have the privileges to uninstall applications.
Happy Programming
I are Troll
|
|
|
|
|
Got the bugger!
It seems that 2 things aren't happening and I can't tell if this is going to be the case every time. It took a bit of doctoring and manual splicing of the the .sln file and the .csproj files. Seems like the configuration manager is not creating the new build configurations inside the .csproj files
Solution:
1. .csproj files, add the build configuration from another file that already has a successful one
2. .sln file (this is bit complicated, backup before you get too ballsy)
i) find the name of the project(s) that is giving you hell, at the far right of that defining line, you'll find a GUID, this is the project GUID that is referenced later, you'll also need to copy the GUID for a working project under the configuration that you want to fix
ii) scroll down and find in the section titled "GlobalSection(ProjectConfigurationPlatforms) = postSolution" an entry for the working project (by GUID) (e.g. {72C74E6F-8D11-4324-A412-1905FFEACD5E}.Radiology|Any CPU.ActiveCfg = Release|Any CPU) Note, you will find that projects left loaded when this configuration is chosen will have two entries, whilst the unloaded ones have only a single line entry
ii)copy this entry and then find the list of entries for the project that's giving you hell (by GUID), insert it into this list by pasting it (you'll see that it does not have a list item); Be sure to replace the GUID in the pasted item to that of the project that's giving you issues.
3.Save the files
4. Fire up VS or if its already open, if asked to reload the solution/projects, accept. If they were unloaded, reload the projects that you manually amended.
5. Build with the projects once
6. Unload the projects you wanted (the ones you just manually spliced)
7. Build again to check.
8. Happy coding (or as much as possible)
If done right, it should work.
The current Solution I'm working on has 19 projects at the moment and there are another 4 on the way. Because of the size of the solution and because build times are beyond annoying and for to simplify traces and a plethora of other reasons, projects that are not involved directly in the current cycle of development and testing are unloaded. This worked like a charm until yesterday evening when a new project was added, along with its own configuration (there are 9 configurations at the moment, I added another 2 last night and eventually there will be 15).
I get this error message when I build:
Error 1 The OutputPath property is not set for this project. Please check to make sure that you have specified a valid Configuration/Platform combination. Configuration='Radiology' Platform='AnyCPU' AppChooser
Now, I've figured out the reason is because I've unloaded the two project being referenced. Reloading them (which brings me back to the complete list of projects) makes the build go perfectly fine.
Googling has shown that others have faced similar problems, I just couldn't find any solutions or workarounds.
Suggestions?
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
modified on Thursday, October 1, 2009 9:38 AM
|
|
|
|
|
|
Thanks Vasudevan, I didn't see your post because I was mucking about with the .csproj and .sln files.
Got it to work
If you'd like to know how, check the OP.
Thanks a zillion though, the method in the link seems a simpler way of doing it.
If the post was helpful, please vote, eh!
Current activities:
Book: Devils by Fyodor Dostoyevsky
Project: Hospital Automation, final stage
Learning: Image analysis, LINQ
Now and forever, defiant to the end.
What is Multiple Sclerosis[ ^]?
|
|
|
|
|
Hi Mustafa!
I've only a little build experience and not a lot in more unusual setups (such as the need to build certain projects), so apologies if I've misunderstood your question.
Rather than unloading unneeded projects, is setting them not to build under the particular configuration an option? You can build all the projects once per config, then disable the ones you aren't going to work on and use the one. This will utlimately speed up your build times for the configs, but you'll have to take the hit of the initial full build.
CCC solved so far: 2 (including a Hard One!)
|
|
|
|
|