46
UNIT III • BUILDING WINDOWS APPLICATION • ACCESSING DATA IN ADO.NET

C# Application program UNIT III

Embed Size (px)

Citation preview

Page 1: C# Application program UNIT III

UNIT III

• BUILDING WINDOWS APPLICATION• ACCESSING DATA IN ADO.NET

Page 2: C# Application program UNIT III

Building Windows Application

Page 3: C# Application program UNIT III
Page 4: C# Application program UNIT III
Page 5: C# Application program UNIT III

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

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
Page 8: C# Application program UNIT III

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

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

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

UNIT IV

BUILDING WEB APPLICATION

Page 12: C# Application program UNIT III

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

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

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

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

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

CANCEL BUTTON

private void btncancle_Click(object sender,EventArgs e)

{ Application.Exit();

}

Page 18: C# Application program UNIT III

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

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

ADO.NET APPLICATION

Page 21: C# Application program UNIT III

SELECTING THE DATA GRID VIEW

DATA GRID VIEW

Page 22: C# Application program UNIT III

SELECTING THE MENU

Page 23: C# Application program UNIT III

ADD THE DATA SOURCE

Page 24: C# Application program UNIT III

SELECT UR DATABASE

Page 25: C# Application program UNIT III

SELECT UR DATABASE

Page 26: C# Application program UNIT III

DB IS ADDED

Page 27: C# Application program UNIT III

THE CONNECTION IS SAVED

Page 28: C# Application program UNIT III

SELECT THE TABEL

Page 29: C# Application program UNIT III
Page 30: C# Application program UNIT III
Page 31: C# Application program UNIT III
Page 32: C# Application program UNIT III

THE TABLE IS ADDED

Page 33: C# Application program UNIT III

SAVE AND BUILD

Page 34: C# Application program UNIT III

THE CODE GENERATED

Page 35: C# Application program UNIT III

RUN THE APPLICATION

Page 36: C# Application program UNIT III

UNIT IV

BUILDING WEB APPLICATION

Page 37: C# Application program UNIT III

OPENING A WEB APPLICATION

Page 38: C# Application program UNIT III

SELECT ASP.NET WEB SITES

Page 39: C# Application program UNIT III

RENAME FROM DEFAULT TO HELLOWORLD

Page 40: C# Application program UNIT III

THE NAME IS CHANGED

Page 41: C# Application program UNIT III

NOW TO CHANGE THE CLASS NAME

Page 42: C# Application program UNIT III

CONFIRM THE CHANGE

Page 43: C# Application program UNIT III

IN THE ASPX CHANGE THE INHERIT ATTRIBUTE

Page 44: C# Application program UNIT III

CODE UR PROGRAM

Page 45: C# Application program UNIT III

WHILE RUN CONFIRM THIS MESSAGE

Page 46: C# Application program UNIT III

THE RESULT