Tuesday, 24 February 2015

At least one object must implement IComparable

Currently I had meet a problem as the title above. It is really weird, because I also had use the Group By and toList() function in the other process and not error pop up.

The coding is as below :

//Get the Detail by grouping with article number, color and category.
                
  1. //Get the Detail by grouping with article number, color and category.  
  2. var DetailGroup = detail.GroupBy(c => new { c.ARTICLE_NUMBER, c.COLOR, c.CATEGORY, c.UOM })  
  3. .OrderByDescending(o => new { o.Key.ARTICLE_NUMBER, o.Key.COLOR }).ToList();  
After looking for the online resources, I find this Article and just realize that it maybe is not about the Group By but the Order By (multiple order by in the group by). 

So that, I modify a bit the coding (add in ThenBy) :
  1. //Get the Detail by grouping with article number, color and category.  
  2. var DetailGroup = detail.GroupBy(c => new { c.ARTICLE_NUMBER, c.COLOR, c.CATEGORY, c.UOM })  
  3. .OrderByDescending(o =>o.Key.ARTICLE_NUMBER).ThenBy( o =>  o.Key.COLOR ).ToList();  
and it is work fine and faster.


Hope this can help you and have a nice day. :)

--------------------------------------------
This article from: http://oysterleelife.blogspot.sg/2012/11/solved-at-least-one-object-must.html

Thursday, 5 February 2015

C# Winform Handle Double Click

To distinguish between clicks in the MouseDown event

  • Handle the MouseDown event and determine the location and time span between clicks using the appropriate SystemInformation properties and a Timer component. Perform the appropriate action depending on whether a click or double-click takes place. The following code example demonstrates how this can be done.
    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    namespace SingleVersusDoubleClick
    {
        class Form1 : Form
        {
            private Rectangle hitTestRectangle = new Rectangle();
            private Rectangle doubleClickRectangle = new Rectangle();
            private TextBox textBox1 = new TextBox();
            private Timer doubleClickTimer = new Timer();
            private ProgressBar doubleClickBar = new ProgressBar();
            private Label label1 = new Label();
            private Label label2 = new Label();
            private bool isFirstClick = true;
            private bool isDoubleClick = false;
            private int milliseconds = 0;
    
            [STAThread]
            public static void Main()
            {
                Application.EnableVisualStyles();
                Application.Run(new Form1());
            }
    
            public Form1()
            {
                label1.Location = new Point(30, 5);
                label1.Size = new Size(100, 15);
                label1.Text = "Hit test rectangle:";
    
                label2.Location = new Point(30, 70);
                label2.Size = new Size(100, 15);
                label2.Text = "Double click timer:";
    
                hitTestRectangle.Location = new Point(30, 20);
                hitTestRectangle.Size = new Size(100, 40);
    
                doubleClickTimer.Interval = 100;
                doubleClickTimer.Tick +=
                    new EventHandler(doubleClickTimer_Tick);
    
                doubleClickBar.Location = new Point(30, 85);
                doubleClickBar.Minimum = 0;
                doubleClickBar.Maximum = SystemInformation.DoubleClickTime;
    
                textBox1.Location = new Point(30, 120);
                textBox1.Size = new Size(200, 100);
                textBox1.AutoSize = false;
                textBox1.Multiline = true;
    
                this.Paint += new PaintEventHandler(Form1_Paint);
                this.MouseDown += new MouseEventHandler(Form1_MouseDown);
                this.Controls.AddRange(new Control[] { doubleClickBar, textBox1, 
                    label1, label2 });
            }
    
            // Detect a valid single click or double click. 
            void Form1_MouseDown(object sender, MouseEventArgs e)
            {
                // Verify that the mouse click is in the main hit 
                // test rectangle. 
                if (!hitTestRectangle.Contains(e.Location))
                {
                    return;
                }
    
                // This is the first mouse click. 
                if (isFirstClick)
                {
                    isFirstClick = false;
    
                    // Determine the location and size of the double click  
                    // rectangle area to draw around the cursor point.
                    doubleClickRectangle = new Rectangle(
                        e.X - (SystemInformation.DoubleClickSize.Width / 2),
                        e.Y - (SystemInformation.DoubleClickSize.Height / 2),
                        SystemInformation.DoubleClickSize.Width,
                        SystemInformation.DoubleClickSize.Height);
                    Invalidate();
    
                    // Start the double click timer.
                    doubleClickTimer.Start();
                }
    
                // This is the second mouse click. 
                else
                {
                    // Verify that the mouse click is within the double click 
                    // rectangle and is within the system-defined double  
                    // click period. 
                    if (doubleClickRectangle.Contains(e.Location) &&
                        milliseconds < SystemInformation.DoubleClickTime)
                    {
                        isDoubleClick = true;
                    }
                }
            }
    
            void doubleClickTimer_Tick(object sender, EventArgs e)
            {
                milliseconds += 100;
                doubleClickBar.Increment(100);
    
                // The timer has reached the double click time limit. 
                if (milliseconds >= SystemInformation.DoubleClickTime)
                {
                    doubleClickTimer.Stop();
    
                    if (isDoubleClick)
                    {
                        textBox1.AppendText("Perform double click action");
                        textBox1.AppendText(Environment.NewLine);
                    }
                    else
                    {
                        textBox1.AppendText("Perform single click action");
                        textBox1.AppendText(Environment.NewLine);
                    }
    
                    // Allow the MouseDown event handler to process clicks again.
                    isFirstClick = true;
                    isDoubleClick = false;
                    milliseconds = 0;
                    doubleClickBar.Value = 0;
                }
            }
    
            // Paint the hit test and double click rectangles. 
            void Form1_Paint(object sender, PaintEventArgs e)
            {
                // Draw the border of the main hit test rectangle.
                e.Graphics.DrawRectangle(Pens.Black, hitTestRectangle);
    
                // Fill in the double click rectangle.
                e.Graphics.FillRectangle(Brushes.Blue, doubleClickRectangle);
            }
        }
    }

