Geekitygeek 480 Nearly a Posting Virtuoso

If all of your classes will store the same data but relevant to different cities then you could add a City member to the class, eg:

class City
{
    string Name;
    string Number;
    string City;
}

Your class would obviously include the necessary properties, modifiers, etc.

If each class will have a different implementation then you can create a virtual class that outlines the members each city must have. Then each derived city class inherits from the base class and overrides the virtual members.

Using this structure, you can create a list of your base class to store all your cities but when you access the virtual members it will call the child versions. Such as:

class Class1
    {
        public Class1()
        {
            A = 1;
        }

        virtual public int A { get; set; }
    }

    class Class2 : Class1
    {
        public Class2()
        {
            A = 2;
        }

        public override int A { get; set; }

    }

    class Program
    {
        static void Main(string[] args)
        {
            Class1 c1 = new Class1();
            Class2 c2 = new Class2();
            List<Class1> classes = new List<Class1>();
            classes.Add(c1);
            classes.Add(c2);

            foreach (Class1 cl in classes)
            {
                Console.WriteLine(cl.A);
            }

            Console.ReadKey();
        }
    }
Geekitygeek 480 Nearly a Posting Virtuoso

Before I answer your question, I just want to cover a couple of things that you ought to know about this code:

if btAdd_Click() = true;

Firstly, if you are comparing objects you need to use the "equal to" operator which in C# is == . ie if(x == y) .
When you use a single '=' it is an assignment operator.
Very small difference in syntax that causes very big differences in behaviour.

Secondly, your are correct that btAdd_Click requires parameters to run so you can't call btAdd_Click() with empty parentheses. The only method signature for btAdd_Click requires two parameters, one of type object and one of type EventArgs.

In your code btAdd_Click(someObject, someEventArgs) == true would still be incorrect because btAdd_Click is declared with a void return. If you had the following method:

//method with return type bool
private bool CheckSomething()
{
    if(something)
        return true;
    else
        return false;
}

Then it is valid syntax to directly compare the methods return value:

if(CheckSomething() == true)
    //do something

Lastly, when dealing with boolean values it is not necesarry to use "== true".
Examine the following:

bool someFlag = true;
if(someFlag == true)
    //do something

Since someFlag is already a boolean, you are basically asking "if (true is true)" so you can use the boolean itself as the condition for the if statement:

if(someFlag)
    //do something

Along the same lines, you have the NOT operator, which in C# is ! . …

Lusiphur commented: Um... Wow! :twisted: +1
Geekitygeek 480 Nearly a Posting Virtuoso

@mono_jit23: Your code would only split the values into a single array, the OP needs Numbers in one array and operators in another.

@rutul: The problem you are going to have is dimensioning your arrays as you wont know how many Numbers and how many operators your string holds until you have parsed it. I would suggest you use a generic collection like List<string> and List<int> instead as they resize as items are added.

As for splitting it, one approach would be to go character by character using a for loop. If your input only has single digit numbers (0 to 9) then you just check if the current character is a number (char.IsDigit()); if its a number add it to your number list, if its not then add it to your operators.
If the numbers can be greater than 9 then you will need to "remember" the start of the current number then search till you hit an operator to mark the end of the current number before you store it.

Have a go at this yourself and post your code so far if you get stuck :)

ddanbe commented: Just plain good! +7
Geekitygeek 480 Nearly a Posting Virtuoso

I believe the question is "Why isnt the text showing when i call 'frm.textbox6.Text = stype' ??"
The answer is, frm holds a reference to a new instance of Form1, an instance that has not been displayed on the screen. Instead of Form1 frm = new Form1() you need to store a reference to your current Form1.
Also, making a control public is terrible OO practice. You should always access internal members through methods and properties.
I have a tutorial here that shows how to pass values back to a control on the calling form.

Geekitygeek 480 Nearly a Posting Virtuoso

