Monday, 16 October 2017

PracticalTest.Controller

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;
using Microsoft.Office.Interop;


namespace WebApplication1.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        private IMS_AppEntities _context = new IMS_AppEntities();
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult Get_Users_List()
        {
            return Json(new { aaData = _context.GetUser() }, JsonRequestBehavior.AllowGet);
        }

        public JsonResult Get_Stone_List()
        {
            return Json(new { aaData = _context.MST_Stone.ToList() }, JsonRequestBehavior.AllowGet);
        }

        //public string Export_Excel_Data()
        //{
        //     Microsoft.Office.Interop.Excel.Application();
        //    Exce wb = new ExcelWorkbook();
        //    wb.Worksheets.Add("TEST EXCEL" + DateTime.Now.ToString());
        //    ExcelPackage p = new ExcelPackage();
        //    ExcelWorksheet ws = wb.Worksheets[1];
        //    ws = (ExcelWorksheet)wb.Worksheets.get_Item(1);
        //    ws.Name = "TEST EXCEL"; //Setting Sheet's name
        //    ws.Cells.Style.Font.Size = 11; //Default font size for whole sheet
        //    ws.Cells.Style.Font.Name = "Calibri"; //Default Font name for whole sheet
        //    ws.Cells[1, 1].Value = "STONE NO";
        //    wb.("your-file-name.xls");
        //    return "";
        //}
       
        private void Download_File()
        {
            var path = Request.QueryString["filepath"];
            var file = new FileInfo(path);
            Response.Clear();
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment; filename=\"" + file.Name + "\"");
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.TransmitFile(file.FullName);
            HttpContext.ApplicationInstance.CompleteRequest();
        }
    }
}

Practical.index

@{
    Layout = null;
}

<!DOCTYPE html>
<link href="~/Content/bootstrap-3.3.6-dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="~/Content/ui-grid-3.0.0-rc.14/ui-grid.css" rel="stylesheet" />
<script src="~/Content/angularjs/angular.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular-touch.js"></script>
<script src="~/Content/ui-grid-3.0.0-rc.14/ui-grid.js"></script>
<html ng-app="MYAPP">

<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <style>
        .spanGrid {
            border: 2px solid black;
            background-color: lightgray;
            height: 36px;
            width: 100%;
            text-align: center;
            line-height: 35px;
            font-weight: bolder;
        }

        .MyHeaderClass {
            background-color: skyblue;
        }
    </style>
</head>
<body ng-controller="MYCTRL">
    <div class="row">

        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <button class="btn btn-info" ng-click="ExportExcel()"><i class="glyphicon glyphicon-export"></i>&nbsp;EXPORT</button>
        </div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 spanGrid">Stone Details</div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
            <div ui-grid="gridOptionsUser" class="grid table table-striped" style="height: calc(100vh - 78px);"
                 ui-grid-pagination ui-grid-auto-resize ui-grid-grouping
                 ui-grid-edit ui-grid-cellnav ui-grid-move-columns ui-grid-exporter
                 ui-grid-pinning ui-grid-resize-columns ui-grid-validate />
        </div>
    </div>
</body>

