Mitja Bonca 557 Nearly a Posting Maven

And here is an example of how to get all files (only names if you want) from a directory + files in all sub directory (change the file path):

class Program
    {
        static void Main(string[] args)
        {
            List<string> allFiles = GettingFiles(@"C:\1");
        }

        public static List<string> GettingFiles(string path)
        {
            List<string> listFiles = new List<string>();

            //1. get files from the current directory:
            string[] currentFiles = Directory.GetFiles(path, "*.*");
            foreach (string file in currentFiles)
                listFiles.Add(file);

            //2. get files from other sub directories:
            string[] directories = Directory.GetDirectories(path);
            foreach (string dir in directories)
            {
                string[] files = GetFilesFromDirectory(dir);
                listFiles.AddRange(files);
            }

            //for the end, lets get only the names of the files (remove the path):
            for (int i = 0; i < listFiles.Count; i++)
            {
                string fileName = Path.GetFileName(listFiles[i]);
                listFiles[i] = fileName;
            }
            return listFiles;
        }

        private static string[] GetFilesFromDirectory(string path)
        {
            string[] files = Directory.GetFiles(path);
            return files;
        }
    }

btw, thx ddanbe :)
Hope it helps,
Mitja

ddanbe commented: You could post this as a snippet! +8
Mitja Bonca 557 Nearly a Posting Maven

ddanbe, but this will only get folders, not files. I think he want to get all files in wanted directory, and in all subdirectories, if Im not mistaken.
This for example will return all the file paths:
string[] filePaths = Directory.GetFiles(@"C:\1", "*.*", SearchOption.AllDirectories);

Mitja Bonca 557 Nearly a Posting Maven

HostMonster restricts access to the DB by IP address. Localhost is always allowed.

Thats the same server providers. When you do your own homepage at any of such offerers, you have to use a localHost as path to the database. So it will not do. Sorry.

Mitja Bonca 557 Nearly a Posting Maven

I have create my table at run time. when new table is create then the data of that table show in datagridview. for that I have use dgv if their is any another control to do this task please tell me.

Depends from where you get data?
If this is from dataBase, the best option for sure is DataTable.
If not, there is plentiy better objects to use, like generic BindingList, or generic List.

Tell me whats your source of data?

Mitja Bonca 557 Nearly a Posting Maven

You need a correct connection string to the server. I will guess:
this is a default connection string type:
"Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"

you can see you need 4 different data, fill them in and you can access to user db on hostMaster.
As simple as that.

Mitja Bonca 557 Nearly a Posting Maven

I did some example code for you, which uses a bindingSource and import, export of data to/from xml.
What you have to do: Put tow buttons (addRow and SaveToXml) and a dataGridView Controls on form, and test this code:

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

namespace Jan30Exercise2
{
    public partial class Form1 : Form
    {
        BindingList<MyData> list;
        public Form1()
        {
            InitializeComponent();
            CreatingDGV();
            GetDataFromXML();
            CreatingDataTable();
        }

        public void GetDataFromXML()
        {
            DataTable dt = CreatingDataTable();
            dt.ReadXml(@"C:\1\test9.xml");
            foreach (DataRow dr in dt.Rows)
                list.Add(new MyData { Id = Convert.ToInt32(dr[0]), Name = dr[1].ToString() });
        }

        private void CreatingDGV()
        {
            list = new BindingList<MyData>();
            dataGridView1.DataSource = list;
            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.CellEndEdit += new DataGridViewCellEventHandler(dataGridView1_CellEndEdit);

            //string[] names = new string[] { "Person 1", "Person 2", "Person 3", "Person 4" };
            //for (int i = 0; i < names.Length; i++)
              //  list.Add(new MyData { Id = (i + 1), Name = names[i] });
        }

        private DataTable CreatingDataTable()
        {
            DataTable dt = new DataTable("Users");
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("userName", typeof(string));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dt.Rows.Add(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString());
            dt.AcceptChanges();
            return dt;
        }

        private void buttonToXml_Click(object sender, EventArgs e)
        {
            DataTable dt = CreatingDataTable();
            dt.WriteXml(@"C:\1\test9.xml");
        }

        internal class MyData
        {
            public int Id { get; set; }
            public string Name { get; set; }
        }

