Search This Blog

Tuesday, August 22, 2017

Angular Js -Directive to allow only numbers, alphanumeric validate


Html- controls

<input type='text' ng-model='a' alpha-numeric/>
<input type='text' ng-model='b' numbers-only/>

Directive 
-----------------

app.directive('alphaNumeric', function () {
    return {
        require: 'ngModel',
        link: function (scope, element, attr, ngModelCtrl) {
            function fromUser(text) {
                var transformedInput = text.replace(/[^0-9a-zA-Z\-\s]/g, '');
                console.log(transformedInput);
                if (transformedInput !== text) {
                    ngModelCtrl.$setViewValue(transformedInput);
                    ngModelCtrl.$render();
                }
                return transformedInput; // or return Number(transformedInput)
            }
            ngModelCtrl.$parsers.push(fromUser);
        }
    };
});

-- ------------------------------------
app.directive('numbersOnly', function () {
    return {
        require: 'ngModel',
        link: function (scope, element, attr, ngModelCtrl) {
            function fromUser(text) {
                if (text) {
                    var transformedInput = text.replace(/[^0-9]/g, '');

                    if (transformedInput !== text) {
                        ngModelCtrl.$setViewValue(transformedInput);
                        ngModelCtrl.$render();
                    }
                    return transformedInput;
                }
                return undefined;
            }
            ngModelCtrl.$parsers.push(fromUser);
        }
    };
});

Wednesday, August 2, 2017

One List to Another List Insert multiple item with Folder Sharepoint 2013

Step 1: Add Script Editor in your page
Step 2: Change ListName ,Site Name
Step 3: Paste Below code

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>One List to Another List Inser</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <script type="text/javascript">

        //We need to run our function only after sp.js file loads
        ExecuteOrDelayUntilScriptLoaded(ViewItem, "sp.js");
        function ViewItem() {
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            var list = web.get_lists().getByTitle('testList');

            //It will fetch all the items from the list
            var myquery = new SP.CamlQuery.createAllItemsQuery();
            myquery.set_viewXml("<View><Query><OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy></Query><RowLimit>5</RowLimit></View>");
            myItems = list.getItems(myquery);
            context.load(myItems);
            //If the items load correctly then success function will be called
            context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
        }
        var newObj = { data: [] };
        function success() {
            var ListEnumerator = this.myItems.getEnumerator();
            while (ListEnumerator.moveNext()) {
                //Will get the current row from the SP List
                var currentItem = ListEnumerator.get_current();
                newObj.data.push({
                    "ID": currentItem.get_item('ID'),
                    "Title": currentItem.get_item('Title')
                });
            }         
        }

        function failed(sender, args) {
            alert("failed. Message:" + args.get_message());
        }
        function createListItem() {

            var contextz = new SP.ClientContext.get_current();
            var web = contextz.get_web();
            contextz.load(web);
            var oList = web.get_lists().getByTitle('testList2');
            contextz.load(oList);        
            var itemCreateInfo = new SP.ListItemCreationInformation();
            // need to specify full path after site domain , ex:         
            itemCreateInfo.set_folderUrl('/sites/test/DGNS/Lists/testList2/testFolder');
            var newItem = null;
            $.each(newObj.data, function (key, item) {
                newItem =  oList.addItem(itemCreateInfo);             
                newItem.set_item('Title', item.Title);
                //set values to other columns of the list here
                newItem.update();
            });
            contextz.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
        }
        function onQuerySucceeded() {

        }
        function onQueryFailed(sender, args) {
            alert("failed. Message:" + args.get_message());
        }


    </script>
</head>
<body>
    <div class="ui-widget">      
        <input id="Submit1" type="submit" onclick="createListItem();" value="Submit Item in Folder" />
    </div>
</body>

</html>

Wednesday, July 19, 2017

Unity And seriLogger Example C#


using Microsoft.Practices.Unity;
using Serilog;
using Serilog.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace UnityAndLoggerExample
{

    /// <summary>
    /// https://csbubblog.wordpress.com/2013/06/22/unity-registration/
    /// </summary>
    class Program
    {
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                .MinimumLevel.Verbose()
                   .WriteTo.Logger(l => l
                        .MinimumLevel.Verbose()
                         .WriteTo.Logger(l2 => l2
                             .WriteTo.Logger(l3 => l3
                             .Filter.ByIncludingOnly(Matching.FromSource<Product>())
                             .MinimumLevel.Verbose()
                            .WriteTo.RollingFile(@"D:\Product-{Date}.txt"))
                           )
                        .WriteTo.Logger(l2 => l2
                           .WriteTo.Logger(l3 => l3
                           .Filter.ByIncludingOnly(Matching.FromSource<Product1>())
                           .MinimumLevel.Verbose()
                           .WriteTo.RollingFile(@"D:\Product1-{Date}.txt"))
                        )
                        .WriteTo.Logger(l2 => l2
                           .WriteTo.Logger(l3 => l3
                           .Filter.ByIncludingOnly(Matching.FromSource<class1>())
                           .MinimumLevel.Verbose()
                           .WriteTo.RollingFile(@"D:\class1-{Date}.txt"))
                        )
                          .WriteTo.Logger(l2 => l2
                           .WriteTo.Logger(l3 => l3
                           .Filter.ByIncludingOnly(Matching.FromSource<class2>())
                           .MinimumLevel.Verbose()
                           .WriteTo.RollingFile(@"D:\class2-{Date}.txt"))
                        )
                 .WriteTo.RollingFile(@"D:\Log-{Date}.txt"))
                .CreateLogger();

            UnityContainer IU = new UnityContainer();
            IU.RegisterType<class1>();
            IU.RegisterType<class2>();
            /* Register a type with specific members to be injected. */
            IU.RegisterType<IProduct, Product1>();
            IU.RegisterInstance<ILogger>(Log.Logger);

            IU.Resolve<Product>().Insertdata();
            IU.Resolve<Product1>().Insertdata();
            IU.Resolve<class1>().Insert1();
            IU.Resolve<class2>().Insert2();
        }
        public class class1
        {
            private IProduct _objpro;
            private ILogger _logger;

            public class1(IProduct objpro, ILogger logger)
            {
                _objpro = objpro;
                _logger = logger.ForContext<class1>();
            }

            public void Insert1()
            {
                // Methods starts
                _objpro.Insertdata();
                _logger.Warning("class1 warning log");
                // Method Ends
            }
        }
        public class class2
        {
            private IProduct _objpro;
            private ILogger _logger;

            public class2(IProduct objpro, ILogger logger)
            {
                _objpro = objpro;
                _logger = logger.ForContext<class2>();
            }

            public void Insert2()
            {
                _objpro.Insertdata();
                _logger.Warning("class2 warning log");
            }

        }
        public interface IProduct
        {
            string Insertdata();
        }
        public class Product : IProduct
        {
            ILogger _logger;
            public Product(ILogger logger)
            {
                _logger = logger.ForContext<Product>();
            }
            public string Insertdata()
            {
                _logger.Warning("Product warning log");

                return "true";
            }
        }

        public class Product1 : IProduct
        {
            ILogger _logger;
            public Product1(ILogger logger)
            {
                _logger = logger;
                _logger = logger.ForContext<Product1>();
            }
            public string Insertdata()
            {
                _logger.Warning("Product1 warning log");
                return "true";
            }
        }


    }
}