|
The employee record doesn't hold much, about 15 fields, like Name, Surname, Id, etc.
There can be up to about 5000 or so Employee records.
The app is batch application that runs every 5min.
I guess I'm not too worried about holding the data in memory, more about how I'm holding this data.
For EG the below class is how I hold and Edit the data.
My methods always seem to be public and I don't think that this is the right way of doing it.
Enen though it works.
public class EMPLOYEE
{
public static List<Tools.DB.OL.Xtime.EMPLOYEE> listEMPLOYEE = new List<Tools.DB.OL.Xtime.EMPLOYEE>();
#region Methods
public static void FillEMPLOYEE()
{
listEMPLOYEE = GenericFactory<Tools.DB.OL.Xtime.EMPLOYEE>.FillList("SELECT * FROM EMPLOYEE");
}
public static void InsertEMPLOYEE(Tools.DB.OL.Xtime.EMPLOYEE employee)
{
GenericFactory<Tools.DB.OL.Xtime.EMPLOYEE>.Insert(ref listEMPLOYEE, employee);
}
public static void UpdateEMPLOYEE(Tools.DB.OL.Xtime.EMPLOYEE employee)
{
GenericFactory<Tools.DB.OL.Xtime.EMPLOYEE>.Update(ref listEMPLOYEE, employee);
}
public static void DeleteEMPLOYEE(Tools.DB.OL.Xtime.EMPLOYEE employee)
{
GenericFactory<Tools.DB.OL.Xtime.EMPLOYEE>.Delete(ref listEMPLOYEE, employee);
}
#endregion
#region SQL Queries
public static Tools.DB.OL.Xtime.EMPLOYEE FindEMPLOYEE(Predicate<Tools.DB.OL.Xtime.EMPLOYEE> p)
{
Tools.DB.OL.Xtime.EMPLOYEE employee = new Tools.DB.OL.Xtime.EMPLOYEE();
if (listEMPLOYEE.Exists(p))
{
employee = listEMPLOYEE.Find(p);
}
return employee;
}
#endregion
}
|
|
|
|
|
Bardy85 wrote:
Tools.DB.OL.Xtime.EMPLOYEE employee = new Tools.DB.OL.Xtime.EMPLOYEE();
if (listEMPLOYEE.Exists(p))
{
employee = listEMPLOYEE.Find(p);
}
This code is inefficient. listEMPLOYEE.Exists(p) loops through the items in the list to return the result. employee = listEMPLOYEE.Find(p); will again do a iteration on all items and leading into worst performance. You can do something like the following instead.
Tools.DB.OL.Xtime.EMPLOYEE employee = listEMPLOYEE.Find(p);
return employee;
Bardy85 wrote: There can be up to about 5000 or so Employee records.
How often do you search on this records? If it is quite frequent, your approach is inefficient. Because, list has sequential storage and searches will lead into O(n) complexity. In such cases, querying database will be efficient. If you still need to keep the items in memory, consider a much superior data structure than a normal list.
If you have a one to one mapping like, getting employee object from the employee name, use a Dictionary where name will be the key and employee instance will be the value. This will give you constant (O(1) ) complexity. Another alternative is to use a sorted list and do binary search for lookup. This will lead into logarithmic complexity and quite efficient with huge recordsets.
Best wishes,
Navaneeth
|
|
|
|
|
Bardy85 wrote: Tools.DB.OL.Xtime.EMPLOYEE employee = new Tools.DB.OL.Xtime.EMPLOYEE(); if (listEMPLOYEE.Exists(p)) { employee = listEMPLOYEE.Find(p); } return employee;
If you're going to keep it as a in memory List, then I think the best otion/performance
is to derive your class from IComparable<employee> and then use binary search.
something like:
public class Person: IComparable(Person){
private string name="";
private string ocupation="";
public string Name{
get{return name;}
set{name=value;}
}
.
.
.
public int CompareTo(Person other){
return this.name.CompareTo(other.name);
}
}
List(Person) persons = Utils.StoredProcs.PersonProcs.GetPersons();
Person p = persons[
persons.BinarySearch(new Person{Name="Some Name"})];
I actually implemented a Reporting program this way. It's blazing fast.
Faster then our "entity" server. Memory consumption is like 170MB for a hole year worth of data.
//And there are tens of milions rows of data from over 10 tables/classes.
Botom line: if your app is to be run by a well established nr of users within your "entity"/firm/enterprise/whatever then go for it.
Try using StoredProcs instead of string commands => significant speed gains.
|
|
|
|
|
I currently do implement IComparable<t>, but don't sort the list of Objects or Use BinarySearch.
I guess this would speed up things up. Only problem I see is that BinarySearch does not take a Predicate as an arguement, and I use Predicates to find a matching object.
Do you know another way arround this? For example my Employee object has quite a few fields and I don't always want to search where the whole employee object matches, only maybe ID or Lastname, thats why I like using Predicates. In your above example you can only search on Name.
I guess you can't do a binary search and then use Predicate to find that specific employee object, because of the way a binary sort works.
Anyway thanks for you comments. They have shed some light on my problems.
Thanks.
|
|
|
|
|
FWIW: I don't use predicates, but this little article[^] explains a lot about user-defined sorting of collections (you can't do smart searches such as BinarySearch unless your collection is sorted on the relevant criterium).
|
|
|
|
|
Agreed. I think then i'll have to sort the List on the field thats going to be most used. Then I can sort the list and use a binary search on that criterium. If I have to search on any other field I'll just have to use the standard search, which I think is a bubble search.
Anyway thanks.
|
|
|
|
|
Bardy85 wrote: I currently do implement IComparable, but don't sort the list of Objects or Use BinarySearch.
I guess this would speed up things up. Only problem I see is that BinarySearch does not take a Predicate as an arguement, and I use Predicates to find a matching object.
Do you know another way arround this? For example my Employee object has quite a few fields and I don't always want to search where the whole employee object matches, only maybe ID or Lastname, thats why I like using Predicates. In your above example you can only search on Name.
True. But it totally depends on what you want to do with the data. In my case there is just one table/class that needs to be sorted on different filed(s) for different reports.
One way to use Binary search no matter the field or fields is to sort the List proving a custom IComparer each time. This makes sence ONLY IF after you sort the list you do a lot of searching
using that comparer cause the Sort time is O(n) = n* log(n) while a LINQ/Predicate is O(n)=n, but if you do a lot of searching after sorting by the "ocupation" filed for example, then the extra time needed for sorting is totally worth the while. Hope you get what I tried to say.
modified on Saturday, January 16, 2010 5:40 PM
|
|
|
|
|
|
Now I read it too . But there are many places where they say SP are faster and I tend
to belive them. I'm no SQL guru but this is how I think of the process:
1) NO SP: => the SQL engine recieves a string/guery that needs to be compiled. So it compiles the
string query and then it performs the actual query
2) SP: => it directly executes the query
|
|
|
|
|
Hi All,
Its been quite a long time since I am stuck with this problem. I am writing an application in which user selects a portion of picture box and rest part (apart from selection) is filled with white color.
Now Problem is that FillRectange fill area more that what is selected. For example here is code to fill from 0,0 of image to first node of rectangular selection:
private void picItem_MouseDown(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left)<br />
{<br />
_selecting = true;<br />
_selection = new Rectangle(new Point(e.X, e.Y), new Size());<br />
}<br />
}<br />
<br />
private void picItem_MouseUp(object sender, MouseEventArgs e)<br />
{<br />
if (e.Button == MouseButtons.Left && _selecting)<br />
{<br />
Rectangle cropRect = _selection; <br />
<br />
using (Graphics g = Graphics.FromImage(picItem.Image))<br />
{<br />
g.FillRectangle(Brushes.White, new Rectangle(0, 0, _selection.X, _selection.Y));<br />
}<br />
<br />
picItem.Refresh();<br />
_selecting = false;<br />
}<br />
}<br />
<br />
private void picItem_MouseMove(object sender, MouseEventArgs e)<br />
{<br />
if (_selecting)<br />
{<br />
_selection.Width = e.X - _selection.X;<br />
_selection.Height = e.Y - _selection.Y;<br />
<br />
picItem.Refresh();<br />
<br />
lblLocation.Text = "Height = " + _selection.Height.ToString() + ", Width = " <br />
+ _selection.Width.ToString();<br />
}<br />
}
Can anyone tell me why this is happening please?
|
|
|
|
|
Without actually running it it is difficult to tell, but:
1) When you show code fragments, enclose them in <pre></pre> blocks (use the "code block" widget) when you paste them - this preserves the formatting, and makes it easier to read.
2) Try bracketing your if clause - it would make it more readable, and may cure the problem.
if (e.Button == MouseButtons.Left && _selecting)
becomes
if ((e.Button == MouseButtons.Left) && _selecting)
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Ok, thanks.
Once again here is scenario:
1) A form with a picture box and image is loaded in picture with StretchImage mode.
2) For time being to solve this issue I want to fill picture box from 0,0 to point where use clicks.
But area filled is little greater then where it is clicked.
|
|
|
|
|
Oh, I see! Do you mean area filled is little greater one pixcel bigger than where it is clicked?
If so, then it is obvious: DrawRectangle paints from Point(X, Y) to Point( X', Y') inclusive
Change
using (Graphics g = Graphics.FromImage(picItem.Image))
{
g.FillRectangle(Brushes.White, new Rectangle(0, 0, _selection.X, _selection.Y));
} To
using (Graphics g = Graphics.FromImage(picItem.Image))
{
int X = _selection.X - 1;
int Y = _selection.Y - 1;
if ((X > 0) && (Y > 0))
{
g.FillRectangle(Brushes.White, new Rectangle(0, 0, X, Y));
}
}
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Hi.
I'm gonna insert a large mount of data in a ListView in VitualMode.
I have set the VrtualMode property to true :
listView1.VirtualMode = true;
Now,whenever I'm gonna add an item to the listview ( listView1.Items.Add(newItem); ) ,
I receive this exception :
When the ListView is in virtual mode, you cannot add items to the ListView items collection. Use the VirtualListSize property instead to change the size of the ListView items collection.
Would you please guide me, how I can resolve it ?
Thanks.
|
|
|
|
|
I think the exception is saying that you need to specify the virtual list size.
listView1.VirtualListSize = 1000;
Once this property is set then I think you should be able to add new items.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Hi All,
Do we have DirectX support in C#.Net?
If not ,do i need to install latest Directx SDK?
Please advice.
Regards,
Ashwath
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:55am.
|
|
|
|
|
Thanks....
I went to the references,from there i found the following references,
Microsoft.DirectX.Direct3D
Microsoft.DirectX.Direct3DX
etc...
Does the availability of above references mean that when we install .Net framework in the computer,that time itself the references are added and i do not need to install the directx SDK.
Please clarify,
thanks,
ashwath
|
|
|
|
|
Message Closed
modified 23-Nov-14 6:54am.
|
|
|
|
|
Does DirectX libraries get installed when we install Microsoft Visual Studio 2008?
|
|
|
|
|
No. It's a separate SDK that you have to download and install manually.
.45 ACP - because shooting twice is just silly ----- "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 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi,
We have developed C# windows base application , we would like to make the UI
more posh with some graphis for all controlls at the same time we dont want
to use any third party controls to bring this. Does .Net Framework - 2005 or 2008 and C# supports this, if so how can i bring up galssy look for my UI.
we are using C# 2008 Express edition for development.
Thanks
|
|
|
|
|
sjs4u wrote: Does .Net Framework - 2005 or 2008 and C# supports this,
Yes. But you need to create custom controls and draw yourself on the screen. This is not a trivial task. If you can use WPF, you will get shiny UIs.
Best wishes,
Navaneeth
|
|
|
|
|
WPF can provide some good UI effects.
If you are still in the initial stages of your project, you can consider WPF as an option for your UI.
There are only 10 types of people in this world — those who understand binary, and those who don't. |
|
|
|
|