</html>
<script>
    var app = angular.module("MYAPP", ['ngTouch','ui.grid', 'ui.grid.edit', 'ui.grid.autoResize', 'ui.grid.pagination', 'ui.grid.grouping', 'ui.grid.cellNav', 'ui.grid.moveColumns', 'ui.grid.exporter', 'ui.grid.pinning', 'ui.grid.resizeColumns', 'ui.grid.selection']);
    app.controller("MYCTRL", ['$scope', '$filter', '$timeout', '$http', '$interval', 'uiGridConstants', 'uiGridGroupingConstants', '$q',
        function ($scope, $filter, $timeout, $http, $q, uiGridConstants, uiGridGroupingConstants, $interval, $window) {
            $scope.MYCTRL = {};
            $scope.Message = 'HIIII';
            $scope.gridOptionsUser = {};
            $scope.gridOptionsUser = {
                columnDefs: [
                    { field: 'stone_id', name: 'stone_id', displayName: 'stone_id', width: "*" },
                    { field: 'stone_no', name: 'stone_no', displayName: 'stone_no', width: "*" },
                    {
                        field: 'weightincarats', name: 'WT', displayName: 'WT', width: "*",
                        footerCellTemplate: '<div class="ui-grid-cell-contents">Total {{col.getAggregationValue()  }}</div>', aggregationType: uiGridConstants.aggregationTypes.sum
                    },
                    { field: 'liveraprate', name: 'liveraprate', displayName: 'liveraprate', width: "*" },
                    { field: 'rapamount', name: 'rapamount', displayName: 'rapamount', width: "*" },
                    { field: 'websitediscount', name: 'websitediscount', enableCellEdit: true, displayName: 'websitediscount', width: "*" },
                    { field: 'websiterate', name: 'websiterate', displayName: 'websiterate', width: "*" },
                    { field: 'websiteamount', name: 'websiteamount', displayName: 'websiteamount', width: "*" },
                    {
                        field: 'Gender', name: 'Gender', displayName: 'Gender', width: "*",
                        enablCellEdit: true,
                        editableCellTemplate: 'ui-grid/dropdownEditor',
                        editDropdownValueLabel: 'Gender',
                        editDropdownOptionsArray: [
                          { id: 1, Gender: 'male' },
                          { id: 2, Gender: 'female' }
                        ]
                    },
                    {
                        name: 'size', displayName: 'Clothes Size', width: '20%', editableCellTemplate: 'ui-grid/dropdownEditor',
                        cellFilter: 'mapSize', editDropdownValueLabel: 'size', editDropdownRowEntityOptionsArrayPath: 'sizeOptions'
                    }
                ]
            }

            $scope.maleSizeDropdownOptions = [
               { id: 1, size: 'SM' },
               { id: 2, size: 'M' },
               { id: 3, size: 'L' },
               { id: 4, size: 'XL' },
               { id: 5, size: 'XXL' }
            ];

            $scope.femaleSizeDropdownOptions = [
              { id: 6, size: '8' },
              { id: 7, size: '10' },
              { id: 8, size: '12' },
              { id: 9, size: '14' },
              { id: 10, size: '16' }
            ];

            $scope.gridOptionsUser.headerCellTemplate = '<div ng-style="{ height: col.headerRowHeight }" ng-repeat="col in renderedColumns" ng-class="col.colIndex()" class="MyHeaderClass" ng-header-cell></div>'
            $scope.gridOptionsUser.enableHorizontalScrollbar = 1;
            $scope.gridOptionsUser.enableVerticalScrollbar = 1;
            $scope.gridOptionsUser.enableSelectAll = false;
            $scope.gridOptionsUser.suppressScrollLag = true;
            $scope.gridOptionsUser.exporterMenuPdf = false;
            $scope.gridOptionsUser.enableGridMenu = false;
            $scope.gridOptionsUser.showColumnFooter = true;
            $scope.gridOptionsUser.enableSorting = true;
            $scope.gridOptionsUser.useExternalSorting = false;
            $scope.gridOptionsUser.enableFiltering = true;
            $scope.gridOptionsUser.useExternalFiltering = false;
            $scope.gridOptionsUser.enablePaginationControls = false;
            $scope.gridOptionsUser.enableCellEdit = false;
            $scope.gridOptionsUser.showGridFooter = false;
            $scope.gridOptionsUser.paginationPageSize = 500000,
            $scope.gridOptionsUser.rowHeight = 22;
            //$scope.gridOptionsUser.rowTemplate = rowTemplateOnDbclick();
            $scope.gridOptionsUser.onRegisterApi = function (gridApi) {
                $scope.gridOptionsUserApi = gridApi;
                gridApi.edit.on.afterCellEdit($scope, function (rowEntity, colDef, newValue, oldValue) {
                    //if (colDef.field == "websiterate") {
                    //    if ($scope.SalesOrderAN.RapDiscPer != undefined && $scope.SalesOrderAN.RapDiscPer != 0) {
                    //        rowEntity.OrderRate = oldValue;

                    //    }
                    //    else {
                    //        rowEntity.OrderRate = newValue == "" ? oldValue : newValue;
                    //    }
                    //    rowEntity.OrderDiscount = parseFloat(((parseFloat(rowEntity.OrderRate) - parseFloat(rowEntity.LiveRapaRate)) * 100) / parseFloat(rowEntity.LiveRapaRate)).toFixed(4);
                    //    rowEntity.FinalDiscount = rowEntity.OrderDiscount;
                    //    rowEntity.OrderAmount = parseFloat(parseFloat(rowEntity.OrderRate) * parseFloat(rowEntity.WT)).toFixed(4);
                    //}
                });

            };

            $scope.Fill_User_GRID = function () {
                debugger
                $http({
                    method: 'GET',
                    url: '@Url.Action("Get_Stone_List", "Home")',
                    dataType: 'json'
                }).then(function success(data) {
                    $scope.gridOptionsUser.data = data.data.aaData;
                });
            }
            $scope.Fill_User_GRID();

            $scope.FUNCTION_Check_ALL = function () {
                debugger
                alert($scope.MYCTRL.CheckAll);
            }

            $scope.ExportExcel = function () {
                $http({
                    method: 'GET',
                    url: '@Url.Action("Export_Excel_Data", "Home")',
                    dataType: 'json'
                }).then(function success(data) {
                    $scope.DownloadExcel("C:\\Users\\Akash\\Downloads\\MST_Stone.xlsx");
                });
            }
            $scope.DownloadExcel = function (path) {
                var url = '@Url.Action("Download_File", "Home")/?filepath=' + path;
                var hiddenIFrameID = 'hiddenDownloaderReportResult';
                var iframe = document.getElementById(hiddenIFrameID);
                if (iframe === null) {
                    iframe = document.createElement('iframe');
                    iframe.id = hiddenIFrameID;
                    iframe.style.display = 'none';
                    document.body.appendChild(iframe);
                }
                iframe.src = url;
            };

            @*$scope.DownloadExcel = function (path) {
                var url = '@Url.Action("Download_File", "Home")/?filepath=' + path;
                var hiddenIFrameID = 'hiddenDownloaderReportResult';
                var iframe = document.getElementById(hiddenIFrameID);
                if (iframe === null) {
                    iframe = document.createElement('iframe');
                    iframe.id = hiddenIFrameID;
                    iframe.style.display = 'none';
                    document.body.appendChild(iframe);
                }
                iframe.src = url;
            };*@
        }]);
