Thursday, 22 August 2013

How to insert records in Access table using Asp.Net


 protected void Button2_Click(object sender, EventArgs e)
    {

        try
        {

            OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\NWIND2.accdb");
            con.Open();
//if you want selected columns :
//I have created student table having stud_name,stud_address,stid(autoincremented)
            String q = "insert into student(stud_address)  values(@ad)";
            OleDbCommand cmd = new OleDbCommand(q, con);
            cmd.Parameters.AddWithValue("@ad", "meerut");

            if (cmd.ExecuteNonQuery() > 0)
                Response.Write("inserted");
            else
                Response.Write("not inserted");

        }
        catch (Exception ee) { }
    }

How to send mail using gmail authentication in Asp.Net



using System.Net;
using System.Net.Mail;
using System.Text;
using System.IO;
using System.Data.OleDb;




    protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage mailMsg = new MailMessage();
            mailMsg.From = new MailAddress("brijeshmalasi@yahoo.com", "Gedutech");
            mailMsg.To.Add( new MailAddress("brjmalasi@gmail.com","global"));
         
            mailMsg.Subject = "hello";
            mailMsg.IsBodyHtml = true;
            mailMsg.BodyEncoding = Encoding.UTF8;
            mailMsg.Body = "this is test mail";
            mailMsg.Priority = MailPriority.Normal;
            mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
            SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
            client.Credentials = new NetworkCredential("your gmail id", "password");
            client.EnableSsl = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            //you can also call client.Send(msg)
            client.Send(mailMsg);
           response.write("Sent");
        }
        catch (SmtpException ee)
        {
            Response.Write(ee);
        }


    }


Saturday, 17 August 2013

How to create pdf file in ASP.NET

If you want to insert image in pdf file using iTextSharp :

var image = iTextSharp.text.Image.GetInstance(Server.MapPath('your image path'));

// where u want your image  (x,y pixels)
image.SetAbsolutePosition(300,300);

document.Add(image)


*************here is code*******

 String imgname = (grid1.Rows[i].Cells[1].FindControl("imagelarge") as System.Web.UI.WebControls.Image).ImageUrl.ToString();
                        //var logo = iTextSharp.text.Image.GetInstance(Server.MapPath(imgname));
                        //Response.Write("img="+imgname);
                        totRequest += "<tr><td><img src="+Server.MapPath(imgname)+" height='100' width='100'></td>";
                        String pname = (grid1.Rows[i].Cells[2].FindControl("name") as Label).Text;
                        totRequest = totRequest + "<td>" + pname;
                        String color = (grid1.Rows[i].Cells[3].FindControl("col") as Label).Text;

Wednesday, 14 August 2013

How to Pass and returns objects via function in C#.Net


class Person
    {
        public int a, b;

        public Person(int x,int y)
        {
            a = x;
             b=y;
        }
        public Person() { }
        public static Person sum(Person pp, Person hh)
        {
            int x = pp.a + hh.a;
            int y = pp.b + hh.b;

            Person temp = new Person();
            temp.a = x;
            temp.b = y;
            return temp;
      //return "a="+a+"b="+b;
        }
         
    }


class A
{
static void Main(String []st)
 {

   Person pp = new Person(34, 60);
            Person hh = new Person(2, 5);

           Person ans = Person.sum(pp, hh);
           MessageBox.Show("a="+ans.a + "b=" + ans.b);
       

}
}


Tuesday, 6 August 2013

C# Dot Net Assignment



TASK FIRST 

Creata a form  as mentioned below in C#.

It will ask name Customer Name,Customer AccNo, Customer Bal, Customer Address.when you click on submit button all details must submit in class object using Constructor function. Class is as follows:
Class Bank
  {
  String name,address;
Int  accno,bal;
                Bank(String na,String add,int ano,int bal){  input data }
                Withdraw( int amt) {with amt}
Deposit(int amt) {dep amt}
checkStatement(int accno) {check statement here }
}

Further, when user click on deposit a new window should appear asking deposit amt .
Same should be followed in case of withdraw amt but in withdraw a module it must take care that if amt is not sufficient to be withdrawn an “warning message must display on MSG box”.

How to send Email By php when user fill registration Form


