Click here to Skip to main content
16,005,236 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to display '0.5' as '1/2'? Pin
Dave Kreskowiak29-May-07 8:52
mveDave Kreskowiak29-May-07 8:52 
AnswerRe: How to display '0.5' as '1/2'? Pin
Giorgi Dalakishvili29-May-07 9:14
mentorGiorgi Dalakishvili29-May-07 9:14 
Questionbind treeviwe with a list Pin
merwa29-May-07 7:42
merwa29-May-07 7:42 
QuestionBindingList and DataGridView question. [modified] Pin
sharp source29-May-07 7:15
sharp source29-May-07 7:15 
AnswerRe: BindingList and DataGridView question. Pin
Dave Kreskowiak29-May-07 7:33
mveDave Kreskowiak29-May-07 7:33 
GeneralRe: BindingList and DataGridView question. Pin
sharp source29-May-07 7:51
sharp source29-May-07 7:51 
GeneralRe: BindingList and DataGridView question. Pin
Dave Kreskowiak29-May-07 8:50
mveDave Kreskowiak29-May-07 8:50 
GeneralRe: BindingList and DataGridView question. Pin
sharp source29-May-07 9:58
sharp source29-May-07 9:58 
Ok, i'll start over.
The goal of the application is to check visual foxpro tables of an application named omniwin for numerous different problems. The important one for this problem is the analysis of the index key's uniqueness.

First the user selects the root of omniwin. After the root is validated this application checks the data tables for double index keys.
All the tables wich have to be checked can be found in a table called tableinfo (tableinfo.dbf) and from that table i take the tablename, index field of table, and location of the file in which it is stored. These variables are stored in an instance of ActiveTable, named tableToAnalyze.

Next the table is analysed by invoking tableToAnalyze.CheckForDoubleKey().
That method checks number of rows (tableToAnalyze.tableRecords) and number of distinct(id) rows (tableToAnalyze.tableUniqueRecords).
If those values do not match the method stores the not distinct keys in a queue (tableToAnalyze.doubleKey)

When the table is checked and tableToAnalyze.doubleKey.count() > 1 the instance tableToAnalyse is added to the BindingList<activetable> listOfDoubleIndexTables.

My intention is to display the BindingList listOfDoubleIndexTables in a DGV on the form. Then I can delete rows before starting a fix method because not all problems should be fixed.

Problem:
I've added a DGV on the form (desinger) and named it: dataGridDoubleKey
I've set the DataSource of the DGV to the appropriate datasource: dataGridDoubleKey.datasource=listOfDoubleIndexTables;
I've set the AutoGenerateColumns property to true.

But the DGV does not create columns and ofcourse does not display any rows.
So i thought, i'll define the rows myself.

i set the the AutoGenerateColumns property to false and defined the colums as such:
//dataGridDoubleKey.Columns.Add("omniwinRoot", "locatie");
//dataGridDoubleKey.Columns[0].Visible = false;
//dataGridDoubleKey.Columns.Add("table", "Table");
//dataGridDoubleKey.Columns.Add("tableKey", "Key");
//dataGridDoubleKey.Columns.Add("tableRecords", "Table records");
//dataGridDoubleKey.Columns[3].Visible = false;
//dataGridDoubleKey.Columns.Add("tableUniqueRecords", "Table Unique Records");
//dataGridDoubleKey.Columns[4].Visible = false;
//dataGridDoubleKey.Columns.Add("diff", "Number of double keys");
//dataGridDoubleKey.Columns.Add("doubleKey", "Queue double keys");
//dataGridDoubleKey.Columns.Add("noNversion", "Queue version id");
//dataGridDoubleKey.Columns[7].Visible = false;
W/o the comment ofcourse. Now i did have columns. And i saw that rows were added to the DGV each time a tableToAnalyze was added tot the bindinglist.
Unfortunately the rows of the DGV were alle emtpy.

My question, what am i doing wrong?

The code:

<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
using System.Windows.Forms.Design;<br />
using System.IO;<br />
using System.Data.OleDb;<br />
<br />
<br />
<br />
namespace nomni<br />
{<br />
<br />
    public partial class FormAlgemeen : Form<br />
    {<br />
        string omniwinRoot;<br />
        bool rootIsValid = false;<br />
        BindingList<ActiveTable> listOfDoubleIndexTables = new BindingList<ActiveTable>();<br />
        BindingList<ActiveTable> listOfNoNversionid = new BindingList<ActiveTable>();<br />
        BindingList<string> tableFailedToAnalyze = new BindingList<string>();<br />
<br />
        public FormAlgemeen()<br />
        {<br />
            InitializeComponent();<br />
            dataGridDoubleKey = new DataGridView();<br />
            dataGridVersionIdProblem = new DataGridView();<br />
            <br />
            dataGridDoubleKey.DataSource = listOfDoubleIndexTables;<br />
            dataGridVersionIdProblem.DataSource = listOfNoNversionid;<br />
   <br />
            dataGridDoubleKey.AutoGenerateColumns = true;<br />
            dataGridVersionIdProblem.AutoGenerateColumns = true;<br />
        }<br />
    <br />
        private void chooseStandardOmniwin(object sender, EventArgs e)<br />
        {   <br />
            //User selected default omniwin directory<br />
            omniwinRoot = "C:\\Program Files\\Omegasoft\\medical\\omniwin\\";<br />
            //Validate omniwin directory by checking required files<br />
            rootIsValid = ValidateOmniWinRoot(omniwinRoot);<br />
            if (!rootIsValid)<br />
            {<br />
                MessageBox.Show("Default directory is not correct.");<br />
            }<br />
            else<br />
            {<br />
                this.stripStatusLabel1.Text = "Selected Omniwin Path: " + omniwinRoot;<br />
                this.Refresh();<br />
            }<br />
<br />
        }<br />
<br />
        private void browseToOmniwin(object sender, EventArgs e)<br />
        {<br />
            //Users wants to browse for omniwin directory<br />
            DialogResult answer;<br />
            FolderBrowserDialog browseFolder = new FolderBrowserDialog();<br />
            browseFolder.Description = "Select the Omniwin folder";<br />
            browseFolder.RootFolder = Environment.SpecialFolder.MyComputer;<br />
            answer = browseFolder.ShowDialog();<br />
            omniwinRoot = browseFolder.SelectedPath + "\\";<br />
            if (omniwinRoot != "" && answer != DialogResult.Cancel)<br />
            {<br />
                rootIsValid = ValidateOmniWinRoot(omniwinRoot);<br />
                if (!rootIsValid)<br />
                    MessageBox.Show("You chose an incorrect folder path.");<br />
                else<br />
                {<br />
                    this.stripStatusLabel1.Text = "Selected Omniwin Path: " + omniwinRoot;<br />
                    this.Refresh();<br />
                }<br />
            }<br />
        }<br />
<br />
        private bool ValidateOmniWinRoot(string rootToValidate)<br />
        {   <br />
            bool tableInfoBestaat = false;<br />
            bool dataTabellen = true;<br />
            bool dataTabellenTussen = false;<br />
            string tabelDir = "",tabelNaam = "";<br />
            string connectionString;<br />
            string sqlQuery = "SELECT ctableid, flocation, cdescr, caliasname FROM tableinfo WHERE (NOT (flocation = '')AND NOT (ctablename = ''))";<br />
            tableInfoBestaat = File.Exists(rootToValidate + "tableinfo.dbf");<br />
            <br />
            if (tableInfoBestaat)<br />
            {<br />
                // check existance of db files from tableinfo<br />
                connectionString = "Provider=VFPOLEDB.1;" + "Data Source=" + rootToValidate + "tableinfo.dbf";<br />
                using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionString))<br />
                {<br />
                    try<br />
                    {<br />
                        ConnTableInfo.Open();<br />
                        OleDbCommand command = new OleDbCommand(sqlQuery);<br />
                        command.Connection = ConnTableInfo;<br />
                        OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
                        while (reader.Read())<br />
                        {<br />
                            tabelDir = reader.GetString(1).Trim();<br />
                            tabelNaam = reader.GetString(3).Trim();<br />
                            dataTabellenTussen = File.Exists(rootToValidate + tabelDir + "\\" + tabelNaam + ".dbf");<br />
                            if (dataTabellenTussen == false)<br />
                            {<br />
                                dataTabellen = false;<br />
                                logBox.AppendText(tabelNaam + " not found!" + Environment.NewLine);<br />
                            }<br />
<br />
                        }<br />
                        ConnTableInfo.Close();<br />
                    }<br />
                    catch (Exception ex)<br />
                    {<br />
                        MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
                    }<br />
                    <br />
                }//ConnTableInfo closed & disposed<br />
<br />
            }<br />
            else<br />
            {<br />
                return false;<br />
            }<br />
            if (dataTabellen)<br />
            {<br />
                logBox.AppendText("All needed Omniwin tables are found." + Environment.NewLine);<br />
                if (File.Exists(rootToValidate + "1816.txt"))<br />
                {<br />
                    //Versie check en print in log<br />
                    logBox.AppendText("Version file: 1816.txt" + Environment.NewLine);<br />
                }<br />
                else<br />
                {<br />
                    logBox.AppendText("Versie bestand is niet aanwezig. \r\n");<br />
                }<br />
                toolsToolStripMenuItem.Enabled = true;<br />
                return true;<br />
            }<br />
            else<br />
            {<br />
                toolsToolStripMenuItem.Enabled = false;<br />
                return false;<br />
            }<br />
        }<br />
