Friday, May 15, 2015

How to shutdown machine from ASP.NET


            Process process = new Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "shutdown";
            startInfo.Arguments = "/s /t 5";
            startInfo.UseShellExecute = true;
            startInfo.Verb = "runas";
            process.StartInfo = startInfo;
            process.Start();

Table column hide/show by checkbox

  function bindCasesTable(pageIndex) {
            var Pegination = {
                PageIndex: pageIndex,
                PageSize: 5,
            }

            var model = { PegInfo: Pegination }
            $.ajax({
                url: baseUrl + 'WS/GetCases',
                type: 'post',
                data: JSON.stringify(model),
                async: false,
                contentType: "application/json; charset=utf-8",
                success: function (data) {
                    console.log(data);
                    var strGrid = "<table id='grdCases' class='display' cellspacing='0' width='100%'> <thead> "
                                + "<tr>"
                                + "<th style='display:none;'>Case ID.</th>"
                                + "<th class='RefNo'>Ref. No.</th>"
                                + "<th class='Department'>Department</th>"
                                + "<th class='SubDivision'>Sub Division</th>"
                                + "<th class='WorkName'>Work Name</th>"
                                + "<th class='Activity'>Activity Type</th>"
                                + "<th class='WorkType'>Work Type</th>"
                                + "<th class='ExpectedCompletionDate'>Expected Completion Date</th>"
                                + "<th class='WorkStatus'>Work Status</th>"
                                + "<th class='WorkProgress'>Work Progress(%)</th>"
                                + "<th class='TotalBillPaid'>Total Bill Paid</th>"
                                + "</tr></thead><tbody>";

                    for (var i = 0; i < data.length; i++) {

                        var ExpextedDate = '';
                        if (data[i].ExpectedCompletionDateString == '') {
                            ExpextedDate = '';
                        }
                        else {
                            var tempaaDate = data[i].ExpectedCompletionDateString.split("/");
                            ExpextedDate = tempaaDate[1] + '/' + tempaaDate[0] + '/' + tempaaDate[2];
                        }



                        strGrid += ("<tr onclick=\"RedirectCaseInfoDashboard(" + data[i].CaseId + ")\">" +
                                    "<td style='display:none;'>" + data[i].UpdateStamp + "</td>" +
                                    "<td class='RefNo' style='text-align:center'>" + data[i].CaseRefNum + "</td>" +
                                    "<td class='Department' style='text-align:center'>" + data[i].DepartmentName + "</td>" +
                                    "<td class='SubDivision' style='text-align:left'>" + data[i].SubDivisionName + "</td>" +
                                    "<td class='WorkName' style='text-align:left'>" + data[i].WorkName + "</td>" +
                                    "<td class='Activity' style='text-align:left'>" + data[i].ActivityTypeName + "</td>" +
                                    "<td class='WorkType' style='text-align:left'>" + data[i].WorkTypeName + "</td>" +
                                    "<td class='ExpectedCompletionDate' style='text-align:center'>" + ExpextedDate + "</td>" +
                                    "<td class='WorkStatus' style='text-align:left'>" + data[i].WorkStatusName + "</td>" +
                                    "<td class='WorkProgress' style='text-align:center'>" + data[i].WorkProgress + "</td>" +
                                    "<td class='TotalBillPaid' style='text-align:right'>" + data[i].TotalBillPaid + "</td>" +
                                    "</tr>");
                    }
                    strGrid += "</tbody></table>";

                    var str = document.getElementById('dvAllCases');
                    str.innerHTML = strGrid;

                    $('#grdCases').dataTable({
                        //"scrollY": "400px",
                        "scrollCollapse": false,
                        "paging": false,
                        "info": "",
                        "order": [[0, "desc"]],
                        //"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [0] }, { 'bSortable': false, 'aTargets': [8] }],
                        "columns": [
                            { "width": "2%" },
                            { "width": "8%" },
                            { "width": "5%" },
                            { "width": "9.5%" },
                            { "width": "9.5%" },
                            { "width": "10%" },
                            { "width": "9%" },
                            { "width": "17%" },
                            { "width": "9.4%" },
                            { "width": "12.1%" },
                            { "width": "10%" }

                        ]
                    });
                    if (data.length > 0) {
                        $(".Pager").ASPSnippets_Pager({
                            ActiveCssClass: "current",
                            PagerCssClass: "pager",
                            PageIndex: pageIndex,
                            PageSize: 5,
                            RecordCount: parseInt(data[0].PegInfo.TotalRecords)
                        });
                    }

                    $(".Pager .page").on('click', function () {
                        bindCasesTable(parseInt($(this).attr('page')));
                    });

                    $('#grdCases_filter').hide();
                },
                error: function (x, y, z) {
                    alert(x.err);
                    alert(x + '\n' + y + '\n' + z);
                }
            });
        }


 $(function () {
            var $chk = $("#grpChkBox input:checkbox");
            var $tbl = $("#grdCases");

            $chk.prop('checked', true);

            $chk.click(function () {
                var colToHide = $tbl.find("." + $(this).attr("name"));
                $(colToHide).toggle();
            });
        });    


<div id="grpChkBox">
            <input type="checkbox" name="RefNo" class="input" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Ref. No </span>
            <input type="checkbox" name="Department" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Department</span>
            <input type="checkbox" name="SubDivision" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Sub Division </span>
            <input type="checkbox" name="WorkName" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Work Name </span>
            <input type="checkbox" name="Activity" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Activity Type </span>
            <input type="checkbox" name="WorkType" />
            <span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Work Type </span>
            <input type="checkbox" name="ExpectedCompletionDate" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Expected Completion Date </span>
            <input type="checkbox" name="WorkStatus" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Work Status </span>
            <input type="checkbox" name="WorkProgress" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Work Progress </span>
            <input type="checkbox" name="TotalBillPaid" /><span style="font-family: Arial; font-size: small; padding-right: 3px; padding-left: 3px">Total Bill Paid </span>
        </div>

