Ketsuekiame 860 Master Poster Featured Poster

What do you mean by a generic syntax for it? ICommand and Delegate Command are pretty generic already. The intention is that you pass delegates or lambda functions in. As you already define what goes in/out of the method (by factor of delegates) I'm not sure what you stand to achieve.

Ketsuekiame 860 Master Poster Featured Poster

How are you writing the file? If you're using File.OpenOrCreate this won't truncate the file. If your new file size is smaller (I don't know what you're doing to the bitmap even though your header is larger) then you'll get junk at the end of the file that was there before you started writing to it.

EDIT: Just clicked you're using File.WriteAllBytes. I don't know if this truncates or not. Will test now...

EDIT 2: Yes it truncates. So I don't know why it would be failing before unless the data you were putting into your header was incorrect?

If you're getting 0 value bytes, it would be good to check what image.Save is outputting and whether or not your header informatin is being inserted, or if you're overwriting by mistake.

Ketsuekiame 860 Master Poster Featured Poster

it looks lik eyou aren't setting CurrentControl to any value and therefore contains null. When your event handler for Click gets called, CurrentControl.Add() doesn't actually have a value.

Ketsuekiame 860 Master Poster Featured Poster

Please copy and paste the error you're getting.

KushMishra commented: good question and meant for all when asking questions like this +2
Ketsuekiame 860 Master Poster Featured Poster

There's so much that I learned and have forgotten from when I used to do Games Programming, simply because I haven't done it for a long time. It's a bit like any other skill, unless you practice and keep practicing you soon forget. But, by the same fact, it's easier to remember again if you went back to it. :)

Ketsuekiame 860 Master Poster Featured Poster

Because it's the unofficial global calendar and not using it would just make things unnecessarily complicated.

Just because someone of faith does something, does not mean an Atheist must not do that something.

Additionally, the Chinese use a lunisolar calendar in a civil capacity (for special social events) as I believe this used to be the national calendar. They did not follow a western religion and so had no exposure to the Gregorian calendar. However, in modern day they do use the Gregorian calendar for business purposes.

In England, the national calendar is the Gregorian calendar. England itself, or America for that matter are countries of faith. Going against the national standard, just because an Atheist doesn't share their belief with, for example Christianity, is illogical.

I also fail to understand why the sudden pop at Atheism when, as far as I can tell, no one has taken a shot at any other belief in this thread.

Ketsuekiame 860 Master Poster Featured Poster

What do you mean by a pure converter?

Ketsuekiame 860 Master Poster Featured Poster

It depends how much data you're copying really. It's nearly always cheaper to pass a class by reference.

Reference types are created on the heap, so there is no penalty of passing a reference type by reference (classes are reference types).

However, to pass a value type (such as a struct) by reference, then you will need to "box" the type and this will allow you to pass by reference.

In essence you will pass value types by reference when;

  1. You have a large structure
    or
  2. You wish to update a value you pass into the method, without returning it as a result.

In option 1, simply boxing, or passing the structure with the ref keyword (must also be in the method declaration) will be quicker than creating a copy of the data on the stack.

With option 2, it is usually better to use the out keyword. Where the out keyword is used, you're specifying that the input value is of no consequence and shouldn't be used, however, you're expecting this value to be filled before the method exits.

Ketsuekiame 860 Master Poster Featured Poster

So first thing I see is that you don't add anything to your toPay variable when you select "Tea" and when you select "Coffee" you break out of your switch statement too early and it doesn't execute the toPay += cost; code.

Also, your input from the choices on your keyboard go into 'int' variables. Then you compare them to a character. This won't work. Simply make your case arguments for your extras selections numbers, not the number character. (Or change the delcaration from int to char)

Ketsuekiame 860 Master Poster Featured Poster

Can you post your new code block please? I know it printed it out last time so I'm not sure what you're doing wrong this time.

Ketsuekiame 860 Master Poster Featured Poster

If it's just that the console disappears before you see it, try adding _getch() just before you return from main. This will wait for you to press enter. You will need to include 'conio.h'

PS. I understand that _getch() used this way is pretty bad practice, however, I don't believe that for this assignment it's worth building in classes that allow the OP to flush the input stream. Just seems a bit overkill ;)

Ketsuekiame 860 Master Poster Featured Poster

They way you calculate your tax is wrong. Multiplying by a number less than one is analagous with dividing. So multiplying by 0.05 will give you the same answer as dividing by 20.

You can simplyify decimal multiplcation by treating both sides of the decimal as different components of the equation and then adding them together.

So;

