Populate a TreeView from database

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace treeTest
{
public partial class Form1 : Form
{
private List<Category> items = new List<Category>();
public Form1()
{
InitializeComponent();
}
/*
* dataSet1 has a table with 3 columns
* col#1=ID (int)
* col#2=ParentID (int)
* col#3=NodeText (string)
*/
private void Form1_Load(object sender, EventArgs e)
{
// Load up a dataset with values – usually from a database, but
// here I can show the data without using a real database.
dataSet1.Tables[0].Rows.Add(1, 0, “First Node”);
dataSet1.Tables[0].Rows.Add(3, 1, “Node 3.1″);
dataSet1.Tables[0].Rows.Add(4, 1, “Node 4.1″);
dataSet1.Tables[0].Rows.Add(5, 0, “Node 5.0″);
dataSet1.Tables[0].Rows.Add(6, 5, “Node 6.5″);
dataSet1.Tables[0].Rows.Add(7, 5, “Node 7.5″);
dataSet1.Tables[0].Rows.Add(8, 5, “Node 8.5″);
dataSet1.Tables[0].Rows.Add(9, 5, “Node 9.5″);
dataSet1.Tables[0].Rows.Add(10, 6, “Node 10.6″);
dataSet1.Tables[0].Rows.Add(11, 6, “Node 11.6″);
dataSet1.Tables[0].Rows.Add(12, 11, “Node 12.11″);
dataSet1.Tables[0].Rows.Add(13, 11, “Node 13.11″);
dataSet1.Tables[0].Rows.Add(14, 11, “Node 14.11″);
dataSet1.Tables[0].Rows.Add(15, 11, “Node 15.11″);

// Populate the items array of Catagory from the dataset
foreach (DataRow dr in dataSet1.Tables[0].Rows)
items.Add(new Category((int)dr[0], (int)dr[1], (string)dr[2]));

// Build the treeview from the catagory list
buildtree();

}

private void buildtree()
{
treeView1.Nodes.Clear(); // Clear any existing items
treeView1.BeginUpdate(); // prevent overhead and flicker
LoadBaseNodes(); // load all the lowest tree nodes
treeView1.EndUpdate(); // re-enable the tree
treeView1.Refresh(); // refresh the treeview display
}

private void LoadBaseNodes()
{
int baseParent = 0; // Find the lowest root category parent value
TreeNode node;
foreach (Category cat in items)
{
if (cat.ParentID < baseParent)
baseParent = cat.ParentID;
}
foreach (Category cat in items) // iterate through the categories
{
if (cat.ParentID == baseParent) // found a matching root item
{
node = treeView1.Nodes.Add(cat.NodeText); // add it to the tree
node.Tag = cat; // send the category into the tag for future processing
getChildren(node); // load all the children of this node
}
}
}

// recursive tree loader. Passes back in a node to retireve its childre
// until there are no more children for this node.
private void getChildren(TreeNode node)
{
TreeNode Node = null;
Category nodeCat = (Category)node.Tag; // get the category for this node
foreach (Category cat in items) // locate all children of this category
{
if (cat.ParentID == nodeCat.ID) // found a child
{
Node = node.Nodes.Add(cat.NodeText); // add the child
Node.Tag = cat; // set its tag to its category
getChildren(Node); // find this child’s children
}
}
}
}

class Category
{
public int ID;
public int ParentID;
public string NodeText;
public Category(int ID, int ParentID, string NodeText)
{
this.ID = ID;
this.ParentID = ParentID;
this.NodeText = NodeText;
}
public override string ToString()
{
return this.NodeText;
}
}
}

Share

Remove the old trace file in oracle using shell script

Normally DBA’s are managed several oracle database server & some application server.Every month during maintenance activity we purged the older trace files in udump,bdump,adump and application event log files.
We planned to automated this activity.

Below scripts are purged the trace file greater than 15 days.Once executed the scripts its automatically trigger the mail to user with before purge status & after purge status information.

SCRIPT #1
##############################################################################

REMOVE THE OLD TRACE FILES
CREATED BY RAJABASKAR THANGARAJ 12-12-2008

##############################################################################

$ cat oldtrace_remove.sh

#!/bin/ksh
echo Removing older trace file greater than 15 days …..
#run the environment variable profile
. $HOME/.bash_profile
PATH=/opt/app/oracle/admin
cd $PATH/$ORACLE_SID
RUNDATE=`date “+%d%m%y at %H:%M:%S”`
LOGFILE=/home/oracle/dbatest/raja/archived
# -mtime +15 remove the older trace file greater than 15 days
#change the days depend upons your need
du -m > $LOGFILE/before_purged_size.log
find $PATH/$ORACLE_SID/udump/*.trc -mtime +15 -exec rm {} \;
find $PATH/$ORACLE_SID/bdump/*.trc -mtime +15 -exec rm {} \;
find $PATH/$ORACLE_SID/adump/*.trc -mtime +15 -exec rm {} \;
du -m > $LOGFILE/after_purged_size.log
cat $LOGFILE/beforepurgestmt.log $LOGFILE/before_purged_size.log $LOGFILE/afterpurgestmt.log $LOGFILE/after_purged_size.log
> $LOGFILE/mail.log
mail -s “Status of $ORACLE_SID Old trace file successfully purging on $RUNDATE ” raja.baskar@abcde.com < $LOGFILE/mail.log
exit;

********************************************************

SCRIPT #2
*********

Below formatted log files are located in /home/oracle/dbatest/raja/archived.
$ cat beforepurgestmt.log

************************************************

BEFORE PURGING THE TRACE FILE SIZE IN MB

*************************************************

SCRIPT #3

Below formatted log files are located in /home/oracle/dbatest/raja/archived.

$ cat afterpurgestmt.log

********************************************************

AFTER PURGING THE TRACE FILES SUCCESSFULLY.SIZE IN MB

*********************************************************

OUTPUT MAIL FORMAT:
*******************************

SUBJECT: Status of orcl Old trace file successfully purging on 121208 at 19:17:16

CONTENT:

************************************************

BEFORE PURGING THE TRACE FILE SIZE IN MB

*************************************************

1056 ./adump

100 ./scripts

2056 ./cdump

10024 ./dpdump

3824 ./udump

38240 ./bdump

10 ./pfile
.

********************************************************

AFTER PURGING THE TRACE FILES SUCCESSFULLY.SIZE IN MB

*********************************************************

512 ./adump

1 ./scripts

512 ./cdump

10024 ./dpdump

1024 ./udump

503 ./bdump

10 ./pfile

*******************************************************************************

Share
←Older