If you are only interested in the Bitmap you extract from the EventArgs i would suggest adding a custom event to your Camera class that alerts listeners that a new bitmap is ready.
There's a good tutorial here that helped me get to grips with the concepts.
My events look something like:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            //attach event handler
            Cam.NewFrameAdded += new NewFrameAddedHandler(Cam_NewFrameAdded);
        }

        void Cam_NewFrameAdded(object sender, EventArgs e)
        {
            //when new frame is added, copy it to picturebox
            pictureBox1.Image = Cam.NewFrame;
        }

        Camera Cam = new Camera();

        private void btnTest_Click(object sender, EventArgs e)
        {
            Cam.TestEvent();
        }
    }

    //create handler signature for your event
    public delegate void NewFrameAddedHandler(object sender, EventArgs e);

    class Camera
    {
        private Bitmap _newFrame;
        public Bitmap NewFrame
        {
            get { return _newFrame; }
            set
            {
                _newFrame = value;
                OnNewFrameAdded(new EventArgs());
            }
        }

        //create event
        public event NewFrameAddedHandler NewFrameAdded;
        public virtual void OnNewFrameAdded(EventArgs e)
        {
            //if there are no listeners attached to an event it will be null
            //raising an event whilst it is null results in exception.
            //perform check to ensure event is not null before raising it:
            if (NewFrameAdded != null)
                NewFrameAdded(this, e);
        }

        public void TestEvent()
        {
            Bitmap b = (Bitmap)Image.FromFile("cele.jpg");
            NewFrame = b;
        }
    }

This is a very basic implementation. The local bitmap is accessed through a property. The set method raises the event whenever the value is set. The listning class then uses the get method of the property to retrieve the …

Geekitygeek 480 Nearly a Posting Virtuoso

I wouldnt say its the best solution. Check out my tutorial on interform control access for a more OO approach :)
Even better would be to create an event handler in your form class that detects the new frame event in the camera class and updates its own picturebox. Is the event exposed by the camera class or is it raised by a private member of the camera class?

tomprice0189 commented: Provided me with a relevant and well written tutorial +0
Geekitygeek 480 Nearly a Posting Virtuoso

You are overthinking the problem but you are on the right tracks.
You had the right idea using the modulus of DaysApart to figure out how far into a pay period a day is, but instead of finding out if this saterday is the first or second sat of a pay period, you can use the same mod calculation to find out how far into the current pay period the date is and work back from that to get the start of the period:

static void Main(string[] args)
    {
        DateTime fixedDate = new DateTime(2008, 09, 27); // Some starting Saturday Pay Period //
        DateTime Today = DateTime.Now;

        //calculate how far into current period date is
        TimeSpan timeSinceFixedDate = Today - fixedDate;
        double dayOfCurrentPeriod = timeSinceFixedDate.Days % 14;

        //calculate start of current pay period
        DateTime startOfCurrentPeriod = Today.AddDays(dayOfCurrentPeriod * -1);

        //for every two week period starting now and ending one year ago, output period dates
        for (DateTime dt = startOfCurrentPeriod; dt > startOfCurrentPeriod.AddYears(-1); dt = dt.AddDays(-14))
        {
            Console.WriteLine(dt.ToShortDateString() + "-" + dt.AddDays(13).ToShortDateString());
        }

        Console.ReadKey();

    }

Be sure to read through and make sure you understand what each part is doing. This is a console app so you'll have to adapt it to your own needs. Let me know if you need me to go over anything :)

Geekitygeek 480 Nearly a Posting Virtuoso

In excel, you have the option to control the iterative calculation; by default it will only apply the circular reference 100 times or until the values change by no more than 0.001. You could emulate this behaviour with a while loop but there may be better way to approach it in C#.
Could you explain what you are trying to achieve with your circular reference? Maybe we can suggest a more efficient method if we know what you're trying to do.

Geekitygeek 480 Nearly a Posting Virtuoso

You can change the type declaration of your property:

protected GCMode mode;
public int Mode
        {
            get
            {
                return (int)this.mode;
            }
            set
            {
                this.mode = (GCMode)value;
            }
        }

When you access the property from COM it will accept and return an int value but in your class it is converted and stored as your enum type.

Geekitygeek 480 Nearly a Posting Virtuoso

Sorry, I may not have explained myself very clearly. Let me try again.
There is data flow between every layer in your n-tier system, thats how it works. The data is passed up and down the layers like a chain. What you don't want is one layer directly affecting another layer...in OO it is bad design to have any class directly manipulating another class. The correct way is to pass data back and forth via exposed methods and properties and in an n-tier system, each level can generally only talk to the level directly above and below it.

If it helps, try to think of it as a system of message pipes; The UI doesn't know what happens inside the business logic layer and it has no knowledge of the data access layer at all. All the UI sees is the message pipes between it and the business logic layer. It knows what it can send down them and what to expect back in return. These are the exposed public methods.

