Friday, 25 November 2016

On Custom button click how to redirect/ call other action method/Page in kendo

<Script>

    function showDetails(e)
    {
        var index = 0;
        var grid = $("#ActualRevenueSummary").data("kendoGrid");
        var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
        var value = $('#ProjectId').val();
        var text = $("#ProjectId").data("kendoDropDownList").text();
        var Month = dataItem.MonthNumber;
        var MonthName = dataItem.MonthName;
        var projectname = dataItem.projectname;
        var NestId = $(this).data('id');
        var url = "/ActualRevenueDetails/GetRevenueDetails?Id=" + value + "&&month=" + Month + "&&MonthName=" + MonthName + "&&projectName=" + text + "";
        window.location.href = url;
    }

</script>

----------------------------------------------------------------------------------

  @(Html.Kendo().Grid<SPAN.OMS.ViewModel.ActualRevenueViewModel>()
                                .Name("ActualRevenueSummary")
                                 .Columns(columns =>
                                 {
                                     columns.Bound(p => p.RevenueSummaryId).Visible(false);
                                     columns.Bound(p => p.ProjectId).Visible(false);
                                     columns.Bound(p => p.Year).Visible(false);
                                     columns.Bound(p => p.MonthNumber).Visible(false);
                                     columns.Bound(p => p.MonthName).Title("Month");
                                     columns.Bound(p => p.ResourceCount).Title("Total no. of Resrc").Format("{0:n2}");
                                     columns.Bound(p => p.TotalBilledRsrcCount).Title("Total no. of Billed Resrc").Format("{0:n2}");
                                     columns.Bound(p => p.OffshoreAmount).Format("{0:c2}").Title("Offshore Revenue");
                                     columns.Bound(p => p.OnsiteAmount).Format("{0:c2}").Title("Onsite Revenue");
                                     columns.Bound(p => p.Travel).Title("Travel Revenue").Format("{0:c2}");
                                     columns.Bound(p => p.Hardware).Title("H/W Revenue").Format("{0:c2}");
                                     columns.Bound(p => p.Software).Title("S/w Revenue").Format("{0:c2}");
                                     columns.Bound(p => p.Misc).Title("Misc Revenue").Format("{0:c2}");
                                     columns.Bound(p => p.ComissionAmount).Title("Commission").Format("{0:c2}").ClientFooterTemplate("Grand Total:");
                                     columns.Bound(p => p.Total).Title("Revenue Total").ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                     columns.Command(command => { command.Edit(); });
                                     columns.Command(command => command.Custom("ViewDetails").Click("showDetails").Text("<i class='fa fa-pencil-square-o fa-lg' ></i>"));
                                 }
                                )
                                    .Resizable(resizing => resizing.Columns(true))
                                    .Events(events => events.DataBound("DataBound"))
                                    .Editable(editabe => editabe.Mode(Kendo.Mvc.UI.GridEditMode.InLine))
                                    .Events(events => events.Edit("edit"))
                                    .DataSource(dataSource => dataSource
                                    .Ajax()
                                    .Events(events => events.Error("error_handler"))
                                    .Events(events => events.Change("isEditable").Sync("sync_handler"))
                                    .Aggregates(aggregates =>
                                    {
                                        aggregates.Add(p => p.Total).Sum();
                                    })
                                    .Model(model =>
                                    {
                                        model.Id(p => p.RevenueSummaryId);
                                        model.Id(p => p.ProjectId);
                                        model.Id(p => p.Year);
                                        model.Id(p => p.MonthNumber);
                                        model.Field(p => p.MonthName).Editable(false);
                                        model.Field(p => p.ResourceCount).Editable(false);
                                        model.Field(p => p.TotalBilledRsrcCount).Editable(false);
                                        model.Field(p => p.OffshoreAmount).Editable(false);
                                        model.Field(p => p.OnsiteAmount).Editable(false);
                                        model.Field(p => p.Travel).Editable(false);
                                        model.Field(p => p.Hardware).Editable(false);
                                        model.Field(p => p.Software).Editable(false);
                                        model.Field(p => p.Misc).Editable(false);
                                        model.Field(p => p.ComissionAmount).Editable(true);
                                        model.Field(p => p.Total).Editable(true);
                                    })
                       .Read(read => read.Action("GetActualRevenueSummary", "ActualRevenue").Data("ItemFormValues"))
               .Update(update => update.Action("RevenueSummaryUpdate", "ActualRevenue").Data("ItemFormValues"))
                                             )
            )

Changing the Background Color of the kendo grid cell