NOTE : you need to download  "class_email.php" file and save it in your main folder.

Here html form for Users:

********************************index.html***********************


<h5>Registraton Form</h5>
<form method="post" action="insert.php" id="ff" class="well span2" style="padding:10px 10px 10px 10px;margin-left:0px;margin-top:0px" >
<label>Your Name :</label><input type=text class="span2" required id="user" name="user" placeholder="Name :">
<label>Mobile No :</label><input type=text class="span2" required name="mob" id="mob" placeholder="Mobile No :">
<label>Email ID :</label><input type=text class="span2" required name="email" id="email" placeholder="Email ID :">
<label>Select Course</label>
<select class="span2" id="crs" name="crs" style="background:white;border:1px solid white;color:black">
<option value="" selected>-select-</option>
<option value="Career Courses">Career Course</option>
<option value="Training Programs">Training programs</option>
</select>
<label>Select Technology</label>
<select class="span2" id="tech" name="tech" style="background:white;border:1px solid white;color:black">
<option value="" selected>-select-</option>
<option value="android">Android</option>
<option value="C#net">.Net C#</option>
<option value="aspNet">Asp.Net</option>
<option value="phpMsql">Php,MySql</option>
<option value="jquery">Jquery</option>
<option value="htmlJavaCss">Html,JavaScript,CSS</option>
<option value="java">Java</option>
<option value="AjaxWebService">Ajax,WebServices</option>
<option value="WordPress">WordPress</option>
<option value="LinqWpfMvc">Linq,Wpf,Mvc</option>
</select>
<button id="bt" class="btn btn-primary">Submit</button>
<input type=reset value=reset class="btn">
</form>





**************************index.html ended here ***********************


Here is php Code sending Mail.


php file name : insert.php

<?php


$name = $_POST["user"];
$mobile = $_POST["mob"];
$email = $_POST["email"];
$course = $_POST["crs"];
$tech = $_POST["tech"];

//echo "hi, Your name is :$name \n mob:$mobile \n email:$email \n course : $course \n tech:$tech";

include( 'class_email.php');

     $ee= new email();

//below is your Server details with port number.

  $ee->set_server('smtp.gmail.com', 465); //465,597,25 ()


//In below line you have to specify your google valid email and password
  $ee->set_auth('abc@gmail.com','password');


  $ee->set_sender( 'sender Details here ', 'sender Mail here' );

//In array() function mention your list to whom you want to send email: you can specify more than one
//like below

$send_to =array('abc@yahoo.com','xyz@gmail.com','pqr@gmail.com');
  $subject = "Enquiry Mail:GEdutech";
  $body="<div style='border:2px solid blue'><table border='0' cellpadding='10'> <tr> <td>Enquiry Name  </td><td>$name</td></tr>
  <tr> <td>Mobile No: </td><td>$mobile</td></tr>
   <tr> <td>Email :  </td><td>$email</td></tr>
  <tr> <td>Course </td><td>$course</td></tr>
   <tr> <td>Technology  </td><td>$tech</td></tr></table> </div>";


  if( $ee->mail($send_to, $subject,$body))
  {
echo true;
}
 else
 {
echo false;
}


?>


String Questions : Java, C#,C, C++


Strings :
1)Write a program to do the following :
1)To output the question “Who is the inventor of JAVA ?”.
2)To accept an answer.
3)To print out “Good” and then stop, if the answer is correct.
4)To output the message “try again”, if the answer is wrong.
5)To display the correct answer when the answer is wrong even at the third attempt and stop.
2)Write a program to extract a portion of a character string and print the extracted string. Assume  that m characters are extracted , starting with the nth character.

3)Write a program, which will get text string and count all occurrences of a particular word.
4)Write a program to read the price of an item in decimal form (like 75.95) and print the output in paise (like  7595 paise).


Questions on Classes and Objects


Classes and objects:

1)Define a class to represent a book in a library. Include the following members:
Data Members
Book Number,Book Name,Author,Publisher,Price,No of copies, No.of copies issued
Member functions
1)To assign initial value                                  2)To issue a book after checking for its availability
3)To return a book                                          4)To display book information