        private void buttonNewRow_Click(object sender, EventArgs e)
        {
            list.Add(new MyData { Id = list.Count + 1, Name = "" });
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            list[e.RowIndex].Name = dataGridView1[1, …
Mitja Bonca 557 Nearly a Posting Maven

The problem is that you do changes in dgv. So if you want to write all the data from dgv to xml, its best to use DataTable object. Create in on form load, and when you want to save the data into xml, pass data from dgv to dataTable, and from there to xml file:

private void Form1_Load(object sender, EventArgs e)
        {
            DataGridView dataGridView1 = new DataGridView();
            DataTable dt = new DataTable("testtable");
            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("name", typeof(string));
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
                dt.Rows.Add(dataGridView1[0, i].Value.ToString(), dataGridView1[1, i].Value.ToString()); 
            dt.AcceptChanges();
            this.dataGridView1.DataSource = dt.DefaultView;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataTable dt = ((DataView)this.dataGridView1.DataSource).Table;
            dt.WriteXml(@"C:\test\text.xml");
        }
kardo commented: 1 +0
Mitja Bonca 557 Nearly a Posting Maven

You mean table as DataTable? DataTable cannot be bind to dgv control. You can only populate dgv with using DataRow object, like for instance:

dataGridView1.Columns.Add("col1", "ID");
            dataGridView1.Columns.Add("col2", "NAME");
            string[] array1 = new string[] { "one", "two", "three" };

            table = new DataTable("myTable");
            table.Columns.Add(new DataColumn("id", typeof(int)));
            table.Columns.Add(new DataColumn("name", typeof(string)));
           
            DataRow dr;
            for (int i = 0; i < array1.Length; i++)
            {
                dr = table.NewRow();
                dr["id"] = i.ToString();
                dr["name"] = array1[i];
                table.Rows.Add(dr);
            }

            int row = 0;
            foreach (DataRow dr1 in table.Rows)
            {
                dataGridView1.Rows.Add();
                dataGridView1[0, row].Value = dr1[0].ToString();
                dataGridView1[1, row].Value = dr1[1].ToString();
                row++;
            }

If you want o use Binding property, you have to use some other object, like BindingList. See this example:

private struct Test
        {
            public int ID { get; set; }
            public string Name { get; set; }
        }

        private BindingList<Test> list = new BindingList<Test>();

        public Form1()
        {
            InitializeComponent();
            dataGridView1.DataSource = list;
            string[] array1 = new string[] { "one", "two", "three" };

            for (int i = 0; i < array1.Length; i++)
                list.Add(new Test { ID = i, Name = array1[i] });
        }

Hope this helps explaining the difference which object you can and which you cannot directly bind to some controls. But there is plenty of objects you can use as a binding source (like arrays ([]), lists,...).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

or create it a bitr shorter:

int rowIndex = 0;
            int columnIndex = 0;
            for (int i = 0; i < 4; i++)
            {
                TextBox Text = new TextBox();
                Text.Name = "text+" + i + 1;
                Text.TextChanged += new System.EventHandler(this.TB_TextChanged);
                if (i % 2 == 0 && i > 0)
                    rowIndex++;
                if (i % 2 != 0 && i > 0)
                    columnIndex++;
                else
                    columnIndex = 0;
               this.tableLayoutPanel1.Controls.Add(Text, columnIndex, rowIndex);                
            }
Mitja Bonca 557 Nearly a Posting Maven
//form1:
private string userName; //class variable
//from1 constructor:
public Form1(string passedValue)
{
     InitializeComponent();
     userName = passedValue; //here you bind a parameter passed into construncot to class variable
}

private void buttonOpenForm2(object sender, EventArgs e)
{
     //USE ONE OR THE OTHER WAY (NOT BOTH, BECUASE YOU WILL GET AN ERROR)
     //1. WAY:
     Form2 form2 = new Form2(userName);
     form2.Show(this);

     //2. WAY:
     Form2 form2 = new Form2();
     form2.ShowingUserName = userName;
     form2.Show(this);
}


//form2:
public Form2(string passedValue)  //1ST WAY (IF 2ND. DELETE THE PARAMETER IN BRACKETS)
{
     InlitializeConponent();
     label1.Text = passedValue; //pass the parameter value to label
}

public void ShowingUserName(string value) //2ND. WAY!
{
     label1.Text = value;
}

Hope this helps explaining how to pass parameters between forms (and methods).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

yes.
The is how the data (parameters) are passed in OOP.
You can check more about passing parameters here.

Mitja Bonca 557 Nearly a Posting Maven

I read your upper post a couple of times, but still don`t get it exactly what you would like to do.
Please make it simple, and dont try to examplin in details.
Do it like:
On form1 dgv has columns: a,b,c
On Form2 dgv has columns: x,y,z

When user add a tick in a dgv on form1, form2 has to open...
and something like it.
Dont complicate.
Sorry, but from your upper explanation, I count get a clue what exactly would you like to do.
If its simplier list with dashes.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I repaired it, but there is a problem with the code:

if (digit4 != '-') {}

I dont know what you have meant, but if user enters q or Q (to quit the program), the code goes into that if, and changes errorFlag to -4. Thats why user is unable to quit.
I changed the code a bit, now its working.
But still, take a look whats with that if statement.

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jan30Exercise
{
    class Program
    {
        // AcknowledgeCall Method - Write modified phone number to console
        static void AcknowledgeCall(char digitOne, char digitTwo, char digitThree,
               char digitFour, char digitFive, char digitSix, char digitSeven, char digitEight)
        {
            Console.WriteLine();
            Console.WriteLine("{0}{1}{2}{3}{4}{5}{6}{7}", digitOne, digitTwo, digitThree, digitFour, digitFive, digitSix, digitSeven, digitEight);
            Console.WriteLine();
            return;
        }
        // ReadDials Method  - Read phone number string and store in variables
        static int ReadDials(int errorFlag, ref int errorHolder, ref string phoneNumber, ref char digit1, ref char digit2, ref char digit3, ref char digit4, ref char digit5,
            ref char digit6, ref char digit7, ref char digit8)
        {
            errorHolder = 0;  // Declare local variables
            char holder = 'x';

            errorFlag = 0;
            if ((phoneNumber.Length != 1) & (phoneNumber.Length <= 7))              // Check for invalid phone number length  
            {                                                                       // and flag as invalid characters (null characters)
                errorFlag = -1;
            }
            //
            //WHAT IT THE CODE BELLOW: 
            //IF USER ENTERS q OR Q THE CODE COMES INTO HERE! SO THIS WAS YOUR PROBLEM!
            if (digit4 != '-')          //  If …
Mitja Bonca 557 Nearly a Posting Maven

As Momerath said, and I would add only that you do not create a new insatance of a Timer class ones again when pressing a start button!
Try to change the code into:

public partial class Form1 : Form
    {
        Timer t1; // timer 1
        Timer t2; // timer 2
        int timeInteger;

        public Form1()
        {
            InitializeComponent();
        }


        private void Start_Click(object sender, EventArgs e)
        {
            t1 = new Timer();
            t2 = new Timer();
            t1.Interval = 60000; // set timer one 1 minute
            t2.Interval = 1000; // set timer two 1 second
            timeInteger = t1.Interval; // set timer 1 in integer


            //Hook event handler
            t1.Tick += new EventHandler(t1_Tick);
            t2.Tick += new EventHandler(t2_tick);
            //start the timer
            t1.Start();
            t2.Start();
        }
  
        //AND THE ADDITIONAL CODE BELLOW HERE...
    }
Mitja Bonca 557 Nearly a Posting Maven

What do you mean? A method in Win form to insert userName, password and an email to sql dataBase?
YOu have to pass the data from textBoxes to sql command parameters, end execute the procedure.
Try this code:

private void InsertingData()
        {
            string connString = @"server=x;uid=y;pwd=z;database=xyz"; //this is an example, you need your own
            using (SqlConnection sqlConn = new SqlConnection(connString))
            {
                string query = String.Format(@"INSERT INTO Users VALUES (@id, @name, @password, @email)");
                using (SqlCommand cmd = new SqlCommand(query, sqlConn))
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.Parameters.Add("@id", SqlDbType.Int).Value = 1; //FIND YOUR NEW ID IF YOU HAVE THIS COLUMN IN DATABASE
                    cmd.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = textBox1.Text;
                    cmd.Parameters.Add("@password", SqlDbType.VarChar, 50).Value = textBox2.Text;
                    cmd.Parameters.Add("@email", SqlDbType.VarChar, 50).Value = textBox3.Text;
                    cmd.Connection.Open();
                    try { cmd.ExecuteNonQuery(); }
                    catch (Exception ex)
                    { 
                        MessageBox.Show(ex.Message); 
                    }
                    finally { cmd.Connection.Close(); }
                }
            }
        }
GAME commented: Sweet, It worked... +0
Mitja Bonca 557 Nearly a Posting Maven

You`re welcome.

Mitja Bonca 557 Nearly a Posting Maven

As they said: if you really have no base, its better to study other "simplier" things 1st.
I was trying to do sometihng similar for some of my projects (to inform customers with sms), but I let it go, becuase in my country for something like it, I would need to pay money - its not free any longer (it used to be, but not any more).

anyway, here you can get some info:
- http://www.daniweb.com/forums/thread192009.html
- http://www.codeproject.com/KB/database/SMS_message_from_SQL.aspx
- http://www.dotnetspider.com/resources/6138-send-sms-using-c.aspx
- http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/ea2cc48c-0cef-4e40-ac27-71007096d854 (a good one)

Mitja Bonca 557 Nearly a Posting Maven

I did a semple code, to see what dataSet and dataTables are all about. To test this method, paste it into a windows application project, and run it.
Put a break point and go through the code line by line (with F11).

private void Method()
        {
            DataSet ds = new DataSet();
            DataTable table1 = new DataTable("table one");
            DataTable table2 = new DataTable("table two");

            //creating columns for the tables:
            table1.Columns.Add(new DataColumn("id", typeof(int)));
            table1.Columns.Add(new DataColumn("someText", typeof(string)));

            table2.Columns.Add(new DataColumn("id2", typeof(int)));
            table2.Columns.Add(new DataColumn("someOtherText", typeof(string)));

            //populating tables, one by one and add them to dataSet:
            //populating table 1:
            DataRow dr;
            for (int i = 1; i < 13; i++)
            {
                dr = table1.NewRow();
                dr["id"] = i;
                dr["someText"] = "text with number " + i.ToString();
                table1.Rows.Add(dr);
            }

            //populating table 2:
            for (int i = 101; i < 113; i++)
            {
                dr = table2.NewRow();
                dr["id2"] = i;
                dr["someOtherText"] = "other text with number " + i.ToString();
                table2.Rows.Add(dr);
            }

            //adding both tables to dataSet:
            ds.Tables.AddRange(new DataTable[] { table1, table2 });
            //you could add them seperately, like:
            //ds.Tables.Add(table1);
            //ds.Tables.Add(table2);

            //Now lets loop through the dataSet and write the results out (int messageBox):
            for (int i = 0; i < ds.Tables.Count; i++)      //LOOP THROUGH TABLES OF DATASET
            {
                string text = null;
                foreach (DataRow dr1 in ds.Tables[i].Rows) //LOOP TRGOUGH THE ROWS OF DATATABLE
                {
                    string a = dr1[0].ToString();
                    string b = dr1[1].ToString();
                    text += a + ". " + b + Environment.NewLine;
                }
                MessageBox.Show("In dataSet is dataTable of index [" + i + "] with values:\n" + text); …
Mr.BunyRabit commented: Went further than just telling me how to do it, but showed me the diffirence between the two +1
Mitja Bonca 557 Nearly a Posting Maven

Do like this:

public Form1(string _strUser) //passing data from main to the constructor!
        {            
            InitializeComponent();
            //OnBeginning(_strUser); comment this line, so it won`t be called!
        }
Mitja Bonca 557 Nearly a Posting Maven

This is the whole code. The only thing you have to take care of, is to get the string of the tag (tag is the name of the object you want to edit - in out example this would be "susp_front"). Or you will set this variable to a tabContol or on some radioButton - its up to you.
And you have to make sure how many textBoxes and lables would you like to have for eact object. You can do a seperated method which would show the exact amount of textBoxes and labels (if you want it to make all automatic). But this is going into a very details.

PS: one more thing: in the method "PopulatingText" you will see I do an array of textBoxes and lables - these are the controls which I putted on the form in a designer, and I operate with them to populate them with appropriate data. With this kind of code you could choose Object by a radio button (front_susp, end_susp,...) and the code will automatically choose how many textBoxes and lables you need (with the appropriate text in each label).

Hope you like it, here it is:

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

namespace Jan28FindIn_TextFile
{
    public partial class Form1 : Form
    {
        string tag;
        string path;
        string allText;
        string originalText;
        string modifiedText;

        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGet_Click(object sender, EventArgs …
Mitja Bonca 557 Nearly a Posting Maven

Login form has to appear before MainForm.Take a look into this code, how to pass data:

//program.cs (where is the Main() method):
    using (Login login = new Login())
    {
        login.StartPosition = FormStartPosition.CenterScreen;
        if (login.ShowDialog() == DialogResult.OK)
        {                        
             Application.Run(new Form1(login.strUserName));
        }
    }

    //LOGIN FORM: 
    public partial class Login : Form
    {
        public string strUserName { get; private set; }

        public Login()
        {           
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strUser = textBox1.Text;
            string strPswd = textBox2.Text;
            if (strUser != String.Empty && strPswd != String.Empty)
            {
                //YOUR METHOD TO CHECK LOGIN DATA:
                if (LoginCheck.CheckingLogin(strUser, strPswd) == true)
                {
                    strUserName = strUser;
                    this.DialogResult = DialogResult.OK;
                    //IF THEY ARE OK, CODE RETURNS TO MAIN METHOD (on program.cs)
                }
            }
        }

     //ON FORM1:
     public partial class Form1 : Form
    {        
        public Form1(string _strUser) //passing data from main to the constructor!
        {            
            InitializeComponent();
            OnBeginning(_strUser);
        }

        private void OnBeginning(string strUserName)
        {
            label1.Text = "Loged user: " + strUserName;
        }

Hope this helps explaining how you should do the login and passing data (username) between classes and methods inside classes.

Mitja Bonca 557 Nearly a Posting Maven

Would you please explain a bit better what would you like to pass where. You only said you have 2 forms, on both there are dataGridViews. And when you add a tick onto dgvCheckBoxColumn this exact row`s data has to pass to another form.
Can you please explain Exactly what you want to do.
then I can help you out,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I will do it, but I am considering th best option. Its not simple, but not impossible. Will do it for sure.

Mitja Bonca 557 Nearly a Posting Maven

The code for exporting all the values from the file for any kind is now working well. Dont worry or those errors now.
Now iam considering how to do the import - send data back to file to the correct spot. Do you have any idea?
This is a hard task you know. Will take more then then the other.

Mitja Bonca 557 Nearly a Posting Maven

One question about this row:
restlen=0.142 ;0.1m RL, 3625N load

Do you want to show all in a textBox, or only to sign ";", so only this:0.142
or all the string

Mitja Bonca 557 Nearly a Posting Maven

I did an import of data. This is my example file:
Name1
{
x=1
y=2,4
z=3,6
}
Name2
{
x=4,5
y=2
z=6
}
Name3
{
x=7,4
y=5,4
z=5
}
Name4
{
x=5,2
y=6
z=7,3
}
(

(so that you wont wonder where from I get "Name1" - its only an example).
I even included label (beside textBoxes) to get auto-named, depending on the name which is on the left side of the equalizer ("="). This is the code:

namespace Jan28FindIn_TextFile
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonGet_Click(object sender, EventArgs e)
        {
            string tag = "Name2";
            string tagEnd = "}";
            string path = Environment.CurrentDirectory + @"\text7.txt";
            string allText = System.IO.File.ReadAllText(path);
            string[] array = allText.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            int start = (Array.IndexOf(array, tag)) + 2;
            int end = 0;
            for (int i = start; i < allText.Length; i++)
            {
                string item = array[i];
                if (item == tagEnd)
                {
                    end = i;
                    break;
                }
            }

            TextBox[] textBoxes = new TextBox[] { textBox1, textBox2, textBox3, textBox4, textBox5 };
            Label[] labels=new Label[]{label1,label2,label3,label4,label5};

            //empty the labels and textBoxes before filling it:
            for (int c = 0; c < textBoxes.Length; c++)
            {
                textBoxes[c].Text = String.Empty;
                labels[c].Text = String.Empty;
            }

            //populating labels and textBoxes from the appropriate content:
            int counter = 0;
            for (int i = start; i < …
ddanbe commented: Nice effort! +8
Mitja Bonca 557 Nearly a Posting Maven

Why do you have 2 closing brackets:
susp_front
{
y=0
z=1.599
restlen=0.142 ;0.1m RL, 3625N load
minlen=0.005
maxlen=0.16
bumpstop_len=0.04
bumpstop_k=70000
k=86150
}
}

Mitja Bonca 557 Nearly a Posting Maven

Ok, I new I was right :)
Anyway, so there is plenty of "NAMES" with their values.
What we need to do, is like ddanbe said, we need some sort of tokenizer to get thw wanted values - and then they need to go back to the same place from where they were taken.

One question:
The pattern is like you said:
NAME1
{
value1
value2
value3
and so on...
}
NAME2
{
value1
value2
value3
and so on...
}


so, how do I know which name to look for?
Just answer me on these 2 questions, and I`ll try to do the code for you.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

I don`t think I can understand you.
Tell me, what is that you are looking for EXACTLY?
Are this only values of X,Y and Z?

If so, are these the only x,y and z in the ini file?
Please, id you need help, I would expect a better understandable explanation.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is the only text you have in the file:
location
{
x=0.35
y=0.56
z=-0.5
}

??

or there is more, and you want to 1st find the text "Location" and th values inside brackets?

Mitja Bonca 557 Nearly a Posting Maven

Please provide us some more information, about what exactly are you trying to validate.

Mitja Bonca 557 Nearly a Posting Maven

Try with using HasSet collection:

class Program
    {
        static void Main(string[] args)
        {
            string[] array = { "a", "b", "c", "b", "d", "e", "c" };
            string[] result = RemovingDuplicates(array);
        }

        private static string[] RemovingDuplicates(string[] array)
        {
            HashSet<string> set = new HashSet<string>(array);
            string[] result = new string[set.Count];
            set.CopyTo(result);
            return result;
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Hi, glad to hear you are at the end of db creation. DB is one of the most important things of the whole project, so its always worth to take some more time on it, rather then regret afterwards (when you cannot get the correct results on some queries).
Anyway, answering your question: Create one table, which will have a new column of "Doctor type".
About E-R model, I dount I can help you out, because I dont know your db structure - I dont know your attrubutes of the entityes.

But it wouldn`t be hard to create one, just follow some basic rules on e-r model.
You always have to have in mind your actual DB (physical model), then you can simply create E-R.
For eaxmple: Create an Entity (Doctors), then create all the attributes for it (id, firstName, lastName, type, botn, specialty, ...) Then another Entity (Patients), with attributes: (id, name, lastName,...) the relationShip between this two tables is "Has" or "Heals".
The Entity is some usually some physical object (object, subject)
The Attribute is a value that has some entity
The RelationShip is (its a verb) which descriubes two or more Entites are related to each other.
So if you will follow this patern, you cannot miss much.

Hope it helps a bit, better explanation can be found here.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If I understand you, you would like to delete rows. If all the requirements (WHICH ONE??) aren`t meat, the user is unable to delete selected row and the error message pops up.
But what I do not understand is what is wrong with the code - so would you be so kind, and past it here some more of your code, to actually see whats wrong with it - any maybe some better explanation would be weclome as well.
thx
mitja

Mitja Bonca 557 Nearly a Posting Maven

Do you want to insert a new row on the top of the dgw, or at the bottom (into a new row)?
If is the last thing, you 1st need to count all the rows and then insert the values into the allRows + 1(so into a new row):

private void button1_Click(object sender, EventArgs e)
        {
            // insert Values into Datagridview
            int allRows = tblAllEntries.Rows.Count;
            
            
            tblAllEntries.Rows[allRows].Cells[1].Value = lbldate.Text.ToString();
            tblAllEntries.Rows[allRows].Cells[2].Value = txtboxReminder.Text.ToString();
            tblAllEntries.Rows[allRows].Cells[3].Value = txtboxCost.Text.ToString();

            tblAllEntries.Rows[allRows].Cells[0].Selected = true; ---<<< I added this because i thought it had to be selected, but it didnt work..
            
            dAdapter.Update(dTable);
          } 
     }

this should do it.

If you want to insert a new row into 1st row of dgv, you will have to create a dataTable before inserteing a new row, fill it with the data from dgv, insert a new row into dgv (or into dataTable - in 1st row), and populate dgv from the dataTable.
But this doesnt make sence - for inserting new row, its best to do an insertion into last row of dgv.

Mitja Bonca 557 Nearly a Posting Maven

Why you dont use ShowDialog method, like I showed in the example above?
You should just modify the code a bit, to look something like this:

//MAIN FORM:
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            using (Form2 form2 = new Form2())
            {
                form2.StartPosition = FormStartPosition.CenterParent;
                if (form2.ShowDialog() == DialogResult.OK)
                {
                    //LOGIN SUCCEEDED
                    //ENABLE THINGS HERE
                }
            }
        }

        //LOGIN FORM:
        private void button1_Click(object sender, EventArgs e)
        {
            string userName = textBox1.Text;
            string password = textBox2.Text;
            if (userName != String.Empty && password!=String.Empty)
            {
                if (userName == "abc" && password == "123")
                    DialogResult = DialogResult.OK;
                else
                    MessageBox.Show("Username and password are not correct.", "Warning");
            }
            else
            {
                MessageBox.Show("Ongeldige gebruikersnaam of wachtwoord", "Waarschuwing",
                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

Try to use this kinda code - it more appropriate then your version - using a ShowDialog() method has plenty of advantages, you can see that in LoginForm you dont need to call a Close() or Dispose() method when you call DialogResult property.
And at the same time, on MainForm, you can use DialogResult property if its equal to OK (depends how you set it in LoginForm), and you can then do a seperate code for OK, or Cancel.

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Only ones of course.
Different would be something like that:

string[] array = GetString();
//method GetString returns an array of strings
//you you go through a foreach loop like it:
foreach(string str in array)
{
   here you can loop through str string!
}
Mitja Bonca 557 Nearly a Posting Maven

How do you populate the users list on main form? Is it from a DataTable (or dataSet) or some array list?
You can use a delegate to pass the data from one form to another, and refreshing the gdv control with calling the method to populate it.
YOu can take a look into this simple example, wgich shows how to pass data from one form to another (from textBox to a label) - you can do the same, only to pass the data to some other method, which would populate dgv (or add a new row to it):

//FORM1:
    public partial class Form1 : Form
    {
        delegate void MyDelegate(string str);

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2(this);
            form2.Show(this);
        }

        public void PassingParameters(string item)
        {
            if (label1.InvokeRequired)
            {
                MyDelegate d = new MyDelegate(PassingParameters);
                label1.Invoke(d, new object[] { item });
            }
            else
                label1.Text = item;
        }
    }

//FORM2:
    public partial class Form2 : Form
    {
        Form1 form1;
        public Form2(Form1 _form1)
        {
            InitializeComponent();
            form1 = _form1;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string item = textBox1.Text;
            form1.PassingParameters(item);
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

dgView.Rows.Add(); //what else?

Mitja Bonca 557 Nearly a Posting Maven

btw, one thing to mention here: Why you dont create a login form before the main one even appears?
You can use DialogResult() method to check if the user has entered the correct login data or not. How to use it, you can take a look on example here: http://support.microsoft.com/kb/816145

And this would be my example:

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            string proc = Process.GetCurrentProcess().ProcessName;
            Process[] processes = Process.GetProcessesByName(proc);
            if (processes.Length > 1)
            {
                MessageBox.Show("Application is already running.", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                using (Login login = new Login())
                {
                    login.StartPosition = FormStartPosition.CenterScreen;
                    if (login.ShowDialog() == DialogResult.OK)
                    {   
                        //passing logged userName into Form1`s constructor                     
                        Application.Run(new Form1(login.strUserName)); 
                    }
                    //if you will turn down the login 
                    //(for example after 3 wrong logins in Login forms)
                    //the app. will close it self!
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Try using Server - Client appication with tcpListener and tcpClient. This is an example code:
Source

//The client:

using System.IO; 
using System.Net; 
using System; 
using System.Threading; 
using N = System.Net; 
using System.Collections; 
using System.Windows.Forms; 
using System.ComponentModel; 
using System.Runtime.InteropServices; 

class TalkUser { 
    
   static Form talk; 
   static N.Sockets.TcpClient TC; 

   [DllImport("kernel32.dll")] 
   private static extern void ExitProcess(int a); 
    
   public static void Main() { 
       talk = new Form(); 
       talk.Text = "TalkUser - The OFFICIAL TalkServ Client"; 
       talk.Closing += new CancelEventHandler(talk_Closing); 
       talk.Controls.Add(new TextBox()); 
       talk.Controls[0].Dock = DockStyle.Fill; 
       talk.Controls.Add(new TextBox()); 
       talk.Controls[1].Dock = DockStyle.Bottom; 
       ((TextBox)talk.Controls[0]).Multiline = true; 
       ((TextBox)talk.Controls[1]).Multiline = true; 
       talk.WindowState = FormWindowState.Maximized; 
       talk.Show(); 
       ((TextBox)talk.Controls[1]).KeyUp += new KeyEventHandler(key_up); 
       TC = new N.Sockets.TcpClient(); 
       TC.Connect("IP OF A SERVER HERE",4296); 
       Thread t = new Thread(new ThreadStart(run)); 
       t.Start(); 
       while(true) { 
           Application.DoEvents(); 
       } 
   } 
    
   private static void talk_Closing(object s, CancelEventArgs e) { 
       e.Cancel = false; 
       Application.Exit(); 
       ExitProcess(0); 
   } 
    
   private static void key_up(object s,KeyEventArgs e) { 
       TextBox TB = (TextBox)s; 
       if(TB.Lines.Length>1) { 
           StreamWriter SW = new StreamWriter(TC.GetStream()); 
           SW.WriteLine(TB.Text); 
           SW.Flush(); 
           TB.Text = ""; 
           TB.Lines = null; 
       } 
   } 
    
   private static void run() { 
       StreamReader SR = new StreamReader(TC.GetStream()); 
       while(true) { 
           Application.DoEvents(); 
           TextBox TB = (TextBox)talk.Controls[0]; 
           TB.AppendText(SR.ReadLine()+"\r\n"); 
           TB.SelectionStart = TB.Text.Length; 
       } 
   } 
}

//And the server:

using System.IO; 
using System.Net; 
using System; 
using System.Threading; 
using N = System.Net; 
using System.Collections; 

class TalkServ { 
    
   System.Net.Sockets.TcpListener server; 
   public static Hashtable handles; 
   public static Hashtable handleByConnect; 
    
   public static void Main() { 
       TalkServ TS = new TalkServ(); 
   } 

   public TalkServ() { 
       handles = new Hashtable(100); 
       handleByConnect = new Hashtable(100); 
       server = new System.Net.Sockets.TcpListener(4296); 
       while(true) { 
           server.Start(); 
           if(server.Pending()) { …
Mitja Bonca 557 Nearly a Posting Maven

I see...

Mitja Bonca 557 Nearly a Posting Maven

Take a look into the code I did only for you. Its a code, which allows the user to insert as many numbers and operands as he wants to create a formula.
On the end, when he wants to create an out put, he only inserts the enter after number:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Jan22Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            bool bEnd = false;
            decimal total = 0M;
            decimal number = 0M;
            string strOperand = null;
            string strFormula = null;
            int counter = 1;

            Console.WriteLine("Calculator: Please enter number by number, seperated by operands.");
            Console.WriteLine("To get the result, simply write the equals sing just after number (X=)");
            do
            {
                string word = GetCounter(counter);              

                Console.WriteLine("Please enter the " + word + " number:");
                string strNumber = Console.ReadLine();

                
                if (strNumber.Contains("="))
                {
                    strNumber = strNumber.Remove(strNumber.Length - 1, 1);
                    bEnd = true;
                }
                bool bChecking = CheckingNumber(strNumber);
                if (bChecking)
                {
                    strFormula += strNumber;
                    counter++;
                    number = Convert.ToDecimal(strNumber);
                    total = GetTotal(number, total, strOperand);

                    bChecking = false;
                    while (!bChecking && !bEnd)
                    {
                        Console.WriteLine("Please enter the operand (+, -, /, *):");
                        strOperand = Console.ReadLine();
                        bChecking = CheckingOperand(strOperand);
                        if (bChecking)
                            strFormula += strOperand;
                        else
                            Console.WriteLine("Wrong operand.");
                    }
                }
                else
                    Console.WriteLine("This is not the number.");
            }
            while (!bEnd);

            //on the end it shows the final result:
            strFormula = strFormula + "=";
            Console.WriteLine("{0}{1}", strFormula, total.ToString());
            Console.ReadLine();
        }

        public static string GetCounter(int counter)
        {
            string word = null;
            string[] words = { "1st", "2nd", "3rd" };
            if (counter < 3)
                word …
Mitja Bonca 557 Nearly a Posting Maven

Take a look into this example, which invokes the label:

public partial class Form1 : Form
    {
        delegate void MyDelegate(string msg);
        public Form1()
        {
            InitializeComponent();
            labelShow.Text = "";
        }

        private void buttonStart_Click(object sender, EventArgs e)
        {
            Thread thread = new Thread(new ThreadStart(DoingTimeConsumingStuff));
            thread.Start();
        }

        private void DoingTimeConsumingStuff()
        {
            for (decimal i = 0.0001M; i < 1000000000; i++)
            {
                UpdatingMyControl(i.ToString());
            }
        }

        private void UpdatingMyControl(string strValue)
        {
            if (this.labelShow.InvokeRequired)
                this.labelShow.Invoke(new MyDelegate(UpdatingMyControl), new object[] { strValue });
            else
                labelShow.Text = strValue;
        }      
    }
Mitja Bonca 557 Nearly a Posting Maven

Try this:
DELETE FROM allBooks
WHERE ([Book Name] = 'book_NameListBox.SelectedItems[0].ToString()')

Mitja Bonca 557 Nearly a Posting Maven

Yo, I`m did the code for you. I hope you like it. I put some effort into it today (yest. didnt have time, sorry).

To test it, create a win form, and put two labels on it. But dont exagurate with the numbers (just for a text, use maybe a few ten).
This is the code:

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

namespace Jan19NumberArray
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            label1.Text = "";
            label2.Text = "";
            YourMain();
        }

        private void YourMain()
        {
            string[] lines = ReadingFile();
            List<List<int>> list = SeperatingNumbers(lines);
            int[,] array = Create2DIntArray(list);
            ShowingArray("horizontal", array);
            int[,] newArray = Transform(array);
            ShowingArray("vertical", newArray);
        }

        private string[] ReadingFile()
        {
            string path = @"C:\1\test6.txt";
            string[] lines = File.ReadAllLines(path);
            return lines;
        }

        private List<List<int>> SeperatingNumbers(string[] lines)
        {

            List<List<int>> listOuter = new List<List<int>>();
            List<int> listInner;
            for (int i = 0; i < lines.Length; i++)
            {
                listInner = new List<int>();
                string[] rowNumbers = lines[i].Split(' ');
                for (int j = 0; j < rowNumbers.Length; j++)
                {
                    int num = Convert.ToInt32(rowNumbers[j]);
                    listInner.Add(num);
                }
                listOuter.Add(listInner);
            }
            return listOuter;
        }

        private int[,] Create2DIntArray(List<List<int>> listOuter)
        {
            int rows = listOuter.Count;
            int maxColumns = listOuter.Max(a => a.Count);
            int[,] array = new int[rows, maxColumns];

            for (int k = 0; k < listOuter.Count; k++)
            {
                List<int> In_list = listOuter[k];
                for (int l = 0; l < listOuter[k].Count; l++)
                {
                    array[k, l] = In_list[l];
                }
            }
            return array;
        }
        
        T[,] Transform<T>(T[,] array) …
vedro-compota commented: ++++++++++++ +1
Mitja Bonca 557 Nearly a Posting Maven

Here is an example of how to use a timer. Important to know: Timer tick is the method which is called when the timer come to zero:

public partial class Form1 : Form
    {
        Timer timer1;
        int counter;

        public Form1()
        {
            InitializeComponent();
            label1.Text = "countier: 0";
            CreatingTimer();
        }

        private void CreatingTimer()
        {
            timer1 = new Timer();
            timer1.Tick += new EventHandler(timer1_Tick);
            timer1.Interval = 1000;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            counter++;
            timer1.Enabled = true;
            label1.Text = "counter: " + counter.ToString();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            timer1.Start();
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

Update what? You mean dgv?

1st of all, you have to put the gdv creation into a seperate method, which has to be called only ones. Another method will populate the dgv - this method can be called numerous times. And you can use DataSource to populate dgv, no need to populate it "manually" in the runtime (like for loop in the upper example).

Mitja Bonca 557 Nearly a Posting Maven

Adapost gave you a great starting point, you only have to build it up a bit:

private void Method()
        {
            string flag = "000-00-0000";
            string[] lines = System.IO.File.ReadAllLines(@"C:\1\test6.txt");
            foreach (string line in lines)
            {
                if (line.Contains(flag))
                {
                    MessageBox.Show("The number was found.");
                    break;
                }
            }
        }
Mitja Bonca 557 Nearly a Posting Maven

Wait, Iam trying to do ...