<br />
<br />
<br />
        private void analysisIds(object sender, EventArgs e)<br />
        {   <br />
            // Tables which will be checked: tables in dbpatient container.<br />
            // indexes which will be checked: key index (and version index)<br />
<br />
            string sqlQueryTableInfo ="SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') ORDER BY caliasname";<br />
            string connectionStringTableInfo = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\tableinfo.dbf";<br />
<br />
            OleDbCommand commandTableInfo = new OleDbCommand(sqlQueryTableInfo);<br />
            ActiveTable tableToAnalyze = new ActiveTable();<br />
            listOfDoubleIndexTables = new BindingList<ActiveTable>();<br />
<br />
            using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
            {<br />
                try<br />
                {<br />
                    ConnTableInfo.Open();<br />
                    commandTableInfo.Connection = ConnTableInfo;<br />
                    OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
                    while (readerTableInfo.Read())<br />
                    {<br />
                        tableToAnalyze = new ActiveTable();<br />
                        tableToAnalyze.omniwinRoot = omniwinRoot;<br />
                        tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
                        tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
                        tableToAnalyze.CheckForDoubleKey();<br />
                        tableToAnalyze.diff = tableToAnalyze.tableRecords - tableToAnalyze.tableUniqueRecords;<br />
<br />
                        if (tableToAnalyze.diff > 0)<br />
                        {<br />
                            try<br />
                            {<br />
                                listOfDoubleIndexTables.Add(tableToAnalyze);<br />
                                listOfDoubleIndexTables.ResetBindings();<br />
<br />
                            }<br />
                            catch (Exception dataGridErrorDoubleKey)<br />
                            {<br />
                                logBox.AppendText("Error adding table to list / datagrid: " + Environment.NewLine + dataGridErrorDoubleKey);<br />
<br />
                            }<br />
                        }<br />
<br />
                    }<br />
                    ConnTableInfo.Close();<br />
<br />
                }<br />
                catch (Exception ex)<br />
                {<br />
                    MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
                }<br />
<br />
            }//ConnTableInfo closed & disposed<br />
           <br />
            logBox.AppendText("***********************************" + Environment.NewLine + "Numbers of tables witch double index key(s) to repair: " + listOfDoubleIndexTables.Count + Environment.NewLine);<br />
            foreach (ActiveTable tableToAnalyzeInList in listOfDoubleIndexTables )<br />
            {<br />
                logBox.AppendText(tableToAnalyzeInList.table + " has " + tableToAnalyzeInList.diff + " double key(s)." + Environment.NewLine);<br />
            }<br />
            // start analisys of nversionid's<br />
            // sqlQueryTableInfo will leave table's without a nversionid column out of the scope<br />
            sqlQueryTableInfo = "SELECT ctableid, flocation, ctablename, caliasname, cidfield, cidindex, cdatabase FROM tableinfo WHERE (cdatabase = 'dpatient') AND (flocation = 'data') AND (cidfield <> '') AND (mstructure LIKE '%NVERSIONID%') ORDER BY caliasname";<br />
            using (OleDbConnection ConnTableInfo = new OleDbConnection(connectionStringTableInfo))<br />
            {<br />
                try<br />
                {<br />
                    ConnTableInfo.Open();<br />
                    commandTableInfo.Connection = ConnTableInfo;<br />
                    OleDbDataReader readerTableInfo = commandTableInfo.ExecuteReader(CommandBehavior.CloseConnection);<br />
                    while (readerTableInfo.Read())<br />
                    {<br />
                        tableToAnalyze = new ActiveTable();<br />
                        tableToAnalyze.omniwinRoot = omniwinRoot;<br />
                        tableToAnalyze.table = readerTableInfo.GetString(3).Trim();<br />
                        tableToAnalyze.tableKey = readerTableInfo.GetString(4).Trim();<br />
                        tableToAnalyze.CheckNversionid();<br />
                        if (tableToAnalyze.noNversion.Count > 0)<br />
                        {<br />
                            try<br />
                            {<br />
                                listOfNoNversionid.Add(tableToAnalyze);<br />
                                listOfDoubleIndexTables.ResetBindings();<br />
<br />
                            }<br />
                            catch (Exception dataGridErrorVersionid)<br />
                            {<br />
                                logBox.AppendText("datagriderror bij version id:" + Environment.NewLine + dataGridErrorVersionid.Message);<br />
                            }<br />
                        }<br />
<br />
                    }<br />
                    ConnTableInfo.Close();<br />
<br />
                }<br />
                catch (Exception ex)<br />
                {<br />
                    MessageBox.Show(ex.Message + Environment.NewLine + "While opening tableinfo table an error occured." + Environment.NewLine + "Make sure OmniWin is not running.");<br />
<br />
                }<br />
            }//ConnTableInfo closed & disposed<br />
            <br />
            logBox.AppendText("***********************************" + Environment.NewLine + "Numbers of tables with versionid problems to repair: " + listOfNoNversionid.Count + Environment.NewLine);<br />
            foreach (ActiveTable tableToAnalyzeInList in listOfNoNversionid)<br />
            {<br />
                logBox.AppendText(tableToAnalyzeInList.table + " has  nversionid problem(s)." + Environment.NewLine);<br />
            }<br />
<br />
        }<br />