jquery check if checkbox checked or not

    $('#chkrefNo').change(function () {

                if ($(this).prop('checked') == true) {
                    alert('1');
                }
                else {
                    alert('2');
                }
            });

jQuery checkbox change and click event

<input type="checkbox" id="checkbox1" /> <br />
<input type="text" id="textbox1" />


$(document).ready(function() {
    //set initial state.
    $('#textbox1').val($(this).is(':checked'));

    $('#checkbox1').change(function() {
        $('#textbox1').val(this.checked);
    });

    $('#checkbox1').click(function() {
        var self = this;
        setTimeout(function() {
           
            if (!self.checked) {
                var ans = confirm("Are you sure?");
                self.checked = ans;
                $('#textbox1').val(ans.toString());
            }
        }, 0);
    });
});

Thursday, May 14, 2015

Tooltip example - Password strenght,characters in password

<html>
<head>
 <style>
 #foo {
position: absolute;
display: none;
background: White;
border: 1px solid #CCCCCC;
margin-left:3px;
margin-left:4px;
}
          </style>
 <script src="jquery-1.10.2.min.js"></script>

</head>
<body>
  <img class="helpIcoPassword" src="../App_Themes/RxWiki/images/help_icon.png"
            style="padding-right: 5px; cursor: help;" data-tooltip="#foo" /></span>

<div id="foo">
              <span style="color:red;font-size:12px">&nbsp;&nbsp; Password needs to meet the following requirements: <br />
                  &nbsp;&nbsp 1 . 8-20 characters. &nbsp;&nbsp <br />
                   &nbsp;&nbsp 2 . Should have at least 1 uppercase and 1 lowercase characters (A-Z, a-z).  &nbsp;&nbsp
                  <br />
                  &nbsp;&nbsp 3 . Should have at least 1 numeric characters (0-9). &nbsp;&nbsp
                  <br />
                   &nbsp;&nbsp 4 . Should have at least 1 special character (=.*[@#$%/!^&+|?<>,~`;:{}-]). &nbsp;&nbsp</span>
           </div>
    <script>

        $(".helpIcoPassword").hover(function (e) {
            $($(this).data("tooltip")).css({
                left: e.pageX + 1,
                top: e.pageY + 1
            }).stop().show(100);
        }, function () {
            $($(this).data("tooltip")).hide();
        });
    </script>

</body>
</html>

Trigger Example

To start with, we will be using the CUSTOMERS table we had created and used in the previous chapters:
Select * from customers;

+----+----------+-----+-----------+----------+
| ID | NAME     | AGE | ADDRESS   | SALARY   |
+----+----------+-----+-----------+----------+
|  1 | Ramesh   |  32 | Ahmedabad |  2000.00 |
|  2 | Khilan   |  25 | Delhi     |  1500.00 |
|  3 | kaushik  |  23 | Kota      |  2000.00 |
|  4 | Chaitali |  25 | Mumbai    |  6500.00 |
|  5 | Hardik   |  27 | Bhopal    |  8500.00 |
|  6 | Komal    |  22 | MP        |  4500.00 |
+----+----------+-----+-----------+----------+
The following program creates a row level trigger for the customers table that would fire for INSERT or UPDATE or DELETE operations performed on the CUSTOMERS table. This trigger will display the salary difference between the old values and new values:
CREATE OR REPLACE TRIGGER display_salary_changes
BEFORE DELETE OR INSERT OR UPDATE ON customers
FOR EACH ROW
WHEN (NEW.ID > 0)
DECLARE
   sal_diff number;
BEGIN
   sal_diff := :NEW.salary  - :OLD.salary;
   dbms_output.put_line('Old salary: ' || :OLD.salary);
   dbms_output.put_line('New salary: ' || :NEW.salary);
   dbms_output.put_line('Salary difference: ' || sal_diff);
END;
/
When the above code is executed at SQL prompt, it produces the following result:
Trigger created.

Creating Triggers

The syntax for creating a trigger is:
CREATE [OR REPLACE ] TRIGGER trigger_name 
{BEFORE | AFTER | INSTEAD OF } 
{INSERT [OR] | UPDATE [OR] | DELETE} 
[OF col_name] 
ON table_name 
[REFERENCING OLD AS o NEW AS n] 
[FOR EACH ROW] 
WHEN (condition)  
DECLARE
   Declaration-statements
BEGIN 
   Executable-statements
EXCEPTION
   Exception-handling-statements
END;
Where,
  • CREATE [OR REPLACE] TRIGGER trigger_name: Creates or replaces an existing trigger with the trigger_name.
  • {BEFORE | AFTER | INSTEAD OF} : This specifies when the trigger would be executed. The INSTEAD OF clause is used for creating trigger on a view.
  • {INSERT [OR] | UPDATE [OR] | DELETE}: This specifies the DML operation.
  • [OF col_name]: This specifies the column name that would be updated.
  • [ON table_name]: This specifies the name of the table associated with the trigger.
  • [REFERENCING OLD AS o NEW AS n]: This allows you to refer new and old values for various DML statements, like INSERT, UPDATE, and DELETE.
  • [FOR EACH ROW]: This specifies a row level trigger, i.e., the trigger would be executed for each row being affected. Otherwise the trigger will execute just once when the SQL statement is executed, which is called a table level trigger.
  • WHEN (condition): This provides a condition for rows for which the trigger would fire. This clause is valid only for row level triggers.