Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven

This error might occur becuase you attempted to insert a row containing a specific identity value into a table that contains an identity column.

Now, you must specify the column list of the Product column when u use the IDENTITY_INSERT ON.

Check for the colution here:http://www.sql-server-helper.com/error-messages/msg-8101.aspx

Mitja Bonca 557 Nearly a Posting Maven

This is the parameter you have issues, right?:

da.Parameters.Add("@Available", SqlDbType.Bit).Value = textBox7.Text;

Bit can only have "true" or "false" values in th database.
What is your value in textBox7?

Its you have 1 or 0 do a conversation to true or false.

EDIT:
and instead of textBox6, in which you have date, you better use dateTimePicker ot monthCalendar. In this case there will never come to any inconveniances in capturing the right date value.

Mitja Bonca 557 Nearly a Posting Maven

Sure you can, but the Validating even it self will do nothing. You have to put the code inside of it, ok ?

Mitja

Mitja Bonca 557 Nearly a Posting Maven

You can test is in this way:
put on the from:
- textBox
- button
- label

Now create a method for a button_Click event and put use this code on it:

private void button1_Click(object sender, EventArgs e)
        {
            string sValue = textBox1.Text;
            int intValue = 0;
            decimal decValue = 0M;
            
            bool bValidating = int.TryParse(sValue, out intValue);
            if (!bValidating)
            {
                bValidating = decimal.TryParse(sValue, out decValue);
                if (!bValidating)
                    label1.Text = sValue + " is a string";
                else
                    label1.Text = sValue + " is a decimal";
            }
            else
                label1.Text = sValue + " is a integer";
        }

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

What do you want to validate? Stirng, int, double, bool?

Mitja Bonca 557 Nearly a Posting Maven

Placing the files in the solution folder won't do anything, you have to
tell the solution to add new project/files. Chose File->Add Project-
>Existing Project and then browse to your individual project files (.csproj
files). You can also right click your solution name and Add->Existing
Items to add individual files in case you don't have a project.

I'm not quite sure what you are trying to do. You can put a whole bunch
projects in a single solution, but if you got more than one static void
Main() in the solution you won't be able to run it with F5/Ctrl-F5. You
can however compile a single project by right clicking the project name in
the solution explorer and choose Build.

If you have a bunch of files with static void Main() in several, comment
out the ones you don't want to run. F5/Ctrl-F5 will then work just fine
and will Compile, then run.

Mitja Bonca 557 Nearly a Posting Maven

If it was, please mark the thread as answered.
thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I have repaired your code in the loop to:

case "Part time":
                        partTimeEmployees Employee = new partTimeEmployees (
                            fnameTextBox.Text,
                          LnameTextBox.Text, 
                          //Convert.ToDecimal(fixedWeeklySalaryTextBox.Text), 
                          Convert.ToDecimal(hourlyPayTextBox.Text), 
                          Convert.ToDouble(totalHoursTextBox.Text),
                          Convert.ToDecimal(overTimePayTextBox.Text));
                        totalEarningLabel.Text = "" + Employee.ToString() + "\r\n\n Weekly Earning : "
                            + Employee.Earnings().ToString("C") + "";
                        break;

..and now works, but Iam not sure if its correct. Now its on you to check it out.
PROBLEM WAS: you didnt pass the same npumber of arameters from button Click event to the constructor of the class "partTimeEmployees". And neither the value types werent the same (decimal, double).
Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

You know whats the problem with your code, you can pass to the constructor of the class (partTimeEmployees) only 3 parametes, but in your switch loop "partTime", you pass them 5. You have to change them to 3, or re-edit the constructor.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

string myEnum =MyEnum.A.Tostring();

Mitja Bonca 557 Nearly a Posting Maven

You mean actaully printing with priner on the paper?
If so, best way would be to use reports (Crystal reports for example, which VS 2008 has). On the report you create your own parameters and pass values to these parameters.

Mitja Bonca 557 Nearly a Posting Maven
catch(Exception ex)
{
    MessageBox.Show(ex.Message,"Error message");
}
Mitja Bonca 557 Nearly a Posting Maven