2 * 0.05 = 2 / 20 = 0.1
2 * 1.05 = (2 * 1) + (2 * 0.05) = 2.1

or even;

2 * 2.05 = (2 * 2) + (2 * 0.05) = 4.1

if you want to simplify the second part (for mental arithmatic), multiply the right side by 10^x till it becomes a whole number and divide that result by the same factor of ten;

2 * 6.05 = (2 * 6) + ( 2 * (0.05 * 100)) / 10 = 12 + ((2 * 5) / 100)
= 12 + (10 / 100) = 12 + 0.1 = 12.1

Can even do it with bigger numbers;

25 * 14.62 = (25 * 14) + ((25 * (0.62 * 100)) / 100)
           = (250 + 100) + ( (25 * 62) / 100)
           = 350 + (1550 / 100)
           = 350 + 15.5
           = 365.5

Also, while I'm at it, simplified way to do mental multiplication with large numbers.

From above we had 25 * 62. This will do...

First do the units of the multiplier;

25 * 62 = (25 * 60) + (25 * 2) = (25 * 60) + 50

Secondly, you can do the "tens" as two stages. First work it out using only the unit value, then multiply the answer by the units factor of ten;

(25 * 60) = (25 * 6) * 10 = ((20 * 6) + (5 * 6)) * 10
          = (120 + 30) * 10
          = 150 * 10
          = 1500

Add back the unit value we previously worked out and you have your result :)

1500 + 50 = 1550 = 25 * 62
Ketsuekiame 860 Master Poster Featured Poster

If you're still getting into the "C" options, it means you're missing a break after the "T" section.

To make life a bit easier, you can surround your case statements in brackets. Personally, I think a case statement should never be more than 3-5 lines long. If it is, call a method :)

If that's outside the remit of your project, fair enough, in this case use brackets to see when your code starts and ends.

Example:

switch(choice)
{
    case 0:
    {
        cout << "Choice 0" << end;
        total += 1;
        subTotal += 1;
        break;
    }
}

Just makes it easier to read and should help you find where your missing break statements are.

Ketsuekiame 860 Master Poster Featured Poster

You're missing several break statements which cause the code to 'fall through' from one case to the next.

break essentially tells it to stop executing instructions in the current switch statement and continue execution at the next instruction after last brace } of the switch statement.

Example:

switch(myChoice)
{
    case 0:
        cout << "You picked 0" << endl;
        break;
    case 1:
        cout << "You picked 1" << endl;
    case 2:
        cout << "You picked 2" << endl;
}
cout << "Finished" << endl;

I have intentionally left the break statement out of case 1. So the output here is:

Input:
    myChoice = 0;
Output:
    You picked 0
    Finished

Input:
    myChoice = 1;
Output:
    You picked 1
    You picked 2
    Finished

Input:
    myChoice = 2;
Output:
    You picked 2
    Finished
Ketsuekiame 860 Master Poster Featured Poster

The hint here is that you need to draw a flow chart. Rather than thinking of a straight line, you will need to break off and create two parallel flows.

Imagine you're standing in line at the coffee shop, the first thing the cashier asks is "What would you like?" In this case you have two options, tea or coffee. So you choose Coffee and the cashier inputs that on their till. This has started the "Coffee" flow. Then they will ask, "Would you like any extras such as Ice or Cream?" if you say "Ice", they then might ask "Would you like it blended?" All this while they're inputting your answers into the till which is totting up the total. At the end they ask "Would you like anything else?" Which begins the process again.

You need to apply this logic to your application. If you're struggling with the concept in code, I guarantee you will find it much easier to write the flow down first and write the code based on the flow.

ddanbe commented: Very good advice +15
Ketsuekiame 860 Master Poster Featured Poster

I don't use Neo4j but it looks like a relational Entity style database. So, I would go with the idea that each table in the database should be modelled on your class. This would be a fairly standard way of modelling your database for this kind of work, in my opinion.

You might be better off asking on the Neo4j Google Group though.

Ketsuekiame 860 Master Poster Featured Poster

I'm pretty much at a loss now as I don't know the module in question. It might be possible to hook into the OpenGL draw events and override the clear colour, but do you really want to go that far?

Unless....I guess it could always just be a form background colour, in which case you can use P/Invoke to override the form's background colour (which is considerably easier)

Ketsuekiame 860 Master Poster Featured Poster

You can have a fillet steak for dessert, right? ... Right?? :S

On a serious note, warm chocolate cake, with chocolate sauce inside with cornish ice cream on the side drools

ChrisHunter commented: ANY time is steak time! +0
Ketsuekiame 860 Master Poster Featured Poster

