Mitja Bonca 557 Nearly a Posting Maven

I don't think this will work in a console application...

nope, images will not do in console. Didnt even noticed that apparently. Only read his post.

Mitja Bonca 557 Nearly a Posting Maven

Its not a bad idea to create (your own website, or some page of it) to point the help from your app. to it, like:

Help.ShowHelp(this, "http://www.helpware.net"); //this is exmaple url
Mitja Bonca 557 Nearly a Posting Maven

vote +1 :)

Mitja Bonca 557 Nearly a Posting Maven

If you wanna see the image put some images (those you need9 into project - into the Resources).
Then you can create a switch statement, and based on an integer you will show appropriate image.
Or simply create an image from some file on the disc (by specifing the path to the image)

like:

int num = 1; //pass value to this variable
            Image img;
            switch (num)
            {
                case 1:  img = Bitmap.FromFile("path to image 1"); break;
                case 2: img = Bitmap.FromFile("path to image 2"); break;
                case 3: img = Bitmap.FromFile("path to image 3"); break;
                //and so on..
            }

This code will be used AFTER you will get the number (from 1 to 6) from some random class.
And use the image on the control (on some button and background image).

Mitja Bonca 557 Nearly a Posting Maven

This is a simple code, that creates an array of 4 integers, and addes a random number to each index.

Dim r As New Random()
Dim nums As Integer() = New Integer(3) {0, 0, 0, 0}
For i As Integer = 0 To 3
	If nums.Sum() <= 100 Then
		nums(i) = r.[Next](1, 101)
	Else
		nums(i - 1) = 0
		nums(i - 1) = 100 - nums.Sum()
		Exit For
	End If
Next
If nums.Sum() < 100 Then
	nums(3) = 100 - (nums(0) + nums(1) + nums(2))
End If
timosoft commented: Execellent +1
Mitja Bonca 557 Nearly a Posting Maven

YOu salved the problem?

Mitja Bonca 557 Nearly a Posting Maven

Hi,
I did much of the code you need. The code retreives the new new date and number.
What is checks.
- If the date in the stirng retreived from datebase (the last one) if older then today, it creates new "number", with today` date and number 1 after slash
- if the date from the number is today`s date, it only add to last number +1

So here is the code that does all (Select, Insert and Changing the number):

Class Program
	Private Shared Sub Main(args As String())
		Dim strDate As String = GetLastDate()
		'string strDate = "03072012/2"; this was only for my test, and it worked OK!
		strDate = CreateNewNumber(strDate)
		'this will create new date with appropriate number!!
		'now you can save it back into the database as well!
		InsertNewDate(strDate)
	End Sub

	Private Shared Function GetLastDate() As String
		Dim result As String = String.Empty
		Dim query As String = "SELECT LAST(YourColumnName) AS LastDate FROM YourTable"
		Using conn As New SqlConnection("connString")
			Using cmd As New SqlCommand(query, conn)
				Using reader As SqlDataReader = cmd.ExecuteReader()
					result = DirectCast(reader(0), String)
				End Using
			End Using
		End Using
		Return result
	End Function

	Private Shared Sub InsertNewDate(str As String)
		'NOTE: I am only insetring one column!!
		'you might have more of them, but do as I do bellow:
		Dim query As String = "INSERT INTO MyTable VALUES (@param1)"
		Using conn As New SqlConnection("connString")
			Using cmd As New SqlCommand(query, conn)
				cmd.Parameters.Add("@param1", System.Data.SqlDbType.VarChar, 50).Value = str
				cmd.ExecuteNonQuery()
			End Using
		End Using …
Mitja Bonca 557 Nearly a Posting Maven

I know :)
Keep up the good work.

Mitja Bonca 557 Nearly a Posting Maven

I did all this in a sinle line of code:

If(radiobutton1.Checked, "male", "female")
Mitja Bonca 557 Nearly a Posting Maven

Use parametrized query, and define in the parameter which value to choose, like (example code):

Dim query As String = "INSERT INTO MyTable VALUES (value1 = @param1, value2 = @param1)"
'value 1 is exmaple id column
'value 2 is the male of female.
Dim conn As New SqlConnection("connString")
Dim cmd As SqlComamnd = New SqlCommand(query, conn)
cmd.Parameters.Add("@param1", SqlDbType.Int).Value = 1
'some example num for id
cmd.Parameters.Add("@param2", SqlDbType.VarChar, 50).Value = If(radiobutton1.Checked, "male", "female")
'this code will insert string "male" if radiobutton1 is checked
'if radiobutton2 is checked, "female" string will be inserted!
Mitja Bonca 557 Nearly a Posting Maven

