Thursday, 19 February 2015

Crop and Upload Image with Thumbnail using jQuery and HTML5 in ASP.Net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.rawgit.com/tapmodo/Jcrop/master/js/jquery.Jcrop.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('#FileUpload1').change(function () {
            $('#Image1').hide();
            var reader = new FileReader();
            reader.onload = function (e) {
                $('#Image1').show();
                $('#Image1').attr("src", e.target.result);
                $('#Image1').Jcrop({
                    onChange: SetCoordinates,
                    onSelect: SetCoordinates
                });
            }
            reader.readAsDataURL($(this)[0].files[0]);
        });

        $('#btnCrop').click(function () {
            var x1 = $('#imgX1').val();
            var y1 = $('#imgY1').val();
            var width = $('#imgWidth').val();
            var height = $('#imgHeight').val();
            var canvas = $("#canvas")[0];
            var context = canvas.getContext('2d');
            var img = new Image();
            img.onload = function () {
                canvas.height = height;
                canvas.width = width;
                context.drawImage(img, x1, y1, width, height, 0, 0, width, height);
                $('#imgCropped').val(canvas.toDataURL());
                $('[id*=btnUpload]').show();
            };
            img.src = $('#Image1').attr("src");
        });
    });
    function SetCoordinates(c) {
        $('#imgX1').val(c.x);
        $('#imgY1').val(c.y);
        $('#imgWidth').val(c.w);
        $('#imgHeight').val(c.h);
        $('#btnCrop').show();
    };
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="file" id="FileUpload1" accept=".jpg,.png,.gif" />
<br />
<br />
<table border="0" cellpadding="0" cellspacing="5">
    <tr>
        <td>
            <img id="Image1" src="" alt="" style="display: none" />
        </td>
        <td>
            <canvas id="canvas" height="5" width="5"></canvas>
        </td>
    </tr>
</table>
<br />
<input type="button" id="btnCrop" value="Crop" style="display: none" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" Style="display: none" />
<input type="hidden" name="imgX1" id="imgX1" />
<input type="hidden" name="imgY1" id="imgY1" />
<input type="hidden" name="imgWidth" id="imgWidth" />
<input type="hidden" name="imgHeight" id="imgHeight" />
<input type="hidden" name="imgCropped" id="imgCropped" />
    </div>
    </form>
</body>
</html>



ADD NAME SPACE

using System.IO;



 protected void Upload(object sender, EventArgs e)
    {
        string base64 = Request.Form["imgCropped"];
        byte[] bytes = Convert.FromBase64String(base64.Split(',')[1]);
        using (FileStream stream = new FileStream(Server.MapPath("~/Images/Cropped.png"), FileMode.Create))
        {
            stream.Write(bytes, 0, bytes.Length);
            stream.Flush();
        }
    }

Software/System Development Life Cycle

SDLC: System Development Life Cycle is the process of developing, implementing, and retiring information systems through a multistep process from initiation, analysis, design, implementation, and maintenance to disposal. It helps in establishing a system project plan, because it gives an overall list of processes and sub-processes required for developing a system, which means that it is a combination of various activities. In the System Analysis
and Design terminology, the system development life cycle also means software development life cycle.

OR

We can say that it is the conceptual model that describes the stages involved in an information system development project in project management.

Why SDLC is necessary?

Software Development Life Cycle (SDLC) is recognized by different website and software developers all over the world. However there's always a question of the need to implement this type of planning. We all know that SDLC could help us answer specific needs of different users. That is a given. But could that problem be answered when you are already familiar with that specific difficulty? In-house developers could even create the software on their own without consultation to users since they are also a part of the user group and has a clear understanding of what is needed. Clearly, SDLC is not needed to create software in this environment.

Various SDLC methodologies have been developed to guide the processes involved including the waterfall model (the original SDLC method), rapid application development (RAD), joint application development (JAD), the fountain model and the spiral model. 

Various System Development Life Cycle models are:
  1. Waterfall Software Development Life Cycle Model
  2. Prototyping Software Development Life Cycle Model
  3. Iterative Enhancement Model
  4. The Spiral Model
  5. Object Oriented Methodology
  6. V- Model Methodology
  7. Joint application development (JAD)
  8. Rapid application development (RAD)

