|
Thank you very much. Only thing about your code is, that you can't cast a BitmapSource to a Image.
So I changed the code to this:
Image img = ShellFile.FromFilePath("C:\\foo.pptx").Thumbnail.Bitmap;
|
|
|
|
|
Sorry for the hasty typing!
/ravi
|
|
|
|
|
I have a simple Employee Class as follows:
I want to create a new Employee object from a different Class having Main
Can I return the Complete Employee object from here when Main class uses GetEmployee method.
The code below errors out saying variable e in last method below is undefined
namespace TestEmployee
{
class Employee
{
int eId;
string eName;
double age;
public Employee(int i, string n, double a)
{
eId = i;
eName = n;
age = a;
}
public Employee()
{
eId = 1105;
eName = "Peter Cava";
age = 32 ;
}
public Employee GetEmployee()
{
Employee e;
e.eId = this.eId;
e.eName = this.eName;
e.eId = this.eId;
return e;
}
}
}
|
|
|
|
|
Employee e <big>= new Employee()</big>;
(Though I don't know why you're cloning the Employee.)
|
|
|
|
|
If you want to create a new employee from your main method you should just use:
Employee myEmployee = new Employee();
if you really want to have a cloned object you should have a look at the Interface ICloneable for implementing the right methods.
|
|
|
|
|
thanks for the reply
I did create a new Employee Object
class Employee
{
int eId;
string eName;
double age;
public Employee(int i, string n, double a)
{
eId = i;
eName = n;
age = a;
}
public Employee()
{
}
public Employee GetEmployee()
{
Employee e = new Employee();
e.eId = this.eId;
e.eName = this.eName;
e.age = this.age;
return e;
}
}
and calling this from a form where I give the 3 inputs and want to see it in new set of fields
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i1 = Convert.ToInt32(textBox1.Text);
string nm = textBox2.Text;
double d2 = Convert.ToDouble(textBox3.Text);
Employee em = new Employee(i1, nm, d2);
em.GetEmployee();
textBox5.Text = em.GetEmployee?? for Employee id from em object
textBox6.Text = em.GetEmployee?? for Employee name from em object
textBox6.Text = em.GetEmployee?? for Employee age from em object
}
|
|
|
|
|
Well the problem is that all your variables in the employee class don't have public, or private set. In that case they will be private and only be seen within the class Employee.
To manage that the correct way, C# offers you the posibility to create so called "Properties".
I've created properties as you see in the code of the class.
public class Employee
{
public int EId{get;set;}
public string EName{get;set;}
public double Age{get;set;
public Employee(int i, string n, double a)
{
eId = i;
eName = n;
age = a;
}
public Employee()
{
}
}
In the Form1 class you can access the properties pretty simple by creating a new Employee with Employee em = new Employee();
and access each property like: em.Name
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int i1 = Convert.ToInt32(textBox1.Text);
string nm = textBox2.Text;
double d2 = Convert.ToDouble(textBox3.Text);
Employee em = new Employee(i1, nm, d2);
textBox5.Text = em.EId.ToString();
textBox6.Text = em.EName;
textBox6.Text = em.Age.ToString();
}
Hope this helps.
|
|
|
|
|
Oh My, cant believe I dropped the ball on private and public declaration.
Thanks very much for the details and how to use the properties.
One last question please
in the Employee class, if I have to return as an object I need to have a variable of the class and do a new, right like in
Employee e = new Employee(); in code below.
class Employee
{
public int eId;
public string eName;
public double age;
public Employee(int i, string n, double a)
{
eId = i;
eName = n;
age = a;
}
public Employee()
{
}
public Employee GetEmployee()
{
Employee e = new Employee();
e.eId = this.eId;
e.eName = this.eName;
e.eId = this.eId;
return e;
}
|
|
|
|
|
You should not expose the class variables as public. Rather good design uses property accessors. That way any logic that may need to be executed when a property is set or accessed will be executed.
You don't always need an instance of a class to access it's properties or methods.
public class Employee
{
private static int m_Id;
public static Foo()
{
}
public static int Id{get; set;}
}
int id = Employee.Id;
Employee.Foo();
Static methods and properties are not bound to an instance of a class. The Factory pattern quite often uses this to create instances
public class Employee
{
public static Employee CreateEmployee()
{
return new Employee();
}
}
Employee e = Employee.CreateEmployee();
No comment
|
|
|
|
|
Thanks very much Mark and Bob for the response. I think I am slowly getting it.
Thanks, Ravi
|
|
|
|
|
I don't understand what the purpose of GetEmployee is. It is functionally doing a clone but that seems to be unnecessary.
|
|
|
|
|
Hi,
Just creating an Instance of Employee Class......
Thanks & Regards
Arya1685
P Before printing think about your responsibility & commitment with the Environment! ü
|
|
|
|
|
when login a page then if invalid pasword so only that particular part is refershed not whole page
|
|
|
|
|
are you sure what you are asking?
***** Programme comme si dept soutien technique. est plein de tueurs en série et ils savent adresse de votre domicile. *****
|
|
|
|
|
I am using a UdpClient to listen for messages from another machine on the same network. I am using port 63000 and this works on all machines except for 1. This one machine gives me an AccessDenied SocketException when I create the object in the constructor.
I have looked at netstat and TCPView and no other apps/processes are using port 63000. If I move the port to 60001, it works.
My constructor for the UdpClient is using the IPEndPoint object:
private static ipEndPoint IPEndPoint = new IPEndPoint(IPAddress.Any, 63000);
Google has not been helpful, as everything I read says that it is likely because another app/process is using the same port. However, I cannot find anything using that port in netstat or TCPView.
Does anyone have any ideas for me to try or look at?
Thanks!
|
|
|
|
|
Have you tried a clean boot to see if it works then?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Check your firewall settings – perhaps it is explicitly blocked as a serving port.
|
|
|
|
|
I came from two different organizations that used this architecture however, I'm not at all sure which is the best between this one and another one.
Architecture #1.
The one I'm use to you have 3 projects: 1. A presenation layer project 2. A business layer project 3. A data layer project. Within the data layer lies your data classes. In your data layer you fill your objects up with Generic List like List<yourdataobject> and pass the collection of objects back to the business layer where you do your business rules and then pass the collection of object/s to the presentation layer.
Architecture #2.
The current way in which my college has proposed and has used in the past is that he has a folder with business objects and a folder with data objects(data layer). Your data layer passes a datatable to your business object which then loads the datatable to a index array for the class. The presentation layer then initializes the business object and calls its methods for CRUD etc ...
What we are not sure about is what is the best way. and WHAT is the pros and cons of both. Are we going to have trouble using WCF between the layers if we choose one over the other ?
Why are architects using one over the other ?
Greatly appreciate any input ..
Thanks
Jon
modified 13-Oct-11 10:56am.
|
|
|
|
|
Personally, I'd say 1 is better (with the proviso that it doesn't have to be different projects unless some of it is common between applications; it can all live in one assembly), because only the data access layer should need to look at data in a database oriented way. Yes, you can create DataTables in code, but they are a database approach and lists of business objects is likely to be much more usable for business layer code.
Passing data tables over WCF sounds like a bad idea. That means that in (2), the database, data and business layers would have to be in the same process. In (1), the data layer and the database would need to be, but not the business layer, as long as you make your business data objects* serialisable (which if you're planning to use WCF in any reasonable way they would have to be).
* - by 'data objects' here I mean objects which contain data and which need to be passed around between modules, i.e. externally accessible method parameters, properties or return types. Typically these classes will include ones derived from table entries, as well as some higher level ones created during business logic but not persisted to the database.
The presentation classes needing to know about database information (I guess that's what you mean by it performing CRUD?) also sounds like a pretty bad idea.
|
|
|
|
|
Thanks .. Some good points to think about ..
Anyone else have anything to say ?
|
|
|
|
|
UBX wrote: I came from two different organizations that used this architecture however, I'm not at all sure which is the best between this one and another one.
You shouldn't be looking for the best (there is no such thing, or we would all be using what's best), but what's most appropriate.
I wouldn't implement three tiers for a simple tool; the DataGridView can easily bind to a DataTable , and I don't add that tier unless it's adding value in one way or another. It's a simple consideration on whether the overhead of transforming the table to a list has any value in that particular project.
With a larger project, the layers help in keeping it structured and help avoid spaghetti-code. How you organize your tiers is up to you; some people put 'em in folders, others in a separate assembly.
Bastard Programmer from Hell
|
|
|
|
|
Hi,
I'm trying to get the content node based on the content value. So I wrote the below expression, which is not working.
XmlDocument doc = new XmlDocument();
doc.LoadXml("c:\test.xml");
XmlElement root = doc.DocumentElement;
XmlNode nd =root.SelectSingleNode("/Data/page[content='Group']/content");
nd results with wrong values. Please correct it.
<Data><page num="33" top="0">
<content width="191" font="0">Securities Corporation</content >
<content width="87" font="0">Distribution</content >
<content width="58" font="0">Group</content >
<content width="140" font="0">Customer Service</content >
</page>
</Data>
|
|
|
|
|
I'm unclear on what you are trying to get. Perhaps "/Data/page/content[.='Group']" will work?
Also, there is an XML / XSL forum here.
|
|
|
|
|
Thank you PIEBALDconsult, its working.. Next time, I'll post in XML forum
|
|
|
|
|
Hi PIEBALDconsult,
the expression is not working when the value contains "%". for example, value is 10.34% and wrote the expression as below
"/Data/page/content[.='10.34%']"
Above expression returns zero results.
I tried as below, still not working. please correct it.
"/Data/page/content[.='<![CDATA[10.34%]]']"
|
|
|
|