|
In the first case, almost all languages allow you to do that, they just discard the return value.
In the second case, code not enclosed in a namespace declaration ends up in the global:: namespace. If there is a naming conflict between two classes, one inside a namespace and the other outside of any namespace, then the latter can be access using the global:: namespace.
namespace WindowsFormsApplication1 {
class Class2 {
}
static class Program {
[STAThread]
static void Main() {
Class2 c2 = new Class2();
c2.DoSomething();
global::Class2 c3 = new global::Class2();
c3.DoSomething();
}
}
}
class Class2 {
public void DoSomething() {
}
}
"Don't confuse experts with facts" - Eric_V
|
|
|
|
|
hello everyone,
i don't know much about service application,
i want to know dat can we create window services in VS2008
using c# ?
i didn't find window service template in my VS2008 professional edition.
and Is this possible that my window app which is develop in
c# VS2008 can work as window service on vista.
thank you.....
-- Modified Monday, August 22, 2011 3:20 AM
|
|
|
|
|
As far as I know the template is only available for C++. However, you may find some reasonable ideas here[^].
|
|
|
|
|
It's available in the Windows section of the c# project types and is called "Windows Service", although I'm not sure if it's installed by default in all versions of VS but would have thought it was in the professional edition.
|
|
|
|
|
yes i found it thank you......
but can i call my app exe in window service.
|
|
|
|
|
I've re-read you question.
Yes you can use your application as a service but not without some modification. If most of the functionality is in class libraries then your application (be it a console application or a windows service) acts as an entry point to your functionality.
You will need to do some extra work around error reporting and service specific things like startup options but a basic introduction to windows services via google will help with this.
modified on Monday, August 22, 2011 9:17 AM
|
|
|
|
|
Hi All,
First of all I would like to thank you for the support. I am new in coding and need assistance in getting a specific xml content to an excel spreadsheet or to a datagridview.
the XML file is not a standard one (i think and below is a sample).
what i need from this xml file is the following data:
the name (Towers xxx] of the alert and the gps points (dont need the utm)
this is the xml
[code]
="1.0"="UTF-16"
<layer>
<name>
SF Zones
</name>
<alert_area_object>
<creation_time>
1303889594
</creation_time>
<name>
Tower 1
</name>
<description>
Fence Alert
</description>
<event_types num="1">
<event_type>
11111
</event_type>
</event_types>
<event_severity>
2
</event_severity>
<event_override_flag>
false
</event_override_flag>
<identities num="0"/>
<categories num="0"/>
<groups num="0"/>
<target_appear_in_area>
true
</target_appear_in_area>
<target_enter_area>
true
</target_enter_area>
<target_leave_area>
true
</target_leave_area>
<from_hour>
0
</from_hour>
<from_minute>
0
</from_minute>
<to_hour>
23
</to_hour>
<to_minute>
59
</to_minute>
<from_speed>
0
</from_speed>
<to_speed>
98.8889
</to_speed>
<weighting>
<weight>
<type>
2
</type>
<value>
99
</value>
</weight>
<weight>
<type>
204
</type>
<value>
99
</value>
</weight>
<weight>
<type>
205
</type>
<value>
99
</value>
</weight>
</weighting>
<visual_feedback>
true
</visual_feedback>
<sound_repeats>
-1
</sound_repeats>
<wave_file>
C:\4C\RunTime\OWP\Sounds\sirenwawa.wav
</wave_file>
<utm_zone>
40
</utm_zone>
<shape type="ClosedPolygon">
<num_of_alloc_points>
22
</num_of_alloc_points>
<num_of_points>
5
</num_of_points>
<geo_position lat="40.76876678920284" long="-73.98097831075269"/>
<geo_position lat="40.76869191861909" long="-73.98078254132794"/>
<geo_position lat="40.76839192572469" long="-73.97999998924834"/>
<geo_position lat="40.76749000414105" long="-73.97804528571041"/>
<geo_position lat="40.76643902004108" long="-73.97593868227233"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
</shape>
</alert_area_object>
<alert_area_object>
<creation_time>
1303890003
</creation_time>
<name>
Towers 1 to 4
</name>
<description>
Fence Alert
</description>
<event_types num="1">
<event_type>
11111
</event_type>
</event_types>
<event_severity>
2
</event_severity>
<event_override_flag>
false
</event_override_flag>
<identities num="0"/>
<categories num="0"/>
<groups num="0"/>
<target_appear_in_area>
true
</target_appear_in_area>
<target_enter_area>
true
</target_enter_area>
<target_leave_area>
true
</target_leave_area>
<from_hour>
0
</from_hour>
<from_minute>
0
</from_minute>
<to_hour>
23
</to_hour>
<to_minute>
59
</to_minute>
<from_speed>
0
</from_speed>
<to_speed>
98.8889
</to_speed>
<weighting>
<weight>
<type>
2
</type>
<value>
99
</value>
</weight>
<weight>
<type>
204
</type>
<value>
99
</value>
</weight>
<weight>
<type>
205
</type>
<value>
99
</value>
</weight>
</weighting>
<visual_feedback>
true
</visual_feedback>
<sound_repeats>
-1
</sound_repeats>
<wave_file>
C:\4C\RunTime\OWP\Sounds\sirenwawa.wav
</wave_file>
<utm_zone>
40
</utm_zone>
<shape type="ClosedPolygon">
<num_of_alloc_points>
22
</num_of_alloc_points>
<num_of_points>
6
</num_of_points>
<geo_position lat="40.76876678920284" long="-73.98097831075269"/>
<geo_position lat="40.76869191861909" long="-73.98078254132794"/>
<geo_position lat="40.76839192572469" long="-73.97999998924834"/>
<geo_position lat="40.76749000414105" long="-73.97804528571041"/>
<geo_position lat="40.76643902004108" long="-73.97593868227233"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
<utm_points x="132131" y="132131"/>
</shape>
</alert_area_object>
</layer>
[/code]
thanks again
|
|
|
|
|
Use XSLT to transform the XML and extract the data you need into the proper format.
I know the language. I've read a book. - _Madmatt
"The OP herself was not sure about her question"
"The OP is from India and I know what she meant." - Shameel
|
|
|
|
|
Hi,
this is the code i currently have but it parse the xml but is missing some nodes and is not exactly what i need.
i need that it will get the name of the alert and all the gps poings while with this code it takes most of the data except the gps points
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Xml;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
XmlDataDocument xmlDatadoc = new XmlDataDocument();
xmlDatadoc.DataSet.ReadXml(@"C:\Desktop\Book Application\zone.xml");
DataSet ds = new DataSet("book DataSet");
ds = xmlDatadoc.DataSet;
dataGridView1.DataSource = ds.DefaultViewManager;
dataGridView1.DataMember = "alert_area_object";
}
}
}
thanks
modified on Thursday, August 25, 2011 3:04 AM
|
|
|
|
|
Edit this and use the code block toolbar item to properly format the code snippet.
I know the language. I've read a book. - _Madmatt
"The OP herself was not sure about her question"
"The OP is from India and I know what she meant."
|
|
|
|
|
|
I have a win app and a web app developed in .Net Framework 3.5.
I want to pass an object from web to win app.
I want the receiver app be notified from coming object and recive it.
What are the solutions?
Best wishes
|
|
|
|
|
Your options:
0) Write a web service that you then access from your desktop app (not kowing the specific details of the data being requested, or why it's being requested, this is the way I'd do it)
1) Write a new page on your web site that you can browse to that returns the data you want, and use the HTTPWebRequest object to browse to that web page.
You can't "push" to the desktop app because web services and web sites are request-driven, meaning the data is only returned when that data is requested.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997
|
|
|
|
|
Please look into the Bayeux Protocol[^]. It was based on the idea of inverting the usual client request / server response paradigm. Of course the client still has to connect to the server and keep that connection open, but after that the server can push notifications/data to the client.
I'm not sure if there are any client side APIs that would let you use this in a WinForm application, but you could circumvent this by using a webbrowser control inside your WinForm application.
Best Regards,
—MRB
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925modified on Monday, August 22, 2011 10:58 AM
|
|
|
|
|
|
Thanks Keith. It looks as if deep linking isn't allowed. I pasted in the link from the google page and now it works.
Cheers!
"With sufficient thrust, pigs fly just fine."
Ross Callon, The Twelve Networking Truths, RFC1925
|
|
|
|
|
Don't have the attention span to post as article - but thought this might be interesting:
Automatic properties are great but the annoyance of not being able to set them automatically defers a lot of people from using them.
What we (read - I) want to be able to do something like this:
double MyPie { get; set; } = "3.141";
string MyLove { get; set; } = "Pizza";
The default value attribute in System.ComponentModel is of no help there, though a lot of us (read - me) tried that in the beginning:
[DefaultValue(0.3141)]
double MyPie { get; set; }
[DefaultValue("Pizza")]
string MyLove { get; set; }
Initializing the properties one by one in the constructor is at least as annoying as simply doing this:
double _myPie = 0.3141;
double MyPie { get { return _myPie; } set { _myPie = value; } }
double _myLove = "Pizza";
double MyLove { get { return _myLove; } set { _myLove = value; } }
Luckily the nice little feature of extension methods allows us something not exactly optimal or fully elegant - but functional and a good exercise in C# clockwork.
So with just a bit of hammering we can enable automatic reset properties to their declared System.ComponentModel.DefaultValueAttribute if any was specified.
Test code:
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using CSharpUtils;
namespace MyAppNamespace
{
public class TestClass
{
[DefaultValue(0.3141)]
public double MyPie { get; set; }
[DefaultValue("Pizza")]
public string MyLove { get; set; }
public TestClass()
{
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}", MyPie, MyLove == null ? "null" : MyLove));
int ret = (this as Object).ResetPropsUsingDefaultAttributes(false);
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}. {2} properties we set", MyPie, MyLove == null ? "null" : MyLove, ret));
MyLove = "My dear wife";
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}", MyPie, MyLove == null ? "null" : MyLove));
ret = (this as Object).ResetPropsUsingDefaultAttributes(false);
MessageBox.Show(string.Format("MyPie = {0}, MyLove = {1}. {2} properties we set", MyPie, MyLove == null ? "null" : MyLove, ret));
}
}
}
This (as you may have already guessed) is done using an extension method to the System.
You will need a public static class to define the extension method in. here's the basic implementation source (feel free to use the code and extend it's functionality):
using System;
using System.Text;
using System.Reflection;
using System.ComponentModel;
namespace CSharpUtils
{
static class CSharpUtilsExtensionMethods
{
public static int ResetPropsUsingDefaultAttributes(this Object oThis, bool initInheritedProperties)
{
int count = 0;
Type oType = oThis.GetType();
PropertyInfo[] infos = oType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
foreach (PropertyInfo inf in infos)
{
if (initInheritedProperties || inf.DeclaringType.Equals(oType))
{
object[] oDefAtts = inf.GetCustomAttributes(typeof(DefaultValueAttribute), initInheritedProperties);
if (oDefAtts.Length > 0)
{
DefaultValueAttribute defAtt = oDefAtts[oDefAtts.Length - 1] as DefaultValueAttribute;
if (defAtt != null && defAtt.Value != null && !defAtt.Value.Equals(inf.GetValue(oThis, BindingFlags.GetProperty, null, null, null)))
{
inf.SetValue(oThis, defAtt.Value, BindingFlags.SetProperty, null, null, null);
count++;
}
}
}
}
return count;
}
}
}
All that's left now is use out test class (here again - with no message box and other nonsense
using System;
using System.ComponentModel;
using System.Text;
using System.Windows.Forms;
using CSharpUtils;
namespace MyAppNamespace
{
public class TestClass
{
[DefaultValue(0.3141)]
public double MyPie { get; set; }
[DefaultValue("Pizza")]
public string MyLove { get; set; }
public void ResetProps()
{
(this as Object).ResetPropsUsingDefaultAttributes(false);
}
public TestClass()
{
ResetProps();
}
}
}
Notes:
- To use the extension method - the .cs file making the call must have a 'using' declaration of namespace where the extension method resides in.
- Passing true for parameter initInheritedProperties also initializes any parent class properties - at the expense of possibly resetting already initialized properties. you can always extend the extension method to try and account for these cases.
- Resetting the properties in this manner works also outside constructor - anywhere in the program with the proper access.
- There's still the annoyance of having to add a line in the constructor - but it is just one line and will no require additional modifications if properties are added, removed or their type/default value is changed.
There you go,
have fun
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
Itai Basel wrote: Don't have the attention span to post as article
Then post it as a Tip/Trick[^]
where do these people come from?
[edit]
I see from the profile - a lurker for 8 years with never a message, impressive. Must have been a bitch trying to find your old password
Do use the tip/trick area as it is specifically designed for those with limited attention spans and good ideas. They do get vetted and need to be released by a gold member but this one would have no problem at all. Keep it up!
[/edit]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks.
I always plan to post cool stuffs but never do due to having to go through all that publishing a web-page for it.. Never been much of a writer and am not a native English speaker so I always find out afterward that I written something funny too.
I'll go look where the tips&tricks area is.
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
And about remembering the password - no worries - since I need it to download sources.
Anyway - I posted as top/trick. now I need to change the awkward signature since it's got html symbols in it and looks weird after it's posted
Yours,
<><<br mode="hold" />Itai
|
|
|
|
|
I'm just glad you weren't discouraged by a grumpy old bugger on a Sunday morning!
There is a definite warm, fuzzy feeling when you see your contribution put to use by others, it's the main reason why this site works I think, people actually do want to help.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I second it as a tip/trick, or at least as a blog entry.
|
|
|
|
|
Agree with others. Based on length better post it as a blog post. If possible attach download for the source code.
Off Topic:
I found broken text in your signature.
thatraja
My Tip/Tricks My Dad had a Heart Attack on this day so don't...
All these are my opinions. Different people. different way of thinking. I am no one to judge others - Chandru
|
|
|
|
|
hi all
I have uploaded a picture into table but i am stuck, that how may I show the picture in Crystal Reports from table.
I used following codes to upload the picture it works fine
fileStream = new System.IO.FileStream(strFile, System.IO.FileMode.Open, System.IO.FileAccess.Read);
reader = new System.IO.BinaryReader(fileStream);
data = reader.ReadBytes((int)fileStream.Length);
cmd = new OleDbCommand();
cmd.Connection = Module.objConnection;
string strQuery =
"SELECT * FROM PICTURES WHERE " +
"STCODE="+ textBox1.Text +" AND " +
"STSEQ="+ dataGridView1["STSEQ",dataGridView1.CurrentCell.RowIndex].Value.ToString() +" ";
cmd.CommandText = strQuery;
dr = cmd.ExecuteReader();
if (dr.HasRows == false)
{
dr.Close();
cmd.CommandText = "INSERT INTO PICTURES (STCODE,STRNO,STSEQ,FILENAME,FILESIZE,FILETYPE) " +
"VALUES(" + textBox1.Text + ", " +
"" + dataGridView1["STRNO", dataGridView1.CurrentCell.RowIndex].Value.ToString() + ", " +
"" + dataGridView1["STSEQ", dataGridView1.CurrentCell.RowIndex].Value.ToString() + ", " +
"'" + fileName + "'," + data.Length + ",'" + type + "') ";
cmd.ExecuteNonQuery();
(Riaz)
|
|
|
|
|