|
Thank you , Sir
I think I will go with the first Option , ( Very Smart Option )
And I think the second Option will not work if the user Exit and start application many times ,
I know nothing , I know nothing ...
|
|
|
|
|
One workaround would be to make some use datetime abilities(C# or DB it self whatever you are more confortable with).
Example:
BytesReceived | DateTime
100 | 10.02.2011::16:40
198 | 10.02.2011::16:50
that would result in 98 new bytes.
I have no ideea if there is a way to Reset the Network adapter(s). And I'm too lazy for bingle.
If the newest read value it's smaller then previous value then clerly the Pc was restarted or the network adapter reset.
All the best,
Dan
modified on Friday, February 11, 2011 3:11 PM
|
|
|
|
|
Thank You Sir ,
MDL=>Moshu wrote: If the newest read value it's smaller then previous value then clerly the Pc was restarted or the network adapter reset.
I think this very important thing ,I will try some test , Looks very interesting
I know nothing , I know nothing ...
|
|
|
|
|
Hello all,
I have a jcaps web service I need to call with details of a document - this includes DateTime field which expects a Date in the format dd-MM-yyyy but I can't get my datetime to serialize in this format instead it always serializes in the format dd/MM/yyyy. This causes the web service to throw a SOAP exception.
I've tried using a new CultureInfo which is a clone of the current CultureInfo and have changed the DateTimeFormat.DateSeparator = "-" - this will survive a ToString() when I provide the new CultureInfo but when I try a DateTime.Parse() providing the string and culture info it again uses the "/" date separator.
I've also tried with ParseExact() to no avail.
Is there a way to persist CultureInfo through serialization? Or (as I'm beginning to suspect) am I barking up the wrong tree?
Thanks
Paul
ETA - Sorry should make clear the above has been attempted to see what the cultureinfo will persist across, when accessing the web service we just provide the datetime property.
|
|
|
|
|
Provided you call ParseExact with the appropriate parameters it should work:
string date = "02-11-1976";
DateTime dt = DateTime.ParseExact(date, "MM-dd-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None);
Parses it fine for me: What are you doing that is different?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
I don't have any issue with the parsing as such it's when I do something with date time afterwards like .ToString() or when it's serialised prior to a web service call. In these cases the "-" is replaced by "/" causing (in my case) the webservice call to fail.
I've re-tried this morning with a fresh head, and used your example but still have the issue.
Cheers
Paul
|
|
|
|
|
Ah! Easy one: ToString always formats to the current Culture, unless you tell it otherwise.
Try
string date = myDateTime.ToString("dd-MM-yyyy");
You will find a complete list of how to format a DateTime to a string here[^]
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Right thanks for that I was sort of assuming that would be the case - whilst I'm aware of the date formatting options I'm assuming that no such options exist for assigning date times to an object being passed to web service?
Thanks for your responses, btw.
Cheers
Paul
|
|
|
|
|
Unless you are passing it as a string, then no options are needed: a DateTime is not as localised object, it is a number of microseconds since a reference date and time. It only becomes localised into any readable format when you extract bits of information, or change it to some other type.
What are you passing to your web service?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
We instantiate a document object which is a proxy class built automatically when creating the web reference, this contains a number of datetime properties.
We populate the various properties including the datetime fields and call the service which accepts this Document object. When using Fiddler we can see the SOAP call and the datetime fields use the "/" date separator but the JCAPS service wants a "-" separator to consider it a valid Date and so fails.
I'm assuming this is done as part of the serialization process when building the SOAP body and was hoping there was a way we could influence it.
|
|
|
|
|
I don't normally use SOAP - I try to avoid serialization - but I thought it used ISO 8601?
So I thought I'd take a quick look with a SoapFormatter:
public static void ToSoap(Object objToSoap, string filePath)
{
IFormatter formatter;
FileStream fileStream = null;
using (fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
formatter = new SoapFormatter();
formatter.Serialize(fileStream, objToSoap);
}
}
Serializing a DateTime gave a SOAP containing Tick information:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<xsd:dateTime id="ref-1">
<ticks>634333105156406250</ticks>
<dateData>9857705142011182058</dateData>
</xsd:dateTime>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Serializing a class containing a DateTime gave ISO8601 data:
demo d = new demo();
d.s = "Hello Paul";
d.d = DateTime.Now;
ToSoap(d, @"F:\Temp\datetime.soap");
[Serializable]
public class demo
{
public string s;
public DateTime d;
}
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Program_x002B_demo id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/ConsoleApplication1/Tester%2C%20Version%3D1.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<s id="ref-3">Hello Paul</s>
<d>2011-02-14T19:54:57.4218750+00:00</d>
</a1:Program_x002B_demo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I know it's not helpful to you, but I'm intrigued now: how are you doing it?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
I'll get back to you later in the week, I'm off site for a couple of days, thanks for your efforts, much appreciated.
|
|
|
|
|
hi
actually i want to play a sound file on btn clk. i select the sound file by OpenFileDialoge. but i want to play this sound on the other btn clik. it happens if both the btns are in the same form. but i want the selected btn in form 1 and play btn in form2.the program runs but it dont play the sound.
can any 1 help me out??
is problem clear?
|
|
|
|
|
In that case you have to pass the sound file path through to the other form, or set up a static class:
public static class MakeNoisesAndGeneralyBeAnnoying
{
public static string KeyClickSoundFile { get; set; }
public static void PlayButtonClick()
{
String play = KeyClickSoundFile;
if (play != null)
{
}
}
}
Set it from your OpenFileDialog:
string path = @"F:\Temp\click.wav";
MakeNoisesAndGeneralyBeAnnoying.KeyClickSoundFile = path;
And then use it in your Click event:
MakeNoisesAndGeneralyBeAnnoying.PlayButtonClick();
This is one of the very few occasions when I would consider using a static variable justified!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
public static string KeyClickSoundFile { get; set; }
what would be placed in get and set?
m new in c# is static class is essential for this?
plz tell me what would i place in get and set?
one more thing where to create a static class? in form 1or in form2?
thanks
|
|
|
|
|
aeman wrote: what would i place in get and set?
Nothing: It is called an "Automatically Implemented Property" (type "prop" in Visual studio, then press TAB twice and it will create it for you).
The compiler automatically creates a virtual variable to hold the data, you access it via the property name.
In this case it is the equivalent of:
private static string keyClickSoundFile;
public static string KeyClickSoundFile
{
get { return keyClickSoundFile; }
set { keyClickSoundFile = value; }
}
They are useful when you want a property, but don't have to do anything extra with the information yet.
aeman wrote: is static class is essential for this?
Not essential - there are other ways - but it is the way I would go.
aeman wrote: where to create a static class? in form 1or in form2?
Neither! Always try to keep things self contained. If you make it part of Form1 then it implies that only Form1 should use it.
Set up a new class for such common - in the sense of used by many things - and put it in there. (Right click your project name in the Solution Explorer, and select "Add...Class". Give it a sensible name (Mine was "MakeNoisesAndGeneralyBeAnnoying" and click OK. Change it to be a static class in the .CS file, and off you go!)
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
thanks i have made a static calss.
but again a problem
if (play != null)
{
System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(openFileDialog1.FileName);
simplesound.Play();
}
this code i usd for play sound. but it was giving me error in 'openFileDialog1' that i was created in form 1. this is not recognize in this class.
and if i write the specific location of file thn it dont give me error but it dont play the sound as b4.
|
|
|
|
|
OK: to solve your problem, replace "openFileDialog1.FileName" with "play":
if (play != null)
{
System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(play);
simplesound.Play();
}
And you will hear your noise.
However, I lied to you, a little bit, earlier.
This is not the way I would do it. The way I would do it is cleaner, and a lot nicer, but it is quite a bit more advanced than I think you are, and needs more advanced C# - which is why I didn't recommend it.
On reflection, I think that may have been a mistake. So, here is the way I would actually have done it: it uses one of the so-called "Pillars of Object Oriented Programming" - inheritance.
What you want to do is make a button "click", or play a sound when it is pressed. That is, to add functionality to a button. The proper way to do that is to produce a new Button, which has all the features of the old, but with the addition of playing a sound. We inherit the button into a new class, and add our functions to it. It isn't difficult: Create a new class (like I told you earlier) only this time, call it "ClickButton". The whole class file consists of:
public class ClickButton : Button
{
private static System.Media.SoundPlayer click = null;
private static string clickPath = null;
public static string ClickSound
{
get { return clickPath; }
set
{
clickPath = value;
if (clickPath == null)
{
click = null;
}
else
{
click = new System.Media.SoundPlayer(clickPath);
}
}
}
public ClickButton()
{
base.Click += new EventHandler(MyClick);
}
private void MyClick(object sender, EventArgs e)
{
if (click != null)
{
click.Play();
}
}
}
All this does is declare a new class, inherited from Button. It adds two private variables: one a string to hold the path to the sound file, and the other a SoundPlayer we can load with the sound to save time when we play it. The only reason we store the string path, is so we can return it in the ClickSound property getter. When you set the property, we load the file and save both the path and the sound in a playable state.
The constructor adds our click handler to the default Button handlers, so whenever our button is clicked, we get told.
Our click handler checks if there is a sound, and if so, plays it.
Build that, then add a ClickButton to your form(s) - it should appear at the top of your Toolbox in design mode.
All you have to do then is set the ClickSound to the appropriate file when the user selects it:
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
ClickButton.ClickSound = ofd.FileName;
}
Every time you want a button that makes a noise, use a ClickButton instead of a Button and it will work (after you have set the sound file).
Did any of that make sense?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
OK: to solve your problem, replace "openFileDialog1.FileName" with "play":
if (play != null)
{
System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(play);
simplesound.Play();
}
And you will hear your noise.
its not working . again the same problem.File not Found exception unhandle on 'simplesound.Play();'
how can attach the file here i will snd u the screen short of my problem.
i try the other code thn tell u.
thanks for helping me.
|
|
|
|
|
Put a breakpoint on the line:
System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(play); And look at the content of "play": does it look like the address of your file?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
ClickButton.ClickSound = ofd.FileName;
}
this is code for the btn in the form 1?
what would i write in click event? mean on the other btn in form 2 where i want to play sound?
thanks
|
|
|
|
|
aeman wrote: this is code for the btn in the form 1?
Probably not: it is the code for the user to select which sound they want played when they click a button. Where you need to put that is going to be up to you and how your code works!
aeman wrote: what would i write in click event? mean on the other btn in form 2 where i want to play sound?
If you are using the ClickButton, then nothing: once a sound file is set, all ClickButtons will play it automatically: that is why it is a better method than the other suggestions.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
i have solved my problm
thanks u realy help me alot.
m snding som code here so that it will help otherz.
DialogResult result = openFileDialog1.ShowDialog();
Form2 f = new Form2();
f.s1 = openFileDialog1.FileName;
when u select a file assign it to a string.thn on which btn u want to play sound write the following code.
System.Media.SoundPlayer simplesound = new System.Media.SoundPlayer(s1);
simplesound.Play();
there u go 
|
|
|
|
|
hmmmm... so your button click event handler in your second form needs to run the same code as it does when in form1. I think your best option is to post you code for both button events (when in form 1) and then post the code you are using for your button click in form2. Then we can help more
return 5;
|
|
|
|
|
I would possibly set up a static event handler in a suitable class and call that from the button click events. If you do this, be sure to unregister the events when you close your forms (this is good practice anyway but essential with static events or event handlers)!
public static void ButtonWithSoundClicked(object sender, EventArgs e)
{
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
button1.Click += YourStaticClass.ButtonWithSoundClicked;
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
button1.Click -= YourStaticClass.ButtonWithSoundClicked;
}
}
|
|
|
|