Tuesday, June 24, 2014

ASP.NET MVC Generate Crystal report to pdf

See the code sample:

   public ActionResult GenerateReport(CustomerPackageReportViewModel CustomerPackageReportViewModel)  
     {  
       List<CustomerPackageDetailsReportViewModel> _customerList = (List<CustomerPackageDetailsReportViewModel>)Session["CustomerPackageInfo"];  
       DataTable tableObj = new DataTable();  
       if (_customerList!=null)  
       {  
         tableObj = Converter.ToDataTable(_customerList);  
       }  
       else  
       {  
         tableObj = Converter.ToDataTable(ArchitectureList);  
       }  
         ReportDocument reportDoc = new ReportDocument();  
         string rptPath = "";  
         rptPath = Server.MapPath("~/Reports/Billing/Crystal/rptCustomerPackage.rpt");  
         reportDoc.Load(rptPath);  
         reportDoc.SetDataSource(tableObj);  
         Stream reportStream = this.ConvertReportToPDF(reportDoc);  
         return new FileStreamResult(reportStream, "application/pdf");  
     }  
  [NonAction]  
     public Stream ConvertReportToPDF(ReportDocument DocReport)  
     {  
       if (DocReport == null)  
       {  
         return null;  
       }  
       return DocReport.ExportToStream(ExportFormatType.PortableDocFormat);  
     }            


asp.net mvc generate rdlc/Excel to pdf report

You can follow the code:


  public ActionResult GenerateReport(CustomerPackageReportViewModel CustomerPackageReportViewModel)  
     {  
       List<CustomerPackageDetailsReportViewModel> _customerList = (List<CustomerPackageDetailsReportViewModel>)Session["CustomerPackageInfo"];  
       DataTable tableObj = new DataTable();  
       if (_customerList!=null)  
       {  
         tableObj = Converter.ToDataTable(_customerList);  
       }  
       else  
       {  
         tableObj = Converter.ToDataTable(ArchitectureList);  
       }  
       ReportDataSource rds = new ReportDataSource("dsCustomerPackageInfo", tableObj);  
       ReportViewer localReport = new ReportViewer();  
       localReport.ProcessingMode = ProcessingMode.Local;  
       localReport.LocalReport.ReportPath = Server.MapPath("~/Reports/Billing/rdlc/rptCustomerPackageInfo.rdlc");  
       localReport.LocalReport.DataSources.Add(rds); // Add datasource here  
       string reportType = "PDF";  // You can change type
       string mimeType;  
       string encoding;  
       string fileNameExtension;  
       //The DeviceInfo settings should be changed based on the reportType  
       //http://msdn2.microsoft.com/en-us/library/ms155397.aspx  
       string deviceInfo =  
       "<DeviceInfo>" +  
       " <OutputFormat>PDF</OutputFormat>" +  
       " <PageWidth>8.5in</PageWidth>" +  
       " <PageHeight>11in</PageHeight>" +  
       " <MarginTop>0.5in</MarginTop>" +  
       " <MarginLeft>1in</MarginLeft>" +  
       " <MarginRight>1in</MarginRight>" +  
       " <MarginBottom>0.5in</MarginBottom>" +  
       "</DeviceInfo>";  
       Warning[] warnings;  
       string[] streams;  
       byte[] renderedBytes;  
       renderedBytes = localReport.LocalReport.Render(  
         reportType,  
         null,  
         out mimeType,  
         out encoding,  
         out fileNameExtension,  
         out streams,  
         out warnings);  
       Response.Clear();  
       Response.ContentType = mimeType;  
       Response.AddHeader("content-disposition", "attachment; filename=CustomerPackageInformation." + fileNameExtension);  
       Response.BinaryWrite(renderedBytes);  
       Response.End();  
       Response.Flush();  
       return View(CustomerPackageReportViewModel);  
     }  


Monday, June 23, 2014

how to get distinct records from list in c#

Try this

 var DistinctItems = employees.GroupBy(x => x.EmpID).Select(y => y.First());  
 foreach(var item in DistinctItems)  
 {  
 //Add to other List  
 }  

Tuesday, June 17, 2014

on demand parameter in kendo grid load

On demand event

  // Bouquet combo change event  
   $('#BooketID').live('change', function () {  
     FillChannelGridByBouquetID();  
   });  

set parameter for grid load

 /* Load kendo grid by bouquetID*/  
   function FillChannelGridByBouquetID() {  
     var a = {};  
     a.BooketID = $("#BooketID option:selected").val();  
     var mAGrid = $('#CustomerPackageChannelKendoGrid').data('kendoGrid');  
     mAGrid.dataSource.read(a);  
     }  