<br />
    }<br />
    <br />
    public class ActiveTable<br />
    {<br />
        public string omniwinRoot;<br />
        public string table;<br />
        public string tableKey;<br />
        public int tableRecords;<br />
        public int tableUniqueRecords;<br />
        public int diff;<br />
        public Queue<string> doubleKey = new Queue<string>();<br />
        public Queue<string> noNversion = new Queue<string>();<br />
        public void CheckForDoubleKey() // method analyzes the uniqueness of the table index key<br />
        {<br />
            string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\" + table + ".dbf";<br />
            string queryNumberRows = "SELECT "  + tableKey + " FROM " + table + " WHERE (nversionid = 0) AND (ldeleted = 0) " + "ORDER BY " + tableKey;<br />
            string queryDistinctRows = "SELECT DISTINCT " + tableKey + " FROM " + table + " WHERE (nversionid = 0) AND (ldeleted = 0) " + " ORDER BY " + tableKey;<br />
            string queryGetNotDistinctId = "SELECT  " + tableKey + ",nversionid, ldeleted, count(*) AS count FROM " + table + " GROUP BY " + tableKey + ",nversionid, ldeleted  HAVING count > 1 AND nversionid = 0 AND (ldeleted = 0) ";<br />
 <br />
            try<br />
            {<br />
                OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
                OleDbCommand command = new OleDbCommand(queryNumberRows);<br />
                command.Connection = ConnDpatient;<br />
                ConnDpatient.Open();<br />
<br />
                tableRecords = command.ExecuteNonQuery();<br />
                command.CommandText = queryDistinctRows;<br />
                tableUniqueRecords = command.ExecuteNonQuery();<br />
                if (tableRecords - tableUniqueRecords > 0)<br />
                {<br />
                    command.CommandText = queryGetNotDistinctId;<br />
                    try<br />
                    {<br />
                        OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
                        while (reader.Read())<br />
                        {<br />
                            doubleKey.Enqueue(reader.GetString(0).Trim());<br />
                        }<br />
<br />
                    }<br />
                    catch (Exception getDoubleIds)<br />
                    {<br />
                        MessageBox.Show(getDoubleIds.Message + Environment.NewLine + "Error while getting double key values.");<br />
                    }<br />
<br />
                }<br />
                ConnDpatient.Close();<br />
            }<br />
            catch (Exception analyzeTableError)<br />
            {<br />
                if (analyzeTableError.Message != "SQL: Column 'NVERSIONID' is not found." && analyzeTableError.Message != "SQL: Column 'COPNAMEID' is not found.")<br />
                {<br />
                    MessageBox.Show(analyzeTableError.Message + Environment.NewLine + "Error while analyzing table " + table);<br />
                }<br />
            }<br />
<br />
        }<br />
<br />
        public void CheckNversionid()<br />
        {<br />
            string connectionStringDpatient = "Provider=VFPOLEDB.1;" + "Data Source=" + omniwinRoot + "\\data\\" + table + ".dbf";<br />
            string queryAll = "SELECT " + tableKey + ", nversionid FROM " + table + " WHERE (ldeleted = 0) ORDER BY " + tableKey + ", nversionid";<br />
            OleDbConnection ConnDpatient = new OleDbConnection(connectionStringDpatient);<br />
            string previousIndex = "";<br />
            <br />
            try<br />
            {<br />
                OleDbCommand command = new OleDbCommand(queryAll);<br />
                OleDbCommand commandOnId = new OleDbCommand();<br />
                command.Connection = ConnDpatient;<br />
                ConnDpatient.Open();<br />
<br />
                OleDbDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);<br />
                while (reader.Read())<br />
                {<br />
                    if (reader.GetString(0).Trim() != previousIndex)<br />
                    {<br />
                        if (reader.GetValue(1).ToString().Trim() != "0")<br />
                        {<br />
                            noNversion.Enqueue(reader.GetString(0).Trim());<br />
<br />
                        }<br />
                    }<br />
                    previousIndex = reader.GetString(0).Trim();<br />
                } // end while<br />
<br />
                ConnDpatient.Close();<br />
           }<br />
           catch (Exception analyzeTableError)<br />
           {   <br />
                if (analyzeTableError.Message != "SQL: Column 'NVERSIONID' is not found." && analyzeTableError.Message != "SQL: Column 'COPNAMEID' is not found.")<br />
                {<br />
                    MessageBox.Show(analyzeTableError.Message + Environment.NewLine + "Error while checking the nversionid's of table: " + table);<br />
<br />
                }<br />
           }<br />
<br />
        }<br />
    }<br />