<style>
    tr.condtn1 td:last-child {
        background-color: #ff3232;
        font-weight: bolder !important;
    }

    tr.condtn2 td:last-child {
        background-color: green;
        font-weight: bolder !important;
    }

    tr.condtn3 td:last-child {
        background-color: yellow;
        font-weight: bolder !important;
    }

    tr.condtn4 td:last-child {
        background-color: transparent;
        font-weight: bolder !important;
    }
</style>


<script>

  function DataBound(e)
    {
        var columns = e.sender.columns;
        var columnIndex = this.wrapper.find(".k-grid-header [data-field=" + "MarginValue" + "]").index();

        // iterate the data items and apply row styles where necessary
        var dataItems = e.sender.dataSource.view();
        for (var j = 0; j < dataItems.length; j++)
        {
            var ForecastedValue = 0;
            var actualRevenue = 0;
            var budgetedValue = 0;
            var marginValue = 0;
            ForecastedValue = dataItems[j].get("ForecastedValue");
            actualRevenue = dataItems[j].get("ActualRevenue");
            budgetedValue = dataItems[j].get("BudgetedValue");
            var row = e.sender.tbody.find("[data-uid='" + dataItems[j].uid + "']");

            if (ForecastedValue > actualRevenue) {
                row.addClass("condtn1"); // refer css style above
            }
            else if (ForecastedValue < actualRevenue) {
                row.addClass("condtn2"); // refer css style above
            }
            else if (budgetedValue < actualRevenue) {
                row.addClass("condtn3"); // refer css style above
            }
            else {
                row.addClass("condtn3"); // refer css style above
            }

        }

    }

</script>


--------------------------------------------------------------------------------------------------------

<div class="director-dashboardProject">
                                        @(Html.Kendo().Grid<SPAN.OMS.ViewModel.SummaryView>()
                                            .Name("UsaProjectGrid")
                                             .Columns(columns =>
                                                {
                                                    columns.Bound(p => p.ProjectName).Format("{0:n2}").ClientFooterTemplate("Grand Total:").Width(122);
                                                    columns.Bound(p => p.BudgetedValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ForecastedValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ActualRevenue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ActualCost).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.CommissionValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.MarginValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                })
                                                .Events(events => events.DataBound("DataBound")) // On data bound we need to check data values and need to do the required changes.
                                                .DataSource(dataSource => dataSource
                                                .Ajax()
                                                .Events(events => events.Error("error_handler"))
                                                    .Aggregates(aggregates =>
                                                {
                                                    aggregates.Add(p => p.BudgetedValue).Sum();
                                                    aggregates.Add(p => p.ForecastedValue).Sum();
                                                    aggregates.Add(p => p.ActualRevenue).Sum();
                                                    aggregates.Add(p => p.ActualCost).Sum();
                                                    aggregates.Add(p => p.CommissionValue).Sum();
                                                    aggregates.Add(p => p.MarginValue).Sum();
                                                })
                                                .Read(read => read.Action("GetUsaProjectSummary", "SummaryView").Data("ItemFormValues"))
                                                )
                                        )
                                    </div>

Binding Kendo grid in MVC Architecture with aggregate for Columns

IN Design Page(View)

       <div class="director-dashboardProject">
                                        @(Html.Kendo().Grid<SPAN.OMS.ViewModel.SummaryView>() // Your View Model
                                            .Name("UsaProjectGrid")
                                             .Columns(columns =>
                                                {
                                                    columns.Bound(p => p.ProjectName).Format("{0:n2}").ClientFooterTemplate("Grand Total:").Width(122);
                                                    columns.Bound(p => p.BudgetedValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ForecastedValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ActualRevenue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.ActualCost).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.CommissionValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                    columns.Bound(p => p.MarginValue).Format("{0:n2}").Width(122).ClientFooterTemplate("#= kendo.format('{0:c}', sum) #").Format("{0:c2}");
                                                })
                                                .Events(events => events.DataBound("DataBound"))
                                                .DataSource(dataSource => dataSource
                                                .Ajax()
                                                .Events(events => events.Error("error_handler"))
                                                    .Aggregates(aggregates =>
                                                {   /// Calculating sum for all the rows
                                                    aggregates.Add(p => p.BudgetedValue).Sum();
                                                    aggregates.Add(p => p.ForecastedValue).Sum();
                                                    aggregates.Add(p => p.ActualRevenue).Sum();
                                                    aggregates.Add(p => p.ActualCost).Sum();
                                                    aggregates.Add(p => p.CommissionValue).Sum();
                                                    aggregates.Add(p => p.MarginValue).Sum();
                                                })
                                                .Read(read => read.Action("GetUsaProjectSummary", "SummaryView").Data("ItemFormValues")) // Action name and Controller Name
                                                )
                                        )
                                    </div>
     