You`re welcome.
If there is anything you would like to know, just go ahead and ask.
And please, don`t forget to mark the thread as answered, if we`ve answered on your question. If there is another question in your mind, please start a new thread.
bye

Mitja

Mitja Bonca 557 Nearly a Posting Maven

YOu names the class as "MAP" and the same name is the method in it.
The constructor can be the only method which can have the same name as the class.

Example:

class ExampleClass
{
    public ExampleClass()
    {
         //constructor of class ExampleClass!
    }

    private void Method1()
    {        
        //method in ExampleClass
    }
   
    private string Method2()   
    {
        method in ExampeClass
        string a = null;
        //some code in here
        return a;
    }
}

remember... no method or even handler can have the same name as the class name (except the class`s constructor).

If you wanted to have some code in the constructor, you can not declare the return type.
You can see the example of constructor declarations here.
Hope this helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you dont use the sign "@" on the beginning of the path`s string, you have to write double back slashes for seperating folder. Example:

string path1 = @"C:\myFoler\myFile.txt";
string path2 = "C:\\myFolder\\myFile.txt";

I hope you see the difference between these two examples.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

If you got the answer on your question, can you please mark the thread as answered please?
thx
Mitja

Mitja Bonca 557 Nearly a Posting Maven

as Momerath said:
ThisList.Clear();

Mitja Bonca 557 Nearly a Posting Maven

if you want to read the file from the debuf folder in your current project you simply bind the text file, like:

string startupPath2 = Application.StartupPath + @"\something.txt"; //or maybe without backslash! try it(I am doing this code by my heart).
Mitja Bonca 557 Nearly a Posting Maven
string startupPath1 = System.IO.Directory.GetCurrentDirectory();
//or:
string startupPath2 = Application.StartupPath;

This will return the path of the debug diredctory in the current project.

Mitja Bonca 557 Nearly a Posting Maven

If you want to check if something has happened with the code correctly or not, you better use boolean values. This is a simpe example:

private void GoingIntoMAP()
        {
            string path = @"C:\1\myFile.txt";
            bool bSuccess = MAP(path);
            if (bSuccess)
                MessageBox.Show("An error has occured while reading file: " + path);
            else
                MessageBox.Show("File has beed read successfully."); //but this is not necessary to show, only errors or warnings!
        }

        public bool MAP(string FilePath)
        {
            using (FileStream fs = new FileStream(FilePath, FileMode.Open))
            {
                try
                {
                    //read the file and stuff you want to do!
                    //on the end:
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }

I hope this explains the concept of catching error.
Do some examples and you will see this is the best way.

Mitja

vedro-compota commented: +++ +1
Mitja Bonca 557 Nearly a Posting Maven

My question: do you want to have numbers seperated with a whitespace, or together?

Your question: Depends how do you want to.
If you know what the 3 is on 2nd place from the right, you can access to it like:

string str1 = "1357";
            string str2 = "1 3 5 7";
            string a1 = str1.Substring(1,1);
            string a2 = str2.Substring(2, 1);
Mitja Bonca 557 Nearly a Posting Maven

I have already showed how to do this:

//use the full upper code:
                    if (line.Contains(','))
                    {
                        line = line.Replace(",", "");
                        Numbers.Add(line);
                    }
Mitja Bonca 557 Nearly a Posting Maven

In the 1st part? What is that suppose to mean?
Did you mean in the same row?

Mitja Bonca 557 Nearly a Posting Maven

SORRY, but PLEASE.... START ANOTHER THREAD!
You question has been answered plenty of times. Even from my side.
Hope you understand the issue.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

This should do it:
But I am not sure what do you want exactly. Or do you want to put every single number from the file into its own row in the List (like: 1,3,7,9 add evey number to the list seperately), or you want to "join" number from one row (like : 1,3,7,9 join into 1379 and add this number to the list)?

This is the code:

FileStream aFile = new FileStream("SomeData.txt", FileMode.Open);
            List<NewList> Numbers = new List<NewList>();
            using (StreamReader sr = new StreamReader(aFile))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    //1.Putting every number into its own row in the list<T>:
                    string[] array = line.Split(',');
                    for (int i = 0; i < array.Length; i++)
                        Numbers.Add(array[i].ToString()); //you can remove ToString() method if not needed

                    //2.Putting all number into one row (removing commas from original):
                    if (line.Contains(','))
                    {
                        line = line.Replace(",", "");
                        Numbers.Add(line);
                    }
                }
            }

If this is not it, please exaplin a bit better what exactly would you like to do with the numbers, ok?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

you could mark this thread as solved using the mark as solved link above the quick reply box. That way I actually get credit for helping you.

Its about time :)

Mitja Bonca 557 Nearly a Posting Maven

I would better suggest you to start with using text files, its way simplier and as efficient as xml (if not even more in your case, becuase you dont have millions of data).

You can use streamWriter to write into txt filen and streamReader to read out of it.

// *** Read from file ***
--------------------------

// Specify file, instructions, and privelegdes
file = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Read);

// Create a new stream to read from a file
StreamReader sr = new StreamReader(file);

// Read contents of file into a string
string s = sr.ReadToEnd();

// Close StreamReader
sr.Close();

// Close file
file.Close();



// *** Write to file ***
--------------------------

// Specify file, instructions, and privelegdes
FileStream file = new FileStream("test.txt", FileMode.OpenOrCreate, FileAccess.Write);
            
// Create a new stream to write to the file
StreamWriter sw = new StreamWriter(file);

// Write a string to the file
sw.Write("Hello file system world!");

// Close StreamWriter
sw.Close();

// Close file
file.Close();
Mitja Bonca 557 Nearly a Posting Maven

Do you mean to close the project (completey)? If so, you have to save the data from listView somewhere, or into some file (xml, text), or into database. Otherwise, how will you retrive the data? When program is closed, all data gets lost. So the only way to retreive them back is to get them from somewhere were they were saved before - you get the point now?

Mitja Bonca 557 Nearly a Posting Maven

It will save the item to where, and load from from where?
Anyway, you can still use my code from above, you only need to modify it a bit.
If you are not sure how, let me know, I`ll show you, but you have to tell me where to save the data (or to database, or into some file (text one)).

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Here you go. I did an example code for you. I save all listView items into a List<T>.
Each row of List is consisted of a string array.

