Thursday, February 27, 2014

MVC razor table row date to compare date between other 2 date in javascript


Consider the senerio of the image that i want to select date from table row date and my selected date will check other 2 date between in javascript.


First i am getting the event of date change:


  </td>    
              <td class="rptrowdata" align="center" style="width: 65px">  
                @{  
               if (Model.EmployeeInformationList[i].OutGoingDate == DateTime.MinValue || Model.EmployeeInformationList[i].OutGoingDate == null)  
               {  
                 @Html.TextBoxFor(m => m.EmployeeInformationList[i].strOutGoingDate, new { @class = "textRegular dtPicker pmtallocated pull-right", @readOnly = "readOnly", maxlength = "10",@dir = "rtl",@onchange = "return DateChecker(this);"  })                     
               }  
               else  
               {  
                  <input type="hidden" value="@Model.EmployeeInformationList[i].OutGoingDate " name="EmployeeInformationList[@i].OutGoingDate" id="EmployeeInformationList_@i __OutGoingDate" />     
                @Model.EmployeeInformationList[i].OutGoingDate.ToString("dd-MM-yyyy")      
               }  
                }  
              </td>        

now implement the DateChecker() in script


  function DateChecker(ctrl) {  
    // getting table row   
     var row = $(ctrl).parent().parent().parent().children().index($(ctrl).parent().parent());  
     var strOutGoingDate = $("#EmployeeInformationList_" + row + "__strOutGoingDate").val();  
    // You can set your value as your self of between date  
     var strFromDate = $("#strFromDate").val();  
     var strToDate = $("#strToDate").val();  
     var outGoingSplitResult = strOutGoingDate.split("-");  
     var outGoingYear = outGoingSplitResult[2].toString();  
     var outGoingMonth = outGoingSplitResult[1].toString();  
     var outGoingDay = outGoingSplitResult[0].toString();  
     var outGoingDate = new Date(outGoingYear + " " + outGoingMonth + " " + outGoingDay + " " + ",00:00:10");  
     var startSplitResult = strFromDate.split("/");  
     var startYear = startSplitResult[2].toString();  
     var startMonth = startSplitResult[0].toString();  
     var startDay = startSplitResult[1].toString();  
     var startDate = new Date(startYear + " " + startMonth + " " + startDay + " " + ",00:00:10");  
     var endSplitResult = strToDate.split("/");  
     var endYear = endSplitResult[2].toString();  
     var endMonth = endSplitResult[0].toString();  
     var endDay = endSplitResult[1].toString();  
     var endDate = new Date(endYear + " " + endMonth + " " + endDay + " " + ",00:00:10");  
    // Your Mathematical Expression  
     if (outGoingDate >= startDate && outGoingDate <= endDate) {  
       return true  
     }  
     else {  
       alert('Please select date between ' + startDate + ' and ' + endDate);  
       $("#EmployeeInformationList_" + row + "__strOutGoingDate").val("")  
       return false;  
     }  
  }  




Monday, February 24, 2014

SQL get last 6 month data

Not only 6 month you can get data as you want.

 SELECT *  
 From PIS.dbo.PIS_tblEmployeeGenInfo  
 WHERE dtJoiningDate > DATEADD(m, -6, current_timestamp)  

Thursday, February 13, 2014

mvc controller post action not working

some times we see that the post is not work, like as button or other. we can manage it using form and script to serialize the form to reach our controller action. define your action path, form id and method type in your form.


 <form id="subscriptionForm" action="/Category/Create" method="post"> 
 <div class="form-horizontal">  
     <h4>PIS_tblCategory</h4>  
     <hr />  
     @Html.ValidationSummary(true)  
     <div class="form-group">  
       <div class="form-group">  
         @Html.LabelFor(model => model.CategoryName, new { @class = "control-label col-md-2" })  
         <div class="col-md-10">  
           @Html.EditorFor(model => model.CategoryName)  
           @Html.ValidationMessageFor(model => model.CategoryName)  
         </div>  
       </div>  
       <div class="form-group">  
         @Html.LabelFor(model => model.GCompanyID, new { @class = "control-label col-md-2" })  
         <div class="col-md-10">  
           @Html.EditorFor(model => model.GCompanyID)  
           @Html.ValidationMessageFor(model => model.GCompanyID)  
         </div>  
       </div>  
       <div class="form-group">  
         <div class="col-md-offset-2 col-md-10">  
           <input type="submit" value="Create" class="btn btn-default" id="Save" />  
         </div>  
       </div>  
     </div>  
     @*}*@  
     <div>  
       @Html.ActionLink("Back to List", "Index")  
     </div> 
 </form>  