So if your UI thread wants to display something in its textbox, first it gets an instance of your business layer and asks the business layer for the data. The business layer in turn gets an instance of your data access layer and asks it for the data it needs. The data access layer sends the data back to the business layer, which then performs any logic needed on it before in turn passing it back …

Lusiphur commented: Great example! Y'know... what I SHOULD have said but was too tired/lazy to type :P +1
Geekitygeek 480 Nearly a Posting Virtuoso

Your "getters and setters" are called properties. You can declare them in an interface (see MSDN for example). I haven't worked with COM classes for C++ so i don't know if there are additional restraints on the interface you create...hope this gets you in the right direction at least.

Geekitygeek 480 Nearly a Posting Virtuoso

@rohand, I agree; rather than retrieving the list of words then having to iterate through them. Pass the body of the message to the database and use a LIKE condition. The database will be able to perform the match this way much quicker and more efficiently than any loop you write :)

However, your syntax is checking for entries in the phrase field which contain the whole of the email body. You would need something like:

SELECT phrases
  FROM emailAbusers
  WHERE (LOWER(@body) LIKE '% ' + LOWER(LTRIM(RTRIM(phrases))) + ' %')
  OR (LOWER(@body) LIKE '% ' + LOWER(LTRIM(RTRIM(phrases)))) 
  OR (LOWER(@body) LIKE LOWER(LTRIM(RTRIM(phrases))) + ' %')

The OP's code suggests they want to ignore case so I have converted both the body and the phrase to lower case before comparing. I also left and right trimmed the phrase to ensure there are no white spaces to disrupt the match and added a space after the first % and before the last as the OP's code suggests they only wish to match whole words.
Finally, the '%' at the start of the match requires there to be at least one character BEFORE the match and the '%' at the end requires at least one character after it so it wont match the first or last word in the string. I have added an extra two LIKE clauses to check for those matches as well.

The above query will return a collection of all the bad phrases that are in …

Geekitygeek 480 Nearly a Posting Virtuoso

A static member exists even when the class has not been instantiated.
For instance:

class myClass
    {

        public myClass()
        {
            myString = "Not Static";
        }

        public static string getStaticString()
        {
            return "Static";
        }

        private string myString;

        public string getString()
        {
            return myString;
        }
    }

    public partial class Form1 : Form
    {
        private void button1_Click(object sender, EventArgs e)
        {
            string staticString = myClass.getStaticString();

            myClass instanceA = new myClass();
            myClass instanceB = new myClass();

            string notStaticA = instanceA.getString();
            string notStaticB = instanceB.getString();
        }

Lets examine the class first:
It has a static method called getStaticString. This method is accessible directly through the class without it being instantiated. This can be seen when we call string staticString = myClass.getStaticString(); . We haven't created an instance of the class, we are calling the static method of the class itself.
The class also has a non static method. In order to access this method we need an instance of the class. So we call myClass instanceA = new myClass(); which creates an instance of myClass in memory and allows us to access all of the members of that instance. In the classes constructor i have set the value of the non static string to be returned.
In my example i have two instances; instanceA and instanceB. In my example they are identical. For a second, imagine that the value of instanceB.myString was changed. We now have two instances of the same class which each contain different values for myString. So …

ddanbe commented: You explained it well :) +7
Diamonddrake commented: Good one! +3
Geekitygeek 480 Nearly a Posting Virtuoso

Alternatively, you can use IF ELSE in queries with SQL Server 2000 or newer.
You can check if the item exists, if it doesn't then insert it. I have done something like this in the past:

IF EXISTS ( SELECT * FROM user_table WHERE userid = @userID )
BEGIN
SELECT False;
END
ELSE
BEGIN
INSERT INTO user_table VALUES ( @userID )
SELECT True;
END

By selecting true or false it returns a boolean value to indicate success. If you use an identity column for primary key you can return Scope_Identity on success or null on fail.

I'm not sure if the syntax is supported in Visual Studio, i was running all my queries in stored procedures.

PierlucSS commented: good one. +1
Geekitygeek 480 Nearly a Posting Virtuoso