<br />
}

GeneralRe: BindingList and DataGridView question. [modified] Pin
Dave Kreskowiak29-May-07 10:44
mveDave Kreskowiak29-May-07 10:44 
GeneralRe: BindingList and DataGridView question. Pin
sharp source29-May-07 11:05
sharp source29-May-07 11:05 
GeneralRe: BindingList and DataGridView question. Pin
Dave Kreskowiak29-May-07 13:21
mveDave Kreskowiak29-May-07 13:21 
GeneralRe: BindingList and DataGridView question. Pin
sharp source30-May-07 8:22
sharp source30-May-07 8:22 
QuestionHow to stop the comboBox from being Edited? Pin
Khoramdin29-May-07 7:14
Khoramdin29-May-07 7:14 
AnswerRe: How to stop the comboBox from being Edited? Pin
Dave Kreskowiak29-May-07 7:25
mveDave Kreskowiak29-May-07 7:25 
AnswerRe: How to stop the comboBox from being Edited? Pin
Tarakeshwar Reddy29-May-07 7:27
professionalTarakeshwar Reddy29-May-07 7:27 
QuestionSending data thru the ethernet to a device Pin
Brad Wick29-May-07 6:54
Brad Wick29-May-07 6:54 
AnswerRe: Sending data thru the ethernet to a device Pin
Dave Kreskowiak29-May-07 7:15
mveDave Kreskowiak29-May-07 7:15 
AnswerRe: Sending data thru the ethernet to a device Pin
kubben29-May-07 7:15
kubben29-May-07 7:15 
GeneralRe: Sending data thru the ethernet to a device Pin
Brad Wick30-May-07 7:46
Brad Wick30-May-07 7:46 
GeneralRe: Sending data thru the ethernet to a device Pin
kubben30-May-07 7:56
kubben30-May-07 7:56 
GeneralRe: Sending data thru the ethernet to a device Pin
Brad Wick30-May-07 11:53
Brad Wick30-May-07 11:53 
GeneralRe: Sending data thru the ethernet to a device Pin
kubben30-May-07 12:36
kubben30-May-07 12:36 
GeneralRe: Sending data thru the ethernet to a device Pin
Brad Wick30-May-07 14:32
Brad Wick30-May-07 14:32 
GeneralRe: Sending data thru the ethernet to a device Pin
Brad Wick30-May-07 14:41
Brad Wick30-May-07 14:41 
GeneralRe: Sending data thru the ethernet to a device Pin
kubben31-May-07 1:47
kubben31-May-07 1:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.