|
There are two layers in my project. one is business layer,and the other is UI layer.
In UI layer, i invoke the method 'SaveInfo' of business layer. by the way ServiceActivator.GetService.
But i can't get 'newInfo' in UI layer.
and if i remove 'throw ex;' in 'SaveInfo' method. i could get it.
i don't know why.
do you know? how could i get newInfo if i want to throw Exception to UI layer.
pls. ths.
'SaveInfo' in Business layer:
public void SaveInfo(ref StudentInfo info,ref List<studentinfodetail> detailList,string strType)
{
try
{
...
info = newInfo;
detailList = newDetailList;
throw new MyException("Information already exist.");
...
}
catch(Exception ex)
{
throw ex;
}
}
the invoke code in UI layer:
try
{
...
mMyDs.SaveInfo(ref curInfo,ref curList,"Add");
...
]
catch(MyException mex)
{
textBox1.text = curInfo.Name;
}
catch(Exception ex)
{
}
MSN:msnadair@hotmail.com
Skype:skyadair
modified on Tuesday, May 12, 2009 8:52 PM
|
|
|
|
|
I have to say that returning to a calling process by throwing an exception is not the normal way to do it.
It would be better to give SaveInfo() a return type of bool and instead of throw new MyException use return true; .
Then in your calling code use
if (mMyDs.SaveInfo(ref curInfo,ref curList,"Add"))
{
}
else
{
}
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
No,i can't. i need to do this.
i should return the latest data from database if the info already exist. and the info may have different status, i should throw out the hint.
MSN:msnadair@hotmail.com
Skype:skyadair
|
|
|
|
|
I have a serial ports list. I declared it like this:
<br />
private List<SerialPort> lstSerialPorts;<br />
<br />
for (int i = 1; i<=cont; i++)<br />
{<br />
SerialPort tempPort = new SerialPort("COM" + cont.ToString(), 2400);<br />
lstSerialPorts.Add(tempPort);<br />
lstSerialPörts[i].DataReceived += SerialDataReceivedEventHandler(TEST_FUNCTION);<br />
}<br />
My TEST_FUNCTION is empty so far:
<br />
<br />
void TEST_FUNCTION(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
throw new NotImplementedException();<br />
}<br />
As you can see, all serial ports have the same handler function. How could I check which serial port triggered the TEST_FUNCTION? It would be great something like this:
<br />
void TEST_FUNCTION(object sender, SerialDataReceivedEventArgs e)<br />
{<br />
Console.WriteLine("This function was triggered by: {0}",anUnknownVariable);<br />
}<br />
Parameter "e" does not have any useful property or function
Any help would be apreciated and excuse me about my English if I made a mistake
Ivan
|
|
|
|
|
You've looked at the e parameter - now try the other one!
The clue is in the name 'sender'. Cast it to a SerialPort from object and you now have the object that raised the event.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Use the sender object, cast it to SerialPort and you will get the object who triggered the function.
Sincerely Samer Abu Rabie
Imagination is more important than knowledge !
|
|
|
|
|
If 'e' is not a lot of use, have you considered looking at 'sender', by any chance?
If you expand it in the debugger, you may find it is a SerialPort object.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Thx a lot guys
|
|
|
|
|
I know your proble is solved but something I noticed in the code and wondered if it was correct.
Should new SerialPort("COM" + cont.ToString()
be new SerialPort("COM" + i.ToString() ?
Good of you to thank the guys. Not everyone does.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
|
|
|
|
|
Yeah my mistake typing that... Thanks!
|
|
|
|
|
I want my application to programatically download a file from skydrive.live.com,
but I encountered a problem:
Microsoft uses script for file download that makes it impossible to download the file using WebClient (at least as far as I know). Could somebody help to find a workaround on how to download the file?
The microsoft's script is:
Download
var $SelfPage = new function()
{
var _download = 'http\x3a\x2f\x2f5odcbq.bay.livefilestore.com\x2fy1pi19dAInfgawlhjDTcs2sbdCJEkvL7jzsz8SVx9qA-EiQwX-ZPeg-DCt63IEoNWu7USu9uUA-j9FkUosBKqU-3Q\x2fApskaita_1.1_beta_update.exe';
var _demote = 'http\x3a\x2f\x2f5odcbq.bay.livefilestore.com\x2fy1pi19dAInfgawlhjDTcs2sbdCJEkvL7jzsz8SVx9qA-EiQwX-ZPeg-DCt63IEoNWu7USu9uUA-j9FkUosBKqU-3Q\x2fApskaita_1.1_beta_update.exe';
var _dirty = false;
this.MarkDirty = function() { _dirty = true; }
this.Download = function()
{
if (_dirty)
{
_dirty = false;
window.location = _demote;
}
else
{
window.location = _download;
}
}
}
|
|
|
|
|
Hi I don't know if anyone could help me. I'm beginner on C# programing and I have an assignment to finish and i don't know how to finish!!!
I started creating a program with a menu with options to creates a new file and read the new file. The files that I create have an boundary limits(not less than 125 and no more than 350 characters in number) and after creating and saving the file there is an option to go to main menu. This is the part that I've done. Now I have to after writting on the new file create an option to encript and save the file and when opening the file it should have another option to go back to plain text format(decrypt). The encryption should be represented as numbers grouped in pairs, and it should create alternate numbers(written twice). for some single letters ( the most common ones a,e,o,r,t), also using null characters I have to include some mechanism for introduce spaces!!! I really apreciate if anyone could help me with some suggestions,
Thanks
|
|
|
|
|
I would encrypt using built in encryption classes like Rijndael-Managed, what is it you want to do, exactly?
|
|
|
|
|
I'm on my first year of C# i've learnt all the basic but I don't know how to encrypt or decrypt any message, that is my biggest problem. Really I don't know how to convert characters to integers,
Thanks for your help
|
|
|
|
|
sofi79 wrote: don't know how to convert characters to integers
Convert.ToInt32(char)[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
sofi79 wrote: I don't know how to convert characters to integers
Probably because it's so simple:
char c = 'a' ;
int i = c ;
System.Console.WriteLine ( i ) ;
c = (char) i ;
I'd be interested in hearing more about this simple encryption process.
|
|
|
|
|
I always assumed I needed an explicit Convert calls here. Learn something new everyday.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
The Convert class is evil; don't use it.
|
|
|
|
|
Are you being serious?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Mostly. The only member of Convert I use is ChangeType and that only in extreme circumstances.
|
|
|
|
|
What do you have against it?
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
|
I'll have to check my code at some point. I could've sworn I found places where I had to use the convert class instead of casting before.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Please do.
I've found ChangeType to be useful when I don't know the destination type at compile time and even generics won't help; it's rare. One example I have is loading a DataTable from a CSV file. Otherwise, if you know the destination type, just use it.
I ran a little test and found int.Parse to be 3% quicker than Convert.ToInt32 (ToInt32 requires an additional method invocation), which isn't much, but as it supports my position I'll consider it significant.
|
|
|
|
|
It was string to int conversion I was thinking of, although why int foo = (int)"1" fails but int foo = (int)'1'; does not is a question I'm afraid to ask.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|