Mike Askew 131 Veteran Poster Featured Poster

So what exactly are you trying to do? Move the label around so that the text always appears in the middle?

Could you not just make the label the maximum size it could be and set the text align to middle?

Mike Askew 131 Veteran Poster Featured Poster

Wheater,

Do you wish to use your own database for this or the built in ASP.Net database? As this can very easily be done using the built in one however I've had issues in the past trying to then link the ASP.Net DB to a custom one for the other details.

I have also done the login using my own DB and also managed to restrict access to pages using code on the master page but this was not so easy, all depends on what other functionality your database has.

Mike Askew 131 Veteran Poster Featured Poster

Surely there is just a lack of rows in whatever you are pulling as you are looking for the row (2) so the third row in. Run a debug and use a break point to see what is contained within the schedule and see if that helps to solve the issue?

Im making assumptions but the error as Thines01 said could either be that it is null or that the schedule actually contains no rows.

Mike Askew 131 Veteran Poster Featured Poster

Have a look at this.

Mike Askew 131 Veteran Poster Featured Poster

Im not sure why you would want to even be pulling 100,000 entries at once, you should look into breaking these down into subcategories such as A-Z or something depending on the data as that will reduce the time taken.

Also would using an AJAX panel remove the hang and reduce it just to the panel hanging which may still allow some of the site to run? Not sure it would work as its not my best topic but im sure someone like thines01 will correct me on this if it wouldn't work.

Mike Askew 131 Veteran Poster Featured Poster

Could you clarify your issue a bit more?

Am i understanding you right in the fact your issue is that the browser hangs while the database operation is run?

Mike Askew 131 Veteran Poster Featured Poster

Have you considered using the MouseClick property of the form instead?

Mike Askew 131 Veteran Poster Featured Poster

Trin,

You would need to use the same switch concept but store the numbers in an array and loop through each number in the array running the switch statement.

This would allow all numbers to be processed :)

So 238947864 would be processed as:

2 - 3 - 8 - 9 - 4 - 7 - 8 - 6 - 4

The issue lies with the fact the switch currently treats 238947864 as one big number instead of breaking it down into its actual values

Mike Askew 131 Veteran Poster Featured Poster

I'm glad it did :)

Mike Askew 131 Veteran Poster Featured Poster

You could simply use the array that I used to switch the image back from the placeholder value and compare if they hold the same value there so:

if (Images[1,1] == Images[3,1])
{
    bool MatchFound = true;
}

Again just using a for loop or something to search for the name of the sender to allow the array match to happen?

Mike Askew 131 Veteran Poster Featured Poster

Thats not what he asked for.

Mike Askew 131 Veteran Poster Featured Poster

Apologies for double post can't edit last. The following code may do what you require, obviously you will need to adapt it for your images and resources folder etc.

public partial class Form1 : Form
    {
        Image[] Pictures = new Image[] { Properties.Resources.RandomImage1, Properties.Resources.RandomImage2, Properties.Resources.RandomImage3, Properties.Resources.RandomImage4, Properties.Resources.PlaceHolder };
        string[,] Images = new string[4,2];


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //Can make this setting happen randomly as you do
            img1.Image = Pictures[0];
            img2.Image = Pictures[1];
            img3.Image = Pictures[2];
            img4.Image= Pictures[3];
            //When you randomly set, set the second part of the array to the number in the Pictures array that holds that images position.
            Images[0, 0] = "img1";
            Images[0, 1] = "0";
            Images[1, 0] = "img2";
            Images[1, 1] = "1";
            Images[2, 0] = "img3";
            Images[2, 1] = "2";
            Images[3, 0] = "img4";
            Images[3, 1] = "3";
        }

        private void ImageClick(object sender, EventArgs e)
        {
            //If picture is not using the placeholder image
            if (((PictureBox)sender).Image != Pictures[4])
            {
                ((PictureBox)sender).Image = Pictures[4];
            }
            else
            {
                //Set back to the previous image using the stored location in the array
                for (int i = 0; i < Images.Length / 2; i++)
                {
                    if (((PictureBox)sender).Name == Images[i, 0])
                    {
                        ((PictureBox)sender).Image = Pictures[Convert.ToInt32(Images[i, 1])];
                    }
                }
            }
        }
    }
Mike Askew 131 Veteran Poster Featured Poster

So the issue is that when you click on a non-visible picture box it doesnt become visible?

I would assume you cant click on a picture box you cannot see therefore may have to consider setting the picture to a placeholder picture and store the assigned images in an array so that when the picture is clicked it flicks between the placeholder 'hidden' image and the actual array stored one.