Grid

 $("#CustomerPackageChannelKendoGrid").kendoGrid({  
     dataSource:  
     {  
       transport:  
       {  
         read: "ChannelReadByBooketID",  
       },  
       schema:  
       {  
         model:  
         {  
           fields:  
           {  
             SelectColumn: {type: "boolean"},  
             ChannelID: { type: "string" },  
             BooketName: { type: "string" },  
             ChannelName: { type: "string" },  
           }  
         }  
       },  
       pageSize: 20,  
       serverPaging: false,  
       serverFiltering: false,  
       serverSorting: false  
     },  
     height: 200,  
     filterable: true,  
     groupable: true,  
     sortable: true,  
     resizable: true,                                  
     pageable:  
     {  
       refresh: false,  
       pageSizes: [20, 40, 60, 80, 100]  
     },  
     columns:  
     [  
       {  
         field: "SelectColumn", title: " ", width: "5%",  
         template: "<input type='checkbox' #= SelectColumn ? checked='checked':'' # class='chkbx' />"  
       },  
       { field: "ChannelID", title: "ChannelID", hidden: true, filterable: false, sortable: false },  
       { field: "BooketName", title: "Bouquet Name", width: "30%" },  
       { field: "ChannelName", title: "Channel Name", width: "30%" },  
     ]  
   });  

Controller:

 public JsonResult ChannelReadByBooketID(CustomerPackageViewModel booketModel)  
     {  
       var models = GetAllChannelByBooketID(booketModel.BooketID.ToString());  
       return Json(models, JsonRequestBehavior.AllowGet);  
     }     
  private List<ChannelViewModel> GetAllChannelByBooketID(string pBooketID)  
     {  
       Guid gBooketID;  
       if (!Guid.TryParse(pBooketID, out gBooketID))  
       {  
         return null;  
       }  
       var ViewModels = _bCService.BillingUnit.ChannelRepository.Get(t => t.BooketID == gBooketID).ToList().Select(  
          md => new ChannelViewModel  
          {  
            ChannelID = md.ChannelID,  
            ChannelName = md.ChannelName,  
            BooketID = md.BooketID,  
            BooketName = md.DJBL_tblBooket.BooketName  
          }).OrderBy(o => o.BooketName);  
       return ViewModels.ToList();  
     }  


Thursday, June 12, 2014

C# Linq left join


See the sample:

  var customer = (from cus in _billingCommonservice.BillingUnit.CustomerRepository.GetAll()  
                          join man in _billingCommonservice.BillingUnit.FunctionRepository.ManagersCustomerValue()  
                          on cus.CustomerID equals man.CustomerID  
                          // start left join  
                          into a  
                          from b in a.DefaultIfEmpty(new DJBL_uspGetAllManagerCustomer_Result() )  
                          select new { cus.MobileNo1,b.ActiveStatus });  


kendo grid column bindable checkbox is not working


bind your grid check box column field

 { field: "SelectStatus", width: "10%",   
       template: "<input type='checkbox' #= SelectStatus ? checked='checked':'' # class='chkbx' />" }  


use the script:

  // Customer grid check event  
   $(function () {  
     $('#CustomerInfoKendoGrid').on('click', '.chkbx', function () {  
       var checked = $(this).is(':checked');  
       var grid = $('#CustomerInfoKendoGrid').data().kendoGrid;  
       var dataItem = grid.dataItem($(this).closest('tr'));  
       dataItem.set('SelectStatus', checked);  
     })  
   })  

Wednesday, June 11, 2014

format kendo grid date column field

I share the script of the grid, Hope it will help you.

  //start Kendo UI Grid  
   $("#CustomerAccountManageKendoGrid").kendoGrid({  
     dataSource: {  
       transport: {  
         read: "CustomerAccountManageRead"  
       },  
       schema: {  
         model: {  
           fields: {  
             CustomerAccountManageID: { type: "string" },  
             ManagerName: { type: "string" },  
             CustomerName: { type: "string" },  
             AssignDate: { type: "date" },  
             ActiveStatus: { type: "string" },  
             ActionLink: { type: "string" }  
           }  
         }  
       },  
       pageSize: 20,  
       serverPaging: false,  
       serverFiltering: false,  
       serverSorting: false  
     },  
     height: 600,  
     filterable: true,  
     groupable: true,  
     sortable: true,  
     resizable: true,  
     pageable: {  
       refresh: true,  
       pageSizes: [10, 20, 40, 60, 80, 100]  
     },  
     columns: [  
         { field: "CustomerAccountManageID", title: "CustomerAccountManageID", hidden: true, filterable: false, sortable: false },  
         { field: "ManagerName", title: "Manager Name", width: "45%" },  
         { field: "CustomerName", title: "Customer Name", width: "45%" },  
         { field: "AssignDate", title: "Assign Date", width: "45%", template: '#= AssignDate == null ? "" : kendo.toString(AssignDate,"dd/MM/yyyy") #' },  
         { field: "ActiveStatus", title: "Active Status", width: "45%" },  
         { field: "ActionLink", title: "Actions", width: "14%", filterable: false, sortable: false, template: "#= ActionLink #" }  
     ]  
   });  