</script>

Friday, 22 September 2017

Project Steup Of MVC And EDMX Step By Step

1>Add New MVC5 Empty Project Give It Name and Add and Build Project

2>Right Click On Solution Add New Project>Select ClASS Library
Give Its Name As Project Name.Model
Click Ok And Delete Created Default Class1.cs File

3>Same As Add Repository
Right Click On Solution
Add New Project>Select ClASS Library
Give Its Name As Project Name.Repository
Clcik Ok And Delete Created Default Class1.cs File

4>Build ModelProject,Repository Project, Project And Solution

5>Right click on repository project and add new item 
    Visual C# Items >Data >ADO.NET Entity Data Model
    Give Its Name As Model Project.edmx
    click add and select EF Designer from database
    click Next
    
    Click new Connection
    Change Datasource To Microsoft Sql Server and click ok
    give server name
    check use sql authentication radio button
    enter user name and password
    select database
    click test connection
    click ok if success
    select Yes, Include The sensitive data in the connection string and Click Next
select Entity Framework Version

Select Atleast One Table To Create Edmx Class
UnCheck First Check Box(Pluralize or singularize generated object names)
Click Finish

6>build 3 projects and solution
7> Right click on repository open folder 
8>Open With NotePad (MyDemo.Repository.csproject) file
9>remove <dependentupon> tag from <None Include="MyDemoModel.tt"> tag

10> Reload All Select
11>Move Repository .tt file into Model Project
12>and remove from repository .tt file
13>add reference in repository of model.dll
14>build 3 projects
15>Open Modle .tt file append const string inputfile = @"repository Name"(const string inputFile =  @"..\MyDemo.Repository\MyDemo.Model.edmx";)
16>build 3 projects getting error for using MyDemo.Model; namspace in MyDemo.Context.cs file(Right Click MyDemo.Context.tt --Propertiese(set Custom Tool NameSpace(MyDemo.Model))
17>add Two new folder in Repository And Give Name ServiceContract(For Repository Interfaces Add) And Services(For Interface Classes Add)








    private MyDemoEntities context;
        public MST_Party_Repository(MyDemoEntities  _context)
        {
            this.context = _context;
        }

        private bool disposed = false;

        protected virtual void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    context.Dispose();
                }
            }
            this.disposed = true;
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

SQL STUFF Function and Get common grid data with pagination, filteration, sorting by sp & functions

========================================================================= STUFF FUNCTION ===================================================...