and script


  <script type="text/javascript">  
     $('#Save').click(function () {  
       var form = $("#subscriptionForm");  
       var url = form.attr("action");  
       var formData = form.serialize();  
       $.post(url, formData, function (data) {  
         $("#msg").html(data);  
       });  
     })  
   </script>  

Saturday, February 8, 2014

asp.net mvc how to separate module wise controller, model, view

First take a look on this.

http://stackoverflow.com/questions/5243158/how-to-configure-areas-in-asp-net-mvc3



In ASP.NET MVC application MVC gives use 3 part Controller, Model & View. But if we want to separate the  Controller, Model & View as our application Module based we can also implement this using AreaRegistration. Consider i want to use PIS module with seperated Controller, Model & View. i have to add a user define class, i just named it PISAreaRegistration.


  public class PISAreaRegistration : AreaRegistration  
   {  
     public override string AreaName  
     {  
       get  
       {  
         return "PIS";  
       }  
     }  
     public override void RegisterArea(AreaRegistrationContext context)  
     {  
       context.MapRoute(  
         "PIS_default",  
         "PIS/{controller}/{action}/{id}",  
         new { action = "Index", id = UrlParameter.Optional }  
       );  
     }  
   }  

if you want to add more module like PIS then you have do the all process as PIS done.

Thursday, February 6, 2014

mvc razor selected datepicker will add 3 month in another datepicker

  Before select date
 after select date

if you want to select any date from a date picker and it will add 3 month / as your self  in another date picker, you can easily do it using script on change event of you first date picker.

  @Html.TextBoxFor(m => m.MaternityLeave.strSymptomDate, new { @class = "textRegular requiredSub dtPicker", @readOnly = "readOnly", maxlength = "10", onchange = "return getConfirmationDate();" })  

second date picker

  @Html.TextBoxFor(m => m.MaternityLeave.strApplyDate, new { @class = "textRegular requiredSub dtPicker", @readOnly = "readOnly", maxlength = "10" })  


on change event script

  function getConfirmationDate() {  
     var confirmOld = $("#MaternityLeave_strSymptomDate").val();  
     var mySplitResult = confirmOld.split("-");  
     var confirm_date = mySplitResult[0].toString();  
     var confirm_month = parseFloat(mySplitResult[1].toString()) + parseFloat(3);  
     var confirm_year = mySplitResult[2].toString();  
     var confirm1 = new Date(confirm_month + '/' + confirm_date + '/' + confirm_year);  
     new Date(confirm_year + " " + confirm_month + " " + confirm_date + " " + ",12:52:39");  
     var confirm = new Date(confirm_month + '/' + confirm_date + '/' + confirm_year);  
     confirm.setDate(confirm1.getDate() - 1);  
     var curr_confirm_date = confirm.getDate();  
     var curr_confirm_month = confirm.getMonth();  
     curr_confirm_month = curr_confirm_month + 1;  
     if (curr_confirm_month.toString().length < 2) {  
       curr_confirm_month = "0" + curr_confirm_month;  
     }  
     if (curr_confirm_date.toString().length < 2) {  
       curr_confirm_date = "0" + curr_confirm_date;  
     }  
     var curr_confirm_year = confirm.getFullYear();  
     var confirmV = curr_confirm_date + '-' + curr_confirm_month + '-' + curr_confirm_year;  
     $("#MaternityLeave_strApplyDate").val(confirmV);  
   }  

sql datetime in join condition

In sql join on date or other query we fall common problem of time span. we can easily remove that to convert the date in to var-char & date format code 106 in sql.


 LEFT JOIN Payroll_tblEmployeeLeave ON PIS.dbo.PIS_tblEmployeeGenInfo.GEmployeeGenInfoID=Payroll_tblEmployeeLeave.GEmployeeGenInfoID   
 and Convert(varchar(11) ,Payroll_tblEmployeeLeave.LeaveDate,106 )=''' + Convert(varchar(11),@OfficeLeaveDate,106 ) + '''  

Tuesday, February 4, 2014

check sql default date value in C#

The Default date value of SQL server sometimes we need to check in C# your date  from sql database value = = DateTime.MinValue


  if (Model.EmployeeInformationList[i].OfficeLeaveDate!=DateTime.MinValue)  
               {  
                  // Do something  
               }  


SQL Get all Index create script from Database

To get all script from database as a create new index into another database you can use the following --Get all Index Script SELECT...