Ketsuekiame 860 Master Poster Featured Poster

I think living without regret is as bad as living with too many! Never having regret means you never took chances, or that you didn't care about the result. Isn't that a sad way to live? I think you can regret things in life you've done, but see it as a positive. Something that made you who you are today.

Ketsuekiame 860 Master Poster Featured Poster

My responsiveness issues relative to iOS have been with straight Android, as recent as ICS. So while you're certainly right that manufacturers (Samsung especially) have been egregious with their crapware, that's not always the answer when someone mentions UI lag

Sorry to hear that, when I re-flashed mine it fixed it right away. I am on 4.1.2 Jellybean if that helps at all?

Ketsuekiame 860 Master Poster Featured Poster

Obfuscation only deters a casual reader. Anyone who's seriously interested in the code will have only a little more difficulty figuring it out from an obfuscated disassembly. Further, no professional in their right mind would manually obfuscate code rather than take advantage of a tool.

True dat. Just stating that it is actually done on purpose ;)

Ketsuekiame 860 Master Poster Featured Poster

No, not that much partying, just enough that hand eye co-ordination was a little off. I'd actually climbined the same thing before, the brick work offered some good purchase. Unfortunately, in a disoriented state, getting down was somewhat difficult =/

I don't believe drinking is the problem, but peer-pressure and socialistic expectations. The "problems" you see from drinking are those who go out and want to end up in that state, in fact, don't think they've "had a good time" unless they reach that state.

This all comes about from a few factors but I think two are primary.
1. Upbringing - If your parents come home hammered every night, then you're likely to do the same growing up.
2. Television/Music - Listen to the pop culture crap that comes on the radio and take note of what they're "singing". I don't think I've heard a song in the last 5 years that doesn't involve going out, getting wasted, finding some boy or girl and taking them home for a good seeing to.

Culture is changing and not for the better, however, you cannot punish the masses for the actions of a minority. The only exception is when harm to others becomes a direct and unavoidable consequence.

For example, you smoking next to me will damage my health. I have no option other than to move away, but if it's the same everywhere, where do I go? In essence, you chose to damage my health and I do …

Ketsuekiame 860 Master Poster Featured Poster

@deceptikon I had responsiveness issues on my S3. Turns out it was due to Samsung's crappy TouchWiz interface. If you flash it with a basic Android ROM it's snappy as hell :) (Bit like Laptops you buy form superstores that come bogged down with all their branded crap)

Ketsuekiame 860 Master Poster Featured Poster

You do that by compiling the code. If you don't want anyone to see your code then don't release it. If you release horribly obfuscated code then you tell the world that you don't know #### about programming (whether or not that is actually the case). Would you leave a ton of crap in your car as an anti-theft device? It might work, but what image do you project to the world?

Obfuscation is quite a common practice, especially in .net where disassembly of libraries is incredibly easy. If you want to protect something proprietry from potential espionage, it will be obfuscated either manually or using some kind of tool before compiling.

Ketsuekiame 860 Master Poster Featured Poster

@Ketsuekiame, why were you drunk in the first place?

It was atheltic union night at the university. There was much partying :P

Ketsuekiame 860 Master Poster Featured Poster

I tried walking back down at first but quickly realised that it was a bad idea ;)

Ketsuekiame 860 Master Poster Featured Poster

I jammed in a gap in the brickwork (like two chimney flues) and sat there until the fire brigade arrived. Managed to get up, but couldn't get down :P

Sahil89 commented: :D +0
Ketsuekiame 860 Master Poster Featured Poster
  1. Should have made more of an effort at University.
  2. A decision I made back in school about where I'd study. At the time I had no idea how that decision would come to affect the other people in my life at the time.
  3. Climbing up the side of a building unaided whilst drunk.
Ketsuekiame 860 Master Poster Featured Poster

There's nothing in Excel to reset, just need to update your row counter back to its original setting (as you keep track of this yourself, up at the top of the method). If this needs to be different each time, it might be worth passing this into the method instead.

