Thursday, October 29, 2015

Sum of a Column in Crystal Reports

Here is this Crystal Reports report. I will be showing data from more than one table in ASP.NET. 

The following 3 tables I am using to create a Crystal Report.

1. Customer

Customer
                                    Image 1.

2. Product


Product
                     Image 2.

3. Cust_Prod_Order

Cust Prod Order
                                                               Image 3.

Now open Visual Studio and go to File -> New Web Site.

New Web Site
                                                                        Image 4.

After this right-click on the project in the Solution Explorer then select Add New Item -> Crystal Report -> Add.

Crystal Report
                                                                     Image 5.

Add
                                                Image 6.

Here expand Create New Connection then select OLE DB (ADO) then a pop-up window will open then select Microsoft OLE DB Provider for SQL Server then click Next.

Microsoft OLE DB Provider
                                                                     Image 7.

Now enter your SQL Server details.

SQL server Details
                                                                  Image 8.

SQL server
                                                            Image 9.

Now select your database then select all your tables and move them over to Selected Tables.

Select Your All Tables
                                                                  Image 10.

Now you can see your tables with relationships.

relationship
                                                                     Image 11.

Now select the columns to show in the reports.

reports
                                                                  Image 12.

Now you can see your report is ready. All the columns are already in the Details sections. You can remove any column or you can add a new column by dragging and dropping from the Field Explorer to the report. Here I did some formatting like header text background, detail column colour and so on.

column colour
                                                               Image 13.

Now in the Field Explorer select Formula Fields -> Right-click - New.

Select Formula Fields
                                                                  Image 14.

Provide a name then click Use Editor.

Click Use Editor
                                                                  Image 15.

Now select your Column Name and drag it to the following editor window and write Sum formula. 

Select Your Column Name
                                                                  Image 16.

Now click on Save and Close.

Now drag the formula fields to the report footer.

Report Footer
                                                                     Image 17.

Now to add a Report Viewer to show this Crystal Report. In the Default.aspx page drag and drop a CrystalReportViewer from the toolbox as in the following.

CrystalReportViewer
                                                                     Image 18.

My aspx code is:
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>  
  2.   
  3. <%@ Register Assembly="CrystalDecisions.Web, Version=10.5.3700.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"  
  4.     Namespace="CrystalDecisions.Web" TagPrefix="CR" %>  
  5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  6. <html xmlns="http://www.w3.org/1999/xhtml">  
  7. <head runat="server">  
  8.     <title>Crystal Report – Sum of a Column</title>  
  9. </head>  
  10. <body>  
  11.     <form id="form1" runat="server">  
  12.     <table cellpadding="10" cellspacing="10" width="70%" height="300px" align="center"  
  13.         style="border: solid 2px gray;">  
  14.         <tr>  
  15.             <td align="center" style="background-color: SkyBlue;">  
  16.                 <span style="font-family: Times New Roman; font-size: 18pt; color: Green;">Customer  
  17.                     Product Order Detail Report</span>  
  18.             </td>  
  19.         </tr>  
  20.         <tr>  
  21.             <td align="center">  
  22.                 <asp:Panel ID="pnlReport" runat="server" Height="400px">  
  23.                     <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />  
  24.                 </asp:Panel>  
  25.             </td>  
  26.         </tr>  
  27.     </table>  
  28.     </form>  
  29. </body>  
  30. </html>  
Now on Page_Load event write the following code:
  1. using System;  
  2. using System.Configuration;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.HtmlControls;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Xml.Linq;  
  12. using CrystalDecisions.CrystalReports.Engine;  
  13.   
  14. public partial class _Default : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.         ReportDocument cryRpt = new ReportDocument();  
  19.         cryRpt.Load(Server.MapPath("EmployeeCrystalReport.rpt"));  
  20.         CrystalReportViewer1.ReportSource = cryRpt;           
  21.     }  
  22. }  
Now run your application:

Run your Application

Thursday, October 15, 2015

Salary Of An IT Professional In India


IT field is one of the highest paid sectors for Indian workforce. Salaries for an IT professional depends on place, person, company, and skill set. Usually, large corporations offer less in-take salaries with better perks. Check out How to choose my next company. Salaries also depend on the project, product, and work type. For example, companies such as Google, Microsoft, and Adobe may pay 3-times for a product engineer than a web developer. 

In this article, I will shed some lights on salary range for IT professionals in India.

PayScale has done a great job capturing salary data from its users. The following graphs show the median salaries of a Software Developer, Sr. Software Developer, and Project Manager. All salaries are in INR.

Software Developer Salary
                                                         Software Developer Salary

Sr. Software Developer Salary
                                                      Sr. Software Developer Salary

Project Manager Salary
                                                               Project Manager Salary

According to PayScale, the following table summarizes the IT professionals’ salaries in India with their job title and number of years of experience. 

salaries in India with their Job titles and number of years of experience


While the above salaries may represent the average salary, the actual salary depends on an individual. Salaries also depends on talent and need. One of the startups I was recently advising needed a developer with experience building an education and learning platform and willing to pay much higher salary than the market rate.

Simple Password Encryption Program

Introduction
This article shows you how to make a simple Password encryption Program.

Using the code

The main code used for the conversion is from the Microsoft.VisualBasic class. Below is the code that is used to convert a string to hexadecimal format. We can't direct convert all characters in to hexadecimal format (eg:@#$%^&*()) that's why firstly I take ASCII value of the character, and then convert ASCII value into hexadecimal format.