HI just need a way to reset the DataAdapter1 into 0 (like reset)

Set datasource to null. This way you reser it.

Mitja Bonca 557 Nearly a Posting Maven

To add: but its almost the same for other providers. If you use OleDb you have to change the query, and not passing parameters into it, instead of you use questionmark "... WHERE pf5_showplaylists.showID = ?"; and define parameter in parametreized query, as I showed up in my previous post.
Hope it helps.
bye

Mitja Bonca 557 Nearly a Posting Maven

If you are using Sql class do as:

SqlConnection conn = new SqlConnection("connString");
String query = "SELECT SUM(pf5_showplaylists.runningtime) FROM pf5_showplaylists WHERE pf5_showplaylists.showID = @param1";
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add("@param1", SqlDbType.Int).Value ShowID; //MUST BE AN INTEGER!! If not 
do:
//cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value ShowID;
int mySum = Convert.ToInt32(cmd.ExecuteScalar());
//dispose iDisposable objects:
conn.Dispose();
cmd.Dispose();
MessageBox.Show("The sum is: " + mySum.ToString());
Mitja Bonca 557 Nearly a Posting Maven

This is a "bad" way of programming. Do as Momerath told you to.

so:

string sql = "UPDATE Orders SET Status= ? WHERE OrderID = ?";
OleDbCommand cmd = new OleDbCommand(sql, connDBString);
cmd.Parameters.AddWithValue("@id", "1"); //NOTE: is OrderID type of varchar? if its integer, pass an integer, not a string! It would be better!!
cmd.Parameters.AddWithValue("@status", status);
Mitja Bonca 557 Nearly a Posting Maven

hi,
into this class (or form) you pass a role value (what ever string or integer type), and based on that you can then use if/else if statements or swith, like you already showed us in your code.
Do it as:

//on form1:
//pass a role variable to form1, from login form!
public Form1()
{
    //main constructor
    InizializeComponent();
}

public Form1(string role)
   : this();
{     
     //additional constructor
     //1st the main constructor`s code will executed, then this one!
     SettingRoles(role)     
}

private void SettingRole(string role)
{
     switch(role)
     {
         case "admin":
         {
              //set it by your self!!
              button1.Visible = true;
              break;
         }
         case "user":
         {
              //set it by your self!!
              button2.Visible = true;
              break;
         }
     }     
}
Mitja Bonca 557 Nearly a Posting Maven

With Microsoft Sql Server:

--
-- Create test case
--
DECLARE @myDateTime DATETIME
SET @myDateTime = '2008-05-03'

--
-- Convert string
--
SELECT LEFT(CONVERT(VARCHAR, @myDateTime, 120), 10)

Mitja Bonca 557 Nearly a Posting Maven

Sorry, was doing some other stuff.
Try like:

Dim table As New DataTable("dataFromWebsite2")
Dim conn As New SqlConnection("ConnString")
Dim query As String = "SELECT Column1, Column2 FROM MyTable"
'create your own query
Dim cmd As New SqlCommand(query, conn)
Dim da As New SqlDataAdapter(cmd)
da.Fill(table)
datagridview1.DataSource = table.DefaultView
cmd.Dispose()
conn.Dispose()
da.Dispose()

Hope it helps,
bye

Mitja Bonca 557 Nearly a Posting Maven

So you would like to retrive these data from the table (on picture)?

Mitja Bonca 557 Nearly a Posting Maven

I cannot help you out, since I dont know what would those C, D and E mean.

Mitja Bonca 557 Nearly a Posting Maven

Which data exactly would you like to work with from website?

Mitja Bonca 557 Nearly a Posting Maven

Which inputs?
You need an appropriate connection string (depending on the database) and the appropriazes classes to access to the data in this database (Sql, Oledb classes).

Mitja Bonca 557 Nearly a Posting Maven

The point is in accessing a database. There is all stored (usernames, passowords,...).
So you need a connection string to the particulat databse (sql, mysql, oracle, ...) and then you have to know table names and columns inside of each. Then you can with some knowledge of sql query statements retreive data from it.

BUT: the database (serve) MUST ALLOW you to access to the it. Many of them do not.

Mitja Bonca 557 Nearly a Posting Maven