Mike Askew 131 Veteran Poster Featured Poster

You need to bind the method to the form's KeyUp method available in the properties. I don't think it can be done using KeyPress instead. The following should work.

Assuming your using a WinForm of course..

private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F2)
            {
                //Enter code to save here
                MessageBox.Show("F2");
            }
        }
Mike Askew 131 Veteran Poster Featured Poster

Could we at least be told what the error is?

Mike Askew 131 Veteran Poster Featured Poster

What exactly isnt functioning?

Line 44 in the above code you linked also looks iffy, your adding the total of i to numberOfCourses each time, so first loop is +1, then +2, then +3 etc. Shouldnt that just be numberOfCourses++ instead of numberOfCourses+=i?

Mike Askew 131 Veteran Poster Featured Poster

Stuck in the for loop im assuming?

From a quick glance over may this be your issue?

for (int i = 1; i <= MAX_COURSES; i++) // ## Increments i by one here everytime loop occurs ##
            {
                try
                {
                    {
                        if (IsValidData())
                        {
                            // Gets user input from from
                            //Converts Grade Percentage to decimal and stores value
                            gradePercentage = Convert.ToInt32(txtGradePercentage.Text);
                            //gradePercentage = int.Parse(txtGradePercentage.Text);
                            //Converts Hours Per Week to decimal and stores value
                            hrsPerWeek = Convert.ToInt32(txtHrsPerWeek.Text);
                            //hrsPerWeek = int.Parse(txtHrsPerWeek.Text);
                            //PROCESS
                            //Calls calculateGPA method
                            gpa = calculateGPA(gradePercentage);
                            //Calculates
                            numberOfCourses++;
                            //Adds the cumulative number  of quality points to the quality points calculation
                            qualityPoints = gpa * hrsPerWeek;
                            cumulativeQualityPoints += qualityPoints;
                            cumulativeGPA = cumulativeQualityPoints / cumulativeHoursPerWeek;
                            // OUTPUT
                            lblGPA.Text = gradePercentage.ToString();
                            lblQualityPoints.Text = qualityPoints.ToString();
                            lblNumberOfCourses.Text = numberOfCourses.ToString();
                            lblCGPA.Text = cumulativeGPA.ToString();
                            //Clears input boxes
                            txtGradePercentage.Text = "";
                            txtHrsPerWeek.Text = "";
                            //Sets focus to Grade Percentage text box
                            txtGradePercentage.Focus();
                            i--; // ## Decrements i by one here counteracting loop? ##
                        }
                    }
                    continue;

Line 34 looks asif it counters out the incrementing functionality of the for loop by setting i back by 1 each loop iteration so it would get stuck on the value of '1' permantently.

Try removing this line and see what happens :)

Mike Askew 131 Veteran Poster Featured Poster

Just looked at it myself, I believe the issue lay with your use of ' ' to add the space between firstname and lastname instead of " ". The following code is functioning as desired:

var LatestEmployeeRatings = (from s in StaffDB.Staffs
                                         join r in StaffDB.Ratings
                                         on s.StaffID equals r.StaffID
                                         select new { StaffID = s.StaffID, Name = s.FirstName + " " + s.LastName, Grade = s.CurrentGrade, RatingDate = r.Date, Rating = r.Rating1, Comment = r.Comments }
                                         into ss                             
                                         group ss by ss.StaffID into g 
                                         select g.OrderByDescending(r => r.RatingDate).FirstOrDefault()).ToList();

Had to change line 7 to use .FirstOrDefault instead of .First as it threw an error there but checked now and its running and outputting the results as required.

Thank you very much for your help with this, +1

Regards,

Mike

Mike Askew 131 Veteran Poster Featured Poster
StaffRatingSystemDBModel.StaffRatingSystemDBEntities StaffDB = new StaffRatingSystemDBModel.StaffRatingSystemDBEntities();
            var LatestEmployeeRatings = (from s in StaffDB.Staffs 
                                         join r in StaffDB.Ratings 
                                         on s.StaffID equals r.StaffID 
                                         select new { StaffID = s.StaffID, Name = s.FirstName + ' ' + s.LastName, Grade = s.CurrentGrade, RatingDate = r.Date, Rating = r.Rating1, Comment = r.Comments } 
                                         into ss 
                                         group ss by ss.StaffID into g 
                                         select g.OrderByDescending(r => r.RatingDate).First()).ToList();

            lstR1.DataSource = LatestEmployeeRatings;
            lstR1.DataBind();

Error occurs on the linq query itself so doesnt reach the databind

Mike Askew 131 Veteran Poster Featured Poster

Yeap linq to an entity model

Mike Askew 131 Veteran Poster Featured Poster

Using this code, ran to check its execution and encountered an exception of type: NotSupportedException.

Unable to create a constant value of type 'System.Object'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

Not entirely sure what is causing this error as I've literally copied the code in to check it runs.

Mike Askew 131 Veteran Poster Featured Poster

Hi Thines01,

I am looking to obtain the StaffID, Name(concat of firstname + last name), grade, rating date, rating and comment.

Mike Askew 131 Veteran Poster Featured Poster

Hi there,

I have two tables in my data entity model accessed by StaffDB.

Staffs contains:
StaffID
FirstName
LastName
Address
Town
County
Postcode
YearJoined
CurrentGrade
Role

Ratings contains:
RatingID
StaffID
Date
Rating1 (automatic to avoid conflict with table name also of rating)
Comments

These are linked by StaffID.

I am trying to select each staff member using their most recent rating date so that I do not get duplicate output as this is then categorised on the web page it outputs.

I have found some code online and adapted it to get the following:

var LatestEmployeeRatings = from s in StaffDB.Staffs
                                        join r in StaffDB.Ratings
                                        on s.StaffID equals r.StaffID
                                        group s by s.StaffID into g
                                        select g.OrderByDescending(r => r.Date).First();

However this code was for using one table not two and therefore I think im going wrong in lines 4 and 5 as line 5 has an error as r.Date does not exist at this point :(

Can anyone enlighten me on how I need to further adapt this to work?

Cheers

Mike Askew 131 Veteran Poster Featured Poster

Ooooh filename passes both the path and name? Thats where I was going wrong :) Thankyou very much thines

Mike Askew 131 Veteran Poster Featured Poster

Hi all,

The project I am currently working on is an Address Book which works off a csv (specification takes the mick as a database would be so much easier), the method to write the lines of information into the CSV is in the class DataLayer and takes a String: filepath and an AddressBook: addressbook.

My question is how do i get the filepath selected from a savedialog and pass it through to the method in the class as I cannot see how using intellisense and MSDN.

Thanks,

Mike

Mike Askew 131 Veteran Poster Featured Poster

Mitja i do wonder if you actually read the post as i didnt mention a JAR file or years anywhere in my post. Lol.

As for Momerath thank you for your input I will use that method :)

