|
Your question would be much more understandable if you put the code for button3_Click that you disclosed to Richard MacCutchan in your original post, and edited the code so only the possible problem area is shown.
If you have a field in your db that is guaranteed unique per row that you can use as a key, then using a Dictionary makes sense ... but, in this case, it appears you don't.
I'd start by modeling data structures from "inside to outside," from "atoms," to "molecules."
So, I'd define an "atomic class" that would hold only the necessary data for a single ship position measurement:
public class Position
{
public bool IsDay { get; private set; }
public double Latitude { get; private set; }
public double Longitude { get; private set; }
public Position(bool isDay, double latitude, double longitude)
{
IsDay = isDay;
Latitude = latitude;
Longitude = longitude;
}
public override string ToString()
{
return
"Time: "
+ (IsDay ? "Day " : "Night ")
+ " Latitude: " + Latitude.ToString()
+ " Longitude: " + Longitude.ToString();
}
} I'd then move on to the question of what my final goal is here: clearly each ship is going to have a collection of instances of Position:
internal class ShipPositionList : List<Position>
{
public override string ToString()
{
string s = "";
foreach (Position pos in this)
{
s += pos.ToString() + Environment.NewLine;
}
return s;
}
} And, finally, I'd consider what the data structure for the outermost object is:
public class Ship
{
public string ShipName { get; private set; }
internal ShipPositionList PositionList { get; private set; }
public Ship(string shipName)
{
ShipName = shipName;
PositionList = new ShipPositionList();
}
public void AddPosition(bool isDay, double lati, double longi)
{
PositionList.Add(new Position(isDay, lati, longi));
}
public override string ToString()
{
return
ShipName
+ Environment.NewLine
+ PositionList.ToString();
}
} At this point, I might well start wondering why I am writing out such an elaborate multi-class model, and start coding lean-and-mean
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
Hi BillWoodruff
thanks for the detailed answer, but now i am even more confused
i would have uploaded the project and the db if i only had were too.
small question: can i use one of the coordindated (for example: longitude) as a unique key and then use the dictionary?
thanks
|
|
|
|
|
Hi Yoni.Kess,
I don't think you need to post any more code in order to solve your challenge
If you get the object-structure right, you can make it serializable into XML; if you've got the XML, you can, if necessary, transform it into KML with an XSLT. I'm not familiar with KML, but I would guess that there's probably good tools available to create it. My impression from looking at your data is that it's simple, and there's nothing there that's recursive, and that you can easily create your own structured output in whatever form with your own simple serializer.
A .NET Dictionary (a collection of KeyValuePairs) must have a unique key for each KeyValuePair: if you are absolutely sure that you'll never have two longitude values that are the same, yes, you can use them as keys. But, what is it that makes you think a dictionary is the right thing in this case ?
fyi: the standard .NET XML serializer cannot handle writing a Dictionary to XML: [^]. I have read that the .NET DataContractSerializer can serialize a Dictionary, but I have not tried this: [^], [^].
Being more confused is not necessarily a bad thing in learning to program, although it may not feel comfortable to be confused. Of course, that's no excuse, if my response confused you !
The goal I had in responding to you was to "point you to" thinking about the "big picture" in your current challenge: what you are really modeling. Thinking in terms of "atoms to molecules to compounds" ... or the reverse ... is just one metaphor for OOP modeling.
There's a lot I can't tell from eye-balling your data: it may be the case that what you really need is to break out the data by Day/Night ... since it appears written that way in the KML fragment you show. Knowing more details is not necessary, however.
I believe if you are clear about what your final goal is, then the design of the data structures you really need will "fall-out" organically: that's a very idealistic statement. In the real-world, it often doesn't work that way: we get "immersed" in the data, and observe patterns of organization in the data, reach conclusions about what variation is in the data, and how that may constrain our solution, and from that we get ideas about how to structure and optimize the data structures we'll create to contain the data.
good luck, Bill
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
I try to add an object to a database, but I get an exception
Code:
DataModelContainer cont = new DataModelContainer();
(...)
cont.AddToStudentSet(cont.StudentSet.CreateObject());
cont.SaveChanges();
After running the code twice, I get:
Exception:
AcceptChanges cannot continue because the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are unique before calling AcceptChanges.
The Id of Student has an AutoIncrement set to TRUE in the database. On the first run a single Student record is created with Id 0. Later, no data is saved to the table at all.
The reason of why is it happening seems to be obvious, but it should work anyway.
Any help appreciated
Greetings - Jacek
modified 6-Oct-13 9:04am.
|
|
|
|
|
Well, since you already have a student record with an Id of 0, you can't add another one. ID's should not start with 0.
|
|
|
|
|
The scenario was:
1. I had designed tables with an inheritance relationship.
2. Decided that it was not a good idea
3. Removed an inheritance relationship
4. Added required IDs to the tables and set IsIdentity to true.
5. Forgot to set an identity property to "Identity".
Well...
Greetings - Jacek
|
|
|
|
|
Hi,
I am using the following code in my Form_Load to read the ConnectionString elements from my WinForm C# application.
sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
MySql.Data.MySqlClient.MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
builder.ConnectionString = sql_connection.ConnectionString;
string server = builder.Server;
string port = builder.Port.ToString();
string user = builder.UserID;
string password = builder.Password;
string database = builder.Database;
string timeout = builder.ConnectionTimeout.ToString();
txtServer.Text = server;
txtPort.Text = port;
txtUserID.Text = user;
txtPassword.Text = password;
txtDatabase.Text = database;
txtTimeOut.Text = timeout;
I want to know how can get this back once changed by user and save it into the App.config's ConnectionString when user Clicks Save button?
Technology News @ www.JassimRahma.com
|
|
|
|
|
|
I have a working program that I want to add a little code to
Being a novice, ok beginner programer, I could use a little help.
Not sure the best way to do this, start another thread and cross thread, or can I do this in the one thread.
tnx
My thread code is like this
public static void Method_8()
{
while (method_state_6 && method_state_7 == true)
{
flooddrain.Write(false);
Thread.Sleep(1 * HourMs);
flooddrain.Write(true);
Thread.Sleep(1 * HourMs);
}
}
|
|
|
|
|
I don't see the need for another thread.
Change the logic here - maybe make your code more flexible by making HoursMS 24.
But unless there are other concerns you should not be going for another thread.
|
|
|
|
|
Well your right it should be done all in one thread.
some thing like this using a for loop a sleep and god knows what else Im really lost here.
for (int i = 0; i < 0; i++)
{
Thread.Sleep(1 * DayMs);
}
|
|
|
|
|
Ummm, do WHAT in another thread??
Also, your variable and method names suck. What in the Hell is "Method_8" supposed to do?? The name doesn't describe it's function at all. "Method_state_6"?? "Method_state_7"?? What do those represent??
Read up on the concept of "self documenting code".
|
|
|
|
|
ve3tru wrote: Then forget about threads, and certainly forget about using Thread.Sleep for long periods like this. Write your app such that it does all that is necessary in one go, and use the Windows scheduler to run it at the times you need.
Veni, vidi, abiit domum
|
|
|
|
|
Hello,i want a code which retrieve the color from an image.where image is in fix format and x-y co-ordinate also...i want a read pixel and find the color of that pixel not by mouse positioning by only co-ordinates.plzzzzzzzzz
|
|
|
|
|
What have you tried so far ? How many bits per pixel in the images: 1,4,8,16,24,32 ? Show us some code.
Google CEO, Erich Schmidt: "I keep asking for a product called Serendipity. This product would have access to everything ever written or recorded, know everything the user ever worked on and saved to his or her personal hard drive, and know a whole lot about the user's tastes, friends and predilections." 2004, USA Today interview
|
|
|
|
|
|
There are two ways depending if you need performance or not.
Use GetPixel (not performant) or LockBits and and seek the byte
(s) (can be calculated using Scan0 position plus y * stride + ( x * bits per pixel) assuming non indexed - for indexed this will give a reference in the pallet object which will hold the colour. Many examples of basic GDI+ lockbits scanning on the web.
|
|
|
|
|
I have 1 DateEdit display format dd/MM/yyyy, dd you want to enter the auto-focus past it always MM. What do you know with his help, thanks.
|
|
|
|
|
Try the DevExpress forum.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi All,
Is it possible to develop a visual studio add-in, which can be installable in any visual studio, I mean, that can be installable and usable in VS2005,VS2008,VS2010, VS2012 & 2013.
I have a visual studio add-in developed in VS2008, I wanted to make it generic such that, it will be installable and usable in any of the Visual studios. is it possible?
Thank you in advance for your help.
Regards
|
|
|
|
|
Guess that it's possible, since the supported hosts are specified in the XML. Keep in mind that every version has it's own deployment-location, so you'd still need to ask what version to install to.
There may be VS-versions where the addin-contract is altered; in that case, make a simple addin, and use that to load your functionality from a shared assembly.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thank you Eddy for the relavent answer. Can you please extend your help in finding me an article/sample which can help me understanding your point "make a simple addin, and use that to load your functionality from a shared assembly".
Thank you,
|
|
|
|
|
There's a thread on SO[^] that talks about sharing stuff between projects.
You'd typically put the shared functionality in a project, and reference that (and invoke it) from your addin-project.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Richard/Team,
Accept my apologies, as I was not sure of the correct forum, i have posted 3 forums...thanks
|
|
|
|
|