From the above models first the SDLC method that describes the various phases involved in the development is the classic Waterfall model methodology which is shown below:

SDLC1.gif




SDLC2.gif





SDLC3.gif


SDLC4.gif



SDLC5.gif
SYSTEM DEVELOPMENT LIFE CYCLE:
SDLC6.gif 


Now let's discuss System Development Life Cycle with its different Phases in detail:
SDLC7.gif 


Phases:
  1. SYSTEM STUDY

    a) Preliminary System Study
    b) Feasibility Study
    c) Detailed System Study
    d) System Analysis
    e) System Design
     
    • Preliminary or General Design
    • Structured or Detailed Design
  2. CODING
  3. TESTING

    • Program Test
    • System Test
     
  4. IMPLEMENTATION
  5. MAINTAINANCE

SYSTEM STUDY:
1. Preliminary System Study: As the name says it is the first stage of a system development life cycle, a brief investigation of the system under consideration and gives a clear picture of what actually the physical system is? It involves the preparation of a 'System Proposal' which lists the Problem Definition, Objectives of the Study, Terms of reference for Study, Constraints, Expected benefits of the new system, etc. A System Analyst will prepare the proposal and cycle proceeds to the next stage. It depends on the management to accept it; they also reject it or request some modifications in the proposal. Actually a system study phase passes through the following steps:
  • Problem identification and project initiation
  • Background analysis
  • Inference or findings (system proposal)

2. Feasibility Study: If the proposal is accepted by the management then the next phase is to examine the feasibility of the system. In this phase the software analysts and strategy makers establish a descriptive view of the intended project and determine its goals & objectives. If the project is to proceed, the feasibility study will produce a project plan and budget estimates for the future stages of development. The main goal of feasibility study is not to solve the problem but to achieve the scope. In the process of feasibility study, the cost and benefits are estimated with greater accuracy to find the Return on Investment (ROI).

3. Detailed System Study: In accordance with the objectives of the proposed system the detailed investigation of the system is carried out. Various operations performed by a system and their relationships within and outside the system. In this process data are collected on the available files, decision points and transactions handled by the present system. It becomes easy to draw the exact boundary of the new system under consideration by following the steps below:
  • Keeping in view the problems and new requirements
  • Workout the pros and cons including new areas of the system

There should be proper documentation of all the data and the findings in the form of
detailed data flow diagrams (DFDs), data dictionary, logical data structures and miniature specification. The important points that should be discussed in this stage are:
  • Specification of what the new system is to accomplish based on the user requirements.
  • Functional hierarchy showing the functions to be performed by the new system and their relationship with each other.
  • Functional network, which are similar to function hierarchy but they highlight the functions which are common to more than one procedure.
  • List of attributes of the entities – these are the data items which need to be held about each entity (record).

4. System Analysis: In this phase there is a main role of system analyst, he is the one who should analyze the end-user information needs and prepare a solid plan. Analysis gathers the requirements for the system. This stage includes a detailed study of the business needs of the organization. Options for changing the business process may be considered. In other words it is a process of collecting factual data, understand the processes involved, identifying problems and recommending feasible suggestions for improving the system functioning. It also includes subdividing of complex process involving the entire system, identification of data store and manual processes. The major objectives of systems analysis are to find answers for each business process: What is being done? How is it being done? Who is doing it? When is he doing it? Why is it being done? and How can it be improved? It is more of a thinking process and involves the creative skills of the System Analyst.

5. System Design: System Design is the most crucial phase in the development of System Software. After the detailed analysis of the existing system and requirement of the user, the new system must be designed, that's why the name of this phase is "System Design". The logical system design arrived at as a result of systems analysis is converted into physical system design. Normally, the design proceeds in two stages:
  • Preliminary or General Design
  • Structured or Detailed Design

a. Preliminary or General Design: The specification of the features of the new system and the cost estimation in implementing these features of the system are estimated in this stage. And if the project is still considered to be feasible, we move to the detailed design stage.

