-->

Tuesday, January 14, 2014

How to Get Last Activity Date of Profile user in ASP.NET

Step-1: Add this code into web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into .aspx page (Before add this code, please create profile first )

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {
       
        
    }  

    protected void update_date(object sender, EventArgs e)
    {
        Label1.Text += "current Date and Time is " + DateTime.Now.ToString() +"<br/>";
        Label1.Text += "Profile LastUpdate Date is " + Profile.LastActivityDate; 
            
         

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Get Last Activity Date</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Get Last activity Date</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get Last Activity Date" 
            Width="169px" onclick="update_date" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>
Code Generate the following output
How to Get Last Activity Date of Profile user in ASP.NET

Monday, January 13, 2014

How to Get Last Updated Date of Profile user in ASP.NET

Step-1: Add this code into web.config file

<?xml version="1.0"?>

<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->

<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into .aspx page (Before add this code, please create profile first )

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {
       
        
    }  

    protected void update_date(object sender, EventArgs e)
    {
        Label1.Text += "current Date and Time is " + DateTime.Now.ToString() +"<br/>";
        Label1.Text += "Profile LastUpdate Date is " + Profile.LastUpdatedDate;
         

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Get Lastupdated Date</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Last updated Date</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Get Last Updated Date" 
            Width="169px" onclick="update_date" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>

Code Generate the following output

How to Get Last Updated Date of Profile user in ASP.NET

ProfileManager.DeleteProfile method delete profile in asp.net example

Step-1: Add this code in web.config file
<configuration>

    <system.web>
      <authentication mode="Windows" />
      <profile>
        <properties>
          <add name="UserName"/>
        </properties>
      </profile>
        <compilation debug="false" targetFramework="4.0" />
    </system.web>

</configuration>

Step-2: Add this code into your .aspx page

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">  
    protected void Page_Load(object sender, System.EventArgs e)  
    {   
        if(!Page.IsPostBack)  
        {
            Profile.UserName = "Jacob Lefore";
            Profile.Save();
            Label1.Text = "Current User:" + Profile.UserName;  
        }  
    }  
  

    

    protected void DelteProfile(object sender, EventArgs e)
    {
        ProfileManager.DeleteProfile(User.Identity.Name);
        Profile.Save();
        Label1.Text = "Profile Deleted";

    }
</script>  
  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head id="Head1" runat="server">  
    <title>Delete Users Profile</title>  
</head>  
<body>  
    <form id="form1" runat="server">  
    <div>  
        <h2>Delete User Profile</h2>
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Delete User Profile" 
            Width="169px" onclick="DelteProfile" />
        <br /><br />  
    </div>  
    </form>  
</body>  
</html>
Code generate the following output
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example
ProfileManager.DeleteProfile method delete profile in asp.net example





Computer Programming: Web Form controls, General introduction in ASP.NET

The Web form controls are closely designed to resemble standard Visual basic Winforms controls. These controls are used for designing the interface for any Web application, for example, when you visit the website of Google, you type your search query in a TextBox, which is a control. ASP.NET provides a standard set of controls that can be used for the development of Web Applications. You can access all these controls from the ToolBox present in the Visual Studio Integrated Development Environment ( IDE ) . These controls can easily be used by just dragging and dropping them at any desired location on the Web form. Based on the tasks performed by them, these controls on the ToolBox are grouped under various categories known as tabs. For example, controls for validating the data are put under the validation tab and controls used for logging on the websites are put under the Login tab. Similarly, controls for common use are put under the standard tab and are known as standard controls . All these controls come under the Control class. All the Standard/ Web server controls are based on the WebControl class, which, in turn, is based on the control class. In other words, the WebControl class has originated from the Control class.

Later session we will discuss about the inheritance hierarchy, pubic properties, public methods, and public events of the Controls and the WebControl classes. We also get to know about the various controls such as Label, Button, TextBox, Literal, Placeholder, Hidden Field, and FileUpload that originate from the WebControl class, along with their implementations.  

Sunday, January 12, 2014

How to Perform Grouping of Data Matching a Criteria: SQL Programming

The database users might need to view data in a user-defined format. These reports might involve summarizing data on the basis of various criteria. SQL Server allows you to generate summarized data reports using the PIVOT clause of SELECT statement.

The PIVOT operator is used to transform a set of columns into values. PIVOT rotates a table-valued expression by turning the unique values from one column in the expression into multiple columns in the output. In addition, it also performs aggregations on the remaining column values if required in the output. Following is the syntax of PIVOT operator is:

SELECT * from table_name
PIVOT (aggregation_function (value_column)
FOR pivot_column
IN (column_list)
) table_alias

Where,

  • Table_name: name of table on which query will execute.
  • Pivot_column: the only column on which condition perform.
  • Table_alias: alias name of the table used in query only.

Consider an example, you want to display the number of purchase orders placed by certain employees, laid down with the vendors. The following query provides this report:

SELECT VendorID, [164] AS Empl, [198] AS Emp2, [223] AS Emp3, [231] AS Emp4, [233] AS Emp5 FROM
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) p
PIVOT
(
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [164], [198],[223], [231], [233] )
) AS pvt
ORDER BY VendorID

