Thursday, 2 April 2020

Calculate number of months between two dates using javascript




<script>

    var dtfrm ='10/01/2019';//////////dd/mm/yyyy
    var dtto = '31/03/2019';
    var d1 = dtfrm.split('/');
    var d2 = dtto.split('/');
    var frstdate = new Date(d1[2], (parseFloat(d1[1]) - 1).toFixed(0), d1[0]);
    var secdate = new Date(d2[2], (parseFloat(d2[1]) - 1).toFixed(0), d2[0]);
    if (frstdate > secdate) {
        var dtothr;
        dtothr = frstdate;
        frstdate = secdate;       
        secdate = dtothr;
    }
    var mnth = ((secdate.getFullYear() * 12 + secdate.getMonth()) - (frstdate.getFullYear() * 12 + frstdate.getMonth()));

  
    alert(mnth);
</script>



Result///

Friday, 6 March 2020

Delete read only condition files in c# or asp.net c# or windows services





public void Delete_file_ReadonlyCondition(string FilePath)
        {
         //// Set file permission to delete file
            FileAttributes attributes = File.GetAttributes(FilePath);
            if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
            {
                attributes &= ~FileAttributes.ReadOnly;
                File.SetAttributes(FilePath, attributes);
                File.Delete(FilePath);
            }
            else
            {
                FileInfo f = new FileInfo(FilePath);
                if (f.Exists)
                {
                    File.SetAttributes(FilePath, FileAttributes.Normal);
                    File.Delete(FilePath);
                }
            }
        }

Thursday, 5 March 2020

xcopy command - copy files from one folder to another using command in c# or windows services


  

/////////////////// Create file for the process execute


public void Create_BatFile_ForCopyFiles()
        {
            string mDrive = "C:",  //// Drive where want to create file
                SourcePath = "\\WindowService\\Service\\Test.txt", //// Source path DIR
                BatFileName = "Testbatch.bat",   ///// Batch file name 'you can create folder with this batch file
                DestinationPath = "E:\\Folder1\\Folder2\\CopyTest.txt";  //// Destination path DIR

            string ProgramPath = mDrive + "\\"+BatFileName;
            try
            {
                List<string> list = new List<string>
                    {
                        ///// command =>> From path =>> To Path
                        "xcopy "+SourcePath+" "+DestinationPath+@"\"   //// @"\" auto permission to copy the file to the given path
                      };
                File.WriteAllLines(mDrive + "\\" + BatFileName, list.ToArray());/// create batch file in C drive
            }
            catch (Exception ex)
            {
            }
            Execute_Process(ProgramPath); //// Execute batch file with process to create list of file inside the DIR
        }

/////////////////// Execute process copy file 


        public void Execute_Process(string ProcessBatFileFullPathWithName)
        {
            try
            {
                Process prsCopy = new Process();
                prsCopy.StartInfo.RedirectStandardError = true;
                prsCopy.StartInfo.RedirectStandardInput = true;
                prsCopy.StartInfo.RedirectStandardOutput = true;
                prsCopy.StartInfo.UseShellExecute = false;
                prsCopy.StartInfo.CreateNoWindow = true;
                prsCopy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                prsCopy.StartInfo.FileName = ProcessBatFileFullPathWithName;
                prsCopy.Start();
                prsCopy.WaitForExit();

            }
            catch (Exception ex)
            {
            }
        }

Create directory using command Prompt / batch file in c# windows services






        public void Create_BatFile_ForDirectories()
        {
            string mDrive = "C:", /////// Drive where want to create file
                mFolder = "\\WindowService\\Service", //// Directory folders names
                BatFileName = "Test.bat";       //// Batch file name 'you can create folder with this batch file
            string ProgramPath = mDrive + mFolder;
            try
            {               
                List<string> list = new List<string>
                    {
                        mDrive,
                        "dir " + mFolder
                      };
                File.WriteAllLines(mDrive + "\\" + BatFileName, list.ToArray()); /// create batch file in C drive

            }
            catch (Exception ex)
            {
            }
            Execute_Process(ProgramPath + "\\" + BatFileName); //// Execute batch file with process to create directory
        }

        public void Create_BatFile_ForListOfFiles()
        {
            string mDrive = "C:",  //// Drive where want to create file
                mFolder = "\\WindowService\\Service", //// Directory folders names
                mTxtFile = "Test.txt", //// Name of the text file where you want to list of the files inside the DIR
                BatFileName = "Testbatch.bat";   //// Batch file name 'you can create folder with this batch file

            string ProgramPath = mDrive + mFolder;
            try
            {
                List<string> list = new List<string>
                    {
                        mDrive,
                        "cd" + mFolder,
                        "dir *.* /s/b >>" + mTxtFile
                      };
                  //// create batch file in C drive
                File.WriteAllLines(mDrive + "\\" + BatFileName, list.ToArray());
            }
            catch (Exception ex)
            {
            }
          //// Execute batch file with process to create list of file inside the DIR
            Execute_Process(ProgramPath + "\\" + BatFileName); 
        }

        public void Execute_Process(string ProcessBatFileFullPathWithName)
        {
            try
            {
                Process prsCopy = new Process();
                prsCopy.StartInfo.RedirectStandardError = true;
                prsCopy.StartInfo.RedirectStandardInput = true;
                prsCopy.StartInfo.RedirectStandardOutput = true;
                prsCopy.StartInfo.UseShellExecute = false;
                prsCopy.StartInfo.CreateNoWindow = true;
                prsCopy.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                prsCopy.StartInfo.FileName = ProcessBatFileFullPathWithName;
                prsCopy.Start();
                prsCopy.WaitForExit();

            }
            catch (Exception ex)
            {
            }
        }

Sunday, 1 March 2020

Calling a Java-Script function named in a variable [FunctionName]

/////////
1.    window["FunctionName"]();

2.  function Abc()
            {
                alert('Function Calling');
            }

            var a = 'Abc';
            window[a]();

Thursday, 20 February 2020

Datatable date sorting issue type dd/mm/yyyy

/////////// There are multiple types of the features in the jquery -

------- Js Plugin --
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
            "date-eu-pre": function (date) {
                date = date.replace(" ", "");

                if (!date) {
                    return 0;
                }

                var year;
                var eu_date = date.split(/[\.\-\/]/);

                /*year (optional)*/
                if (eu_date[2]) {
                    year = eu_date[2];
                }
                else {
                    year = 0;
                }

                /*month*/
                var month = eu_date[1];
                if (month.length == 1) {
                    month = 0 + month;
                }

                /*day*/
                var day = eu_date[0];
                if (day.length == 1) {
                    day = 0 + day;
                }

                return (year + month + day) * 1;
            },

            "date-eu-asc": function (a, b) {
                return ((a < b) ? -1 : ((a > b) ? 1 : 0));
            },

            "date-eu-desc": function (a, b) {
                return ((a < b) ? 1 : ((a > b) ? -1 : 0));
            }

        });

--------- Call Function--

     //// Example
     // $('#example').dataTable( {
     //   columnDefs: [
     //     { type: 'date-eu', targets: 0 }
     //   ]

     //});

Sequence----

1. == >  Extension
2. == >  Datatable.html
3. == >  Datatable.js

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...