2)Declare a class to represent fixed deposit account of 10 customers with the following data memers :
Name of the depositor, Account Number, Timer Period (1 or 4 or 5 years), Amount. The class also contains following member function:
a)To initialize data members                                       b)For withdrawl of money (after half of the time period has passed)
c)To display the data members

3)Define a class to represent batsmen in a cricket team.Include the following members:
Data Members :
First Name, Last Name, Runs made, Number of fours, Number of sixes.
Member functions
1)To assign the initial values
2)To update runs made (It should simultaneously update fours and sixes, if required )
3)To display the batsman’s information
Make appropriate assumption about access labels

4)Write a program to manage a rooms statistics. The room class includes the following members :
Data Members :
Length, Width, Height
Member Functions :
a)To assign initial values                                                                b)To calculate area
c)To display information (length,width,height & area)

5)Declare a class to represent bank account of 10 customers with the following data members. Name of the depositor, Account Number, Type of account(S for savings and C for Current ), Balance amount. The class also contains member functions to do the following :
1)To initialize data members                       2)To deposit money
3)To withdraw money after checking the balance (min.balance in Rs.1000)
4)To display the data members.

6)Define a class worker with the following specification :
Wname                25 characters
hrwrk,wgrate    float(hours worked and wagerate per hour)
totwage                               float(hrwrk * wgrate)
calcwg()               A function to find hrwrk * wgrate with float return type
Public member function of class worker
                in_data()                             a function to accept values for wno,wname,hrwrk,wgrate and invoke calcwg() to calculate totwage
Out_data()         a function to display all the data members on the screen you should give definitions of functions.

7)Define a class teacher with the following specification :
a)name                                                20 characters
b)subject                             10 characters
c)Basic,Da,Hra                   float
d)salary                                                float
                Calculate() function computes the salary and returns it.
Salary is sum of Basic,DA, HRA
public members:
ReadData()function accepts the data values and invoke the calculate functions.
DisplayData() function prints the data on the screen
8)Define a class student with the following specification:
Private mebers :
Roll_no                                 integer
name                                    20 characters
class                                       8 characters
marks[5]                              integer
Percentage                         float
Calculate() function that calucates overall percentage of marks and returns the percentage of marks
Public members:
ReadMarks() a function that reads marks and invokes the calculate functions
Displaymarks() a functions that prints the marks

9)Imagine a ticket selling booth at a fair. People passing by are requested to purchase a ticket. A ticket is priced as Rs.2.50/.The booth keeps track of the number of people that have visited the booth, and of the  total amount of money collected.
Model this ticketselling booth with a class called ticbooth including the following members :
Data Members :
1)number of people visited
2)total amount of money collected.
Member Functons:
1) To assign initial values(assign 0 to both data members )
2)To increment only people total in case ticket is not sold out.
3)To increment people total as well as amount total if a ticket is sold out.
4)To display the two totals
5)To display the number of tickets sold out(a tricky one)

10) Write a C # program to perform various operations on  a string class without using without using lanugae supported built in string functions. The operations on a class are:
a)Read a string                                  b)Display  the string
c)Reverse the stirng                       d)Copy the string into an empty string
e)Concatenate two strings.


11)A book shop maintains the inventory of books that are being sold at the shop. The list includes details such as author, title , price,publisher and stock position.Whenever a customer want a book, the sales person inputs the title and author and the system searches the list and displays whether it is available or not. If it is not, an appropriate message is displayed.If it is then the system displays the book details and requests for the number of copies required. If the requested copies are available, the total cost of the required copies is displayed, otherwise the message “Sorrry”! These many copies are not in stock” is displayed.
Design a system using a class called stock with suitable member functions and constructors.


12)Imagine a publishing company that markets both books and audio-cassette versions of its works. Create a class publication that stores the title and price of a publication.From this class derive two classes : BOOK which adds a page count and TAPE which adds a playing time in minutes. Each of these three classes should have a getdata() functions to get its data from the user at the keyboard and a putdata() function to display its data. Write a main() program to test the book and tape classes by creating instances of them, asking the user to fill in their data with getdata() and then displaying the data with putdata().
3)Write a C sharp to read and display information about employees and managers.EMPLOYEE is a class that contains employee number, name, address and department. Manager class contains all information of the employee class and a list of employees working under a manger.