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

C# Application program UNIT III

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