DNK Gif

Dot Net Knowledge

Labels

Tuesday, 25 August 2015

SQL Paging

SQL Paging Select Query


SELECT *
  FROM (SELECT *
          FROM ( SELECT ROWNUM SNO
                      , RESULT.*
                   FROM (
SELECT DISTINCT PSD.PSD_SUMMARYID   PMD_SUMMARYID,
                                                  TO_CHAR(PSD.PSD_CREATEDTIME, :dateFormat) PSD_CREATEDTIME,
                                                  PSD.PSD_CREATEDTIME CREATEDTIME,
                                                  INS.INS_NAME  INSURERNAME                                             
                                               
                                    FROM [SCHEMA].PLC_PSD_PAYMENTSUMMARYDETAILS PSD
                                                INNER JOIN [SCHEMA].PLC_PMD_PAYMENTDETAILS PMD
                                                ON PSD.PSD_SUMMARYID = PMD.PMD_SUMMARYID
                                                INNER JOIN [SCHEMA].PLC_PLC_POLICY PLC
                                                ON PMD.PMD_POLICYID = PLC.PLC_POLICYID
                                                INNER JOIN [SCHEMA].MST_INS_INSURERMASTER INS
                                                ON INS.INS_INSURERID              = PSD.PSD_INSURERID
                                                WHERE PLC.PLC_APPLICATIONCLIENTKEY = :APPLICATIONCLIENTKEY
                                                AND PLC.PLC_DEALERID               = :PLC_DEALERID
                                                AND PMD.PMD_SUMMARYID IS NOT NULL
                                     order by PMD_SUMMARYID desc
) RESULT
                  WHERE ROWNUM <=(:Page_No*10) ORDER BY ROWNUM DESC )
         WHERE ROWNUM <=10 ORDER BY ROWNUM DESC
       )
 ORDER BY SNO

Thursday, 6 August 2015

pointer-events:none Chrome, IE, FireFox solved

pointer-events:none property for Chrome, IE & Firefox

This property work fine in Chrome & Firefox.
 
Alternative for Internet Explorer is given below
 
$(document).on('mousedown', '.TopElement', function (e) {
            $(this).hide();
            var BottomElement = document.elementFromPoint(e.clientX, e.clientY);
            $(this).show();
            $(BottomElement).mousedown(); //Manually fire the event for desired underlying element
            return false;
        });

Example:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        $(this).hide();
    });
});
$(document).on('mousedown', '#divPointer', function (e) {
            $(this).hide();
            var BottomElement = document.elementFromPoint(e.clientX, e.clientY);
            $(this).show();
            $(BottomElement).mousedown(); //Manually fire the event for desired underlying element
            return false;
        });
</script>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me away!</p>
<p>Click me too!</p>
<div id="divPointer">
<input type="text" value="umesh" style="pointer-events:none"></input></div>
</body>
</html>

Wednesday, 5 August 2015

Track changes in a HTML form (DOM onchange Event handler)

How to track changes made in a HTML form?

Description: Bind an event handler to the "change" JavaScript event, or trigger that event on an element.