Are you wanting to change the background colour of the control or the background of a window in the control?

Ketsuekiame 860 Master Poster Featured Poster

I would have thought this information would have been available in Object Explorer, perhaps not. Essentially, if the property is now private, you can use reflection to set a value into a private member.

Ketsuekiame 860 Master Poster Featured Poster

Does the property still exist as a private field?

Ketsuekiame 860 Master Poster Featured Poster

I imagine this goes off and hits DirectX/OpenGL underneath. If the control itself doesn't have a property to set the background control it might be more of a "hack" than a correct way to do it.

Ketsuekiame 860 Master Poster Featured Poster

The easiest way is to set up a proxy list.

In your drag drop event, move the items that you've "dragged" into a secondary list and cancel the entire dragdrop event.

Watch this list for changes. When you detected changes to this list, pull out any you wish to "cancel". Anything you want to keep add to the new ListView and remove from the old ListView manually. You should be able to find them using Equals as they should be object references though I can't confirm this.

This is just an idea, unfortunately dragdrop doesn't do what you want to do natively and this is the best "workaround" I can think of in 2 minutes.

Ketsuekiame 860 Master Poster Featured Poster

It's also the reason why I don't think that you can use scanner copying as an analagy for DNA copying. Typically you get an exact copy, minus some of the telomeric sequences. If the replication doesn't go correctly, there's actually a process of DNA repair that it goes under.

Otherwise we'd all be dead pretty quickly :P But typically if you get an incorrect DNA sequence, you end up with all sorts of syndromes and genetic disorders and cancers. The human body is miraculous itself.

Ketsuekiame 860 Master Poster Featured Poster

You can't open an empty location with your FileStream.

You could guard with String.IsNullOrEmpty before you try and load anything.

What you should do is redesign this. All of the work you're doing can be done with a single method over multiple iterations, or, by passing the parameters into an array and passing that to the database methods.

So you could have one method called byte[] GetImageBytes(string filePath) which would load the image up. This way you could call it from a loop, or, individually if you had to.

...
List<byte[]> images = new List<byte[]>();

if(!String.IsNullOrWhiteSpace(picLoc))
{
    images.Add(GetImageBytes(picLoc));
}
...

Finally, you should never, ever, ever build up a query string like that.

You could quite easily write a small script into any of the textboxes that will cause your script to drop your customer table and ignore everything else afterwards. you're already using parameters for your images, so I don't know why you didn't for everything else too.

Ketsuekiame 860 Master Poster Featured Poster
  1. Have you stepped through with the debugger to see what's happening?
  2. You will need to post some code.
Ketsuekiame 860 Master Poster Featured Poster

DNA replication is like making a copy of a sheet of text. You then make a copy of the copy. After 1000000 or more of such copies, I guess you can't read the text anymore.

I think you need to get a better scanner... ;)

Ketsuekiame 860 Master Poster Featured Poster

I think that eventually, "eternal" life will end up being our only way to cross the stars. It might be more feasible to make the species live forever than to find a way to travel faster than light.

Generation ships are too risky as you may end up losing the definition of the species after several generations. Look at how much people have changed over the last 2 or 3 generations. Additionally, extra-solar colonisation will alleviate the potential over-crowding problem. Or like China, introduce a policy of one child per family. The "accidental death" count should offset the newborn population count.

Ketsuekiame 860 Master Poster Featured Poster

Did you check to see what the contents of picbyte were when you were stepping through in the debugger?

Ketsuekiame 860 Master Poster Featured Poster

Your database design should change slightly. Having an ID that is not unique is not very well named, so pick something that better describes this.

Your image table should contain three columns:
1. The primary key column, probably an int, possibly an identity column (auto generated id).
2. This other "id" column you have, preferably with a better name depending on the context.
3. The byte data.

Then you can insert multiple rows that have the same "id" but they will have a unique primary key. This maintains the sanity of the table.

When you select the images back out, you will need to select all of them based on your current "id". Your dataset will then populate correctly with all the images.

Ketsuekiame 860 Master Poster Featured Poster

Yes, for the simple reason that I'm always curious about "tomorrow" or "the future"

I want to know how the species is doing 1000 years from now, I want to see the new technologies and sciences. What discoveries have we made, have we finally conquered the oceans, the stars etc.

I want to know, I'm driven by curiosity. There is an infinite universe within which to spend an infinite long life span.

Ketsuekiame 860 Master Poster Featured Poster

I refuse to answer that question on the basis that the answer may serve to incriminate me ;)

EDIT: I'm afraid I'm going to be no help in this thread, so bowing out now before it derails :)