Ketsuekiame 860 Master Poster Featured Poster

Do you only need to pick out the date once from the spreadsheet? Seems counter-intuitive to what you're doing in the foreach loop (aren't they the orders?)

In any case;

ws.Cells[CurrentOrderRow, excelColumnNumber] = ((DateTime)row.Cells[DATEColumnIndex].Value).ToOADate();
((Range)ws.Cells[CurrentOrderRow, excelColumnNumber]).NumberFormat = "YYYY/MM/DD" // International Date Format
Ketsuekiame 860 Master Poster Featured Poster

Tea snobs ho! o/

I drink imported dried Jasmine tea or green tea.

Ketsuekiame 860 Master Poster Featured Poster

You forgot to put .Value on your SelectedCells line. :)

Not entirely sure what you're trying to do on line 17 though...?

Ketsuekiame 860 Master Poster Featured Poster

Cast it to DateTime and call ToOADate()

eg. ((DateTime)row.Cells[DATEColumnIndex].Value).ToOADate();

You should probably do a null/empty check first :)

EDIT: You should also set the number format of the cell in Excel to be Date format.

((Range)ws.Cells[CurrentOrderRow, 3]).EntireColumn.NumberFormat = "YYYY/MM/DD";

Note you can do it individually or the entire column like I have shown. If you do the entire column, you don't need to do it every single iteration, just once when you're finished and before you save.

Ketsuekiame 860 Master Poster Featured Poster

You're updating CurrentRow, not CurrentOrderRow, so it's over-writing the old value each time :)

Ketsuekiame 860 Master Poster Featured Poster

