c# application program unit iii
TRANSCRIPT
![Page 1: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/1.jpg)
UNIT III
• BUILDING WINDOWS APPLICATION• ACCESSING DATA IN ADO.NET
![Page 2: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/2.jpg)
Building Windows Application
![Page 3: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/3.jpg)
![Page 4: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/4.jpg)
![Page 5: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/5.jpg)
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
![Page 6: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/6.jpg)
TREE VIEW CONTROL
SET THE CHECK BOX CONTROL OF LEFT (SOURCE) TREEVIEW TO TRUE AND OTHER AS FALSE
![Page 7: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/7.jpg)
![Page 8: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/8.jpg)
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(); } }
![Page 9: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/9.jpg)
FILL_DIRECTORY TREEprivate 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(); } }
![Page 10: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/10.jpg)
SUBDIRECTORYprivate 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); } } }
![Page 11: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/11.jpg)
UNIT IV
BUILDING WEB APPLICATION
![Page 12: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/12.jpg)
COPY BUTTON
private void Btncopy_Click(object sender, EventArgs e) { List<FileInfo> filelist = Getfilelist(); foreach (FileInfo file in filelist) { try { lblstatus.Text = "Copying" + txtTargetdir.Text + "\\" + file.Name + "..."; Application.DoEvents(); file.CopyTo(txtTargetdir.Text + "\\" + file.Name, chkoverwrite.Checked); } catch (Exception ex) { MessageBox.Show(ex.Message); } } lblstatus.Text = "Done"; Application.DoEvents(); }
![Page 13: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/13.jpg)
IMPLEMENTIN COPYprivate 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; }
![Page 14: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/14.jpg)
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 ? "":"\\"); } }
![Page 15: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/15.jpg)
DELETE BUTTONprivate void btndelete_Click(object sender, EventArgs e) { System.Windows.Forms.DialogResult result = MessageBox.Show("Are u quit sure?","Delete
files",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 = "Deleting" + file.Name + "..."; Application.DoEvents(); file.Delete(); } catch(Exception ex) { MessageBox.Show(ex.Message); } lblstatus.Text = "Done"; Application.DoEvents(); } } }
![Page 16: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/16.jpg)
CLEAR BUTTONprivate void btnclear_Click(object sender, EventArgs e) {
foreach(TreeNode node in tvsource.Nodes) { SetCheck(node,false); } }
![Page 17: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/17.jpg)
CANCEL BUTTON
private void btncancle_Click(object sender,EventArgs e)
{ Application.Exit();
}
![Page 18: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/18.jpg)
TREEVIEW private void tvtarget_AfterSelect(object sender,System.Windows.Forms.TreeViewEventArgs e) { string theFullpath = GetParentstring(e.Node); if(theFullpath.EndsWith("\\")) { 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); } } }
![Page 19: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/19.jpg)
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) { } } }
![Page 20: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/20.jpg)
ADO.NET APPLICATION
![Page 21: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/21.jpg)
SELECTING THE DATA GRID VIEW
DATA GRID VIEW
![Page 22: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/22.jpg)
SELECTING THE MENU
![Page 23: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/23.jpg)
ADD THE DATA SOURCE
![Page 24: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/24.jpg)
SELECT UR DATABASE
![Page 25: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/25.jpg)
SELECT UR DATABASE
![Page 26: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/26.jpg)
DB IS ADDED
![Page 27: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/27.jpg)
THE CONNECTION IS SAVED
![Page 28: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/28.jpg)
SELECT THE TABEL
![Page 29: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/29.jpg)
![Page 30: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/30.jpg)
![Page 31: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/31.jpg)
![Page 32: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/32.jpg)
THE TABLE IS ADDED
![Page 33: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/33.jpg)
SAVE AND BUILD
![Page 34: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/34.jpg)
THE CODE GENERATED
![Page 35: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/35.jpg)
RUN THE APPLICATION
![Page 36: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/36.jpg)
UNIT IV
BUILDING WEB APPLICATION
![Page 37: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/37.jpg)
OPENING A WEB APPLICATION
![Page 38: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/38.jpg)
SELECT ASP.NET WEB SITES
![Page 39: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/39.jpg)
RENAME FROM DEFAULT TO HELLOWORLD
![Page 40: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/40.jpg)
THE NAME IS CHANGED
![Page 41: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/41.jpg)
NOW TO CHANGE THE CLASS NAME
![Page 42: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/42.jpg)
CONFIRM THE CHANGE
![Page 43: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/43.jpg)
IN THE ASPX CHANGE THE INHERIT ATTRIBUTE
![Page 44: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/44.jpg)
CODE UR PROGRAM
![Page 45: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/45.jpg)
WHILE RUN CONFIRM THIS MESSAGE
![Page 46: C# Application program UNIT III](https://reader033.vdocument.in/reader033/viewer/2022052523/55628813d8b42a04418b57a6/html5/thumbnails/46.jpg)
THE RESULT