I think you guys may be confusing DataGridViewRows with DataRows. Datatables don't store formatting information because they aren't directly displayed. You need to set the background colour of the DataGridView's Row.
I'd suggest looking at the CellFormatting event as it is only called against cells that are to be displayed. If you have a datagridview thats big enough to display ten rows at a time but has 100's or 1000's of rows in it then you only want to change the appearance of rows that are currently visible; looping through every single row could cause your program to freeze momentarily.
In the CellFormatting event, check the value of the status column and set the row's .DefaultCellStyle.BackColor property accordingly:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (dataGridView1.Rows[e.RowIndex] == null || dataGridView1.Rows[e.RowIndex].IsNewRow)
            return;

        if (dataGridView1["Status", e.RowIndex].Value != null && dataGridView1["Status", e.RowIndex].Value.ToString() == "Terminated")
        {
            dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Red;
        }
        else
        {
            dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = DefaultBackColor;
        }
    }
PierlucSS commented: :) +1
Geekitygeek 480 Nearly a Posting Virtuoso

WHilst you can use regex.Split to match patterns that are beyond the string.split function, in this case i think you would be better using a full regex match.
Using the regex.split function Lusipher gave above would only split the string where the closing and opening tags are together. Lets look at the following string:
"<html>
<body>
<p><a href="blah.com">link text</a>"

With my code you would get:
"html"
"body"
"p"
"a href="blah.com"
"/a"

With regex.split shown above you would get:
"<html>
<body>
<p"
"a href="blah.com">link text</a>"

Because "><" only occurs once due to white space the match only occurs once.

Lusiphur commented: Good point :) Was just giving a general usage example though :P +1
Geekitygeek 480 Nearly a Posting Virtuoso

You could use the ItemActivate event. You can sepcify in the ListView properties whether the item has to be clicked once or twice to activate, then use the ListView.FocusedItem property to see which item currently has focus.
Or you could set the MultiSelect property to false and use the SelectedIndex changed event to query the ListView.SelectedIndices colelction for the currently selected item.

Geekitygeek 480 Nearly a Posting Virtuoso

If you get stuck with part of a tutorial and get no feedback on the site, you can always post the section of code here and ask for help. There are plenty of solvers here who can explain the code for you :)

ddanbe commented: The way to go! +7
Geekitygeek 480 Nearly a Posting Virtuoso

I refer you to my answer to your other post. Daniweb is a community forum to share knowledge and experience. To work together to solve problems and aid in one another's development as coders. It is not a one-stop-shop for your coding needs.
Please attempt your project yourself then post here if you have any specific problems. We will be happy to help you locate and correct errors or understand coding concepts you are struggling with but we aren't going to do you homework for you.

Lusiphur commented: 100% agreed! +1
Geekitygeek 480 Nearly a Posting Virtuoso

Hi Avi, welcome to Daniweb. The policy here is to help those who show an effort and help themselves. Rather than post a broad "I need code for this" question, please make an attempt at the project then post if you have problems with specific errors or coding techniques.
I would recommend you start out by planning your prject using pseudocode and other design concepts (UML, ERD, etc) before you start trying to code.

Geekitygeek 480 Nearly a Posting Virtuoso

I just noticed you have response.redirect so this is must be an ASP.net project. Be aware that the ButtonClick events are handled after the page has loaded. Is it possible something in your page load is firing an event?
Put a breakpoint at the start of your event code and step through it to find out which lines of code definitely fire rather than guessing which ones may have fired.

ddanbe commented: Good thinking. +7
Geekitygeek 480 Nearly a Posting Virtuoso

^Should be wearing underwear!! O.O
<Wishes he hadnt looked up!
V Wont see anything up my skirt :p

Geekitygeek 480 Nearly a Posting Virtuoso

You will struggle to make it an instant process; you will always have a delay based on your internet speed as the program needs to connect to the webpage and download the html. I did a couple of tests (far from exhasutive) and found that using a HttpWebRequet and HttpWebResponse to get the HTML source of the apge was consistently a second or two faster than using a WebClient:

HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
    HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
    Stream stream = httpWebResponse.GetResponseStream();
    StreamReader streamReader = new StreamReader(stream, Encoding.ASCII);
         
    string page = streamReader.ReadToEnd();

Also, once you have loaded the HTML into a string, rather than converting it to an HTML document, finding all the div tags and iterating through them, you could use a regular expression to search for the tag you need:

Regex imgTag = new Regex(@"img class=""GamePoster"" src=""(?<url>.*?)""");
    Match m = imgTag.Match(page);
    if (m.Success)
    {
       pictureBox1.ImageLocation = m.Groups["url"].Value;
    }