In Controller:


 public ActionResult GetUsaProjectSummary(int month,[DataSourceRequest]DataSourceRequest request)
        {
            int year = Convert.ToInt32( System.DateTime.Now.Year);
            List<SummaryView> projectdetail = new List<SummaryView>();
            projectdetail = ManagementService.Getdata(month, year); // Getting Data from your service class
            IQueryable<SummaryView> res = projectdetail.AsQueryable<SummaryView>();
            DataSourceResult res1 = res.ToDataSourceResult(request);
            return Json(res1, JsonRequestBehavior.AllowGet);

        }



   

Monday, 26 September 2016

Lock Request time out period exceeded.

If the table or Stored procedures has locked by Sql server means Use the below Commands to release.


TO check Due to which operation its got blocked:
DBCC opentran()

To see in detail.
sp_who2 70
sp_lock 70

Kill That transaction
KILL 70

Monday, 13 October 2014

Downloading files from server folder in C# on link button clicked Event which is inside GridView

     


              
 protected void lnk_attach4_Click(object sender, EventArgs e)
    {
        try
        {
            LinkButton _lnk = (LinkButton)sender;
            GridViewRow _row = (GridViewRow)_lnk.NamingContainer;
            int _i = Convert.ToInt32(_row.RowIndex);
            int _reqID = Convert.ToInt32(gv_hrmrequest.DataKeys[_i][0].ToString());

            string _LogPath = ConfigurationManager.AppSettings["Docs"].ToString();
            string _filename1 = _LogPath + _reqID + "_4_" + _lnk.Text;

            if (_lnk.Text != string.Empty)
            {
                if (_lnk.Text.EndsWith(".txt"))
                {
                    Response.ContentType = "application/txt";
                }
                else if (_lnk.Text.EndsWith(".pdf"))
                {
                    Response.ContentType = "application/pdf";
                }
                else if (_lnk.Text.EndsWith(".docx"))
                {
                    Response.ContentType = "application/docx";
                }
                else
                {
                    Response.ContentType = "image/jpg";
                }

                string filePath = _lnk.Text;

                Response.AddHeader("Content-Disposition", "attachment;filename=\"" + filePath + "\"");
                Response.TransmitFile(_filename1);
                Response.End();
            }
        }
        catch (Exception ex)
        {

        }
        finally
        {

        }
    }

Monday, 4 August 2014

Select / Dis select all the check boxes inside the Grid view using java script.


// javascript block



function SelectAll() {
            var gv = document.getElementById('<%=gv_orderdetails.ClientID%>');

            if (gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked == true) {
                for (var i = 1 ; i < gv.rows.length; i++) {
                    gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked = true;
                }
            }
            else {
                for (var i = 1 ; i < gv.rows.length; i++) {
                    gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked = false;
                }
            }

        }

        function disselect()
        {
            var gv = document.getElementById('<%=gv_orderdetails.ClientID%>');

            var x = false;

            for (var i = 1 ; i < gv.rows.length-1; i++)
            {
                if (gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked == true)
                {
                    x = true;
                }
                if (gv.rows[i].cells[5].getElementsByTagName("INPUT")[0].checked == false)
                {
                    x = false;
                    break;
                }

            }

            if (!x)
            {
                gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked = false;
            }
            else
            {
                gv.rows[0].cells[5].getElementsByTagName("INPUT")[0].checked = true;
            }
        }




------------------------------------------------------------------

// In Design


             <asp:TemplateField HeaderStyle-Width="30px">
                    <HeaderTemplate>
                        <asp:CheckBox ID="chk_Headerselect" runat="server"                              onclick="Javascript:SelectAll();" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chk_select" runat="server"
  onclick="Javascript:disselect();"/>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Center" />
                    <HeaderStyle HorizontalAlign="Center" />
                </asp:TemplateField>






Sunday, 3 August 2014

Creating New Outlook mail Item Using C#


using Microsoft.Office.Interop.Outlook;
using OutlookApp = Microsoft.Office.Interop.Outlook.Application;

-----------------------------------------------------------------------------


               OutlookApp outlookApp1 = new OutlookApp();
                MailItem _mi =(MailItem) outlookApp1.CreateItem(OlItemType.olMailItem);
                _mi.Subject = "This is the subject";
                _mi.To = "someone@example.com";
                _mi.Body = "This is the message.";
                _mi.Attachments.Add(@"C:/Users/Manjunath.le/Downloads/Annexure.pdf");
                _mi.Display(false);


// This will open New Outlook mail Create Window.