This is how you save the data from listView:

List<string[]> list;
        private void PopulatingListView()
        {
            ListViewItem item1 = new ListViewItem("item1", 0);
            // Place a check mark next to the item.
            item1.Checked = true;
            item1.SubItems.Add("1");
            item1.SubItems.Add("2");
            item1.SubItems.Add("3");
            ListViewItem item2 = new ListViewItem("item2", 1);
            item2.SubItems.Add("4");
            item2.SubItems.Add("5");
            item2.SubItems.Add("6");
            ListViewItem item3 = new ListViewItem("item3", 0);
            // Place a check mark next to the item.
            item3.Checked = true;
            item3.SubItems.Add("7");
            item3.SubItems.Add("8");
            item3.SubItems.Add("9");

            // Create columns for the items and subitems.
            // Width of -2 indicates auto-size.
            listView1.Columns.Add("Item Column", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 2", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 3", -2, HorizontalAlignment.Left);
            listView1.Columns.Add("Column 4", -2, HorizontalAlignment.Center);

            listView1.View = View.Details;
            //Add the items to the ListView.
            listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
        }

        private void buttonSaveFromListView_Click(object sender, EventArgs e)
        {
            //getting all the values into a list
            list = new List<string[]>();
            foreach (ListViewItem lvi in listView1.Items)
            {
                string[] values = new string[] { lvi.Text, lvi.SubItems[1].Text, lvi.SubItems[2].Text, lvi.SubItems[3].Text };
                list.Add(values);
            }
        }

And this is how you populate the listView again from the List<T>:

private void buttonPopulateListView_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count > 0)
            {
                listView1.Items.Clear();
                foreach (string[] item in list)
                {
                    ListViewItem lvi = new ListViewItem(item[0]);
                    lvi.SubItems.Add(item[1]);
                    lvi.SubItems.Add(item[2]);
                    lvi.SubItems.Add(item[3]);
                    listView1.Items.Add(lvi);
                }
            }

Take some time toi study. The code works well.
I hope this is what you have been looking for..

bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