Erk, that error could be a multitude of things :(

Try adding this line above where you Open the workbook:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

(You might want to save your old culture settings to reset them after you finish working with the spreadsheet...)

YAE! (Yet Another Edit)
Seems Microsoft took retardation to a whole new level. Excel objects start at array index 1 and not 0...

Ketsuekiame 860 Master Poster Featured Poster

What line is it referring to?

EDIT:

Try access your spreadsheet like this instead:
ws.Cells[CurrentRow, 0] = row.Cells[accRefDgvColumnIndex]

Ketsuekiame 860 Master Poster Featured Poster

Yep! You access it by the column names that were in your database/dataset table.

It's the name of the column, not the header value :)

Ketsuekiame 860 Master Poster Featured Poster

No, if you continue on from your last update, just make the amendments I posted. The first three code lines of my last post, place above your foreach loop, adjust the foreach loop to reference the columns as in the posted code at the bottom of the post (I used yours as a template so you should be able to copy/paste)

I made the mistake of forgetting that what I use here, isn't exactly the same as what you will have. We have a toolkit here that extends ADO functionality. What I posted to you before, works here, but won't on your machine. So I had to go and find all the original ways of doing it. It just made it slightly messier.

Ketsuekiame 860 Master Poster Featured Poster

Right I see, it's not letting you call a cell index by name. Sorry, I'm not a regular user of straight up ADO, we have layers covering it to expand the natural functionality.

In that case you need to fetch the right column with that name.

Before you begin your data extraction, set three values that contain the column index of your datagridview column you're interested in.

This can be done like this:

Int32 accRefDgvColumnIndex = dataGridView1.Columns["AccountRef"].Index;
Int32 nameDgvColumnIndex = dataGridView1.Columns["Name"].Index;
Int32 postcodeDgvColumnIndex = dataGridView1.Columns["PostCode"].Index;

Admittedly this is getting a bit messy now. Might be wise to put all the column indexes into a Dictionary and key it on String.

So you would use:

foreach(DataGridViewRow row in dataGridView1.Rows)
{
    ws.Rows[CurrentRow].Column[0] = row.Cells[accRefDgvColumnIndex].Value;
Ketsuekiame 860 Master Poster Featured Poster

Sorry I didn't give you actually working code, it was more pseudo code for logic.

The dgv.DataRows should just be dgv.Rows, this will give you a type of DataGridViewRow, which will have the property Cells, which you access via array to pull the value.

So more like;

foreach(DataGridViewRow row in datagridView1.Rows)
{
    Object column1Value = row.Cells["AccountRef"].Value;
    ...
}
Ketsuekiame 860 Master Poster Featured Poster

It becomes easier to conceptualise the outcome if you visualise the data segregation. Rather than seeing row numbers and column numbers, think about them in name format.

Your DGV already knows columns such as Name, Address, Account Reference etc.
You know where they will be going on your Excel report.

So in order for your code to know where they're going, setup some basic steps. This is hardcoding and therefore "bad" but in time you could always rip it out and make it configurable.

But let's say you output Account Ref, Name, Postcode;

public int AccRefColumn = 0; // Column A
public int NameColumn = 1; // Column B
public int PostCodeColumn = 2; // Column C

public int CurrentRow = 6; // Row 6

// semi-pseudo code incoming...
foreach(var dataRow in dgv.DataRows)
{
    excelSheet.Row[CurrentRow].Column[accRefColum] = dataRow["AccountRef"].Value;
    excelSheet.Row[CurrentRow].Column[NameColumn] = dataRow["Name"].Value;
    ...
    CurrentRow++;
}

excelSheet.Save();

Although it's good to strive for completely generic ways of doing things, sometimes, you just need to make it specific for the task. Without a lot more work outside of this particular function, I think this is the best approach.

Just heading off for lunch, I'll be back in about an hour if you need more assistance.

Ketsuekiame 860 Master Poster Featured Poster

I think the easiest way to approach this is to give your application knowledge of what columns contain which data. Simply keep track of what row you're dealing with and increment through each iteration of your export.

Ketsuekiame 860 Master Poster Featured Poster

They say that The only thing to fear, is fear itself. Well, I say they've probably never been face to face with a bear!

Ketsuekiame 860 Master Poster Featured Poster

Used iPhone 4 and Galaxy S3; prefer the Galaxy S3 because it's better at what I want it to do. It's a more open architecture and I can poke and play with it to my heart's content. The music player is somewhat poor and has now been replaced with Spotify :P
The camera is much better than the 4, assuming this is down to software not the lens.

The iP4 is a good phone if you want something simple and does everything for you. It's a "nannying" phone. But if you want a music player, somewhere to store your photos and Facebook, the iPhone is probably what you want.

iOS vs Android - Android. For the simple reason that I don't have to pay to develop for it and I don't have to jump through 10,000 hoops to get software I've written onto the phone that I own.

tl;dr - Choose the right one for what you want. They both have pros and cons in different areas but are about the same overall.

Ketsuekiame 860 Master Poster Featured Poster

Same. At least 8 hours at work (usually around 10) then whatever time is left until 1am at home. I have activity days though where I will not go home but instead play Badminton or go Ice Skating or just visit friends.

As much as I love what I do, I like to unlock the chains every now and again ;)

Ketsuekiame 860 Master Poster Featured Poster

You can retrieve the UsedRange of the worksheet. That way you can determine if the worksheet has any data on it. If it's empty, you can delete the sheet.

Ketsuekiame 860 Master Poster Featured Poster

Yeah, you should be able to get the office library to remove the worksheets you don't need.

Once you load your spreadsheet, you should be able to select the worksheet (via an array) and call Delete() on it.

When you're done, save it again and you should be good to go :)

Ketsuekiame 860 Master Poster Featured Poster

Seems odd that Reporting Services would add blank worksheets, wonder the reasoning behind it...

Do you have access to the MS Office library for .NET? That will be quite powerful for doing what you need.

Ketsuekiame 860 Master Poster Featured Poster

I have written some pretty horrific LINQ one liners in my time when I've been rushing.

Generally I newline curled bracers, nest everything and if a line gets too long, drop each argument to its own line, indented as appropriate to the current nested scope.

Ketsuekiame 860 Master Poster Featured Poster

Okay, there's a couple of ways you can do it.

Firstly, have a public field through which you can set the value.
Secondly, call a public method which sets the value explicitly.

First:

Form2 secondForm = new Form2();
secondForm.ConnectionString = textBox1.Text;
secondForm.Show();


....

In Form2:

OnLoad(object sender, EventArgs evt)
{
    textBox1.Text = ConnectionString;
}

Second:

Form2 secondForm = new Form2();
secondForm.SetConnectionString(textBox1.Text);
secondForm.Show();

....

Form2:

public void SetConnectionString(String connectionString)
{
    textBox1.Text = connectionString;
}

Alternatively, use the constructor. The best way would be to use a configuration object that you can call from your second form (Singleton accessor) so you needn't pass the data around.

Ketsuekiame 860 Master Poster Featured Poster

How does form2 get shown? Are they both showing simultaneously?

Ketsuekiame 860 Master Poster Featured Poster

Can you post your ConnectionString please?

Ketsuekiame 860 Master Poster Featured Poster

ExecuteScalar is used when you return a single value from your procedure. You can typically use this to return things such as the row identity if you're inserting or an aggregate value or something along those lines.

ExecuteNonQuery is used when you have nothing to return from the procedure. What you get as the result is the number of rows affected by your query. Importantly, you can use ExecuteNonQuery when you expect OUTPUT parameters, but no specific return value. Like a void method that takes a ref parameter argument.

Ketsuekiame 860 Master Poster Featured Poster

To have using statements is better but not necessary. Also I presume you meant to include your connection in the using statement? The OP would also be able to put the SqlCommand into another using statement.

ExecuteScalar is unnecessary because his procedure returns no values.

Ketsuekiame 860 Master Poster Featured Poster

Try executing the stored procedure in SQL Studio and see if it gives you the same result.

It could be that;
A) You created the Users table on a different schema to dbo. (Kind of unlikely because you'd know about it...)
B) Your SQL connection string hasn't selected an initial database to use and is connected to 'master' by default.
C) Try using [dbo].[Users]. It shouldn't make a difference but consistency doesn't hurt.