//For this I made while loop
while (Data.Length > 0)
{
    //first I take each character using substring     
sValue= Data.Substring(0, 1).ToString()
//then convert character into ascii.
sValue= Strings.Asc(sValue)
//then convert ascii value into Hex Format
sValue = Conversion.Hex(sValue)
//after converting remove the character.
Data = Data.Substring(1, Data.Length - 1);
sHex = sHex + sValue;
}

Ony two functions I used for this application
      
public string PasswordDecription(ref string Data)
{
    string Data1 = "";
    string sData = "";

    while (Data.Length > 0)
    {
        Data1 = System.Convert.ToChar(System.Convert.ToUInt32(Data.Substring(0, 2), 16)).ToString();
        sData = sData + Data1;
        Data = Data.Substring(2, Data.Length - 2);
    }
    return sData;
}

public string PasswordEncription(ref string Data)
{
    string sValue;
    string sHex = "";
    while (Data.Length > 0)
    {
        sValue = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString()));
        Data = Data.Substring(1, Data.Length - 1);
        sHex = sHex + sValue;
    }
    return sHex;

}

Authentication-Authorization / Windows built-in Role enumeration

In web.config file you will get following
<system.web>
          <authentication mode="Windows/Form/Passport/None">
          </authentication>
</system.web>
Windows: Is used togther with IIS authentication, where authentication is perform in the following ways: Basic,digest or integrated windows.

Form: Request that are not authenticated are redirected to an HTML form

Passport: A centrilized authentication service provided by the microsoft that offers single login and core profile services for member site.
In this tutorial my focus will be on Form-Based Authentication: this type of authentication will have following web.config file.
<system.web>
          <authentication mode="Forms">
                   <forms name="FrmLogin" loginUrl="./Login.aspx" path="/"> </forms>
          </authentication>
          <authorization>
                   <deny users="?"/>
          </authorization>
</system.web>
Here loginURL attribute points to the page that contain the applications login page and
attribute path specifies location to which cookies get stored as users access token.

Checking credentials against SQL Server
Here is login.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table>
            <tr>
                <td colspan="2">User Authentication</td>
            </tr>
            <tr>
                <td>Login Name:</td>
                <td><asp:TextBox ID="txtLoginName" runat="server"></asp:TextBox></td>
            </tr>
            <tr>
                <td>Password:</td>
                <td><asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox></td>
            </tr>
            <tr>
                <td style="height: 26px"></td>
                <td style="height: 26px"><asp:Button ID="btnLogin" runat="server"OnClick="btnLogin_Click" Text="Login Me" /></td>
            </tr>
            <tr>
                <td colspan="2">
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"ControlToValidate="txtLoginName"
                        Display="Dynamic" ErrorMessage="Login name is required"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"ControlToValidate="txtPassword"
                        Display="Dynamic" ErrorMessage="Password is required"></asp:RequiredFieldValidator></td>
            </tr>
        </table>   
    </div>
        <asp:Label ID="lblMessage" runat="server" ForeColor="Red"></asp:Label>
    </form>
</body>
</html>
Here is code behind code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        SqlConnection SqlCon = newSqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
        string strSql = "SELECT UserName, UserPassword FROM Tbl_Login WHERE UserName='" + txtLoginName.Text.Replace("'""") + "' AND UserPassword='" + txtPassword.Text.Replace("'""") + "'";
        SqlCommand SqlComd = new SqlCommand(strSql, SqlCon);
        SqlDataReader sqlRdr;
        try
        {
            SqlCon.Open();
            sqlRdr = SqlComd.ExecuteReader(CommandBehavior.CloseConnection);
            if (sqlRdr.Read())
            {
                FormsAuthentication.RedirectFromLoginPage(txtLoginName.Text, true);
            }
            else
            {
                lblMessage.Text = "Invalid credential supplied!";
            }
        }
        catch (Exception ex)
        {
            lblMessage.Text = ex.Message;
        }
        finally
        {
            //SqlCon.Close();
        }
    }
}
You can use SignOut() method as
On default.aspx/cs page I have used signout functionality as
protected void DoLogout(object sender, EventArgs e)
{
    FormsAuthentication.SignOut();
    Response.Redirect("./Login.aspx");
}
If you are using Windows authentication you can use WindowsIdentity object and other objects. To have access to these richer objects you should use System.Security.Principle which uses role from the WindowsBuiltInRole enumeration, which has following roles.
  1. AccountOperator
  2. Administrator
  3. BackupOperator
  4. Guest
  5. PowereUser
  6. PrintOperator
  7. Replicator
  8. SystemOperator
  9. Users
On seperate page you can have code as
protected void Page_Load(object sender, EventArgs e)
{
    WindowsIdentity LgnUser = new WindowsIdentity("Administrator");
    Response.Write("Authenticatio Type:" + LgnUser.AuthenticationType.ToString() + "<br>");
    Response.Write("Impersonate Level:" + LgnUser.ImpersonationLevel.ToString() + "<br>");
    Response.Write("Is Guest:" + LgnUser.IsGuest + "<br>");
    Response.Write("Is Authenticated:" + LgnUser.IsAuthenticated.ToString());
    Response.Write("Name:" + LgnUser.Name.ToString());
}

You can print the current identity details. For this you might need to change trust level.