Wednesday, 14 January 2015

Concatenate many rows into a single text string using SQL Server 2008

Using COALESCE function - concatenate many rows into a single text string output in SQL Server.

The following code is used to concatenate many rows into a single text string with comma separated using SQL Server COALESCE function.

My table format is like this:
RAM
GURU
Sundar
Shyam
Inba
Kalai
I need output like this:
"RAM, GURU, Sundar, Shyam, Inba, Kalai"

I use the following query:
DECLARE @Names VARCHAR(8000)  
SELECT @Names = COALESCE(@Names + ', ', '') + Name FROM People
SELECT @Names


---------------------------------------------------------------------------------
Come from: http://www.codeproject.com/Tips/334400/Concatenate-many-rows-into-a-single-text-string-us

Monday, 12 January 2015

MVC How to Create A jQuery Modal Popup

Please visit the youtube site below,
https://www.youtube.com/watch?v=jpg_2vLAJxc

And how to open a jQuery UI Dialog without a title bar?
I figured out a fix for dynamically removing the title bar.
$("#example").dialog(dialogOpts);
// remove the title bar
$(".ui-dialog-titlebar").hide();
This will remove all elements with the class 'ui-dialog-titlebar' after the dialog box is rendered.

Thursday, 8 January 2015

Creating mouseover text with HTML


 

Using <SPAN> Tag

Mouseover text is simple to make.
When you are editing a page, click on <HTML> button on the toolbar. 
 
What you'll want to do is enclose whatever text you'd like to have a mouseover in span tags. those look like this: <span>This is the text I want to have a mousover</span>. You can do this by either finding the text you want in the HTML editor, or by typing it yourself.
 
To add the mouseover text though, you'll need to take advantage of the span's title attribute. Assigning a value to an attribute looks like this: 
 
<span title="I am hovering over the text">This is the text I want to have a mousover</span>
 
Note that attribute values are always in quotes.
 
And voila! You're done. The text should now have a mouseover pop-up. You can see an example below. Spans can also be used to give custom css to a section of text (see the bottom of this page for some brief notes on how this is done).
 
This is the text I want to have a mouseover
 

Using <A> Tag

ALL OF THE BELOW IS USEFUL INFO ABOUT HTML, BUT IT IS NOT ACTUALLY NECESSARY TO SOLVE THIS PROBLEM
 
Mouseover text is pretty simple to create. Basically, what you're going to want to do is to create a link with an empty reference attribute (so clicking it doesn't take you anywhere), and use the title attribute to create whatever mouseover text you would like. 
 
To create an empty link, you're going to have to use the google sites html editor (click the button that says <HTML> in the page editor).
 
the link uses the tag <a>. So a link might look like <a>This is the text I want to show</a>. (ALWAYS REMEMBER TO USE THE CLOSING TAG - in this case, </a>)
 
But links also need a location, given by the "href" attribute. so to add that, <a href="http://mysite.com">This is a link to my site</a>. (attribute values are ALWAYS in quotes).
 