Hi, read here. Its all well explained. Take your time, so you can learn it beside reading and trying to write new code.

Mitja Bonca 557 Nearly a Posting Maven

Who voted -1 for me and why?
damn thx, really appreciate it.

About your error: Check the TYPE of your column before we continue. Is it a bit type, is it a varchar, or what?
No need to vote -1, if the error is yours!!!

Mitja Bonca 557 Nearly a Posting Maven

Then do:

Dim query As String = "UPDATE cg_security_user_right  SET user_id, right_id ,enable_flag  WHERE LastName = @param1 AND right_id = @param2 AND enable_flag = @param3"
Dim conn As New SqlConnection("connString")
Dim cmd As SqlComamnd = New SqlCommand(query, conn)
cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = tuser.Text
cmd.Parameters.Add("@param2", SqlDbType.Int).Value = Integer.Parse(tright.Text)
'check if its not an integer, if its string, do as in line before
cmd.Parameters.Add("@param3", SqlDbType.Bit).Value = If(CheckBox1.Checked, 1, 0)
cmd.ExecuteNonQuery()
Mitja Bonca 557 Nearly a Posting Maven

and its y type of boolean? But in your database is type of what? bit? if so, then you need 1 or 0.

Mitja Bonca 557 Nearly a Posting Maven

hmm another question is there any way for the form (or the windows) to make it resolution independent?

It actually cannot be fully independent, it always has to addapt on the screen resolution (it has to based on it). You can have app. in 1290 x 1500 (or what ever), and if your screen is in 1680 X 1050, then you will have sliders inside your application to view all the content. And this is not something we want.
And one more thing: you cannot never know the resolution of user, right?
But something is deffenatelly sure, if your app. is on max 800x600, there is no worries - noone has lower resolution any longer :)

But to be sure, you always can do the check of the current resolution and addapt your application (and all the controls inside) based on the measurement of the screen.

Does this make any sence?
Hope it does :)
bye

Mitja Bonca 557 Nearly a Posting Maven

Use parametreized query:

Dim query As String = "UPDATE cg_security_user_right  SET user_id, right_id ,enable_flag  WHERE LastName = @param1 AND right_id = @param2 AND enable_flag = @param3"
Dim conn As New SqlConnection("connString")
Dim cmd As SqlComamnd = New SqlCommand(query, conn)
cmd.Parameters.Add("@param1", SqlDbType.VarChar, 50).Value = tuser.Text
cmd.Parameters.Add("@param2", SqlDbType.Int).Value = Integer.Parse(tright.Text)
'check if its not an integer, if its string, do as in line before
cmd.Parameters.Add("@param3", SqlDbType.[Boolean]).Value = CheckBox1.Checked
'?? you want to use TRUE/FALSE - checked/unchecked?
cmd.ExecuteNonQuery()
Mitja Bonca 557 Nearly a Posting Maven

to restrict the user so that he/she cannot enter the date in the past.