Post Kendo Grid data with model data to Controller in MVC

Your save button:

 <button type="submit" class="btn btn-mini btn-primary" id="btnAddCustomerAccountManage" name="btnAddCustomerAccountManage" onclick="SaveUserProjectDetails()">  
           <i class="icon-save bigger-125"></i>Save</button>  

button click function

  function SaveUserProjectDetails()  
   {  
     var projectPermissionType = 1;  
     var postUrl;  
     var paramValue;  
     if (projectPermissionType == 1) {  
       var gridData = $("#CustomerInfoKendoGrid").data("kendoGrid").dataSource.data();  
       // set model data  
       for (var i = 0; i < gridData.length; i++) {  
         gridData[i].ManagerGenInfoID = $("#GEmployeeGenInfoID").val();  
         gridData[i].AssignDate = $("#AssignDate").val();  
       }  
       postUrl = '@Url.Content("~/Billing/CustomerAccountManage/GetDepartmentWiseCategoryList")';  
       paramValue = JSON.stringify({ CustomerInformationList: gridData });// you can also set model data using','  
     }  
     $.ajax({  
       url: postUrl,  
       type: 'POST',  
       dataType: 'json',  
       data: paramValue,  
       contentType: 'application/json; charset=utf-8',  
       success: function (result) {  
         console.log(result);  
       },  
       error: function (objAjaxRequest, strError) {  
         var respText = objAjaxRequest.responseText;  
         console.log(respText);  
       }  
     });  
   }  

Controller:

   public JsonResult GetDepartmentWiseCategoryList(CustomerAccountManageViewModel CustomerAccountManagemodel)  
     {  
         var strMessage = string.Empty;  
         // Get grid value  
         foreach (var item in CustomerAccountManagemodel.CustomerInformationList.Where(m => m.SelectStatus == true))  
         {  
           CustomerAccountManageViewModel viewModel = new CustomerAccountManageViewModel();  
           viewModel.CustomerInformationList = new List<CustomerEntryViewModel>();  
           viewModel.EmployeeList = new List<EmployeeViewModel>();  
           var userName = HttpContext.User.Identity.Name;  
           viewModel.IUser = userName;  
           viewModel.IDate = DateTime.Now;  
           viewModel.EDate = DateTime.Now;  
           viewModel.CustomerAccountManageID = Guid.NewGuid();  
           viewModel.CustomerID= item.CustomerID;  
           viewModel.GEmployeeGenInfoID=item.ManagerGenInfoID;  
           viewModel.AssignDate=item.AssignDate;  
           viewModel.ActiveStatus = true;  
           var entity = viewModel.ToEntity();  
           _billingCommonservice.BillingUnit.CustomerAccountManageRepository.Add(entity);  
           _billingCommonservice.BillingUnit.CustomerAccountManageRepository.SaveChanges();  
         }  
       return Json(new { strMessage = strMessage });  
     }  



Monday, June 9, 2014

html get checkbox value by id

try this:

 <input id="SelectedCB" type="checkbox" style = "z-index: 99999 !important; margin-top: 0px;" onchange="return getCustomer(this);" />  

   function getCustomer(ctrl) {  
       if ($('#SelectedCB').is(':checked'))  
       {  
         alert('checked');  
       }  
       else {  
         alert('Unchecked');  
       }  
       return false;  
     }  


Monday, June 2, 2014

asp.net mvc add & remove item from html table


To add & remove item in HTML table like this image you can like the this:

Model:

  public class StudentDetailsModels  
   {  
     public System.Guid? StudentId { get; set; }  
     public System.String StudentName { get; set; }  
     public System.String StudentFatherName { get; set; }  
     public System.String StudentAddress { get; set; }  
   }  


  public class StudentModels  
   {  
     [Key]  
     public System.Guid? StudentId { get; set; }  
     public System.String StudentName { get; set; }  
     public System.String StudentFatherName { get; set; }  
     public System.String StudentAddress { get; set; }  
     private List<StudentDetailsModels> _studentDetailsList = new List<StudentDetailsModels>();  
     public List<StudentDetailsModels> StudentDetailsList  
     {  
       get { return _studentDetailsList; }  
       set { _studentDetailsList = value; }  
     }  
   }  