b. Structured or Detailed Design: The design of the system becomes more structured at this stage. Structured design is a blueprint of a computer system solution to a given problem having the same components and inter-relationships among the same components as the original problem. Input, output, databases, forms, codification schemes and processing specifications are drawn up in detail.
In the design stage, the programming language and the hardware and software platform in which the new system will run are also decided.

The various tools and techniques used to describe the system design are:
  • Flowchart
  • Data flow diagram (DFD)
  • Data dictionary
  • Structured English
  • Decision table
  • Decision tree

The System design involves the following steps:
  1. Defining precisely the required system output
  2. Determining the data requirement for producing the output
  3. Determining the medium and format of files and databases
  4. Devising processing methods and use of software to produce output
  5. Determine the methods of data capture and data input
  6. Designing Input forms
  7. Designing Codification Schemes
  8. Detailed manual procedures
  9. Documenting the Design

CODING

The system design needs to be implemented to make it a workable system which means that once the design is complete, this demands the coding of design into computer understandable language i.e. programming language, that's why this phase is also known as a programming phase. The goal of the coding phase is to translate the design of the system into code in a given programming language. For a given design, the aim of this phase is to implement the design in the best possible manner. The coding phase affects both testing and maintenance profoundly. A well written code reduces the testing and maintenance effort. As the cost of testing and maintenance is much higher than the coding cost, the goal of coding should be to reduce the testing and maintenance effort. Hence, during coding the focus should be on developing programs that are easy to write. Simplicity and clarity should be strived for, during the coding phase. It is an important stage where the defined procedures are transformed into control specifications by the help of a computer language. It is generally felt that the programs must be modular in nature. This helps in fast development, maintenance and future changes, if required.

TESTING

The main thrust of the approach is to intensively test the front end in the first two releases, thus raising approximately 80% of errors in this period. Software testing is a process of verifying and validating that a software application or program meets the business and technical requirements that guided its design and development, and works as expected.

Formal review points in testing:

SDLC8.gif

The diagram above outlines the Test Approach. Boxes 1 - 6 show the major review stages prior to Test execution. Boxes 7 - 10 show the phases planned for & after test execution.

It is an important phase of a successful system. After codifying the whole programs of the system, a test plan should be developed and run on a given set of test data. The output of the test run should match the expected results. Using the test data following test run are carried out:
  • Program Test
  • System Test

Program Test: In program test the programs must be individually tested with the prepared test data at the time of coding, compiling and brought to working conditions. Any undesirable happening must be noted and debugged (error corrections).

System Test: After the program test for each program of the system, and also the errors are removed then its turn for System test. In this the test is done on actual data. The complete system is executed on the actual data. At each stage of the execution, the results or output of the system is analyzed. At the time of result analysis, it may be found that the outputs are not matching the expected output of the system. In such case, the errors in the particular programs are identified and are fixed and further tested for the expected output.

IMPLEMENTATION

After having the user acceptance of the new system developed, the Implementation Phase begins. In the implementation phase, the organization configures and enables system security features, tests the functionality of these features, installs or implements the system, and obtains a formal authorization to operate the system. Design reviews and system tests should be performed before placing the system into operation to ensure that it meets all required security specifications. In addition, if new controls are added to the application or the support system, additional acceptance tests of those new controls must be performed. This approach ensures that new controls meet security specifications and do not conflict with or invalidate existing controls. The results of the design reviews and system tests should be fully documented, updated as new reviews or tests are performed, and maintained in the organization's official records.

The major steps involved in this phase are:
  • Acquisition and Installation of Hardware and Software
  • Conversion
  • User Training
  • Documentation

During this phase, all the programs of the system are loaded onto the user's computer. After loading the system, training of the user starts. Main topics of such type of training are:
  • How to execute the package
  • How to enter the data
  • How to process the data (processing details)
  • How to take out the reports

After the users are trained about the computerized system, working has to shift from manual to computerized working. The process is called 'Changeover'. The following strategies are followed for changeover of the system:
  • Direct Changeover
  • Parallel Run
  • Pilot Run

MAINTENANCE