Thread solved.

Mike Askew 131 Veteran Poster Featured Poster

Hi all,

My program is proving Kaprekar's Constant - 6174.

To do this I will need to store values exactly how they come out without losing any preceding 0's which int has a habit of cutting off.

For example:
Number to store exactly: 0147
Int stores: 147

A googling session has left me short and so i wondered is it actually possible to stop an int from cutting off preceding zeros or will I need to use strings?

Cheers,

Mike

Mike Askew 131 Veteran Poster Featured Poster

Apologies, have run my code properly now and ironed out any issues. This code was made on a form using two textbox and two labels.

Private Sub TextBox1_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtFiveString.LostFocus '// Can change the to .TextChanged if preferred
        '// For the Five String issue //
        If IsNumeric(txtFiveString.Text) = True Then '// Checks to see that string entered is numbers
            If Len(txtFiveString.Text) = 5 Then '// Checks length of the entered string is 5
                lblFiveString.Text = "this is a five digit code"
            Else
                lblFiveString.Text = "Not a 5 digit code, please enter a new one" '// Took the 'r' off renter on this line, type i presume
            End If
        Else
            lblFiveString.Text = "Not a numeric code, please enter a new one" '// New error message for numeric check     
        End If
    End Sub

    Private Sub txtThreeString_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtThreeString.LostFocus
        '// For the Three String issue //
        '// Validation for string containing: On Off Mnt Na
        '// Change "Textbox1.text" to your textbox
        If Not txtThreeString.Text = "ON" Then '// If textbox doesnt contain ON then
            If Not txtThreeString.Text = "OFF" Then '// If textbox doesnt contain OFF then
                If Not txtThreeString.Text = "MNT" Then '// If textbox doesnt contain MNT then
                    If Not txtThreeString.Text = "NA" Then '// If textbox doesnt contain NA then
                        lblThreeString.Text = "Must be either: ON/OFF/MNT/NA" '// Error message displayed
                    Else
                        lblThreeString.Text = "Correct Entry"
                    End If
                Else
                    lblThreeString.Text = "Correct Entry"
                End If
            Else …
Mike Askew 131 Veteran Poster Featured Poster