Following output is displayed by the preceding statements.

How to Perform Grouping of Data Matching a Criteria: SQL Programming


How to use Compute and ComputeBy Clauses in Query: SQL Programming

The COMPUTE clause, with the SELECT statement, is used to generate summary rows by using aggregate functions in the query results, in sql programming. The COMPUTE BY clause can be used to calculate summary values of the result set on a group of data. The column on which the data is to be grouped is mentioned after the BY keyword.

The GROUP BY clause is used to generate a group summary report and does not produce individual table rows in the result set, whereas the COMPUTE and COMPUTE BY clauses generate the summary report with individual data rows from the table. In other words, the COMPUTE clause is used for control-break summary reporting applications that generate detailed information in the result set.

Syntax:

SELECT column_list
FROM table_name
ORDER BY column_name
COMPUTE aggregate_function (column_name) [, aggregate_function(column_name) …]
[BY column_name [, column_name]…]

Where,

  • ORDER BY column_name specifies the name of the column(s) by which data in the result is to be sorted.
  • COMPUTE aggregate_function specifies any row aggregate function from the aggregate function list.
  • Column_name specifies the name of the column(s) for which the summary report is to be displayed.
  • BY column_name specifies the name of the column(s) by which data is to be grouped.

The following SQL query uses the COMPUTE BY clause to calculate the average sickLeaveHours and VacationHours from the Employee table and display them based on Title, VacationHours, and SickLeaveHours:

SELECT Title, 'Average VacationHours' = VacationHours, 'Average SickLeaveHours' = SickLeaveHours FROM HumanResources.Employee
WHERE Title IN ('Recruiter', 'Stocker')
ORDER BY Title, VacationHours, SickLeaveHours
COMPUTE avg(VacationHours), Avg (SickLeaveHours) BY Title

In the preceding query, the data of the VacationHours and SickLeaveHours column is grouped for the recruiter and stocker and the summation of the vacation hours and sick leave hours for both is retrieved, as shown in the following figure.

Consider another example, where you need to use the COMPUTE BY clause to calculate the subtotals of VacationHours and SickLeaveHours for each value in the Designation column. The COMPUTE clause calculates the grand total of VacationHours and SickLeaveHours:

SELECT Title, 'Total VacationHours' = VacationHours, 'Total SickLeaveHours' = SickLeaveHours
FROM HumanResources.Employee
WHERE Title IN ('Recruiter', 'Stocker')
ORDER BY Title, VacationHours, SickLeaveHours
COMPUTE sum (VacationHours), sum(SickLeaveHours) BY Title COMPUTE sum (VacationHours) , sum (SickLeaveHours)

In the preceding example, initially the data of the VacationHours and SickLeaveHours column is grouped for the recruiter and stocker and the summation of the vacation hours and sick leave hours for the recruiter and stocker.

Both these keywords are not supported in the SQL Server management studio 2012, these queries can be executed in 2008 version.

How to Create First MVC Application in Visual Studio: Introduction to MVC

MVC framework, as explained in previous article, separates your logic, views and your database of the web application. Here are simple steps to create an MVC application using Visual Studio 2013, discussed below.
  • Click on File-->New--> Project in Visual Studio (I have used VS 2013)
  • The New Project window opened with a list of categories in the left pane and some of their installed templates. Select ASP.NET MVC 4 Web Application under the Web categories.


Leave the name as is, you can change it, and click on Ok button.
  • Another window will opened which provides the options to choose the framework (by default the application may have) like empty, basic, internet or shown in the list.


  • Select Internet application and click on Ok button, it will start creating an MVC application according to your selected options. 
  • A dialog box appears to notify you about the process, after some time (depend on your system) your MVC project will create having some folders shown in the solution explorer below.

What are the uses of these folders and how they can be used by the programmer will be discussed later.

© Copyright 2013 Computer Programming | All Right Reserved