This is how you get selected item from a listBox:

private void PopulatingListBox()
        {
            string[] ar = new string[] { "Coffee", "Cream" };
            listBox1.Items.AddRange(ar);
        }
 
         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string item = this.listBox1.SelectedItem.ToString();
            MessageBox.Show("Selected item is : " + item);
        }

Hope it helps,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Array covariance specifically does not extend to arrays of value-types. For
example, no conversion exists that permits an int[] to be treated as an
object[]."

When you pass an int[], it gets loaded into an object[] of length 1 and
passed to your method.

Mitja Bonca 557 Nearly a Posting Maven

You didnt put the dataGrid on the tab control, but on the main form.

Didn`t I tell you the same as you have find out now by your self?
Plase, be a bit more careful next time.
And mark the thread answered.

bye,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

or on the end of some code do:

this.btnLogin.Focus();

this should put the focus on login button. So after checking the user`s name and password, user can press the button with pressing Enter key.

Hope it helps,
Mitja

Mitja Bonca 557 Nearly a Posting Maven

Give me all the project, otherwise I cannot help you out. Upload it somewhere and give me the link (you can even pm me).
Mitja

Mitja Bonca 557 Nearly a Posting Maven

If this is the error, that means that one of 2 arrays (array[0] or array[1]) but mostly would be array[1] cannot get filled, becuase there is no data for it. Thats means that in the "line" there was no comma (,) and the string couldnt get splitted. There is only one string - but the adding code requires 2 strings.

Please check your file, if there is a comma on EVERY single line.
And please put a break point to go through the code line by line. And tell me exactly when this error occures (which line is in that moment in the streamReader).

Break point is thta red dot, which you put it by clicking on the far left side of the text editor. When code comes to break point, go with pressing F11 line by line.

kvprajapati commented: Very helpful!!! +11
Mitja Bonca 557 Nearly a Posting Maven

As I said, I have put your text into my file, and it all works fine. No errors at all.
I dont know what can be wrong on our side.

Mitja Bonca 557 Nearly a Posting Maven

You didnt put the dataGrid on the tab control, but on the main form.

Mitja Bonca 557 Nearly a Posting Maven

I have tried your text and it works good.
You have to set your own path (full path) to the file. Mine is:@"C:\1\testFile.txt". You set your own.

Mitja Bonca 557 Nearly a Posting Maven

Hmm regarding your text file, you cannot have integer as the value parameter. Change the int to string (in the dictonary).

like that:

static void Main(string[] args)
        {
            Dictionary<string, string> dir = new Dictionary<string, string>();
            using (StreamReader sr = new StreamReader(@"C:\1\testFile.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] array = line.Split(',');
                    dir.Add(array[0], array[1]);
                }
            }
            Show(dir);
        }

        private static void Show(Dictionary<string, string> dir)
        {
            foreach (KeyValuePair<string, string> line in dir)
            {
                Console.WriteLine("KEY: {0}, VALUE: {1}", line.Key, line.Value);
            }
            Console.ReadLine();
        }

... let me know if is it workin, ok?
Mitja

Mitja Bonca 557 Nearly a Posting Maven

I dont understand. Can you do some pictures, that I can see what do you menan?

Mitja Bonca 557 Nearly a Posting Maven

I did what I was thinking you want it to do:

class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, int> dir = new Dictionary<string, int>();
            using (StreamReader sr = new StreamReader(@"C:\1\testFile.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    string[] array = line.Split(',');
                    dir.Add(array[0].ToString(), Convert.ToInt32(array[1]));
                }
            }
            Show(dir);
        }

        private static void Show(Dictionary<string, int> dir)
        {
            foreach (KeyValuePair<string, int> line in dir)
            {
                Console.WriteLine("KEY: {0}, VALUE: {1}", line.Key, line.Value);
            }
            Console.ReadLine();
        }
    }

Hope it helps, if not, let me know.
bye,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

What means columnar format?
You mean one value under another?
PS: would you like to have an array of items?

Mitja Bonca 557 Nearly a Posting Maven

you said that "Panding" column name is a type of "bit". That means only true, or false value are required for insertion and selection. I did that in the upper example:
... Value = true; //this is it!

