Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

C# Application program UNIT III

950 views

Published on

Published in: Education
  • Be the first to comment

C# Application program UNIT III

  1. 1. UNIT III <ul><li>BUILDING WINDOWS APPLICATION </li></ul><ul><li>ACCESSING DATA IN ADO.NET </li></ul>
  2. 2. Building Windows Application
  3. 5. Program Flow <ul><li>Fill Directory & Sub Directory </li></ul><ul><li>Create an order list of all selected file used by both copy and delete button </li></ul><ul><li>GetCheckedFile and GetParentString used by the list file </li></ul><ul><li>Explanation for each button </li></ul><ul><li>Get the full path of the chosen directory – Target_AfterSelect </li></ul><ul><li>Mark each node below the current one with current value of checked – source_Aftercheck </li></ul><ul><li>Recursively set to clear - SetCheck </li></ul>
  4. 6. TREE VIEW CONTROL SET THE CHECK BOX CONTROL OF LEFT (SOURCE) TREEVIEW TO TRUE AND OTHER AS FALSE
  5. 8. FILE COMPARE CLASS <ul><li>public frmfilecopier ( { </li></ul><ul><li>InitializeComponent(); </li></ul><ul><li>FillDirectoryTree(tvsource, true); </li></ul><ul><li>FillDirectoryTree(tvtarget, false); </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>public class FileComparer : IComparer<FileInfo> </li></ul><ul><li>{ </li></ul><ul><li>public int Compare(FileInfo file1, FileInfo file2) </li></ul><ul><li>{ </li></ul><ul><li>if (file1.Length > file2.Length) </li></ul><ul><li>{ </li></ul><ul><li>return -1; </li></ul><ul><li>} </li></ul><ul><li>if (file1.Length < file2.Length) </li></ul><ul><li>{ </li></ul><ul><li>return 1; </li></ul><ul><li>} </li></ul><ul><li>return 0; </li></ul><ul><li>} </li></ul><ul><li>public bool Equals(FileInfo x, FileInfo y) { throw new NotImplementedException(); } </li></ul><ul><li>public int GetHashCode(FileInfo x) { throw new NotImplementedException(); } </li></ul><ul><li>} </li></ul>
  6. 9. FILL_DIRECTORY TREE <ul><li>private void FillDirectoryTree(TreeView tv, bool isSource) </li></ul><ul><li>{ </li></ul><ul><li>tv.Nodes.Clear(); </li></ul><ul><li>string[] strDrives = Environment.GetLogicalDrives(); </li></ul><ul><li>foreach ( string rootDirectoryName in strDrives ) </li></ul><ul><li>{ </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>DirectoryInfo dir = new DirectoryInfo( rootDirectoryName ); </li></ul><ul><li>dir.GetDirectories(); </li></ul><ul><li>TreeNode ndRoot = new TreeNode( rootDirectoryName ); </li></ul><ul><li>tv.Nodes.Add( ndRoot ); </li></ul><ul><li>if(isSource) </li></ul><ul><li>{ </li></ul><ul><li>GetSubDirectoryNodes( ndRoot,ndRoot.Text,true,1); </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>GetSubDirectoryNodes( ndRoot,ndRoot.Text,false,1); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>catch </li></ul><ul><li>{ </li></ul><ul><li>} </li></ul><ul><li>Application.DoEvents(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>  </li></ul>
  7. 10. SUBDIRECTORY <ul><li>private void GetSubDirectoryNodes(TreeNode parentNode, string fullName, bool getFileNames, int level) </li></ul><ul><li>{ </li></ul><ul><li>DirectoryInfo dir = new DirectoryInfo(fullName); </li></ul><ul><li>DirectoryInfo[] dirSubs = dir.GetDirectories(); </li></ul><ul><li>foreach (DirectoryInfo dirSub in dirSubs) </li></ul><ul><li>{ </li></ul><ul><li>if ((dirSub.Attributes & FileAttributes.Hidden) != 0) </li></ul><ul><li>{ </li></ul><ul><li>continue; </li></ul><ul><li>} </li></ul><ul><li>TreeNode subnode = new TreeNode(dirSub.Name); </li></ul><ul><li>parentNode.Nodes.Add(subnode); </li></ul><ul><li>if (level < MaxLevel) </li></ul><ul><li>{ </li></ul><ul><li>GetSubDirectoryNodes(subnode, dirSub.FullName, getFileNames, level + 1); </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>if (getFileNames) </li></ul><ul><li>{ </li></ul><ul><li>FileInfo[] files = dir.GetFiles(); </li></ul><ul><li>foreach (FileInfo file in files) </li></ul><ul><li>{ </li></ul><ul><li>TreeNode filenode = new TreeNode(file.Name); </li></ul><ul><li>parentNode.Nodes.Add(filenode); </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>  </li></ul>
  8. 11. UNIT IV BUILDING WEB APPLICATION
  9. 12. COPY BUTTON <ul><li>private void Btncopy_Click(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>List<FileInfo> filelist = Getfilelist(); </li></ul><ul><li>foreach (FileInfo file in filelist) </li></ul><ul><li>{ </li></ul><ul><li>try </li></ul><ul><li>{ </li></ul><ul><li>lblstatus.Text = &quot;Copying&quot; + txtTargetdir.Text + &quot;&quot; + file.Name + &quot;...&quot;; </li></ul><ul><li>Application.DoEvents(); </li></ul><ul><li>file.CopyTo(txtTargetdir.Text + &quot;&quot; + file.Name, chkoverwrite.Checked); </li></ul><ul><li>} </li></ul><ul><li>catch (Exception ex) </li></ul><ul><li>{ </li></ul><ul><li>MessageBox.Show(ex.Message); </li></ul><ul><li>} </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>lblstatus.Text = &quot;Done&quot;; </li></ul><ul><li>Application.DoEvents(); </li></ul><ul><li>} </li></ul><ul><li>  </li></ul>
  10. 13. IMPLEMENTIN COPY <ul><li>private List<FileInfo> Getfilelist() </li></ul><ul><li>{ </li></ul><ul><li>List<string> fileNames = new List<string>(); </li></ul><ul><li>foreach (TreeNode thenode in tvsource.Nodes) </li></ul><ul><li>{ </li></ul><ul><li>GetCheckedFiles(thenode, fileNames); </li></ul><ul><li>} </li></ul><ul><li>List<FileInfo> fileList = new List<FileInfo>(); </li></ul><ul><li>foreach(string fileName in fileNames) </li></ul><ul><li>{ </li></ul><ul><li>FileInfo file = new FileInfo(fileName); </li></ul><ul><li>if(file.Exists) </li></ul><ul><li>{ </li></ul><ul><li>fileList.Add(file); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>IComparer<FileInfo> Comparer = (IComparer<FileInfo>) </li></ul><ul><li>new FileComparer(); </li></ul><ul><li>fileList.Sort(Comparer); </li></ul><ul><li>return fileList; </li></ul><ul><li>} </li></ul>
  11. 14. IMPLEMENTIN COPY 2 <ul><li>private void GetCheckedFiles(TreeNode node, List<string> filenames ) </li></ul><ul><li>{ </li></ul><ul><li>if(node.Nodes.Count == 0) </li></ul><ul><li>{ </li></ul><ul><li>if(node.Checked) </li></ul><ul><li>{ </li></ul><ul><li>string fullpath = GetParentstring(node); </li></ul><ul><li>filenames.Add(fullpath); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>else{ </li></ul><ul><li>foreach (TreeNode n in node.Nodes) </li></ul><ul><li>{ </li></ul><ul><li>GetCheckedFiles(n,filenames); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>private string GetParentstring(TreeNode node) </li></ul><ul><li>{ </li></ul><ul><li>if(node.Parent == null) </li></ul><ul><li>{ </li></ul><ul><li>return node.Text; </li></ul><ul><li>} </li></ul><ul><li>else </li></ul><ul><li>{ </li></ul><ul><li>return GetParentstring(node.Parent) + node.Text + (node.Nodes.Count == 0 ? &quot;&quot;:&quot;&quot;); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  12. 15. DELETE BUTTON <ul><li>private void btndelete_Click(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>System.Windows.Forms.DialogResult result = MessageBox.Show(&quot;Are u quit sure?&quot;,&quot;Delete files&quot;,MessageBoxButtons.OKCancel,MessageBoxIcon.Exclamation,MessageBoxDefaultButton.Button2); </li></ul><ul><li>if(result == System.Windows.Forms.DialogResult.OK) </li></ul><ul><li>{ </li></ul><ul><li>List<FileInfo> filenames = Getfilelist(); </li></ul><ul><li>foreach(FileInfo file in filenames) </li></ul><ul><li>{ </li></ul><ul><li>try{ </li></ul><ul><li>lblstatus.Text = &quot;Deleting&quot; + file.Name + &quot;...&quot;; </li></ul><ul><li>Application.DoEvents(); </li></ul><ul><li>file.Delete(); </li></ul><ul><li>} </li></ul><ul><li>catch(Exception ex) </li></ul><ul><li>{ </li></ul><ul><li>MessageBox.Show(ex.Message); </li></ul><ul><li>} </li></ul><ul><li>lblstatus.Text = &quot;Done&quot;; </li></ul><ul><li>Application.DoEvents(); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>  </li></ul>
  13. 16. CLEAR BUTTON <ul><li>private void btnclear_Click(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>foreach(TreeNode node in tvsource.Nodes) </li></ul><ul><li>{ </li></ul><ul><li>SetCheck(node,false); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  14. 17. CANCEL BUTTON <ul><li> private void btncancle_Click(object sender,EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>Application.Exit(); </li></ul><ul><li>} </li></ul>
  15. 18. TREEVIEW <ul><li>private void tvtarget_AfterSelect(object sender,System.Windows.Forms.TreeViewEventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>string theFullpath = GetParentstring(e.Node); </li></ul><ul><li>if(theFullpath.EndsWith(&quot;&quot;)) </li></ul><ul><li>{ </li></ul><ul><li>theFullpath = theFullpath.Substring(0,theFullpath.Length-1); </li></ul><ul><li>} </li></ul><ul><li>txtTargetdir.Text =theFullpath; </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>private void tvsource_AfterCheck(object sender, System.Windows.Forms.TreeViewEventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>if (e.Action != TreeViewAction.Unknown) </li></ul><ul><li>{ </li></ul><ul><li>SetCheck(e.Node, e.Node.Checked); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>private void SetCheck(TreeNode node, bool check) </li></ul><ul><li>{ </li></ul><ul><li>foreach (TreeNode n in node.Nodes) </li></ul><ul><li>{ </li></ul><ul><li>n.Checked = check; </li></ul><ul><li>if (n.Nodes.Count != 0) </li></ul><ul><li>{ </li></ul><ul><li>SetCheck(n, check); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  16. 19. Cont.. <ul><li>private void tvExpand(object sender, TreeViewCancelEventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>TreeView tv = (TreeView)sender; </li></ul><ul><li>bool getFiles = tv == tvsource; </li></ul><ul><li>TreeNode currentnode = e.Node; </li></ul><ul><li>string fullName = currentnode.FullPath; </li></ul><ul><li>currentnode.Nodes.Clear(); </li></ul><ul><li>GetSubDirectoryNodes(currentnode, fullName, getFiles, 1); </li></ul><ul><li>} </li></ul><ul><li>  </li></ul><ul><li>private void tvsource_AfterSelect(object sender, TreeViewEventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>  </li></ul><ul><li>private void chkoverwrite_CheckedChanged(object sender, EventArgs e) </li></ul><ul><li>{ </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>  </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  17. 20. ADO.NET APPLICATION
  18. 21. SELECTING THE DATA GRID VIEW DATA GRID VIEW
  19. 22. SELECTING THE MENU
  20. 23. ADD THE DATA SOURCE
  21. 24. SELECT UR DATABASE
  22. 25. SELECT UR DATABASE
  23. 26. DB IS ADDED
  24. 27. THE CONNECTION IS SAVED
  25. 28. SELECT THE TABEL
  26. 32. THE TABLE IS ADDED
  27. 33. SAVE AND BUILD
  28. 34. THE CODE GENERATED
  29. 35. RUN THE APPLICATION
  30. 36. UNIT IV BUILDING WEB APPLICATION
  31. 37. OPENING A WEB APPLICATION
  32. 38. SELECT ASP.NET WEB SITES
  33. 39. RENAME FROM DEFAULT TO HELLOWORLD
  34. 40. THE NAME IS CHANGED
  35. 41. NOW TO CHANGE THE CLASS NAME
  36. 42. CONFIRM THE CHANGE
  37. 43. IN THE ASPX CHANGE THE INHERIT ATTRIBUTE
  38. 44. CODE UR PROGRAM
  39. 45. WHILE RUN CONFIRM THIS MESSAGE
  40. 46. THE RESULT

×