View:

 @{  
   ViewBag.Title = "StudentInfo";  
   Layout = "~/Views/Shared/_Layout.cshtml";  
 }  
  <div id="divStudentDetails">  
   @Html.Partial("StudentInfoDetails")  
 </div>  

 @model ADD_REMOVE_ITEM_TABLE.Models.StudentModels  
 <script>  
   function Add() {  
     {  
       var targetDiv = '#divStudentDetails';  
       var url = "/Student/AddStudent";  
       var form = $('#frmStudentDetails');  
       var serializedForm = form.serialize();  
       $.post(url, serializedForm, function (result) { $(targetDiv).html(result); }, "html");  
       return false;  
     }  
   }  
   function Remove(ctrl) {  
     if (confirm('Pressing OK will delete this record. Do you want to continue?') == false) {  
       return false;  
     }  
     var row = $(ctrl).parent().parent().parent().children().index($(ctrl).parent().parent());  
 //    alert(row);  
     $("#refRowIndex").val(row);  
     var form = $("#frmStudentDetails");  
     var serializedForm = form.serialize();  
     var url = "/Student/RemoveStudentDetails";  
     $.post(url, serializedForm, function (result) {  
       $("#divStudentDetails").html(result);  
     }, "html");  
     return false;  
   }  
 </script>  
 <form id="frmStudentDetails">  
   <input type="hidden" id="refRowIndex" name="refRowIndex" />  
   <div class="form-horizontal">  
     <h4>Fermar Information</h4>  
     <hr />  
     <div class="form-group">  
       <table>  
         <tr>  
           <td>  
              @Html.LabelFor(model => model.StudentName, "Name" )  
           </td>  
           <td>  
              @Html.EditorFor(model => model.StudentName)  
              @Html.ValidationMessageFor(model => model.StudentName)  
           </td>  
           <td>  
              @Html.LabelFor(model => model.StudentFatherName, "Father" )  
           </td>  
           <td>  
             @Html.EditorFor(model => model.StudentFatherName)  
             @Html.ValidationMessageFor(model => model.StudentFatherName)  
           </td>  
             </tr>  
           <tr>  
           <td>  
              @Html.LabelFor(model => model.StudentAddress, "Address" )  
           </td>  
           <td>  
           @Html.EditorFor(model => model.StudentAddress)  
           @Html.ValidationMessageFor(model => model.StudentAddress)  
           </td>  
           <td>  
             <input type="submit" value="Add" class="btn btn-default" onclick="return Add();" />  
           </td>  
             </tr>  
       </table>  
       <table class="table">  
         <tr>  
           <th>  
            Name  
           </th>  
           <th>  
              Father Name  
           </th>  
           <th>  
             Address  
           </th>  
           <th>  
             Remove  
           </th>  
         </tr>  
         @for(int i=0;i<Model.StudentDetailsList.Count();i++)  
         {  
           <tr>  
             <td>  
               @Html.EditorFor(m => m.StudentDetailsList[i].StudentName)  
             </td>  
             <td>  
               @Html.EditorFor(m => m.StudentDetailsList[i].StudentFatherName)  
             </td>  
             <td>  
               @Html.EditorFor(m => m.StudentDetailsList[i].StudentAddress)  
             </td>  
             <td >  
               <input value="Remove" type="button" onclick="return Remove(this);" />  
             </td>  
           </tr>  
         }  
       </table>  
        <input value="Save" type="button" />  
     </div>  
     </div>  
   </form>  

Controller:

 public ActionResult StudentInfo()  
     {  
       StudentModels model = new StudentModels();  
       model.StudentDetailsList = new List<StudentDetailsModels>();  
       return View(model);  
     }  
     public ActionResult AddStudent(StudentModels model)  
     {  
       StudentDetailsModels studentObj = new StudentDetailsModels();  
       studentObj.StudentName = model.StudentName;  
       studentObj.StudentFatherName = model.StudentFatherName;  
       studentObj.StudentAddress = model.StudentAddress;  
         model.StudentDetailsList.Add(studentObj);  
         return PartialView("StudentInfoDetails", model);  
     }  
     public ActionResult RemoveStudentDetails(StudentModels model, FormCollection collection)  
     {  
       int rowIndex = int.Parse(collection.Get("refRowIndex"));  
       model.StudentDetailsList.RemoveAt(rowIndex - 1);  
       ModelState.Clear();  
       return PartialView("StudentInfoDetails", model);  
     }  


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