It is the least glamorous and perhaps most important step of all, goes forever during whole system life. Inevitably the system will need maintenance. Software will definitely undergo change once it is delivered to the customer. There are many reasons for the change. Change could happen because of some unexpected input values into the system. In addition, the changes in the system could directly affect the software operations. The software should be developed to accommodate changes that could happen during the post implementation period. Maintenance is necessary to eliminate errors in the system during its working life and to tune the system to any variations in its working environments. It has been seen that there are always some errors found in the systems that must be noted and corrected. It also means the review of the system from time to time. The review of the system is done for:
  • Knowing the full capabilities of the system
  • Knowing the required changes or the additional requirements
  • Studying the performance.

If a major change to a system is needed, a new project may have to be set up to carry out the change. The new project will then proceed through all the above life cycle phases.

Tuesday, 17 February 2015

Interview Phase

Last week I attended an interview with Infosys, Chennai. When I entered the compound, there were very many candidates. The atmosphere and culture in Infosys was very nice.
Please find the original article here :

Background
I have attended many interviews in my life. But the interview with Infosys was something different. I thought to share that experience with you all.

Points to be remember (There are some mistakes I made in the interview. I don't want you to do the same :) )
  1. Please ensure that you are maintaining eye contact with the interviewer.
  2. Be confident of what you say. Don't change your answer if the interviewer tries to make you do so.
  3. Please avoid the unwanted examples.
  4. Please never use any other technical terms that may provoke the interviewer into asking questions about.
  5. If you don't know the answer, please say "I don't know". It is always better to say so instead of going with the wrong answer.


Questions asked and answers 

(Here I am giving the answers that I answered .)

1. Tell me about yourself?

A. You can find many answers to this question in the internet. Please see the following link:


2. What is your role in your project? What is the team size?

A. I said "My main role is coding, unit testing, big fixing and maintenance. My team size is 7".

3. What is the hierarchy of your team?

A. First I was confused by this question. Then I answered "Project Manager, Team Leader, Software Engineers, Trainees".

4. Describe the projects that you have worked on?

A. I described them. Please include the technologies you used in your projects and what kind of architecture (for example: 3-tire, n- tier) you used.

5. What is the employee size in your company? You don't need to be accurate. You can provide the approximate value.

A. I said "150 to 200".

Then he moved to the programming section.

6. Write an algorithm and program to determine whether or not a word is a palindrome.

We can do it in either of the following two ways:

a) Using a built-in function as in the following:
  1. string strRev,strReal = null;  
  2. Console.WriteLine("Enter the string..");  
  3. strReal = Console.ReadLine();  
  4. char[] tmpChar = strReal.ToCharArray();  
  5. Array.Reverse(tmpChar);  
  6. strRev=new string(tmpChar);  
  7. if(strReal.Equals(strRev, StringComparison.OrdinalIgnoreCase))  
  8. {  
  9.     Console.WriteLine("The string is pallindrome");  
  10. }  
  11. else  
  12. {  
  13.     Console.WriteLine("The string is not pallindrome");  
  14. }  
  15.     Console.ReadLine();  


b) Without using a built-in function.

When I wrote the first program, the interviewer asked me to write the same without using a built-in function.
  1. private static bool chkPallindrome(string strVal)  
  2.        {  
  3.            try  
  4.            {  
  5.                int min = 0;  
  6.                int max = strVal.Length - 1;  
  7.                while (true)  
  8.                {  
  9.                    if (min > max)  
  10.                        return true;  
  11.                    char minChar = strVal[min];  
  12.                    char maxChar = strVal[max];  
  13.                    if (char.ToLower(minChar) != char.ToLower(maxChar))  
  14.                    {  
  15.                        return false;  
  16.                    }  
  17.                    min++;  
  18.                    max--;  
  19.                }  
  20.            }  
  21.            catch (Exception)  
  22.            {  
  23.                  
  24.                throw;  
  25.            }  
  26.        }  
7. Write a program to determine the count of a specific character in a string.

