Skip to main content

Posts

Showing posts from 2013

Get the number of calendar weeks between 2 dates in C#

1. const int firstDayOfWeek = 0;  // 0 = Sunday int wasteDaysStart = (7 + Convert.ToInt32(first.DayOfWeek) - firstDayOfWeek) % 7; int diff = (int)(((last - first).TotalDays + wasteDaysStart + 6) / 7); diff = diff + 1; ==================================================== 2. DateTime periodStart = first; DateTime periodEnd = last; const DayOfWeek FIRST_DAY_OF_WEEK = DayOfWeek.Monday; const DayOfWeek LAST_DAY_OF_WEEK = DayOfWeek.Sunday; const int DAYS_IN_WEEK = 7; DateTime firstDayOfWeekBeforeStartDate; int daysBetweenStartDateAndPreviousFirstDayOfWeek = (int)periodStart.DayOfWeek - (int)FIRST_DAY_OF_WEEK; if (daysBetweenStartDateAndPreviousFirstDayOfWeek >= 0) firstDayOfWeekBeforeStartDate = periodStart.AddDays(-daysBetweenStartDateAndPreviousFirstDayOfWeek); else firstDayOfWeekBeforeStartDate = periodStart.AddDays(-(daysBetweenStartDateAndPreviousFirstDayOfWeek + DAYS_IN_WEEK)); DateTime lastDayOfWeekAfterEndDate; int daysBetweenEndDateAndFollowingLast...

JQuery Event for user pressing enter in a textbox?

$ . fn . pressEnter = function ( fn ) { return this . each ( function () { $ ( this ). bind ( 'enterPress' , fn ); $ ( this ). keyup ( function ( e ){ if ( e . keyCode == 13 ) { $ ( this ). trigger ( "enterPress" ); } }) }); }; //use it: $ ( 'textarea' ). pressEnter ( function (){ alert ( 'here' )})   Ref : http://stackoverflow.com/questions/6524288/jquery-event-for-user-pressing-enter-in-a-textbox

Pass array to mvc Action via AJAX - MVC

$ . ajax ({ url : 'controller/myaction' , data : JSON . stringify ({ myKey : myArray }), success : function ( data ) { /* Whatever */ } }); Then your action method would be like so: public ActionResult ( List <int> myKey )   {   // Do Stuff     } For you, it looks like you just need to stringify your values. The JSONValueProvider in MVC will convert that back into an IEnumerable for you.  Ref : http://stackoverflow.com/questions/5489461/pass-array-to-mvc-action-via-ajax/5489511#5489511 OR public ActionResult test(string data) { System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); object obj = serializer.DeserializeObject(data); } var data = JSON.stringify({ AccountType: $("#AccountType").val(), P_FirstName: $('#P_FirstName').val() }); $.ajax({ type: "GET", url: "Home/test", data: { data: data }, .... });

Kendo UI - Nested ClientTemplates not working

=================================================== #= firstName# (Bind main Grid) =================================================== \\#=Media\\# (Bind data in Sub-grid) =================================================== @(Html.Kendo().Grid<DbModels.Test>()                                             .Name("grdTest")                                             .Columns(columns =>                                             {                                                 columns.Template(e => { }).ClientTemplate("<i...

SQL - Types of Joins

When you join tables, the type of join that you create affects the rows that appear in the result set. You can create the following types of joins: Inner join    A join that displays only the rows that have a match in both joined tables. (This is the default type of join in the  Query and View Designer .) For example, you can join the  titles  and  publishers  tables to create a result set that shows the publisher name for each title. In an inner join, titles for which you do not have publisher information are not included in the result set, nor are publishers with no titles. The resulting SQL for such a join might look like this: SELECT title, pub_name FROM titles INNER JOIN publishers ON titles.pub_id = publishers.pub_id Note Columns containing NULL do not match any values when you are creating an inner join and are therefore excluded from the result set. Null values do not match other null values. O...

C# - HTTP request with post

HttpWebRequest httpWReq = ( HttpWebRequest ) WebRequest . Create ( "http://domain.com/page.aspx" ); ASCIIEncoding encoding = new ASCIIEncoding (); string postData = "username=user" ; postData += "&password=pass" ; byte [] data = encoding . GetBytes ( postData ); httpWReq . Method = "POST" ; httpWReq . ContentType = "application/x-www-form-urlencoded" ; httpWReq . ContentLength = data . Length ; using ( Stream stream = httpWReq . GetRequestStream ()) { stream . Write ( data , 0 , data . Length ); } HttpWebResponse response = ( HttpWebResponse ) httpWReq . GetResponse (); string responseString = new StreamReader ( response . GetResponseStream ()). ReadToEnd ();

Best Practices for Speeding Up Your Web Site

Minimize HTTP Requests tag: content 80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages. One way to reduce the number of components in the page is to simplify the page's design. But is there a way to build pages with richer content while also achieving fast response times? Here are some techniques for reducing the number of HTTP requests, while still supporting rich page designs. Combined files  are a way to reduce the number of HTTP requests by combining all scripts into a single script, and similarly combining all CSS into a single stylesheet. Combining files is more challenging when the scripts and stylesheets vary from page to page, but making this part of your release process improves response times. CSS...