|
Thanks Vestras,
It worked!
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
|
|
I'm trying to roll up some old (originally .net 1.1) abstract classes into generics. The classes in question all provide similar functionality for a data object of a specific type. For the most part things are going well, but I've ran into a few places where one one of the data objects is of a type that needs extra processing in one method beyond what all the other types need. I can check the type of T to see if it's the type I need to do the special processing for, but the cast from T to SpecialType won't compile. Is there a different way I can do this, or is what I want to do impossible?
class MyGenericClass<T> : ICloneable where T: class, new()
{
private T m_storedClass;
...
private DoStuff()
{
if (typeof(T) == typeof(SpecialType))
{
((SpecialType)m_storedClass).SpecialString = "foo";
}
}
The European Way of War: Blow your own continent up.
The American Way of War: Go over and help them.
|
|
|
|
|
I am working on a C# application which accepts users information including their photos. So can you tell me the code how to store this photo in a data base......................... in the database there is a table called Personal ..................... and there is a column called photo(its data type is Image) which helps me to save a picture .............. Help me please........ Thank you
|
|
|
|
|
There are hundreds and hundreds of solutions to this problem on the web just search for save image to database c#.
To narrow the search a little replace 'database' in the search term by the name of the database you are using e.g.sqlserver.
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.”
|
|
|
|
|
Hello,
I am new to C#. I would like to read a line of data which contains several items separated by spaces, e.g.
10 20 30
In C++, I would accomplish this by infile>>num1>>num2>>num3
However all of the examples I have seen in C# are for reading an entire line of string data.
Any help would be appreciated.
|
|
|
|
|
It really depends on the exact format of your data, but if your example is an accurate representation, then two approaches spring to mind.
1) as the examples you have seen do, read an entire line into a string (call it dataString ), then
string[] numbers = dataString.Split(' ');
foreach (string s in numbers)
{
someIntVariable = int.Parse(s);
}
2) BinaryReader has a ReadInt32() method. Which can be used, for binary streams, obviously.
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.”
|
|
|
|
|
Thank you so much it worked.
|
|
|
|
|
Hi all,
I have an MDI window with a ButtonBar (defined as master) and from there I can call the child windows (outside the master).
And from one child window I am calling an DialogWindow.
And here comes the problem:
When I am closing this dialog window, the FormClosing event (of the dialog) fires 34 times, and after that the FormClosed event fires 10 times.
I am shure that the events are only initialized for one time.
So you can say that 3 layers are opened. (MDI-Master --> MDI-->Slave --> DialogForm)
It wouldn't be a problem at all, if the dialog window wouldn't hang up. The whole Program stops.
in the FormClosing method is only a quiet simple code.
Dialog_FormClosing(.....)
{
try
{
Console.WriteLine("closing");
if(!can_close)
{
Messagebox.Show("You have to finish your app first");
e.Cancel = true;
}
else
{
e.Cancel = false;
}
}
catch
{
}
}
The question is: Why fires the event so often ?
And why hangs up the dialog (the dialog does not close)
Some ideas ? - using .NET 2.0.xxx
Tnx
Frank
|
|
|
|
|
After I call DoDragDrop, the MouseUp event does not fire. I spent some time Googling this and I see that other people have noticed this behavior.
Here's my code. Anyone know what to do about this?
Thanks
public delegate void SpliiterMovedEventHandler(object sender, SplitterMovedEventArgs e);
public partial class _Splitter : UserControl
{
private bool _bDragging = false;
private int _OldPosition = 0;
public _Splitter()
{
InitializeComponent();
_OldPosition = this.Top;
}
public event SpliiterMovedEventHandler SplitterMoved;
protected void OnSpliiterMoved()
{
if (SplitterMoved != null)
{
SplitterMovedEventArgs args = new SplitterMovedEventArgs(_OldPosition, this.Top);
SplitterMoved(this, args);
}
}
private void _Splitter_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
_bDragging = true;
_OldPosition = this.Top;
this.Cursor = Cursors.SizeNS;
this.DoDragDrop(sender, DragDropEffects.Copy);
}
}
private void _Splitter_MouseMove(object sender, MouseEventArgs e)
{
if (_bDragging)
{
this.Cursor = Cursors.SizeNS;
this.Left = 0;
}
}
private void _Splitter_MouseUp(object sender, MouseEventArgs e)
{
if (_bDragging)
{
_bDragging = false;
this.Cursor = Cursors.Default;
OnSpliiterMoved();
_OldPosition = this.Top;
}
}
private void _Splitter_MouseLeave(object sender, EventArgs e)
{
this.Cursor = Cursors.Default;
}
private void _Splitter_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
e.UseDefaultCursors = false;
this.Cursor = Cursors.SizeNS;
}
private void _Splitter_MouseEnter(object sender, EventArgs e)
{
this.Cursor = Cursors.SizeNS;
}
}
Everything makes sense in someone's mind
|
|
|
|
|
Just to clarify this for me.
Are you saying the the mouseup which is part of dropping doesn't fire, or
are you saying that after completing a drag-drop, the next time a mouseup occurs the event doesn't fire?
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.”
|
|
|
|
|
Not sure I understand what you're asking me. In the code I pasted, the _Splitter_MouseUp event does not execute.
Everything makes sense in someone's mind
|
|
|
|
|
I am sorry that I have been slow in replying, but you replied to yourself, not to me, so I didn't know you had replied.
I'll try to explain what I want to know (remember you said mouseup did not fire after dodragdrop)
When you do the drop part of a dragdrop you have to release the mouse button. That is a mouseup , so is it this mouseup that you are asking about, or is it those that happen after that one that are the problem.
BTW you do know that there is a built in splitter control in .NET, right?
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.”
|
|
|
|
|
Yes, I know about the .Net spliiter.
DragDrop is new to me in C#. It sounds like you're saying that there are two MouseUp events - The standard MouseUp on many controls, and one related to DragDrop.
Or am I clueless?
Everything makes sense in someone's mind
|
|
|
|
|
KMAROIS wrote: It sounds like you're saying that there are two MouseUp events
What I was trying to establish was that there is a mouseup movement as part of the drop but that it does not fire the event, it fires the ondrop event instead.
But never mind.
Have you seen this stackoverflow[^], and more to the point, does it help in your case?
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.”
|
|
|
|
|
Ok, so you're asking me if I let go of the mouse button while over the control? Yes, I did.
If I comment out the DoDragDrop in the MouseDown, then the MouseUp will fire. So it's something
to do with DragDrop consuming the mouse events.
And yes, I did see the stackoverflow article, although I'm not sure I understood all of it. It looks like they coded their solution so that the drop does not occur of the mouse over the control being dragged, therefore the mouseup will fire?
Everything makes sense in someone's mind
modified on Tuesday, July 14, 2009 4:53 PM
|
|
|
|
|
From the code that you posted I can see nothing that would cause the problem behaviour. So the chances are that somehow, after the DoDragDrop, your application still thinks that the dragdrop operation is still continuing, which is why the mouseup events are not being fired. Something about the way you are handling the DragDrop event might not be completing properly.
If you have not already done so try working through the DoDragDrop example on MSDN[^], to see if you can spot any difference to the way you are doing it.
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.”
|
|
|
|
|
I'm certainly open to my code being wrong, but as I said in my original post, I Googled it and found other people facing the same problem.
But I will look at the MSDN example.
Everything makes sense in someone's mind
|
|
|
|
|
Hi
I have a binary file and I would like to start reading it from an origin. That origin is the location of a string.
I try to find that string with this method:
public long STRLOC(string File, string strToDig)
{
FileStream fs = null;
BinaryReader br = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
try { br = new BinaryReader(fs); }
catch { throw new Exception("Binary okuyucu oluşturulamadı."); }
try
{
byte[] icerik = new byte[fs.Length];
br.Read(icerik, 0, (int)br.BaseStream.Length);
string asText = Encoding.UTF8.GetString(icerik);
int index = asText.IndexOf(strToDig);
if (index == -1)
return -1;
if (strToDig != asText.Substring(index, strToDig.Length))
return -2;
return index;
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { br.Close(); fs.Close(); fs.Dispose(); }
}
I successfully get the location of that string with this method. My string starts at 551828.
Then I want to start reading the file to it's end with this method:
public string ReadBinary(string File, long origin)
{
FileStream fs = null;
BinaryReader br = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
try { br = new BinaryReader(fs); }
catch { throw new Exception("Binary okuyucu oluşturulamadı."); }
try
{
br.BaseStream.Position = origin;
byte[] icerik = new byte[br.BaseStream.Length - origin];
br.Read(icerik, 0, (int)(br.BaseStream.Length - origin));
return Encoding.ASCII.GetString(icerik);
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { br.Close(); fs.Close(); fs.Dispose(); }
}
I call it with ReadBinary("MY FILE'S LOCATION", 551828)
But it doesn't start reading from the position of my string. It just starts from somewhere a lot before my string or beginning.
What am I doing here wrong? Why doesn't my BinaryReader start from the location that I've set with br.BaseStream.Position = origin; , I've tried br.BaseStream.Seek(origin,SeekOrigin.Begin); but it doesn't work too.
Thanks in advance.
|
|
|
|
|
Hello
Im trying to build a client in c# that talks with some remote (php)server with SOAP using the NuSOAP library.
Here im using a struct/object that will containt the user info of some user:
public struct UserProfile {
public string username;
public string password;
public string email;
public string site;
public string signature;
public int age;
public int points;
And this is the PHP Code:
server->wsdl->addComplexType(
'UserProfile',
'complexType',
'struct',
'all',
'',
array(
'username' => array('name' => 'username', 'type' => 'xsd:string'),
'password' => array('name' => 'password', 'type' => 'xsd:string'),
'email' => array('name' => 'email', 'type' => 'xsd:string'),
'site' => array('name' => 'site', 'type' => 'xsd:string'),
'signature' => array('name' => 'signature', 'type' => 'xsd:string'),
'age' => array('name' => 'age', 'type' => 'xsd:int'),
'points' => array('name' => 'username', 'type' => 'xsd:int'),
)
);
$server->wsdl->addComplexType(
'UserProfileArray',
'complexType',
'array',
'',
'SOAP-ENC:Array',
array(),
array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:UserProfile[]')),
'tns:UserProfile'
);
$server->register("getUserProfile",
array(),
array('return' => 'tns:UserProfileArray'),
$namespace,
false,
'rpc',
false,
'Get the user profile object'
);
function getUserProfile(){
$profile['username'] = "user";
$profile['password'] = "pass";
$profile['email'] = "usern@ame";
$profile['site'] = "u.com";
$profile['signature'] = "usucsdckme";
$profile['age'] = 111;
$profile['points'] = time() / 2444;
return $profile;
}
Now I already have a working login function, and I want to get the info about the logged in user but I dont know howto obtain these. This is what im using to get the userinfo:
string user = txtUser.Text;
string pass = txtPass.Text;
SimpleService.SimpleService service = new SimpleService.SimpleService();
if(service.login(user, pass)){
}
SoapApp.SimpleService.UserProfile[] user = service.getUserProfile();
MessageBox.Show(user[0].username + "--" + user[0].points);
The getUserProfile() function produces an error:
System.Web.Services.Protocols.SoapException was unhandled
Message="unable to serialize result"
Source="System.Web.Services"
The article I used for this was from: http://www.sanity-free.org/125/php_webservices_and_csharp_dotnet_soap_clients.html[^]
The difference on what they are doing and what I try to do is that I only want to get one object returned instead of multiple 'MySoapObjects'.
I hope someone is familiar with this and could help me, thanks in advance!
Regards,
opx
|
|
|
|
|
Ok, php and .net are different platform. So data structers are different. Normally different platform can not talk each other.
If we talk about windows side; windows solve this problem with WCF (Window Communication Foundation). On java side; Sun's Project Tango
http://java.sun.com/developer/technicalArticles/glassfish/ProjectTango/[^]
But your server side is PHP. How to solve I don't know. May you can parse XML format. I know it is not good solution but you can solve using XML parsing.
Best Regards...
|
|
|
|
|
Thank you sir
Parsing XML/String, I can live with that.
Thanks again,
- opx
|
|
|
|
|
|
dataminers wrote: Ok, php and .net are different platform. So data structers are different. Normally different platform can not talk each other.
that's totally incorrect.
the whole point of service oriented architectures is so that disparate systems can work together.
C# can talk to java, java can talk to php, php can talk to C# and vice versa. it doesn't matter what the source or destination languages are, as long as they can serialize/encode and deserialize/decode an http request / response to and from SOAP.
|
|
|
|
|