GAME commented: I LOVE YOU :) +0
Geekitygeek 480 Nearly a Posting Virtuoso

Im not sure whats preventing the font from loading on some computers. But i do have a tip for you; rather than setting the fonts of every textbox and button you can group them together in Panels then set the font on the panel. By default, controls inherit the font from their parent container. If you have changed the font of a control then it will retain those changes, but if you haven't, then changing the panels font will change the font of the controls contained within it. Saves you some 300 lines of code :)

Geekitygeek 480 Nearly a Posting Virtuoso

I wrote a tutorial a while back that covers some elements of classes and objects.
Other than that, there is lots of material online if you google it or check out the msdn reference.

Geekitygeek 480 Nearly a Posting Virtuoso

Sorry, your original post didn't mention that you were showing the form modally (which is what happens when you call ShowDialog), the code above was an example of how you can execute code in Form1 when Form2 is closed. this.Refresh() was an example, it just causes the form to repaint, it wouldn't update the listbox..sorry for any confusion.

You don't need this code at all. You are showing Form2 with ShowDialog so you can run the code to update the listbox in the same method that shows Form2 because the code will pause until Form2 is closed. See the code in my last post to see how you set the DialogResult in Form2 then run code based on the result in Form1.

Geekitygeek 480 Nearly a Posting Virtuoso

Its your code, you can handle it anyway you like :p
I couldnt let it lie so i made a minor tweak to the method. It will now check the textboxes of a passed control and has an overloaded method that will set error text using the passed errorProvider:

private bool TextBoxEmpty(Control checkControl)
        {
            foreach (Control c in checkControl.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    if ((c as TextBox).Text == "")
                    {
                        return true;
                    }
                }
            }

            return false;
        }

        private bool TextBoxEmpty(Control checkControl, ErrorProvider error)
        {
            bool emptyFound = false;
            foreach (Control c in checkControl.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    if ((c as TextBox).Text == "")
                    {
                        emptyFound = true;
                        error.SetError(c, "Valid input required");
                    }
                    else
                    {
                        error.SetError(c, "");
                    }
                }
            }

                return emptyFound;
        }

This removes the need for handling the Validating event on each textbox. However, it does mean that the errors will only be shown when you call "TextBoxEmpty()", not when the textbox loses focus.

To check a checked list box you can use checkListBox.CheckedItems.Count to find out how many items have been checked.

kvprajapati commented: string.IsNullOrEmpty() method is pretty handy!!! +10
Geekitygeek 480 Nearly a Posting Virtuoso

You could have a single validation method, but the purpose of the code discussed above was to set error messages against indiviual controls using the ErrorProvider control so it was necessary to check each control seperately.

If you want to just check that none are empty you could place the 8 texboxes inside a panel then use a foreach loop to iterate through the panel's control collection to check them:

private void button2_Click(object sender, EventArgs e)
        {
            if (TextBoxEmpty())
                MessageBox.Show("Empty");
        }

        private bool TextBoxEmpty()
        {
            foreach (Control c in panel2.Controls)
            {
                if (c.GetType() == typeof(TextBox))
                {
                    if ((c as TextBox).Text == "")
                        return true;
                }
            }
            return false;
        }

You could also extend the TextBoxEmpty method by passing it a panel to check:

private bool TextBoxEmpty(Panel CheckPanel)

Or even pass it a control, but then you would need to ensure that the control to be checked has a control collection :)

AngelicOne commented: nice +1
Geekitygeek 480 Nearly a Posting Virtuoso

This doesnt check if the Item is Checked, it checks if the Selected item has the text value "Others". You need to check for both if you only want the code to run when the "Others" item is checked:

If (checkedListBox1.SelectedItem.ToString() == "Others" && checkedListBox1.SelectItem.Checked)
{
//do something
}
Geekitygeek 480 Nearly a Posting Virtuoso

There are lots of solvers here who will be happy to help you, provided you keep within the rules. So, stop posting in this old thread and start a new thread with your own question. Be more specific, give details of what you are trying to achieve. Most importantly, try for yourself first. We are not going to hand you a complete code solution. There is a link in the post above to some python code which you can use as a basis for your work. Make an attempt at solving the problem then post if you have a specific issue, including the code you have so far.

kvprajapati commented: Words! +10