This method is a shortcut for .on( "change", handler ) in the first two variations, and .trigger( "change" ) in the third.
The change event is sent to an element when its value changes. This event is limited to <input> elements, <textarea>boxes and <select> elements. For select boxes, checkboxes, and radio buttons, the event is fired immediately when the user makes a selection with the mouse, but for the other element types the event is deferred until the element loses focus.
For example, consider the HTML:
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>change demo</title>
  <style>
  div {
    color: red;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 <form>
<select name="sweets" multiple="multiple">
  <option>Chocolate</option>
  <option selected="selected">Candy</option>
  <option>Taffy</option>
  <option selected="selected">Caramel</option>
  <option>Fudge</option>
  <option>Cookie</option>
</select>
<div></div>
<div id="divChange"></div>
<input id="tb" type="text" value="umesh"></input>
  </form>
<script>
$( "form" )
  .change(function () {

    var str = "";
    $( "select option:selected" ).each(function() {
      str += $( this ).text() + " ";
    });
    $( "div" ).text( str );
$("#divChange").text($("#tb").val());
  })
  .change();
</script>
 
</body>
</html>

For more information:

Tuesday, 21 July 2015

Read and Write Object data from and to NotePad using C#

Read and Write data from and to NotePad

Is this possible by C#? Yes, this is possible by C#. Newtonsoft.Json.dll is needed for this. 

Well a ViewModel is need to be declared and data will be read or written from or to notepad as a type of this ViewModel.

Writing an Object data into a notepad

public static void WrieDataToNotePad(string filePath, Object obj)
        {
            StreamWriter writer = new StreamWriter(filePath);
            string jsonData = JsonConvert.SerializeObject(obj);
            writer.Write(jsonData);
            writer.Close();
           
        }
Example:-
NotePadInteractor.WrieDataToNotePad(AppDomain.CurrentDomain.BaseDirectory + "AppData.txt", new NotePadData { RunApp=true,ModifiedMonth=DateTime.Today.Month});

Here NotePadData is a ViewModel.

If "AppData.txt" is not available in the above location(filePath), it’ll create a file with this name in that location. Data will be stored in JSON format in the .txt file and can be used later in an application as required.

Note:- JsonConvert.SerializeObject(obj) is a part of Newtonsoft.Json.dll 

Reading an Object data from a notepad

public static NotePadData ReadNotePadData(string filePath)
        {
            try
            {
              StreamReader reader = new StreamReader(filePath);
              string jsonData = reader.ReadToEnd();
              reader.Close();
              return JsonConvert.DeserializeObject<NotePadData>(jsonData);
            }
            catch(Exception ex)
            {
                return null;
               throw ex;
            }
           
        }

If location provided in the filePath doesnot contain a file, with the given name then file not found exception will be encountered. So in order to handle this exception, codes need to be written in the catch block.

Type of ViewModel need to be given in this function JsonConvert.DeserializeObject<ViewModelName>(jsonData);

Obviously, this function is a part of Newtonsoft.Json.dll

How to Write Object Data to an XML File using C#

Write Object Data to an XML File using C# 

This example writes the object from a class to an XML file using the XmlSerializer class.This code example defines a class named Book, creates an instance of the class, and uses XML serialization
to write the instance to an XML file.

Example:-

public class XMLWrite
{
         static void Main(string[] args)
           {
                  WriteXML();
            }
               public class Book
               {
                    public String title {get; set; };
                }
                
                 public static void WriteXML()
                {
                    Book overview = new Book();
                    overview.title = "Serialization Overview";
                    System.Xml.Serialization.XmlSerializer writer =
                       new System.Xml.Serialization.XmlSerializer(typeof(Book));
                   System.IO.StreamWriter file = new System.IO.StreamWriter(
                                      @"c:\temp\SerializationOverview.xml");
                   writer.Serialize(file, overview);
                   file.Close();
                }
}

Security

This example creates a new file, if the file does not already exist. If an application needs to create a file, that application needs Create access for the folder. If the file already exists, the application needs only Write access, a lesser privilege. Where possible, it is more secure to create the file during deployment, and only grant Read access to a single file, rather than Create access for a folder.

How to Read Object Data from an XML File using C#

Reading Object Data from an XML File using C#

This example reads object data that was previously written to an XML file using the XmlSerializer class.

public class Book
{
        public String title{get; set;};
}

public void ReadXML()
{
System.Xml.Serialization.XmlSerializer reader =
new System.Xml.Serialization.XmlSerializer(typeof(Book));

System.IO.StreamReader file = new System.IO.StreamReader(
@"c:\temp\SerializationOverview.xml");

Book overview = new Book();

overview = (Book)reader.Deserialize(file);

Console.WriteLine(overview.title);
}

Note:- 

By using this method only simple ViewModel data can be read,

Tuesday, 7 July 2015

Opening password protected Excel2013 file using Aspose.cells

How to open Password protected Excel file ?

Hey! I am not going to hack or any thing like that, Of course password is needed to open the file. 

For this latest version of Aspose.cells.dll is needed.
This version  Aspose.Cells for .NET v8.5.0.2 supports this feature, you can download the same.

This is the code to do this programmatically.

            LoadOptions loadoptions = new LoadOptions( );            
            loadoptions.Password = "umesh1";    
            string filepath="C:\\Dev\\MyExcel.xlsx";       
            Workbook workbook = new Workbook(filePath, loadoptions);