I have another preposition: do now allow user to write date. Use MonthCalendar to select the date, and do not show the date older then you want (or today`s date or what ever).
Can you do that?

Mitja Bonca 557 Nearly a Posting Maven

You still didnt tell us any formula you want to use to get these kindof results.

Here is how you create and loop through multidimensional array:

Dim multiArray As Integer(,) = New Integer(,) {{5, 0, 10}, {0, 10, 0}, {10, 0, 34}}
Dim x As Integer = 0
For i As Integer = 0 To multiArray.GetLength(0) - 1
	For j As Integer = 0 To multiArray.GetLength(1) - 1
		x = multiArray(i, j)
	Next
Next
Mitja Bonca 557 Nearly a Posting Maven

have you heard of multidimensional arrays?
This is the answer here.
btw, how do we get those results (any formulas)?

Mitja Bonca 557 Nearly a Posting Maven

Thx, Im blushing :)

M.Waqas Aslam commented: sweet comment ahahhaahah :) u make me smile , +5
Mitja Bonca 557 Nearly a Posting Maven

Here is the solution (actually two of them):

'I have put 3 buttons on my form!!
Private buttons As Button()
Private pressedButton As Button
'OR:
Private _pressedButton As String
Public Sub New()
	InitializeComponent()

	'now lets create a common code for all:
	buttons = New Button() {button1, button2, button3}
	For i As Integer = 0 To buttons.Length - 1
		buttons(i).Name = "My button " & (i + 1)
		'specify name of the button
		buttons(i).Text = "Pres button " & (i + 1)
		'specify the text on the button
		buttons(i).Click += New EventHandler(AddressOf Buttons_Click)
	Next
End Sub

Private Sub Buttons_Click(sender As Object, e As EventArgs)
	Dim button As Button = TryCast(sender, Button)
	If button IsNot Nothing Then
		pressedButton = button
		_pressedButton = button.Name

		'show it here:
		RetreivePressedButton()
	End If
End Sub

Private Sub RetreivePressedButton()
	'you can call this method every time after click on button:
	MessageBox.Show("Pressed button was: " & Convert.ToString(pressedButton.Name) & ". And it still keeps this name in variable")
	'OR:
	MessageBox.Show("Pressed button was: " & _pressedButton & ". And it still keeps this name in variable")
End Sub
Mitja Bonca 557 Nearly a Posting Maven

Hi,
1st of all, you have to create an array of all buttons, accessible inside a class (or form).
Then use access to them with only one event:

Public Partial Class Form1
	Inherits Form
	'I have put 3 buttons on my form!!
	Private buttons As Button()
	Public Sub New()
		InitializeComponent()

		'now lets create a common code for all:
		buttons = New Button() {button1, button2, button3}
		For i As Integer = 0 To buttons.Length - 1
			buttons(i).Name = "My button " & (i + 1)
			'specify name of the button
			buttons(i).Text = "Pres button " & (i + 1)
			'specify the text on the button
			buttons(i).Click += New EventHandler(AddressOf Buttons_Click)
		Next
	End Sub

	Private Sub Buttons_Click(sender As Object, e As EventArgs)
		Dim button As Button = TryCast(sender, Button)
		If button IsNot Nothing Then
			MessageBox.Show("You pressed " + button.Name)
		End If
	End Sub
End Class
Mitja Bonca 557 Nearly a Posting Maven

With my code. Its not important what email users have, as long as yours in gmail (it can be other too, but I showed you an example how this can be done with using gmail).
So:

List<string> emails = new List<string>();
email.Add("abc@gmail.com");
email.Add("bcd@hotmail.com");
email.Add("cde@yahoo.com");

//and so on..
Mitja Bonca 557 Nearly a Posting Maven

I would suggest you to make method static. The problem is that all the content of them stays in the memory until you close the application.
So use static only if really needed (or for some small methods).

About your question, it would be good to share the code with us, so we can explicitly see whats troubling you.

Mitja Bonca 557 Nearly a Posting Maven

Do you use Crystal Reports?
You can do that, simply create parameters in your report, and pass values from textboxers to these parameters.

Mitja Bonca 557 Nearly a Posting Maven

Do you already have emails of users?
If you have an account on gmail, you can simply use it, to send emails to others.
What you need, is to create a list of users (with their emails is enough), and then do a loop through them and on each loop execute this code:

List<string> emails = new List<string>();
//fill the list with emails!

foreach(string email in emails)
{
    System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
    System.Net.NetworkCredential cred = new System.Net.NetworkCredential(”yourid@gmail.com”, “your password”); //of your email accout
    mail.To.Add(”acme@acme.com”); //email of user //do through a loop
    mail.Subject = “subject”;
    mail.From = new System.Net.Mail.MailAddress(”yourid@gmail.com”);
    mail.IsBodyHtml = true;
    mail.Body = “message to send”;

    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient(”smtp.gmail.com”);
    smtp.UseDefaultCredentials = false;
    smtp.EnableSsl = true;
    smtp.Credentials = cred;
    smtp.Port = 587; //this is of gmail
    smtp.Send(mail);
}
Mitja Bonca 557 Nearly a Posting Maven

Sure it does. Try using ONY my code. You will see it works.
Otheriwse, try using your own brains while looking into my code - you will see what Linj queries are getting. Try chaning them a bit - if my code is not exactly what you are lookin for.
If you still have problems, let me now, i`ll try to help you out, ...
but 1st try to find the solution just by your self - its not fat off now.

bye

Mitja Bonca 557 Nearly a Posting Maven

Try this way:

public partial class Form1 : Form
    {
        static List<string> urls;
        static Random random = new Random();
 
        public Form1()
        {
            InitializeComponent();
            if(urls ==  null)
            {
                urls = GetWebsiteUrls();  //Need to implement
            }
           
            string url = urls[random.Next(urls.count)];
            System.Diagnostics.Process.Start("iexplore.exe", url); //try using some other webbrowser too
        }
    }
Mitja Bonca 557 Nearly a Posting Maven

for controls its more simple. Use ANCHOR property. By default, controls are set to top-left. Try to play with them a bit, and you will see what suits you most.

Mitja Bonca 557 Nearly a Posting Maven

Ok, I think you should use the following technique: using dataTable and your main data source, from where all queries will be done, by using some linq.
Take a look at here:

Private table As New DataTable("myTable")
Public Sub New()
	InitializeComponent()
	table.Columns.Add("ID", GetType(String))
	table.Columns.Add("Type", GetType(String))
	table.Columns.Add("Name", GetType(String))
	table.Columns.Add("Description", GetType(String))

	table.Rows.Add("1", "Pizza", "Pizza 1", "description 1")
	table.Rows.Add("2", "Burger", "Burger 1", "description 2")
	table.Rows.Add("3", "Pizza", "Pizza 2", "description 3")
	table.Rows.Add("4", "Meat", "Meat 1", "description 4")
	table.Rows.Add("5", "Burger", "Burger 2", "description 5")

	'get only distinct names from table, to show in comboBox:
	Dim items As IEnumerable(Of String) = table.AsEnumerable().[Select](Function(s) DirectCast(s("Type"), String)).Distinct()
	'set datasource to combobox:
	comboBox1.DataSource = New BindingSource(items, Nothing)
	'set datasource to dgv:
	dataGridView1.DataSource = New BindingSource(table, Nothing)
End Sub

Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
	Dim rows As EnumerableRowCollection(Of DataRow) = table.AsEnumerable().Where(Function(w) DirectCast(w("Type"), String) = comboBox1.SelectedItem.ToString()).OrderBy(Function(o) o("Name"))
	Dim dataView As DataView = rows.AsDataView()
	dataGridView1.DataSource = New BindingSource(dataView, Nothing)
End Sub

Code is proven working, its tested.
I hope you like it.

bye

Mitja Bonca 557 Nearly a Posting Maven

Where come these data of yours that populates gridview? Is gridview databound?
Tell us more, so we can help you more.

Mitja Bonca 557 Nearly a Posting Maven

You have to find our the screen resolution, and based on that, you then adjust your image (resize it).
How to get screen resolution and resize image:

Dim width As Integer = Screen.PrimaryScreen.WorkingArea.Width
Dim height As Integer = Screen.PrimaryScreen.WorkingArea.Height

Dim image__1 As Image = Image.FromFile("filePathToImage")
Dim newImage As New Bitmap(width, height)
Using gr As Graphics = Graphics.FromImage(newImage)
	gr.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias
	gr.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
	gr.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality
	gr.DrawImage(image__1, New Rectangle(0, 0, width, height))
End Using
'now use newImage as background!
Mitja Bonca 557 Nearly a Posting Maven

Tital i double type, so convert the value from dataRow to double (use Convert ot parse method).

Mitja Bonca 557 Nearly a Posting Maven

Try using:

Dim conn As New SqlConnection("connString")
Dim query As String = "SELECT * FROM products"
Dim cmd As New SqlCommand(query, conn)
Dim da As SqlDataAdapter = New SqlDataAdaper(cmd)
Dim table As New DataTable("myTable")
da.Fill(table)
'dispose all IDisposable objects...
Mitja Bonca 557 Nearly a Posting Maven

This problem occurs because the MySQL ODBC driver reports catalog and table names for the table, but reports an empty string for the schema. Visual Studio is expecting a schema here, and is formulating the 3-part name that you see, in the format "catalog.schema.table". Since there is no schema, you end up with 2 dots between the catalog and table name, which MySQL apparently doesn't allow.

You should still be able to programmatically use the ODBC driver with the System.Data.Odbc classes, because this particular behavior is a result of how the the Visual Studio designer tools format the query string. I.e. ADO.NET itself is not in control of this.

A response from the VS team on this problem is available here.

You may also get some more information by posting to the data controls forum here.

Mitja Bonca 557 Nearly a Posting Maven

Ok, thx

Mitja Bonca 557 Nearly a Posting Maven

Nice.
btw, what exactly does this exclusive-OR assignment operator "^=" with numbers?
I know for boolean values that the result is true if and only if exactly one of its operands is true.

Mitja Bonca 557 Nearly a Posting Maven

codeorder: How on earth can you multiply strings together (or any other math operations)? Never seen thi before...