Friday, December 27, 2013

Sunday, December 15, 2013

sql get month & year from date



 SELECT   
 OTDate as Date  
 ,CONVERT(CHAR(4), OTDate, 100) as Month   
 ,CONVERT(CHAR(4), OTDate, 120)as Year  
 FROM Payroll_tblEmployeeOTHour  

Tuesday, September 24, 2013

SQL Query Execution time of you in SQL Management Studio


You can check the Execution time of you SQL Query in SQL Management Studio. like this


It is very simple that you just put your SQL Query in to the Estimated time execution query


 DECLARE @StartTime datetime  
 DECLARE @EndTime datetime  
 SELECT @StartTime=GETDATE()   
  -- Write Your Query  
 SELECT @EndTime=GETDATE()  
 --This will return execution time of your query  
 SELECT DATEDIFF(NS,@StartTime,@EndTime) AS [Duration in millisecs]   


Thursday, May 16, 2013

how replace null to 0 in sql query

If you want to replace the null value in 0 in your sql query like the output:






you have to just write as  ISNULL(DC_Requisition.MainStockID,0) as MainStockId

Saturday, May 11, 2013

How to disable specific grid column in kendo ui Grid on inline editing

If you want to stop editing on specific Grid column in Kendo Ui grid like this


Just use theDataAnnotations [Editable(false)] in your custom class for the grid

i am just share my code for your help

 using System;  
 using System . Collections . Generic;  
 using System . ComponentModel . DataAnnotations;  
 using System . Linq;  
 using System . Web;  
 namespace FEWO . ViewModel  
 {  
   public class Limitation  
   {  
     public long Id { get; set; }  
     public int? LFDNR { get; set; }  
     public Guid? ob_guid { get; set; }  
     public DateTime? von { get; set; }  
     public DateTime? bis { get; set; }  
     public string einschrank { get; set; }  
     public string wtagvon { get; set; }  
     public string wtagbis { get; set; }  
     public int numtagvon { get; set; }  
     public int? numtagbis { get; set; }  
     public int? nummonvon { get; set; }  
     public int? nummonbis { get; set; }  
     public int? numjahrvon { get; set; }  
     public int? numjahrbis { get; set; }  
     [Editable(false)]  
     public string ob_name { get; set; }  
      [Editable ( false )]  
     public string ob_code { get; set; }  
     public DateTime FromTag { get; set; }  
     public DateTime ToTag { get; set; }  
     public string FromDay { get; set; }  
     public string ToDay { get; set; }  
   }  
 }  

in your controller for read



  public ActionResult FilterMenuCustomization_Read ( [DataSourceRequest] DataSourceRequest request )  
     {  
       return Json ( GetAllLocation ( ) . ToDataSourceResult ( request ) );  
     }  
     private static IEnumerable<Limitation> GetAllLocation ( )  
     {  
       FEWOEntities db = new FEWOEntities ( );  
       var t_institution = from p in db . einschrank  
        select p;  
       List<Limitation> limitationListObj = new List<Limitation> ( );  
       foreach ( var p in t_institution )  
       {  
         Limitation student = new Limitation ( );  
         student . Id = p . Id;  
         student . ob_guid = p . ob_guid;  
         student . ob_name = p .objects. ob_name;  
         student . ob_code = p .objects. ob_code;  
         student . von = p . von;  
         student . bis = p . bis;  
         student . FromDay =p.FromDay;  
         student . ToDay = p.ToDay;  
         student . einschrank = p . einschrank1;  
         limitationListObj . Add ( student );  
       }  
       // return View ( viewDataInstitutions . ToList ( ) );  
       return limitationListObj;  
     }  