Do you mean generate a random number between those boundaries?

Mike Askew 131 Veteran Poster Featured Poster

Have you tried using the length function in VB.Net?

If isNumeric(myDouble) = True Then '// Checks to see that string entered is numbers
        If Len(myDouble) = 5 Then '// Checks length of the entered string is 5
            lblmessage.Text = "this is a five digit code"
        Else
            lblmessage.Text = "Not a 5 digit code, please enter a new one" '// Took the 'r' off renter on this line, type i presume
        End If
Else 
        lblmessage.Text = "Not a numeric code, please enter a new one" '// New error message for numeric check     
End If
    End Sub

And for the second string you could use the following to lock down the entry option to the four options, i would suggest using a label beside it or above to tell the user what they can enter, unless they already knew this.

'// Validation for string containing: On Off Mnt Na
        '// Change "Textbox1.text" to your textbox
        If Not TextBox1.Text = "ON" Then '// If textbox doesnt contain ON then
            If Not TextBox1.Text = "OFF" Then '// If textbox doesnt contain OFF then
                If Not TextBox1.Text = "MNT" Then '// If textbox doesnt contain MNT then
                    If Not TextBox1.Text = "NA" Then '// If textbox doesnt contain NA then
                        MsgBox("Must be either: ON/OFF/MNT/NA, MsgBoxStyle.Exclamation") '// Error message displayed
                    End If
                End If
            End If
        End If
Mike Askew 131 Veteran Poster Featured Poster

Try this:

If password.text <> confirmpassword.text Then
    Msgbox("Password not the same")
End If
Mike Askew 131 Veteran Poster Featured Poster

Many thanks ninjaimp, that helped alot :)

Mike Askew 131 Veteran Poster Featured Poster

@Unhnd_Exception

Using your code i still receive the same error, therefore I can also assume its the byte data. Do you have a method you use for converting the image to byte data to store in the database as it seems my current code hasn't worked properly.

Would be most appreciated,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Not entirely sure myself if that is the same thing either, never seen it written that way myself.

Mike Askew 131 Veteran Poster Featured Poster

The code for this is:

'IMAGE HANDLING
                Dim bytes() As Byte = DS.Tables("Location").Rows(0).Item(4)
                Dim ProductImage As Image = Image.FromStream(New System.IO.MemoryStream(bytes))
                pic_ProductImageDisplay.Image = ProductImage
                pic_ProductImageDisplay.Load()

The error occurs line 3 stating "ArgumentException was unhandled: Parameter is not valid."

Any idea on a solution to this problem?

Mike Askew 131 Veteran Poster Featured Poster

Can we see the code for this?

Mike Askew 131 Veteran Poster Featured Poster

Have a look at THIS webpage.

Can apply the same technique of date/time measurement possibly? Not entirely sure though.

Mike Askew 131 Veteran Poster Featured Poster

What is the exact syntax error? and what input are you entering into the textbox?

Mike Askew 131 Veteran Poster Featured Poster

Not entirely sure on cause then, I suggest googling the issue and seeing if any other possible solutions are available.

Mike Askew 131 Veteran Poster Featured Poster

Trying making VS repair itself via add/remove programs

Mike Askew 131 Veteran Poster Featured Poster

"Data type mismatch in criteria expression." is an error relating to your SQL.

In this case you are putting '11' around the number 11. When using numbers in the SQL you should leave out the ' ' :)

Mike Askew 131 Veteran Poster Featured Poster

Shall have an experiment with the code and solutions you have provided. Most appreciated.

Mike Askew 131 Veteran Poster Featured Poster

Is it possible to use an array setup which can store text as well as the rectangle information?

Cheers,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Codeorder, one bit of the code is confusing me :)

At the very beginning when your are declaring the array contents, its done in a way i have never seen and so therefore adapting the code is proving a tad difficult.

How would one adapt the array contents and split to use a 2D array. The reasoning for the 2D array is simple i can match the second half of the array to my database before redrawing with first part of arrays dimensions.

I have tried simply removing the declaration of contents from the Dim statement and doing manually on form load for 2D however that didn't seem to work.

Any suggestions on how to convert the code?

Many thanks,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Ok thank you for that, i will need to debate the recoding of my entire grid now hehe :)

Will mark thread as solved as this is what im looking for, great help.

Cheers,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Was debating whether or not to use this code at first due to the nature of the complexity of mapping out an entire grid using this method.

Must firstly apologise for the very slow reply, i have been distracted by other aspects of life and havn't really had a chance to get back to looking at this part of my project.