Ketsuekiame 860 Master Poster Featured Poster

tinstaafl, I just did a search for a BigInteger class (not .net 4) and couldn't find anything. Do you have a link to the post in question? I'd be curious to see how they implemented it in C#

Ketsuekiame 860 Master Poster Featured Poster

Hi csss, the only way to retrieve the numeric value is to use the BigInteger class. This will let you have a theoretically infinitely large number.

However, the caveat to this is that everything you use will be limited to a minimum of .NET 4 framework. If you cannot use .NET 4 or above I'm afraid you're out of luck.

Additionally, rather than use Math.Pow you will need to use BigInteger.Pow but this should work for you.

Ketsuekiame 860 Master Poster Featured Poster

If you're wanting to do what I think you want to do; you want to split your power by units of ten and the remainder?

If so let's take your 33 as an example;

public void Method()
{
    int value = 6;
    int power = 33;

    int iterations = (int)Math.Floor(power / 10); // We want to lose the decimal point
    int remainder = power % 10; // This will return 3. As it returns the remainder of a division operation

    Double result = 1; // Important as we're going to muliply our results together. Starting from 0 would yield 0. Also, we're dealing with "power" so big numbers may result. In these cases, you need to use exponent notation.

    for(int currentIteration = 0;currentIteration < iterations; currentIteration++)
    {
        result = result * Math.Pow(value, 10);
    }

    result = result * Math.Pow(value, remainder);

    Console.WriteLine("Result is: {0}", result);
    Console.WriteLine("Actual   : {0}", Math.Pow(value, power));

    Console.ReadLine();
}

It's important to note, that you won't be able to display this in normal integer format for large numbers as the structures simply aren't big enough even with unsigned 64-bit addressing (unless you converted it to a string...)