In your index view:

 @model IEnumerable<FEWO.ViewModel.Limitation>  
 @{  
   ViewBag.Title = "Bearbeiten des Mieterstatus";  
 }  
 <h3> einschrankungen</h3>  
 <p>  
   @Html.ActionLink("zusatzleitungen neu", "Create")  
 </p>  
 <script type="text/javascript">  
   function error_handler(e) {  
     if (e.errors) {  
       var message = "Errors:\n";  
       $.each(e.errors, function (key, value) {  
         if ('errors' in value) {  
           $.each(value.errors, function () {  
             message += this + "\n";  
           });  
         }  
       });  
       alert(message);  
     }  
   }  
   function nameFilter(element) {  
     element.kendoAutoComplete({  
       dataSource: {  
         transport: {  
           read: "@Url.Action("FilterMenuCustomization_Names")"  
         }  
       },  
       optionLabel: "--Select Value--"  
     });  
 }  
 function bookingNumber(element) {  
   element.kendoAutoComplete({  
     dataSource: {  
       transport: {  
         read: "@Url.Action("FilterMenuCustomization_BookingNumber")"  
       }  
     }  
   });  
 }  
 function region(element) {  
   element.kendoAutoComplete({  
     dataSource: {  
       transport: {  
         read: "@Url.Action("FilterMenuCustomization_Region")"  
       }  
     }  
   });  
 }  
   function FromDayFilter(element) {  
     element.kendoAutoComplete({  
       dataSource: {  
         transport: {  
           read: "@Url.Action("FilterMenuCustomization_FromDayFilter")"  
       }  
     }  
   });  
 }  
 </script>  
 @(Html.Kendo().Grid(Model)    
   .Name("Grid")  
   .Columns(columns => {  
     columns . Bound ( e => e . Id ) . Hidden ( );  
     columns . Bound ( e => e . ob_guid ) . Hidden ( );  
     columns . Bound ( e => e . ob_name ).Title("Objekt")  
           . Filterable ( filterable => filterable . UI ( "nameFilter" ) )  
         . Width ( 200 );  
     columns . Bound ( e => e . ob_code ) . Title ( "Code" );  
     columns . Bound ( e => e . von ).Title("Von");  
     columns . Bound ( e => e . FromDay ) . Title ( "Von Tag" ) . Filterable ( filterable => filterable . UI ( "FromDayFilter" ) )  
         . Width ( 200 );  
     columns . Bound ( e => e . bis ).Title("Bis");  
     columns . Bound ( e => e . ToDay ).Title("Bis tag");  
     columns . Bound ( e => e . einschrank ).Title("Einschrankung");  
         columns.Command(command => { command.Edit(); command.Destroy(); }).Width(172);    
   })  
    .Filterable(filterable => filterable  
     .Extra(false)  
     .Operators(operators => operators  
       .ForString(str => str.Clear()  
         .StartsWith("Starts with")  
         .IsEqualTo("Is equal to")  
         .IsNotEqualTo("Is not equal to")  
       ))  
     )    
   .Editable(editable => editable.Mode(GridEditMode.InLine))  
   .Pageable()  
   .Sortable()  
   .Scrollable()  
    .ColumnMenu()  
    .Selectable()  
     .Groupable()  
      .DataSource(dataSource => dataSource      
     .Ajax().PageSize(20)  
     .Events(events => events.Error("error_handler"))  
     .Model(model => model.Id(p => p.Id))  
     .Read(read => read.Action("FilterMenuCustomization_Read", "Limitations"))  
     .Update(update => update.Action("EditingInline_Update", "Limitations"))  
     .Destroy(update => update.Action("EditingInline_Destroy", "Limitations"))  
    )   
     )   

Wednesday, May 8, 2013

kendo ui web selected combobox value set in textbox



Here i am using razor view

 <div class="editor-label">  
       @Html.LabelFor(model => model.ob_guid,"Im Objekt")  
     </div>  
     <div class="editor-field">  
       @(Html.Kendo().ComboBoxFor(model=>model.ob_guid)  
        .Name("categories")  
        .HtmlAttributes(new { style = "width:300px",id="categories" })  
        .Placeholder("Select category...")  
        .DataTextField("CategoryName")  
        .DataValueField("CategoryId")  
        .Filter(FilterType.Contains)  
        .DataSource(source =>  
        {  
          source.Read(read =>  
          {  
            read . Action ( "GetCascadeCategories" , "Limitations" );  
          });  
        })  
     )  
       </div>  
      <div class="editor-label">  
       @Html.LabelFor(model => model.von,"Code")  
     </div>  
     <div class="editor-field">  
       <input type="text" name="target" id="target" />  
     </div>  
     