Ketsuekiame 860 Master Poster Featured Poster

We write our own (in a word document) as generally TFS can't be trusted :)

Ketsuekiame 860 Master Poster Featured Poster

Well I'm not entirely sure what you're doing wrong, but the pattern should be silimar to:

string _connectionString = "CONN_STR_HERE";

...

public void SaveAge(int userId, int age)
{
    using(SqlConnection con = new SqlConnection(_connectionString))
    {
        using(SqlCommand command = new SqlCommand("SaveAge", conn))
        {
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add(new SqlParameter("@UserId", userId));
            command.Parameters.Add(new SqlParameter("@Age", age));

            conn.Open();
            command.ExecuteNonQuery();
        }
    }
}

If this doesn't work, something is wrong somewhere else.

Ketsuekiame 860 Master Poster Featured Poster

Keeping the connection open is what's causing the timeout and is bad design.

You should not be controlling this yourself manually, let the framework do the work for you.
All the connections are maintained in a connection pool. This will leave connections open and you won't have to worry about timeout problems. It's what it was designed to do.

When you call close, it returns the connection to the pool, but leaves it open. When you next call open, the pool will return you the next available open connection or open a new one for you.

If you don't want to do this you will need to implement IDisposable on your Database interface layer in which you can dispose of the connection you are keeping open.

Also, please ensure you're disposing your command objects. Not doing so will cause a memory leak.

Ketsuekiame 860 Master Poster Featured Poster

I would do the following...

public void DoSomethingWithSql()
{
    using(SqlConnection conn = new SqlConnection(connectionString))
    {
        conn.Open();
        using(SqlCommand command = new SqlCommand(/* args in here */))
        {
            command.ExecuteNonQuery(); // Or whatever you need
        }
    }
}