I must question however, what do the four numbers in the location array represent? Co-ordinates? or a measurement of some kind?

Also is this method viable considering i am using approx. 100-150 rectangles :)


Many thanks and apologies again,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Not entirely sure if this is even possible as have yet to find a solution anywhere for this but here goes.

The form currently looks at a database and pulls a text name from location:

DS.Tables("Location").Rows(0).Item(4)

The resultant text entry from this location, for example: "loc_fvh_Flowers", will then be compared against an array of every location possible in the program.

Is it possible to, when a match is found, the use the "loc_fvh_Flowers" as a reference and effectively add

.BackColor = Color.Crimson

Onto it to make:

loc_fvh_Flowers.BackColor = Color.Crimson

Which is the full code to change the object colour to crimson.

The issue being in being able to get the value from the array of the location reference, concatenate it with the end of the command and then execute the command.

All help appreciated and many thanks in advance,
Mike

Mike Askew 131 Veteran Poster Featured Poster

Yes thanks the issue was this coupled with a phantom [space] in one of the table names that only became apparent during testing recently. +1'ed

Mike Askew 131 Veteran Poster Featured Poster

Just to update the thread, i ran the SQL off line 14 directly in access and the query constantly asks for parameter input. I am guessing this is the issue and now its just a matter of working out why my SQL is misbehaving :(

Any input?

Mike Askew 131 Veteran Poster Featured Poster

Full code for form:

Public Class MainLocation
    Dim SelectedProduct As String
    Dim PageLoadStage As Integer = 1
    Dim LocationPossibilities(XTotal) As String
    Dim MaxLocations As Integer
    Dim X As Integer
    Dim XTotal As Integer
    'Database Variables
    Dim Con As New OleDb.OleDbConnection
    Dim DBP As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
    Dim DBS As String = "Data Source = Z:\Documents\College\Computing\Project\Project-MikeAskew\ProjectDBFinal.mdb"
    Dim SQL As String
    Dim DS As New DataSet
    Dim DA As OleDb.OleDbDataAdapter

    Private Sub MainLocation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
        SelectedProduct = ProductSearch.txt_HiddenVarStore.Text
        Call QueryDatabase()
    End Sub

    Function QueryDatabase()
        Select Case PageLoadStage
            Case 1
                Con.ConnectionString = DBP & DBS
                Con.Open()
                SQL = "SELECT * FROM tbl_Information WHERE Product_Name = '" & SelectedProduct & "';"
                DA = New OleDb.OleDbDataAdapter(SQL, Con)
                DA.Fill(DS, "Info")
                Con.Close()
                Call InformationRender()
            Case 2
                Con.Open()
                SQL = "SELECT * FROM tbl_Stock WHERE Product_Number = '" & SelectedProduct & "';"
                DA = New OleDb.OleDbDataAdapter(SQL, Con)
                DA.Fill(DS, "Stock")
                MaxLocations = DS.Tables("Stock").Rows.Count
                Con.Close()
                Call InformationRender()
            Case 3
                Con.Open()
                SQL = "SELECT * FROM tbl_Location WHERE Line_Number = '" & SelectedProduct & "';"
                DA = New OleDb.OleDbDataAdapter(SQL, Con)
                DA.Fill(DS, "Location")
                Con.Close()
                Call InformationRender()
        End Select

        If PageLoadStage <> 4 Then
            Call QueryDatabase()
        End If

    End Function

    Function InformationRender()
        Select PageLoadStage
            Case 1
                lbl_ProductNameV.Text = DS.Tables("Info").Rows(0).Item(1)
                lbl_ProductPriceV.Text = "£" & DS.Tables("Info").Rows(0).Item(2)
                lbl_AdditionalInfoV.Text = DS.Tables("Info").Rows(0).Item(3)
                SelectedProduct = DS.Tables("Info").Rows(0).Item(0)
                PageLoadStage = 2
            Case 2
                lbl_LineNumberV.Text = DS.Tables("Stock").Rows(0).Item(0)
                lbl_SoldbySectionV.Text = DS.Tables("Stock").Rows(0).Item(1)
                lbl_CurrentStockV.Text = DS.Tables("Stock").Rows(0).Item(2)
                lbl_NextDeliveryDateV.Text = DS.Tables("Stock").Rows(0).Item(3)
                lbl_NextDeliveryTimeV.Text = DS.Tables("Stock").Rows(0).Item(4)
                SelectedProduct = DS.Tables("Stock").Rows(0).Item(0)
                PageLoadStage = 3
            Case 3
                X = 0
                ' Below currently unused …