A.
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace FindCountCharOccurance  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             string strOccur,strChar = null;  
  13.             Console.WriteLine("Enter the string in which you need to find the count of a char occurance");  
  14.             strOccur = Console.ReadLine();  
  15.               
  16.             Console.WriteLine("Enter the char to be searched..");  
  17.             strChar = Console.ReadLine();  
  18.             int intCnt =strOccur.Length- strOccur.Replace(strChar, string.Empty).Length;  
  19.             Console.WriteLine("Count of occurance is "+intCnt);  
  20.             Console.ReadLine();  
  21.         }  
  22.     }  
  23. }  

8. Next he gave me a program like the following and asked me what the output of this will be.
  1. public class A  
  2.     {  
  3.         public int A()  
  4.         {  
  5.             Console.WriteLine("Hi you are in class A");  
  6.         }  
  7.     }  
A. I said "Here we have a constructor A; a constructor should not have a return type. So the code above will throw a compilation error."

9. What may be the output of the following program?
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace RefClass  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.             B bObj= new B();  
  13.             Console.ReadLine();  
  14.   
  15.         }  
  16.     }  
  17.     public class A  
  18.     {  
  19.         public  A()  
  20.         {  
  21.             Console.WriteLine("Hi you are in class A");  
  22.         }  
  23.     }  
  24.   
  25.     public class B:A  
  26.     {  
  27.         public B()  
  28.         {  
  29.             Console.WriteLine("Hi you are in class B");  
  30.         }  
  31.     }  
  32. }  
A. I said the output will be:

Hi you are in class A

Hi you are in class B

Even though you are creating an object of the derived class, it will invoke the base class first.

10. Write the output of the following program.
  1. class Program  
  2.     {  
  3.         static void Main(string[] args)  
  4.         {  
  5.             B bObj= new B(2);  
  6.             Console.ReadLine();  
  7.   
  8.         }  
  9.     }  
  10.     public class A  
  11.     {  
  12.         public  A()  
  13.         {  
  14.             Console.WriteLine("Hi you are in class A");  
  15.         }  
  16.   
  17.         public A(int x)  
  18.         {  
  19.               
  20.         }  
  21.     }  
  22.   
  23.     public class B:A  
  24.     {  
  25.         public B()  
  26.         {  
  27.             Console.WriteLine("Hi you are in class B");  
  28.         }  
  29.     }  
A. It will throw a compilation error.

B does not contain a constructor that takes 1 argument. If you want to make this program run, you must create a parameterized constructor for class B also.

11. Abstract and interface real time examples

B.Please read it here: Real time example of interface

12. Describe authentication, types, differences?

A. Forms, Windows, Passport. Please read more here: ASP.NET authentication and authorization
13. Why DBMS? Why don't we save data in separate files?

A. I didn't know what exactly he meant, I got stuck there for a while. Finally I came up with the answer that "Normalization" is the main advantage of a DBMS.

Read more here: Why use a DBMS?

14. What is the differences between a Primary key and a Unique key?

A. Primary key doesn't allow NULL, a unique key does.

15. What exactly is happening when we make a field a primary key?

A. A clustered index will be created for that specific field.

16. How may clustered index we can create in table?

A. Basically we can create only one clustered index, but there is a way to have more. Please read here: Only one clustered index can be created on table <Tablename>. (Visual Database Tools)

17. What is the difference between a clustered and a non-clustered index?

A. I explained, please read here: Clustered and Non-Clustered Index in SQL 2005

18. What is a Distributed System?

A. A collection of autonomous computers.
19. What will be the output for the below mentioned lines in JQuery?
     
  1. alert('5' + 5 + 5);  
  2. alert(5 + 5 + '5');  
  3. alert(5 + '5' + '5');  
  4. alert(5 + '5' );  
That was little tricky at that time. For a while I thought, and I just wrote the question to a paper, and replied.       
  1. alert('5' + 5 + 5);    Output= 555  
  2. alert(5 + 5 + '5');    Output=105  
  3. alert(5 + '5' + '5');  Output=555  
  4. alert(5 + '5' );       Output=55  
Hmmm finally he said "You are selected for the next round" :)

Next was the direct HR round. That was a simple round. He just asked me to fill in some forms.