Ketsuekiame 860 Master Poster Featured Poster

When executing SQL, to be safe, you should use parameters. Otherwise someone could quite easily perform an SQL Injection attack.

More on parameters Here

tux4life commented: Good advice :) +13
Ketsuekiame 860 Master Poster Featured Poster

He's just setting the wrong columns is all.

If you look at the screenshot, his "Company Name" header works, which is index 2. He's just mis-counted the array index for the other two columns. Should be using named indexing to avoid this issue ;)

Ketsuekiame 860 Master Poster Featured Poster

Where you assign the header text, call the array by column name rather than position number.

So dataGridView1.Columns["CashAccRef"].HeadText = "Account";

You've mis-counted your array indeces. I'm making the presumption that the naming below, is also the index position they have in the array. In which case you should be using indexes 1, 2 and 7.

However, should the order change it will be wrong again. Safer to use column names :)

ddanbe commented: Great thinking! +14
Ketsuekiame 860 Master Poster Featured Poster

string dFileName = String.Format(@"{0}", fileName);

What are you trying to acheive with this line?

Also, I can't see anything wrong with your code in particular.

Could you provide the code for your RenderConsoleProgress method so that I can test the code?

Thanks.

Ketsuekiame 860 Master Poster Featured Poster

If you're given another report to upload, surely this is another separate Excel file?

Otherwise, deceptikon is correct, simply don't upload the existing report. If you want to delete it from the database, send an SQL query to do that for you.

Why you'd want to delete from the database I don't know, seems kind of pointless...

Ketsuekiame 860 Master Poster Featured Poster

That still doesn't make much sense. Just don't upload the first worksheet.

I didn't realise you could be that selective. In my mind I was using the concept of a workbook and uploading this container, rather than uploading the individual worksheets.

He's accessing Excel through an OleDB connection, so aside from a few sticking points like the worksheet name, it's just straight ADO.NET. I like to use this method as well for when installing Office on a machine is prohibitive (the "official" Excel interop requires office to be installed...), even though it's not as convenient for more advanced tasks.

Believe it or not, I actually have little to no experience in this area. I work with straight SQL connections usually and have done some very basic Data Grid View binding, but OleDb is something I seemed to have avoided over the past 10 years. I don't know the capabilities of ADO.NET nor how they link with the Excel data structures.

I was only hoping to clarify his question so you could give the answer sooner rather than later. Although if what you're saying is correct (which I have no doubt) then yeah, seems like this is a bit of a No-Op...

Ketsuekiame 860 Master Poster Featured Poster

I think he means that the Workbook contains many Worksheets and he needs to delete the first worksheet before uploading it to the database. (Maybe for privacy concerns?)

Unfortunately I don't know anything about using Excel in C# so beyond my interpretation I can't offer anything else ^^

Ketsuekiame 860 Master Poster Featured Poster

What is the last available date? At the moment you're requesting the hard-coded date of the 15th Jan, 2013. You realise that this site only stores data up to December 2012?

Ketsuekiame 860 Master Poster Featured Poster

/Agree

Your best option is to re-write and re-compile using the C++ language and gcc compiler for Linux.

Mono might just work, so it's worth a try, but don't hold your breath.

Ensure your client understands that there will be porting work involved as you're switching operating systems. Make sure you give realistic time-scales and set expectations appropriately. The worst thing you can do is lie to your client.

It does you no favours and gives all developers a bit of a bad rep. Having a client that expects you to lie and deceive them is especially frustrating!

As you're going to effectively be re-developing your application, you should be able to charge them again for it (at a reduced rate obviously). But this depends on your initial contract that you signed.

If you can't program in C++ or for Linux, then unfortunately I don't think there is much that can be done to help.

Ketsuekiame 860 Master Poster Featured Poster

Ahh, fair enough. I read it in a different way than you intended, but I'd still rather do it manually, for the reasons I gave above.

using does make it more readable, but you sacrifice some control. Depends on your needs and requirements :)