Guest User

Lab Manual

a guest
Apr 16th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.44 KB | None | 0 0
  1. 1. PROGRAM TO ACCEPT STUDENTS REGNO,NAME AND MARKS AND DISPLAY THE REQUIRED DETAILS OF THE STUDENT
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections;
  5. using System.Text;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int[] rno = new int[20];
  14. int i = 0, hm = 0, pos = 0, ch = 0, cnt = 0;
  15. ArrayList name = new ArrayList();
  16. int[] m1 = new int[20];
  17. int[] m2 = new int[20];
  18. int[] m3 = new int[20];
  19. int[] total = new int[20];
  20. char ans;
  21. do
  22. {
  23. Console.Clear();
  24. cnt = cnt + 1;
  25. Console.WriteLine("ENTER REGNO AND NAME");
  26. rno[i] = int.Parse(Console.ReadLine());
  27. name.Add(Console.ReadLine());
  28. Console.WriteLine("ENTER THREE SUB MARKS");
  29. m1[i] = int.Parse(Console.ReadLine());
  30. m2[i] = int.Parse(Console.ReadLine());
  31. m3[i] = int.Parse(Console.ReadLine());
  32. total[i] = m1[i] + m2[i] + m3[i];
  33. if (total[i] > hm)
  34. {
  35. hm = total[i];
  36. pos = i;
  37. }
  38. Console.WriteLine("DO YOU WANT TO CONTINUE ? (Y/N)");
  39. ans = char.Parse(Console.ReadLine());
  40. i = i + 1;
  41. }
  42. while (ans == 'y');
  43.  
  44.  
  45.  
  46. while (ch != 4)
  47. {
  48. Console.Clear();
  49. Console.WriteLine("MENU");
  50. Console.WriteLine("1.DISPLAY ALL STUDENTS DETAILS");
  51. Console.WriteLine("2.DISPLAY SYUDENTS WHO OBTAINED HIGHEST MARKS");
  52. Console.WriteLine("3.DISPLAY STUDENTS NAME IN ASCENDING OEDER");
  53. Console.WriteLine("4.EXIT");
  54. Console.WriteLine("ENTER YOUR CHOISE");
  55. ch = int.Parse(Console.ReadLine());
  56. switch (ch)
  57. {
  58. case 1:
  59. Console.WriteLine("REGNO NAME M1 M2 M3 TOTALMARKS");
  60. for (i = 0; i < cnt; i++)
  61. Console.WriteLine("{0,9} {1,-10} {2,-8} {3,-8} {4,-8} {5}", rno[i], name[i], m1[i], m2[i], m3[i], total[i]);
  62. break;
  63. case 2:
  64. Console.WriteLine("STUDENTS WHO SCORED HIGHEST MARKS");
  65. Console.WriteLine("REGNO:{0} \n NAME:{1} \n TOTALMARKS:{2}", rno[pos], name[pos], total[pos]);
  66. break;
  67. case 3:
  68. name.Sort();
  69. Console.WriteLine("STUDENTS NAME IN ASCENDING ORDER");
  70. for (i = 0; i < cnt; i++)
  71. Console.WriteLine(name[i]);
  72. break;
  73. case 4:
  74. break;
  75. }
  76. Console.ReadKey();
  77. }
  78. }
  79. }
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90. 2. PROGRAM TO DEMONSTRATE THE ACTIVITIES PERFORMED BY A SHOP KEEPER IN A BOOK SHOP
  91. using System;
  92. using System.Collections.Generic;
  93. using System.Text;
  94.  
  95. namespace ConsoleApplication2
  96. {
  97. class Book
  98. {
  99. string title;
  100. string author;
  101. int price;
  102. int sp;
  103. int noc;
  104. public Book()
  105. {
  106. sp = 0;
  107. }
  108. public void Addnew()
  109. {
  110. Console.WriteLine("ENTER TITLE OF THE BOOK AND AUTHOR NAME");
  111. title = Console.ReadLine();
  112. author = Console.ReadLine();
  113. Console.WriteLine("ENTER BOOK PRICE");
  114. price = int.Parse(Console.ReadLine());
  115. Console.WriteLine("ENTER NO OF COPIES");
  116. noc = int.Parse(Console.ReadLine());
  117. sp = sp + noc;
  118. }
  119. public void Addexist(string name, string athr, int n)
  120. {
  121. if (name == title && author == athr)
  122. sp = sp + n;
  123. }
  124. public int search(string name, string athr, int n)
  125. {
  126. if (name == title && author == athr)
  127. {
  128. int total = n * price;
  129. if (n > sp)
  130. Console.WriteLine("BOOK IS OUT OF STOCK");
  131. else
  132. Console.WriteLine("TOTAL AMOUNT" + total);
  133. return 1;
  134. }
  135. else return 0;
  136. }
  137. public void Disp()
  138. {
  139. Console.WriteLine("{0,-10} {1,-10} {2,-4} {3,6}", title, author, price, sp);
  140. }
  141. class Program2
  142. {
  143. static void Main(string[] args)
  144. {
  145. Book[] b = new Book[20];
  146. string t, a;
  147. int ch = 0, count = 1, flag, cs, n;
  148. while (ch != 5)
  149. {
  150. Console.Clear();
  151. Console.WriteLine("MENU");
  152. Console.WriteLine("1.ADD NEW BOOKS.\n2.ADD EXISTING \n3.SEARCH\n4.DISPLAY ALL\n 5.EXIT \n");
  153. Console.WriteLine("ENTER YOUR CHOICE");
  154. ch = int.Parse(Console.ReadLine());
  155. switch (ch)
  156. {
  157. case 1:
  158. b[count] = new Book();
  159. b[count].Addnew();
  160. count++;
  161. break;
  162. case 2:
  163. Console.WriteLine("ENTER BOOK TITLE,AUTHOR,NUMBER OF COPIES");
  164. t = Console.ReadLine();
  165. a = Console.ReadLine();
  166. n = int.Parse(Console.ReadLine());
  167. for (int i = 1; i < count; i++)
  168. b[i].Addexist(t, a, n);
  169. break;
  170. case 3:
  171. flag = 0;
  172. Console.WriteLine("ENTER BOOK TITLE,AUTHOR,NUMBER OF COPIES");
  173. t = Console.ReadLine();
  174. a = Console.ReadLine();
  175. n = int.Parse(Console.ReadLine());
  176. for (int i = 1; i < count; i++)
  177. {
  178. cs = b[i].search(t, a, n);
  179. if (cs == 1)
  180. flag++;
  181. }
  182. if (flag == 0)
  183. Console.WriteLine("BOOK NOT FOUND");
  184. break;
  185. case 4:
  186. Console.WriteLine("-----------------BOOK DETAILS---------------");
  187. Console.WriteLine("TITLE AUTHOR PRICE NO-OF-COPIES");
  188. for (int i = 1; i < count; i++)
  189. b[i].Disp();
  190. break;
  191. }
  192. Console.ReadKey();
  193. }
  194. }
  195. }
  196. }
  197. }
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224. 3. PROGRAM TO DISPLAY STUDENT DETAILS USING INDEXERS
  225. using System;
  226. using System.Collections.Generic;
  227. using System.Collections;
  228. using System.Text;
  229.  
  230. namespace ConsoleApplication3
  231. {
  232. class Program
  233. {
  234. static void Main(string[] args)
  235. {
  236. string name, regno, result;
  237. int m1, m2, m3, total;
  238. double avg;
  239. Console.WriteLine("ENTER THE NAME AND REGISTERNO");
  240. name = Console.ReadLine();
  241. regno = Console.ReadLine();
  242. Console.WriteLine("ENTER 3 SUBJECTS MARKS");
  243. m1 = int.Parse(Console.ReadLine());
  244. m2 = int.Parse(Console.ReadLine());
  245. m3 = int.Parse(Console.ReadLine());
  246. sample s = new sample();
  247. s["name"] = name;
  248. s["regno"] = regno;
  249. s[3] = m1;
  250. s[4] = m2;
  251. s[5] = m3;
  252. total = s[3] + s[4] + s[5];
  253. avg = total / 3;
  254. if (s[3] < 35 || s[4] < 35 || s[5] < 35 || avg < 40)
  255. result = "FAIL";
  256. else if (avg >= 80 && avg <= 100)
  257. result = "DISTINCTION";
  258. else if (avg >= 60 && avg <= 79)
  259. result = "FIRST CLASS";
  260. else if (avg >= 50 && avg <= 59)
  261. result = "SECOND CLASS";
  262. else
  263. result = "THIRD CLASS";
  264. Console.Clear();
  265. Console.WriteLine("STUDENT INFORMATION");
  266. Console.WriteLine("\n REGISTERNO:" + s["regno"]);
  267. Console.WriteLine("\n name:{0,-10}", s["name"]);
  268. Console.WriteLine("\n marks1:" + s[3]);
  269. Console.WriteLine("\n marks2:" + s[4]);
  270. Console.WriteLine("\n marks3:" + s[5]);
  271. Console.WriteLine("\n Total marks:" + total);
  272. Console.WriteLine("\n percentage:" + avg);
  273. Console.WriteLine("\n class:" + result);
  274. Console.ReadLine();
  275. }
  276. }
  277. }
  278. class sample
  279. {
  280. private string name, regno;
  281. private int m1, m2, m3;
  282. public string this[string index]
  283. {
  284. get
  285. {
  286. if (index == "name")
  287. return name;
  288. if (index == "regno")
  289. return regno;
  290. return null;
  291. }
  292. set
  293. {
  294. if (index == "name")
  295. name = value;
  296. else if (index == "regno")
  297. regno = value;
  298. }
  299. }
  300. public int this[int index1]
  301. {
  302. get
  303. {
  304. if (index1 == 3)
  305. return m1;
  306. else if (index1 == 4)
  307. return m2;
  308. else
  309. return m3;
  310. }
  311. set
  312. {
  313. if (index1 == 3)
  314. m1 = value;
  315. else if (index1 == 4)
  316. m2 = value;
  317. else m3 = value;
  318. }
  319. }
  320. }
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  
  340.  
  341.  
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362. 4. PROGRAM TO FIND DIFFERENCE AND SUM OF TWO MATRICIES USING DELEGATES
  363.  
  364. using System;
  365. using System.Collections.Generic;
  366. using System.Text;
  367.  
  368. namespace ConsoleApplication1
  369.  
  370. {
  371. delegate void mcast_del();
  372. public class add_sub
  373. {
  374. static int n;
  375. static int[,]matrix1=new int [10,10];
  376. static int[,]matrix2=new int [10,10];
  377. public void inputs()
  378. {
  379. Console.WriteLine("enter the ordr of matrix");
  380. n=int.Parse(Console.ReadLine());
  381. Console.WriteLine("enter the first matrix elements");
  382. for(int i=0;i<n;i++)
  383. for(int j=0;j<n;j++)
  384. matrix1[i,j]=int.Parse(Console.ReadLine());
  385. Console.WriteLine("enter the second elements of matrix");
  386. for(int i=0;i<n;i++)
  387. for(int j=0;j<n;j++)
  388. matrix2[i,j]=int.Parse(Console.ReadLine());
  389.  
  390. }
  391. public static void addition()
  392. {
  393. int[,] add=new int[10,10];
  394. for(int i=0;i<n;i++)
  395. for(int j=0;j<n;j++)
  396. add[i,j]=matrix1[i,j]+matrix2[i,j];
  397. Console.WriteLine("sum of two matrixes \n\n");
  398. for(int i=0;i<n;i++)
  399. {
  400. for(int j=0;j<n;j++)
  401. {
  402. Console.Write("\t"+add[i,j]);
  403. }
  404. Console.WriteLine("\n");
  405.  
  406.  
  407. }
  408.  
  409. }
  410. public static void subtraction()
  411. {
  412. int[,] sub=new int[10,10];
  413. for(int i=0;i<n;i++)
  414. for(int j=0;j<n;j++)
  415. sub[i,j]=matrix1[i,j]-matrix2[i,j];
  416. Console.WriteLine("subtraction of two matrixes \n\n");
  417. for(int i=0;i<n;i++)
  418. {
  419. for(int j=0;j<n;j++)
  420. {
  421. Console.Write("\t"+sub[i,j]);
  422. }
  423. Console.WriteLine("\n");
  424. }
  425. }
  426.  
  427. class program
  428. {
  429. static void Main(string[] args)
  430. {
  431. mcast_del m1=new mcast_del(add_sub.addition);
  432. mcast_del m2=new mcast_del(add_sub.subtraction);
  433. mcast_del m3=m1+m2;
  434.  
  435. add_sub obj=new add_sub();
  436. obj.inputs();
  437. m3();//invoking the multicast delegate
  438. Console.ReadKey();
  439. }
  440.  
  441. }
  442. }
  443. }
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454. 5. PROGRAM TO GENERATE ā€˜nā€™ EVEN NUMBERS AND FIBONACCI NUMBERS USING EVENTS
  455. using System;
  456. using System.Collections.Generic;
  457. using System.Text;
  458.  
  459. namespace ConsoleApplication1
  460. {
  461. public delegate void edel(int n);
  462. class event_class
  463. {
  464. public event edel status;
  465. public void event_triggared()
  466. {
  467. int n;
  468. Console.WriteLine("enter the value for N");
  469. n = int.Parse(Console.ReadLine());
  470. status(n);
  471. }
  472. }
  473.  
  474. class program
  475. {
  476. static void Main(string[] args)
  477. {
  478. program p = new program();
  479. event_class e = new event_class();
  480. e.status += new edel(p.event_catch);
  481. e.status += new edel(p.event_catch1);
  482. e.event_triggared();
  483. Console.ReadKey();
  484. }
  485. public void event_catch(int n)
  486. {
  487. Console.Clear();
  488. Console.WriteLine("the first {0} even numbers are",n);
  489. int count=2;
  490. for(int i=0;i<n;i++)
  491. {
  492. Console.WriteLine("\n"+count);
  493. count+=2;
  494. }
  495. }
  496. public void event_catch1(int n)
  497. {
  498. Console.WriteLine("\n \n the first {0} fibonacci numbers are", n);
  499. int f1 = 0, f2 = 1, f, count;
  500. Console.WriteLine("\n" + f1);
  501. Console.WriteLine("\n" + f2);
  502. for (count = 3; count <= n; count++)
  503. {
  504. f = f1 + f2;
  505. Console.WriteLine("\n" + f);
  506. f1 = f2;
  507. f2 = f;
  508.  
  509. }
  510. }
  511. }
  512. }
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544. 6. PROGRAM TO CREATE A BANK DATABASE SYSTEM
  545.  
  546. using System;
  547. using System.Collections.Generic;
  548. using System.Text;
  549. using System.Data.SqlClient;
  550.  
  551. class Program
  552. {
  553. static void Main(string[] args)
  554. {
  555. string source = "Data Source=VISHNU-PC;Initial Catalog=bank;Integrated Security=True";
  556. string qur1 = "SELECT * FROM customer";
  557. string qur2 = "SELECT acno,name FROM customer WHERE actype='sb'";
  558. string qur3 = "UPDATE customer SET balance=balance+500 WHERE balance>=10000";
  559. int choice;
  560. SqlConnection con = new SqlConnection(source);
  561. SqlCommand cmd1 = new SqlCommand(qur1, con);
  562. SqlCommand cmd2 = new SqlCommand(qur2, con);
  563. SqlCommand cmd3 = new SqlCommand(qur3, con);
  564. do
  565. {
  566. Console.Clear();
  567. Console.WriteLine("\t\t\t\t\n MENU ");
  568. Console.WriteLine("\t\t\n 1.Display all the records.");
  569. Console.WriteLine("\t\t\n 2.Display the information whose account type is SB.");
  570. Console.WriteLine("\t\t\n 3.Updating the record whose balance >=10000");
  571. Console.WriteLine("\t\t\n 4.Exit");
  572. Console.Write("\t\t\n\n Enter ur choice:");
  573. choice = int.Parse(Console.ReadLine());
  574. Console.Clear();
  575. switch (choice)
  576. {
  577. case 1: con.Open();
  578.  
  579. SqlDataReader rd = cmd1.ExecuteReader();
  580. Console.WriteLine("Acc_no\t\tNAME\t\tAc- TYPE\t\tBALANCE\n\n");
  581. while (rd.Read())
  582. {
  583.  
  584. Console.Write(rd[0]);
  585. Console.Write("\t\t" + rd[1]);
  586. Console.Write("\t\t" + rd[2]);
  587. Console.Write("\t\t" + rd[3]);
  588. Console.WriteLine("\n");
  589.  
  590. }
  591. con.Close();
  592. Console.ReadKey();
  593. break;
  594.  
  595. case 2: con.Open();
  596. SqlDataReader rd1 = cmd2.ExecuteReader();
  597. Console.WriteLine("Acc_no\tNAME\n\n");
  598. while (rd1.Read())
  599. {
  600.  
  601. Console.Write(" " + rd1[0]);
  602. Console.Write("\t" + rd1[1]);
  603. //Console.Write("\t " + rd1[2]);
  604. Console.WriteLine("\n");
  605. }
  606. con.Close();
  607. Console.ReadKey();
  608. break;
  609.  
  610. case 3: con.Open();
  611. int count = cmd3.ExecuteNonQuery();
  612. Console.WriteLine("No of Rows updated:" + count);
  613. Console.ReadKey();
  614. con.Close();
  615. break;
  616. }
  617. }
  618. while (choice != 4);
  619. }
  620.  
  621. }
  622.  
  623.  
  624.  
  625.  
  626.  
  627.  
  628.  
  629.  
  630.  
  631.  
  632.  
  633. 7. VALIDATE FORM FOR REGISTERED USERS TO ENTER DETAILS LIKE NAME,ADDRESS,GENDER AND DISPLAY THE DETAILS IN RICH TEXT BOX
  634. using System;
  635. using System.Collections.Generic;
  636. using System.ComponentModel;
  637. using System.Data;
  638. using System.Drawing;
  639. using System.Text;
  640. using System.Windows.Forms;
  641. using System.Data.SqlClient;
  642.  
  643. namespace WindowsApplication2
  644. {
  645.  
  646. public partial class Form1 : Form
  647. {
  648. SqlConnection con = new SqlConnection("Data Source=VISHNU-PC;Initial Catalog=student;Integrated Security=True");
  649. public Form1()
  650. {
  651. InitializeComponent();
  652. }
  653.  
  654. private void Form1_Load(object sender, EventArgs e)
  655. {
  656.  
  657. }
  658.  
  659. private void button2_Click(object sender, EventArgs e)
  660. {
  661. int a = int.Parse(textBox3.Text);
  662. int b = int.Parse(textBox4.Text);
  663. int c = int.Parse(textBox5.Text);
  664. int d = (a + b + c) / 3;
  665. textBox6.Text = d.ToString();
  666. if ((d >= 35) && (d <= 50))
  667. textBox7.Text = "pass class";
  668. else if ((d >= 51) && (d <= 60))
  669. textBox7.Text = "second class";
  670. else if ((d >= 61) && (d <= 75))
  671. textBox7.Text = "First class";
  672. else
  673. textBox7.Text = "distinction";
  674. }
  675.  
  676. private void button3_Click(object sender, EventArgs e)
  677. {
  678. con.Open();
  679. SqlCommand cmd = new SqlCommand("insert into stud values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "')", con);
  680. cmd.ExecuteNonQuery();
  681. MessageBox.Show("successfully inserted");
  682. con.Close();
  683. richTextBox1.Text = ("regno:" + textBox1.Text + "\n" + "name:" + textBox2.Text + "\n" + "m1" + textBox3.Text + "\n" + "m2" + textBox4.Text + "\n" + "m3" + textBox5.Text + "\n" + "percentage" + textBox6.Text + "\n" + "result:" + textBox7.Text);
  684. }
  685.  
  686. private void button1_Click(object sender, EventArgs e)
  687. {
  688. printDialog1.AllowSomePages = true;
  689. printDialog1.AllowCurrentPage = true;
  690. if(printDialog1.ShowDialog()==System.Windows.Forms.DialogResult.OK)
  691.  
  692. {
  693. printDocument1.PrinterSettings = printDialog1.PrinterSettings;
  694. printDocument1.Print();
  695. }
  696.  
  697. }
  698.  
  699. private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs i)
  700. {
  701. i.Graphics.DrawString(richTextBox1.Text,richTextBox1.Font,new SolidBrush(Color.Red),new Rectangle(50,50,i.PageBounds.Height
  702. ,i.PageBounds.Width));
  703. }
  704.  
  705. private void richTextBox1_TextChanged(object sender, EventArgs e)
  706. {
  707.  
  708. }
  709. }
  710. }
  711.  
  712.  
  713. 8. FORM TO DISPLAY STUDENT DETAILS FROM THE DATABASE
  714.  
  715. using System;
  716. using System.Collections.Generic;
  717. using System.ComponentModel;
  718. using System.Data;
  719. using System.Drawing;
  720. using System.Text;
  721. using System.Windows.Forms;
  722. using System.Data.SqlClient;
  723. namespace WindowsApplication3
  724. {
  725. public partial class Form1 : Form
  726. {
  727. SqlConnection con;
  728. public Form1()
  729. {
  730. InitializeComponent();
  731. }
  732.  
  733. private void Form1_Load(object sender, EventArgs e)
  734. {
  735. // TODO: This line of code loads data into the 'studentDataSet.stud' table. You can move, or remove it, as needed.
  736. this.studTableAdapter.Fill(this.studentDataSet.stud);
  737.  
  738. }
  739.  
  740. private void button1_Click(object sender, EventArgs e)
  741. {
  742. con = new SqlConnection("Data Source=VISHNU-PC;Initial Catalog=student;Integrated Security=True");
  743. con.Open();
  744. string sel = this.comboBox1.GetItemText(this.comboBox1.SelectedItem);
  745. SqlCommand cmd = new SqlCommand("select * from stud where regno='" + sel + "'", con);
  746.  
  747. SqlDataReader dr = cmd.ExecuteReader();
  748. while (dr.Read())
  749. {
  750.  
  751. textBox1.Text = dr[1].ToString();
  752. textBox2.Text = dr[5].ToString();
  753. textBox3.Text = dr[6].ToString();
  754. }
  755.  
  756. dr.Close();
  757. con.Close();
  758. }
  759.  
  760. private void button2_Click(object sender, EventArgs e)
  761. {
  762. textBox1.Text = "";
  763. textBox2.Text = "";
  764. textBox3.Text = "";
  765. }
  766.  
  767. private void textBox1_TextChanged(object sender, EventArgs e)
  768. {
  769.  
  770. }
  771.  
  772. private void textBox2_TextChanged(object sender, EventArgs e)
  773. {
  774.  
  775. }
  776.  
  777. private void textBox3_TextChanged(object sender, EventArgs e)
  778. {
  779.  
  780. }
  781. }
  782. }
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789.  
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.  
  797.  
  798.  
  799.  
  800. 9.PROGRAM TO VALIDATE USER LOGIN
  801.  
  802. using System;
  803. using System.Collections.Generic;
  804. using System.ComponentModel;
  805. using System.Data;
  806. using System.Drawing;
  807. using System.Text;
  808. using System.Windows.Forms;
  809.  
  810. namespace WindowsApplication4
  811. {
  812. public partial class Form1 : Form
  813. {
  814. Form2 f2 = new Form2();
  815. public Form1()
  816. {
  817. InitializeComponent();
  818. }
  819.  
  820. private void Form1_Load(object sender, EventArgs e)
  821. {
  822.  
  823. }
  824.  
  825. private void label1_Click(object sender, EventArgs e)
  826. {
  827.  
  828. }
  829.  
  830. private void button1_Click(object sender, EventArgs e)
  831. {
  832. if (textBox1.Text == "admin" && textBox2.Text == "admin")
  833. button2.Visible = true;
  834. else
  835. DialogResult = MessageBox.Show("Invalid User ID & Password", "Message", MessageBoxButtons.YesNo);
  836. if (DialogResult == DialogResult.Yes)
  837. {
  838. textBox1.Text = " ";
  839. textBox2.Text = " ";
  840. textBox1.Focus();
  841. }
  842. }
  843.  
  844. private void button3_Click(object sender, EventArgs e)
  845. {
  846. f2.Show();
  847. }
  848. }
  849. }
  850.  
  851.  
  852. //FORM2
  853.  
  854.  
  855. using System;
  856. using System.Collections.Generic;
  857. using System.ComponentModel;
  858. using System.Data;
  859. using System.Drawing;
  860. using System.Text;
  861. using System.Windows.Forms;
  862. using System.Data.SqlClient;
  863.  
  864. namespace WindowsApplication4
  865. {
  866. public partial class Form2 : Form
  867. {
  868. SqlConnection con;
  869. public Form2()
  870. {
  871. InitializeComponent();
  872. }
  873.  
  874. private void button1_Click(object sender, EventArgs e)
  875. {
  876.  
  877. if (textBox2.Text == textBox3.Text)
  878. {
  879. con.Open();
  880. SqlCommand cmd = new SqlCommand("insert into login values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')", con);
  881. cmd.ExecuteNonQuery();
  882. MessageBox.Show("Registration Successful");
  883. con.Close();
  884. }
  885. else
  886. MessageBox.Show("password Not Match");
  887. textBox2.Text = " ";
  888. textBox3.Text = " ";
  889. textBox2.Focus();
  890. }
  891.  
  892. private void Form2_Load(object sender, EventArgs e)
  893. {
  894. con = new SqlConnection("Data Source=VISHNU-PC;Initial Catalog=admin;Integrated Security=True");
  895. }
  896. }
  897. }
  898.  
  899.  
  900.  
  901.  
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912.  
  913.  
  914.  
  915.  
  916.  
  917.  
  918.  
  919.  
  920.  
  921.  
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.  
  929.  
  930.  
  931.  
  932.  
  933.  
  934.  
  935. 10.COMPANY WEBSITE TO DEMONSTRATE STATE MANAGEMENT
  936. //default//
  937.  
  938.  
  939. using System;
  940. using System.Data;
  941. using System.Configuration;
  942. using System.Web;
  943. using System.Web.Security;
  944. using System.Web.UI;
  945. using System.Web.UI.WebControls;
  946. using System.Web.UI.WebControls.WebParts;
  947. using System.Web.UI.HtmlControls;
  948.  
  949. public partial class _Default : System.Web.UI.Page
  950. {
  951. protected void Page_Load(object sender, EventArgs e)
  952. {
  953. Application["view"] = ((int)(Application["view"])) + 1;
  954. TextBox1.Text = Application["view"].ToString();
  955.  
  956.  
  957. }
  958. protected void TextBox1_TextChanged(object sender, EventArgs e)
  959. {
  960.  
  961. }
  962. }
  963.  
  964.  
  965.  
  966. //DEFAULT2
  967.  
  968. using System;
  969. using System.Data;
  970. using System.Configuration;
  971. using System.Collections;
  972. using System.Web;
  973. using System.Web.Security;
  974. using System.Web.UI;
  975. using System.Web.UI.WebControls;
  976. using System.Web.UI.WebControls.WebParts;
  977. using System.Web.UI.HtmlControls;
  978.  
  979. public partial class Default2 : System.Web.UI.Page
  980. {
  981. public double a, da, ta, hra, pf, loan, gs, ns;
  982. protected void Page_Load(object sender, EventArgs e)
  983. {
  984.  
  985. }
  986. protected void Button1_Click(object sender, EventArgs e)
  987. {
  988. if (TextBox1.Text == "111".ToString())
  989.  
  990. Panel1.Visible = true;
  991. else
  992. {
  993. TextBox1.Text = "";
  994. Session["s"] = ((int)(Session["s"])) + 1;
  995. int a1 = ((int)(Session["s"]));
  996.  
  997.  
  998. if (a1 == 3)
  999. Response.Redirect("Default3.aspx");
  1000. }
  1001.  
  1002. }
  1003. protected void Button2_Click(object sender, EventArgs e)
  1004. {
  1005. a = double.Parse(TextBox2.Text);
  1006. hra = (a * 0.08);
  1007. da = (a * 0.05);
  1008. ta = (a * 0.05);
  1009. pf = (a * 0.12);
  1010. loan = (a * 0.04);
  1011. gs = (a + hra + da + ta);
  1012. ns = gs - (pf + loan);
  1013. TextBox3.Text = da.ToString();
  1014. TextBox4.Text = hra.ToString();
  1015. TextBox5.Text = ta.ToString();
  1016. TextBox6.Text = loan.ToString();
  1017. TextBox7.Text = pf.ToString();
  1018. TextBox8.Text = gs.ToString();
  1019. TextBox9.Text = ns.ToString();
  1020.  
  1021.  
  1022.  
  1023. }
  1024. }
  1025.  
  1026.  
  1027.  
  1028. //GLOBAL
  1029.  
  1030. <%@ Application Language="C#" %>
  1031.  
  1032. <script runat="server">
  1033.  
  1034. void Application_Start(object sender, EventArgs e)
  1035. {
  1036. // Code that runs on application startup
  1037. Application["view"] = 0;
  1038.  
  1039. }
  1040.  
  1041. void Application_End(object sender, EventArgs e)
  1042. {
  1043. // Code that runs on application shutdown
  1044.  
  1045. }
  1046.  
  1047. void Application_Error(object sender, EventArgs e)
  1048. {
  1049. // Code that runs when an unhandled error occurs
  1050.  
  1051. }
  1052.  
  1053. void Session_Start(object sender, EventArgs e)
  1054. {
  1055. // Code that runs when a new session is started
  1056. Session["s"] = 0;
  1057.  
  1058. }
  1059. void Session_End(object sender, EventArgs e)
  1060. {
  1061. // Code that runs when a session ends.
  1062. // Note: The Session_End event is raised only when the sessionstate mode
  1063. // is set to InProc in the Web.config file. If session mode is set to StateServer
  1064. // or SQLServer, the event is not raised.
  1065. }
  1066.  
  1067. </script>
  1068.  
  1069.  
  1070.  
  1071.  
  1072. 11. ASP.NET APPLICATION TO DEMONSTRATE LOGIN CONTROL AND GRIDVIEW CONTROL
  1073.  
  1074.  
  1075. using System;
  1076. using System.Data;
  1077. using System.Configuration;
  1078. using System.Web;
  1079. using System.Web.Security;
  1080. using System.Web.UI;
  1081. using System.Web.UI.WebControls;
  1082. using System.Web.UI.WebControls.WebParts;
  1083. using System.Web.UI.HtmlControls;
  1084.  
  1085. public partial class _Default : System.Web.UI.Page
  1086. {
  1087. protected void Page_Load(object sender, EventArgs e)
  1088. {
  1089.  
  1090. }
  1091. protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
  1092. {
  1093. if (Login1.UserName == "admin" && Login1.Password == "admin")
  1094. e.Authenticated = true;
  1095. else
  1096. e.Authenticated = false;
  1097.  
  1098. }
  1099. }
  1100.  
  1101.  
  1102.  
  1103. //DEFAULT2
  1104.  
  1105.  
  1106. using System;
  1107. using System.Data;
  1108. using System.Configuration;
  1109. using System.Collections;
  1110. using System.Web;
  1111. using System.Web.Security;
  1112. using System.Web.UI;
  1113. using System.Web.UI.WebControls;
  1114. using System.Web.UI.WebControls.WebParts;
  1115. using System.Web.UI.HtmlControls;
  1116.  
  1117. public partial class Default2 : System.Web.UI.Page
  1118. {
  1119. protected void Page_Load(object sender, EventArgs e)
  1120. {
  1121.  
  1122. }
  1123. protected void Button1_Click(object sender, EventArgs e)
  1124. {
  1125. GridView1.Visible = true;
  1126. }
  1127. protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  1128. {
  1129.  
  1130. }
  1131. protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
  1132. {
  1133.  
  1134. }
  1135. }
  1136.  
  1137.  
  1138.  
  1139.  
  1140.  
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147.  
  1148.  
  1149.  
  1150.  
  1151.  
  1152.  
  1153.  
  1154.  
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161.  
  1162.  
  1163. 12.WEBSITE TO APPLY FOR A JOB USING VALIDATION CONTROL
  1164.  
  1165. using System;
  1166. using System.Data;
  1167. using System.Configuration;
  1168. using System.Web;
  1169. using System.Web.Security;
  1170. using System.Web.UI;
  1171. using System.Web.UI.WebControls;
  1172. using System.Web.UI.WebControls.WebParts;
  1173. using System.Web.UI.HtmlControls;
  1174. using System.Data.SqlClient;
  1175. public partial class _Default : System.Web.UI.Page
  1176. {
  1177. SqlConnection con;
  1178. SqlCommand cmd;
  1179. public string s1, s2, s3, s4, s5, s6, s7;
  1180. public void Data()
  1181. {
  1182. s1 = TextBox1.Text;
  1183. s2 = TextBox2.Text;
  1184. s3 = TextBox3.Text;
  1185. s4 = TextBox4.Text;
  1186. s5 = DropDownList1.SelectedItem.ToString();
  1187.  
  1188. if (RadioButton1.Checked)
  1189. s6 = "experienced";
  1190. else
  1191. s6 = "fresher";
  1192. s7 = TextBox5.Text;
  1193. }
  1194.  
  1195. protected void Page_Load(object sender, EventArgs e)
  1196. {
  1197. con = new SqlConnection("Data Source=VISHNU-PC;Initial Catalog=employer;Integrated Security=True");
  1198.  
  1199. }
  1200. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  1201. {
  1202.  
  1203. }
  1204. protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
  1205. {
  1206.  
  1207. }
  1208. protected void Button1_Click(object sender, EventArgs e)
  1209. {
  1210. Data();
  1211. con.Open();
  1212. cmd=new SqlCommand("insert into register values('"+s1+"','"+s2+"','"+s3+"','"+s4+"','"+s5+"','"+s6+"','"+s7+"')",con);
  1213. cmd.ExecuteNonQuery();
  1214. con.Close();
  1215. Response.Write("record sucessfully inserted....");
  1216. TextBox1.Text = "";
  1217. TextBox2.Text = "";
  1218. TextBox3.Text = "";
  1219. TextBox4.Text = "";
  1220. TextBox5.Text = "";
  1221.  
  1222. }
  1223. protected void Button2_Click(object sender, EventArgs e)
  1224. {
  1225.  
  1226. }
  1227. }
  1228.  
  1229.  
  1230.  
  1231.  
  1232.  
  1233.  
  1234.  
  1235.  
  1236.  
  1237.  
  1238.  
  1239.  
  1240.  
  1241.  
  1242.  
  1243.  
  1244.  
  1245.  
  1246.  
  1247.  
  1248.  
  1249.  
  1250.  
  1251.  
  1252. 13. WEB PAGE OF A FRUITSHOP THAT ALLOWS USER TO EDIT THEIR RECORDS
  1253.  
  1254. using System;
  1255. using System.Data;
  1256. using System.Configuration;
  1257. using System.Collections;
  1258. using System.Web;
  1259. using System.Web.Security;
  1260. using System.Web.UI;
  1261. using System.Web.UI.WebControls;
  1262. using System.Web.UI.WebControls.WebParts;
  1263. using System.Web.UI.HtmlControls;
  1264. using System.Data.SqlClient;
  1265.  
  1266. public partial class Default3 : System.Web.UI.Page
  1267. {
  1268. SqlConnection con;
  1269. protected void Page_Load(object sender, EventArgs e)
  1270. {
  1271. con = new SqlConnection("Data Source=VISHNU-PC;Initial Catalog=employee;Integrated Security=True");
  1272.  
  1273.  
  1274. }
  1275. protected void Button1_Click(object sender, EventArgs e)
  1276. {
  1277. con.Open();
  1278. SqlCommand cmd = new SqlCommand("insert into emp values ('" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "')", con);
  1279.  
  1280. cmd.ExecuteNonQuery();
  1281. Response.Write("RECORD SAVED SUCESSFULLY");
  1282. con.Close();
  1283. TextBox1.Text = "";
  1284. TextBox2.Text = "";
  1285. TextBox3.Text = "";
  1286. TextBox4.Text = "";
  1287. TextBox5.Text = "";
  1288. TextBox6.Text = "";
  1289.  
  1290. }
  1291. protected void Button2_Click(object sender, EventArgs e)
  1292. {
  1293. con.Open();
  1294. SqlCommand cmd = new SqlCommand("delete from emp where emp_id='" + TextBox1.Text + "'", con);
  1295. cmd.ExecuteNonQuery();
  1296. Response.Write("record deleted sucessfully");
  1297.  
  1298. con.Close();
  1299. TextBox1.Text = "";
  1300.  
  1301.  
  1302. }
  1303. protected void Button3_Click(object sender, EventArgs e)
  1304. {
  1305. con.Open();
  1306. SqlCommand cmd = new SqlCommand("update emp set emp_name='" + TextBox2.Text + "',emp_age='" + TextBox3.Text + "',emp_deg='" + TextBox4.Text + "',emp_add='" + TextBox5.Text + "',emp_salary='" + TextBox6.Text +"'where emp_id='"+TextBox1.Text+ "'", con);
  1307. cmd.ExecuteNonQuery();
  1308. Response.Write("employee record updated sucessfully");
  1309. con.Close();
  1310. TextBox1.Text = "";
  1311. TextBox2.Text = "";
  1312. TextBox3.Text = "";
  1313. TextBox4.Text = "";
  1314. TextBox5.Text = "";
  1315. TextBox6.Text = "";
  1316.  
  1317. }
  1318. protected void Button4_Click(object sender, EventArgs e)
  1319. {
  1320. con.Open();
  1321. SqlCommand cmd = new SqlCommand("select * from emp where emp_id='" + TextBox1.Text + "'", con);
  1322. SqlDataReader reader = cmd.ExecuteReader();
  1323. while (reader.Read())
  1324. {
  1325. TextBox2.Text = reader[1].ToString();
  1326. TextBox3.Text = reader[2].ToString();
  1327. TextBox4.Text = reader[3].ToString();
  1328. TextBox5.Text = reader[4].ToString();
  1329. TextBox6.Text = reader[5].ToString();
  1330. }
  1331. con.Close();
  1332.  
  1333. }
Add Comment
Please, Sign In to add comment