If this is not working for you, I dont know what can be wrong.. but I guess your Pending column is not a type of bit. Please take a look and check the code and database ones again.

Mitja

Mitja Bonca 557 Nearly a Posting Maven

Which error?

Mitja Bonca 557 Nearly a Posting Maven

I have re-made your code. I didnt test it, but it should work. Here you have it:

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;

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

        private void btnRun_Click(object sender, System.EventArgs e)
        {

            int intStart,
            intEnd;

            string strMsg1 = "Goodbye",
            strIncrement = btnIncrement.Text;

            if (txtStart.Text == "" ||
            txtEnd.Text == "")
            {
                MessageBox.Show(
                "Please enter a starting and ending value.",
                "Missing Information", MessageBoxButtons.OK,
                MessageBoxIcon.Exclamation);
            }
            else
            {
                intStart = Convert.ToInt32(txtStart.Text);
                intEnd = Convert.ToInt32(txtEnd.Text);

                if (btnIncrement.Text == "Increment")
                {
                    while (intStart <= intEnd)
                    {
                        lstOutput.Items.Add(intStart);
                        intStart++;
                    }
                }
                else
                {
                    int value = intEnd;
                    while (intStart <= intEnd)
                    {
                        lstOutput.Items.Add(value);
                        intStart++;
                        value--;
                    }
                }
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            lstOutput.Items.Clear();
            txtStart.Text = "";
            txtEnd.Text = "";
        }

        private void btnIncrement_Click(object sender, EventArgs e)
        {
            if (btnIncrement.Text == "Increment")
                btnIncrement.Text = "Decrement";
            else
                btnIncrement.Text = "Increment";
        }
    }
}
Mitja Bonca 557 Nearly a Posting Maven

This is your 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 Dec9Exercise
{
    public partial class Form1 : Form
    {
        string direction;

        public Form1()
        {
            InitializeComponent();
            direction = Direction.Increment.ToString();
        }

        private void buttonRun_Click(object sender, EventArgs e)
        {
            int[] array = Calculation();
            if (array.Length > 0)
                PopulatingValues(array);
        }

        private int[] Calculation()
        {
            int[] array = null;
            try
            {
                int value1 = Convert.ToInt32(textBox1.Text);
                int value2 = Convert.ToInt32(textBox2.Text);
                int counter = 0;
                array = new int[value2 - 1];

                if (direction == Direction.Increment.ToString())
                {
                    for (int i = value1; i <= value2; i++)
                        array[counter++] = i;
                }
                else
                {
                    for (int i = value2; i >= value1; i--)
                        array[counter++] = i;
                }
            }
            catch
            {
                MessageBox.Show("Some error has occured during calculation...");
            }
            return array;
        }

        private void PopulatingValues(int[] array)
        {
            for (int i = 0; i < array.Length; i++)
                this.listBox1.Items.Add(array[i]);
        }

        private void buttonChange_Click(object sender, EventArgs e)
        {
            if (buttonChange.Text == Direction.Increment.ToString())
            {
                direction = Direction.Decrement.ToString();
                buttonChange.Text = Direction.Decrement.ToString();
            }
            else
            {
                direction = Direction.Increment.ToString();
                buttonChange.Text = Direction.Increment.ToString();
            }
        }

        private enum Direction
        {
            Increment,
            Decrement
        }
    }
}

I hope you like it. It works fine.
DONT FORGET: Rename the controls (textBoxes, buttons, and listBox) like you have it in your project! Then its got to work.

I hope you like it,

Mitja

Mitja Bonca 557 Nearly a Posting Maven

How you want to have numbers listed? Horizontal ot vertical?

Mitja Bonca 557 Nearly a Posting Maven

Try something like this:

public partial class Form1 : Form
        {
            private Graphics g1;

            public Form1()
            {
                InitializeComponent();

                pictureBox1.Image = new Bitmap(500, 500);
                g1 = Graphics.FromImage(this.pictureBox1.Image);
                Pen gridPen = new Pen(Color.Black, 2);
                g1.DrawLine(gridPen, 0, 0, 100, 100);
            }
        }

... and read it here for some more info: http://www.questionhub.com/StackOverflow/4095260