<script>  
    $(document).ready(function () {  
      $("#categories").change(function () {  
        var url = '@Url.Content("~/")' + "Limitations/ThanaByDistrict_SelectedState";  
        var ddlsource = "#categories";  
        var ddltarget = "#target";  
        $.getJSON(url, { Sel_StateName: $(ddlsource).val() }, function (data) {  
          $(ddltarget).empty();  
          $(ddltarget).val(data);  
        });  
      });  
    });  
    </script>  


In my controller

  // Get object Combox vale  
     public JsonResult GetCascadeCategories ( )  
     {  
       return Json ( db . objects . Select ( c => new { CategoryId = c . ob_guid , CategoryName = c . ob_name } ) , JsonRequestBehavior . AllowGet );  
     }  
            // Get selected combox value  
     public JsonResult ThanaByDistrict_SelectedState ( Guid Sel_StateName )  
     {  
       JsonResult result = new JsonResult ( );  
       objects temp=db . objects . Single ( m => m . ob_guid == Sel_StateName );  
       result . Data = temp.ob_code;  
       result . JsonRequestBehavior = JsonRequestBehavior . AllowGet;  
       return result;  
     }  

Monday, April 29, 2013

html5 print page

HTML print


Just use the code in your page.

 <input type="button" onClick="window.print()" value="Print" name="Print"  />  

Wednesday, April 24, 2013

how to import .csv file into sql server using c#

I am using the ASP.NET MVC. here is the code that might help you that how to you convert the CSV file in List and after that you will able to save the List data in to SQL.


     [HttpPost]  
     public ActionResult Create(t_NextDevAttendence t_nextdevattendence, IEnumerable<HttpPostedFileBase> files)  
     {  
       // Read the CSV file name & file path  
                // I am usisg here Kendo UI Uploader  
                string path = "";  
       string filenamee = "";  
       if (files != null)  
       {  
         foreach (var file in files)  
         {  
           var fileName = Path.GetFileName(file.FileName);  
           path = Path.GetFullPath(file.FileName);  
           filenamee = fileName;  
         }  
                     // Read the CSV file data  
         StreamReader sr = new StreamReader(path);  
         string line = sr.ReadLine();  
         string[] value = line.Split(',');  
         DataTable dt = new DataTable();  
         DataRow row;  
         foreach (string dc in value)  
         {  
           dt.Columns.Add(new DataColumn(dc));  
         }  
         while (!sr.EndOfStream)  
         {  
           value = sr.ReadLine().Split(',');  
           if (value.Length == dt.Columns.Count)  
           {  
             row = dt.NewRow();  
             row.ItemArray = value;  
             dt.Rows.Add(row);  
           }  
         }  
         // Insert CSV data in List  
         List<EmpAttendence> employeeList = new List<EmpAttendence>();  
         var myEnumerable = dt.AsEnumerable();  
         foreach (var item in myEnumerable)  
         {  
                     // set the CSV file column with my class  
                     // here it is Important that all field should be string when your inset in DB  
           EmpAttendence emp = new EmpAttendence();  
           emp.EmployeeId = item.Field<String>("User ID");  
           emp.EntryDate = item.Field<String>("Date");  
           emp.EntryTime = item.Field<String>("Time");  
           emp.fileName = filenamee;  
           employeeList.Add(emp);  
         }  
         // Insert in database from List  
         foreach (var item in employeeList)  
         {  
                     // table name  
           t_NextDevAttendence t_next = new t_NextDevAttendence();  
           t_next.EmployeeCode = item.EmployeeId;  
           t_next.EntryDate = item.EntryDate;  
           t_next.EntryTime = item.EntryTime;  
           t_next.CSVFileName = item.fileName;  
           db.t_NextDevAttendence.AddObject(t_next);  
         }  
         db.SaveChanges();  
         return RedirectToAction("Index");  
       }  
       return View(t_nextdevattendence);  
     }  