We don't want the link to actually take people anywhere, so instead of providing the href attribute with an actual url, just use empty quotes: " ". So: <a href=" ">This is a link to my site</a>.
 
We now have our link. to add mouseover text, just use the "title" attribute, like so: <a href=" " title="This is some text I want to display.">This link has mouseover text.</a> (see the next line to check this out in action.)
 
The unfortunate result of this is that your link will have the same styles as all the rest of the links on your site (e.g. a different background color or having blue colored text). However, we can override this with the "style" attribute, which allows you to add inline CSS to virtually any HTML tag. To change the background color to white, the text color to black, and remove the underline from the link we'll write:
 
<a href=" " title="This is some text I want to display." style="background-color:#FFFFFF;color:#000000;text-decoration:none">This link has mouseover text.</a>
 
Notice that the color attributes (backgroundcolor for...the background color, and color for the text color) use hexadecimal to determine the color. In general, the first two hex characters represent the amount of red in the color, the second two the green, and the final pair represent how blue the color is. For a full reference of colors and their hex values, see http://www.december.com/html/spec/color.html
 
And that's it! We now have a sentence with text that appears when you hover your mouse over it, and doesn't look like a link. Mouseover the sentence below to check out the final product.
 
note: you'll notice that the style attribute works a little bit differently, in that it can modify multiple things about the link. In general the syntax is "attribute-name:value;nextattributename:value". This is CSS, which you can learn more about from a variety of sources (like here).
 
----------------------------------------------------------------------

Wednesday, 17 December 2014

Clear values of all fields and remove ValidationSummary error messages validation-summary-errors with jquery.

Problem:

I have an ASP.NET MVC 4 application. On several of the pages, I have a "add new item" button relevant to the page. Clicking that button displays a dialog with a form to fill out. The dialog has two buttons, "submit" and "cancel".
Validation of the "Add new item" form is handled in typical MVC style by adding this razor tag just inside the form element:
@Html.ValidationSummary(true)
For the most part, this all works just fine. If a field fails validation, then the submit button causes it to show the validation message.
The problem is this - if the form fails validation, and then the user clicks "cancel", the dialog simply hides itself. The next time "Add new item" is clicked, the dialog appears again, but the validation message is still there from the last failed attempt.
This looks unprofessional. When the user clicks "cancel" the form and the validation should reset.
I am not sure what validation library is being called for validation here. I could always add some javascript to change the CSS of the validation label, etc. but I want to make sure that I'm not breaking the validation, or leaving behind misc javascript, etc.

Answer:

$('.field-validation-error') .removeClass('field-validation-error') .addClass('field-validation-valid').empty();
$('.input-validation-error') .removeClass('input-validation-error') .addClass('valid').empty();

Thursday, 23 October 2014

Running a SQL Stored Procedure from Excel (No VBA)

 

May 4th, 2010 by Leave a reply »
We all know we can use MS Query to get data from a SQL server. Typically though, we pull from a Table or a View. Well in some organizations, the IT department wants all interaction with the server to be done through Stored Procedure. This adds a level of risk management and makes the DBAs feel better.
 
So today, I'll show you how to easily make Excel run a Stored Procedure to get data.
 
Step 1: Data tab - > From Other Sources -> From SQL Server
 
 
Step 2: Enter Credentials. Your server name can be an IP address
 
 
Step 3: Choose any old table or view. Pick a small one because we'll discard it later anyway.
 
 
Step 4: Excel will pop up the Import Data dialog box. Click Properties here (NOT THE OK BUTTON).
 
Step 5: Click on the Definition tab. There, change Command Type to SQL, and then enter your Stored Procedure name in the Command Text input.
 
 
Step 6: Excel complains about something….blah…blah…blah. Click Yes – (as in yes I know what I'm doing).
 
 
Step 7: Excel will activate the Import Data dialog box again. This time click OK to fire the Stored Procedure and return the results.
 
 
Step 8: Marvel at your results
 
 
Notes:
  1. Excel will fire the Stored Procedure each time you "Refresh"
  2. If you have to pass a parameter, you can enter it in the command text like this:

     
  3. If you have to pass dynamic parameters you'll have to turn to VBA. See this post.
  4. I assume you can do this with ORACLE databases too.
  5. I've yet to test whether this will fire a Stored Procedure that doesn't return data. In other words, Stored Procedures that perform Insert, Update or Delete actions. I assume that if you can, there is the possibility of updating SQL from Excel through a simple connection. Pretty cool.


This article is from http://datapigtechnologies.com/blog/index.php/running-a-sql-stored-procedure-from-excel/