This ensures that your connection is closed (or in MySQL's case returned to the connection pool) and that your objects are disposed properly. It also means that you don't have to manage your SQL Connection. The connector does a lot of work for you in this respect.

Ketsuekiame 860 Master Poster Featured Poster

Use of that timer is perfectly fine. The main difference is that Threading.Timer is more light-weight.

It's better practice to open/close SQL Connections as you use them. MySQL connections are stored in a connection pool anyway (by default in .NET) so just close the connection after you've made the call.

Your error is actually on Connect though from looking at your log and the error message is more indicative that the server you're trying to connect to can't be found (possibly a DNS error or the server went offline). This might be more related to the POP server you're trying to connect to rather than the database (As indicated by the 'POP3 Retrieval' comment in your log). I would put a bit extra logging in there so you know for sure where the log is being generated from.

Ketsuekiame 860 Master Poster Featured Poster

System.Threading.Timer is your best bet. You can set this up with recurring 5 minute intervals.

Ketsuekiame 860 Master Poster Featured Poster

It shouldn't be crashing in the first place, but yes, your subsequent sends are out of sync. This could indicate a threading issue with your code.

If you want, PM me with a location that I can download your entire source from and I'll take a look and debug through it. At this point, I think this is the fastest way to help you because I can't see anything wrong now.

Ketsuekiame 860 Master Poster Featured Poster

No, send will block until you've sent the entire buffer to the system buffer, unless you have it in "non-blocking mode", in which case it's not guaranteed to send the entire buffer to the system buffer, but only the amount of space available in the system buffer.

It would be good practice in your case (as you're having issues) to check whether you're sending the correct amount of data before we continue debugging, but I've put millions of bytes into the buffer before and not had issues...

The fact that you end up with skewed numbers indiciates that either you're reading too much or too little data on one of your read operations. It may be that the payload calculation size is off. Have you stepped through and checked all the buffer sizes etc.

As an aside, your first receive isn't looping. Whilst I realise that it's only 4 bytes, there's no guarantee that you received all 4 straight away.

To make it more efficient, the system will attempt to fill as much data as possible into the buffer, until it reaches a certain thresh-hold. If this thresh-hold is not reached, the system will delay the send until a certain period of time, or, there is more data to send. So if your thresh-hold is 128 bytes, your last packet filled 126 and then your payload size for the next item goes on, hits 128, the driver sends the buffer and the rest of your int (the final 2 bytes) …

Ketsuekiame 860 Master Poster Featured Poster

When you write how many bytes are received on line 16, does this match up with the number of bytes sent?

Ketsuekiame 860 Master Poster Featured Poster

Socket.Receive even with the byte length argument, isn't guaranteed to actually have that much data. Essentially, the byte length argument is a "max limit". It will receive as much data as possible up to that value. So if your socket has sent 15 of 30 bytes in the first TCP window, your receive method will pick up the 15 bytes and return. It will not wait for the second 15.

Essentially, I think this is what's happening to you. Although you've sent say 100bytes, if Windows or the network driver decides to only send 98 for example, your receive will be short.

For reliability purposes, you should loop your receive method (it will return to you exactly how many bytes it placed into your buffer) until you have received all data or a timeout occurs.

Ketsuekiame 860 Master Poster Featured Poster

Essentially you only defined the query but you never executed it (this is called deferred execution). You should be able to correct that simply by putting .ToList() on the end of your LINQ.

var words = File.ReadAllLines(path)
                .Where(line => line.StartsWith(intro))
                .Select(line => line.Substring(intro.Length).Trim())
                .ToList();  

This will cause the query to execute and your words variable should contain a List<string>

Your loop can be achieved with foreach

foreach(string movieFileName in words.Where(str => videosnames.Contains(str)))
{
    // Do stuff here
}
Ketsuekiame 860 Master Poster Featured Poster

I know the RichTextBox exists and what its ecaxt name is because it's the same name as the new tab and I used the same string variable to set both.

Well that's a key bit of information that makes it all easier...

string tabName = tabControl1.SelectedTab.Name;
RichTextBox textBox = tabControl1.SelectedTab.Controls.Find((tabName), true).FirstOrDefault();
if(textBox == null)
{
    MessageBox.Show("Could not find textbox!");
    return;
}

MessageBox.Show(textBox.Text);

If you're sure that the name of the tab and the name of the textbox are the same, it makes more sense to do it this way around to avoid any typographical errors and such.

Ketsuekiame 860 Master Poster Featured Poster

Attach .FirstOrDefault() to the .Find() method.

If the framework doesn't allow this, you will need to pull out the controls into an array, check that the array contains a single element and then cast that element into the textbox object.

Ketsuekiame 860 Master Poster Featured Poster

To expand on the previous post...

RichTextBox textBox = TabControl1.SelectedTab.Controls.Find("MyRichTextBox", [True]) as RichTextBox;

Sure you can figure out the rest...

Ketsuekiame 860 Master Poster Featured Poster

This is why I mentioned that you need a service you can call using IPC (inter process communication)

By far the easiest method is WCF, you can call it just like a webservice. (I'll keep going on about WCF because I like it and use it all the time ;))

If you seriously can't do that, you will need to implement something like Named Pipes communication.

Have a look Here, this will help you get set up with NP-IPC.

Ketsuekiame 860 Master Poster Featured Poster

No problem, good luck in your endeavor!

Ketsuekiame 860 Master Poster Featured Poster

I'll answer in order;

  1. WCF is a framework that can run inside Windows Services. Think of Windows Services as a bucket, doesn't matter what you put inside, so long as it fits.
  2. This is where service communication comes in. If you really can't use WCF, then you should look at .NET Remoting. You will need to review the MSDN and some tutorials. It's too big to talk about here in detail.
  3. It's the service side that I'm talking about :) Your Windows Service will likely run under the account "LOCAL SYSTEM" or "NETWORK SERVICE". Neither of these accounts are attached to the user who logs in to the desktop. So to the service, it has no concept of where that special folder is for the specific client you've logged in as. Where your WPF is concerned, special folders can be used as normal because you're logged in to a desktop session on a standard user account.
  4. Database is the best tool for the job. It will not get that large over the lifetime of the account unless you send huge attachments to it. You could also maintain a maximum age policy whereby everything after say, one month, is automatically deleted from your local store. A good idea here would be to download the headers only (not sure if the OpenPOP client will let you do that) OR download everything and only store the required information for display (such as the subject/datetime/summary) and then download the entire mail later. Depends how …
Ketsuekiame 860 Master Poster Featured Poster

First, I need to warn you about services and users/desktop sessions.

Your message boxes will never be shown (On Vista and up). The services don't run on any desktop session, so they don't have anywhere to be shown and you should never attempt to show UI from a service. Additionally, services will not typically run under your user account so the concept of special folder locations will not apply as you think it might.

As for your design question, the database would be the perfect tool for the job, but I think you're missing out on the services aspect of it. In my opinion, the client should be a thin client, only dealing with the layout of your UI and putting the data on to it.

Retrieving the data from the database and shipping it to something understandable should be the job of your service. Your client would then call the service and ask it for a list of emails. This is why I mentioned WCF as it gives you a nice way of hosting a service that you can call and debug easily. You can do it with standard windows services, but I find NET Remoting a bit clunky compared to WCF.