Sunday, March 24, 2013

C# remove item from ListObject



  private void OnDeleteItemCommand(BO.DC_RequisitionItem reqItem)  
     {  
         if (reqItem.id != 0)  
           {  
             var objReqItem = ViewData.Requisition.DC_RequisitionItemList.SingleOrDefault(m => m.id == reqItem.id);  
             if (objReqItem != null)  
             {  
               //Get deleted item by item id  
               var itemList = new ObservableCollection<BO.DC_RequisitionItem>();  
               foreach (var mx in ViewData.Requisition.DC_RequisitionItemList.Where(mx => mx.ReqRefNo == reqItem.id))  
               {  
                 itemList.Add(mx);  
               }  
               if (itemList.Any())  
               {  
                 foreach (var m in itemList)  
                 {  
                   ViewData.Requisition.DC_RequisitionItemList.Remove(m);  
                   var da = ViewData.Requisition.DC_RequisitionItemList.FirstOrDefault( mx =>m.ReqRefNo == objReqItem.id);  
                   if (da != null)  
                     ViewData.Requisition.DC_RequisitionItemList.Remove(da);  
                 }  
               }  
               //delete from requisition item  
               ViewData.Requisition.DC_RequisitionItemList.Remove(objReqItem);  
             }  
           }  
     }  

Monday, February 4, 2013

Directory Listing -- / in silverlight application


In your silverlight application if can see the error.


It may also arise after get latest from the source safe control.

No need to worry just set up as start up page of your web ASPX file.

Thursday, January 24, 2013

Silverlight assembly rename

1. Rename your Silverlight application as you want to give the assembly name of your application.




2. Right click on the project -> properties -> Silverlight  rename the same as you give first on the red marking only.





3. Click on assembly also rename here only marking




4. Buid the project. if you run it you will get error. becoz the aspx file now running the previous xap file.
so you must also have to rename as your newly assembly file/xap file in the aspx file as following figure.



Now build & run you application.

Tuesday, January 22, 2013

C# Linq Sum from a listObject

we can easily find out the sum from a list of collection. if the list is used in data grid or any other control as a data source we can easily find out the sum of any item field from the list using LINQ.

  var totalQty = ViewData.Requisition.DC_RequisitionItemList.Sum(item => item.ItemTotalValue);  
  ViewData.TotalQty = totalQty;  


Thanks.

Thursday, January 17, 2013

Add service after Migrating a Silverlight application in VS-2012




After migrating a Silverlight application in VS-2012, our existing service is not exposed in VS-2012.
Or if we create a new Silverlight application in VS-2012 and want to use the existing service in new application then our existing service will not exposed in VS-2012.
We can use existing service in VS-2012 Silverlight application by following the steps.


1.     1.  We have to open the application in VS-2010
 



 



1.      2. If you are using n tier project in your then many other project will not be show (incompatible). But this is not a problem. You just clean the Silverlight client application.







1.    3.  Expand the client project right click on Service References . Here it is important that if are using source control & if you have already ServiceReferences.ClientConfig file. Then it should also be check out & check that which service you are going to add is that already exist. If exist delete the service from Client & also from ServiceReferences.ClientConfig.











1.        4.In the address bar enter your service path which you want to use. Here my path is
Then Click on Go.  It will find your existing service. Give a name of your service; I am giving my service name AdminService. Then Click ok.





5  .  You will see that your service is added in your application.





     6      Select your client project and click show all in solution explorer. Now expand your service.     Expand the Reference.svcmap and check that did you can see your service method…? If not then 7




7 Right click on your service and click Configure Service References 





8 In address bar take the mouse cursor and press Enter. You will see you all service option. Then click ok.





9. Now again right click on your service and click Update Service References  . If you are using source safe control then just check in all and close the application from VS-2010.




10. Finally open the solution in VS-2012 and declare your service where you want to use. 






Hope now you can resolve your service problem.









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...