castajiz_2 35 Posting Whiz

I think you got it correct now. But your writting is only a bit incorrect if I may say so.

just adds on everytime the random number is selected.

Yes this is true in one way but the correct sentence would be that it adds everytime no matter the randomnumber. The randomnumber just defines the random index (for example when you throw the dice you don't know what number you will get, that's what the random number does, it gives a random INDEX of the array which actually represents your dice number and then adds the frequency SAYING , OK THIS NUMBER APPEARED SO JUST INCREMENT THE COUNTER OF THAT NUMBER. The counter is actually the frequency and yes you can say that there are 6 counters in your array since for each index you are incrementing a let's say special counter every time the specific number occurs.

theashman88 commented: Thanks so much +2
castajiz_2 35 Posting Whiz

I decided to write the following piece of code in order for you to get a better understanding...

public static void Main(string[] args)
        {
            Random randomNumbers = new Random(); 
            int[] frequency = new int[7];
            int y = 0;
            int[] index = new int[30];


            for (int roll = 0; roll < 30; roll++)
            {
               index[roll] = randomNumbers.Next(1, 7);
               y+= ++frequency[index[roll]];
            }

            Console.WriteLine( "Face"+" "+"Frequency");

            for (int face = 0; face < 7; face++)
            {
                Console.WriteLine(face + "     " + frequency[face]);
            }
            Console.WriteLine("Y value is"+y);

            Console.WriteLine("-------------------------------------------------");
            y = 0;
            for (int i = 0; i < 7; i++) // just setting the values to 0
            {
                frequency[i] = 0;
            }

            for (int roll = 0; roll <30; roll++)
            {
                y+=frequency[index[roll]]++;
            }
            Console.WriteLine("Face" + " " + "Frequency");

            for (int face = 0; face < 7; face++)
            {
                Console.WriteLine(face + "     " + frequency[face]);
            }

            Console.WriteLine("Y value is:"+y);
            Console.ReadLine();
        } 

Answer to your first Question is "It doesn't matter if you use frequency[i]++ OR
you use ++frequency[i] you'll get same results".

I ve made another array to track the random numbers so that you can prove to yourself that preincrement or afterincrement won't change anything. The thing that will change something is setting up a new variable y which when you store the numbers in it will be different (storring the preincrement in y is not the same as storing the afterincrement in y)
You can simplify the code by removing the '+' sign and just making y --> …

castajiz_2 35 Posting Whiz

1.Correct
2-4. doesn't have to be frequency[1] it could be any number between 1,6 depending on the .Next C# integrated function. The function produces a random index. The whole purpose of frequency is to sum all of the occurances of each dice(how many times did a number on the dice appear)

castajiz_2 35 Posting Whiz

When i was learning C i remember that i wrote down something concerning that problem
and with this writting you ll get a full understanding of it.

example1:

 int y;
 int x = 2;

 y = x++;// or y=x=(x+1) , y stores x imediatlly and THEN x is being incremented y=2 here
 y=x;// if you would go now and write this line you would see that y=3;

 // with preincrement there is nothing much being explained
 // first the value is incremented and thus it is stored in the variable y

 int y;
 y=2;
 y=++x;// y=3

This is a storage problem, if you do ++x and output it and x++ and ouput it youll get same results because you didn't store them anywhere after,, eventualy they increment to +1 . Now just apply this to your array...

castajiz_2 35 Posting Whiz
string sql = "INSERT INTO STU(EID,FIRST_NAME,LAST_NAME,IMAGE)VALUES(" + textBox1.Text + "," + textBox2.Text + "," + textBox3.Text + ",@img)";
                if (cn.State != ConnectionState.Open)
                    cn.Open();
                command = new SqlCommand(sql, cn);
                command.Parameters.Add(new SqlParameter("@img", img));

On line 5 remove the monkey sign(@), on line 2 (line one but second row) look where you comma is ",@img", remove the comma concatenate it separetly, try then and tell if errors appear. Try not to use the concatention it's messy and not a good practice since it's vulnerable once your database is ready to use...

castajiz_2 35 Posting Whiz

-When your event fires just store the supplier ID into a variable;
-Use that variable in your SQL query for example--> select address from table where id=@some_number. Since every value is unique you will get only one result. After you read the executed query table store your address in a variable or display it in the textbox immediatly. Ofcourse you must open a connection, write the sql query, execute the reader so that you can achieve the desired.
If a problem occures along just post you code here...

castajiz_2 35 Posting Whiz

Learn asp.net ... and find a hosting service that supports asp.net files. Free hosting services do not support asp.net but you can use php instead (example 000webhost)

castajiz_2 35 Posting Whiz

Okay, now i realize that I misslead you. I tought that you were working in WPF(basically an upgraded winform framework). I' ve googled how to implement that on windows form but there are quite complex solutions. If you can transfer your app to wpf that would be great. You could easily solve you problem usin wpf framework. Consider downloading visual studio express 2010. IT's free. I m not sure if you version supports wpf.

castajiz_2 35 Posting Whiz

I think not, Did you manage to do some extra work once you imported your dll?

castajiz_2 35 Posting Whiz

you will have to use another logic for you program. altough your logic is good at first if you lower your triangle (if you reduce the number of rows) then you 'll see that your solution isn't good
Click Here

for instance:

        5
       1 2
      9 4 5
     9 7 6 12
   11 2 33 4 5

following your code you would do this:
5+2+5+12+5=29--> final result
but have in my mind that there are other routes as well

for instance:
take the most left route and go down
--> 5+1+9+9+11=35
35>29 --> that is your solution isn't 100% correct

ddanbe commented: Keep up the good work! +15
castajiz_2 35 Posting Whiz

what is the problem?

castajiz_2 35 Posting Whiz

first of all you should make a new thread. I do know how your data is stored but neverless, you should specify for each one of them the snooze time and then do your code logic...

castajiz_2 35 Posting Whiz

try this then:
`

 class Program
    {
        static void Main(string[] args)
        {
            cars.color = "blue";
            cars.price = 0.2;
            cars.model = "volvo";
            cars.mark = "volvo";



            cars.WriteInfo();

            //book parameters

            Console.ReadKey();
        }
    }
}
class cars
{
    public  static string mark;
    public  static string model;
    public   static string color;
    public  static double price;

    public static  void WriteInfo()
    {
        Console.WriteLine("cars: mark: {0} model: {1}. color: {2}. price: {3}", mark, model, color, price);
    }
}

`

castajiz_2 35 Posting Whiz
class cars
{
    public  string mark;
    public  string model;
    public   string color;
    public  double price;
    public cars(string markee, string modelee, string coloree,double pricee) 
    {
        mark = markee;
        model = modelee;
        color = coloree;
        price = pricee;
    }
    public  void WriteInfo()
    {
        Console.WriteLine("cars: mark: {0} model: {1}. color: {2}. price: {3}", mark, model, color, price);
    }
}

class Program
    {
        static void Main(string[] args)
        {
            cars e1 = new cars("bmq","","",0.2);
            books e2 = new books();



            e1.WriteInfo();

            //book parameters
            e2.author = "Fyodor Dostoyevsky";
            e2.genre = "morality";
            e2.name = "The Brothers Karamazov";
            e2.price = 25;
            Console.WriteLine(e1);
            Console.ReadKey();
        }
    }

use a constructor for this SO that you can built your object, learn constructors, i ve put some silly values inside but you ll figure it out, do the rest on your own

castajiz_2 35 Posting Whiz

You arent calling the method from your class to the static vodi main()

castajiz_2 35 Posting Whiz

I ve found one for free, but it seems that i will have to buy a domain because this one does t offer migration from mssql to mysql but thanks.

castajiz_2 35 Posting Whiz

Basically from my part I can tell you that it's just a smooth way of writting the code. If you know that you are not going to EXTEND your class then seal it. Personally, I've never used it but I think that other members could tell you more about it. Otherwise just google it or try to find a tutorial on youtube if you really must know about the sealed keyword in depth...

castajiz_2 35 Posting Whiz

Google this yourself, and then you can write something yourself and if you dont understand it will help you out.

castajiz_2 35 Posting Whiz

Click Here

I dont know if this is what you want but yes it should do the thing.

Don't forget to import the DLL so that you can access the required property.
TO IMPORT THE DLL DO THE FOLOWING: view-->solution explorer--> right click refferences--> add reference --> search the framework section and find it there

castajiz_2 35 Posting Whiz

Try this:

OleDbConnection con;

        private void button1_Click(object sender, EventArgs e)
        {
            string items = textBox2.Text;
                string[] splittedText1 = items.Split(' ');
            string quantity = textBox1.Text;
                string[] splittedText2 = quantity.Split(' ');
            string price = textBox3.Text;
                string[] splittedText3 = price.Split(' ');

            con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=path_to_your_database_file;
                                Persist Security Info=False;");  // have a look here if you run into trouble
                                                                // http://www.connectionstrings.com/access/
            con.Open();
            for (int i = 0; i < splittedText1.Length; i++) // the ID's will be updated automatically,
            {                                              // supposing that all arrays correspond to each other(the sizes are the same)


                OleDbCommand cmd = new OleDbCommand(@"INSERT INTO Product (productname,productquantity,productprice)
                                                  VALUES (@items,@quantity,@price)", con);
                cmd.Parameters.Add(new OleDbParameter("items", splittedText1[i]));
                cmd.Parameters.Add(new OleDbParameter("quantity", splittedText2[i]));
                cmd.Parameters.Add(new OleDbParameter("price", splittedText3[i]));

                cmd.ExecuteNonQuery();

            }
            con.Close();
            con.Dispose();

        }

have a look at the comments,

OleDbCommand CmdSql = new OleDbCommand("Insert into [sales] ([productname], productquantity, productprice) VALUES (splittedText1, splittedText2, splittedText3);

It is enough to specify the table name without the brackets the squared bracktes [] and the values without the square brackets as well [].

castajiz_2 35 Posting Whiz

I have a database wich i made in SQL server managment studio (Microsoft based). I m curious on how would i export my entire database to a webserver? My application is built in visual studio 2012 with C# (c# complitely). It s a University database without cotaining the student's entity(Table) because their is no need for a login form. The database isn t much of a size(all proffesors, timetables, proffesor_rooms, rooms for teaching students several buildings at various locations...
If you could give me some links or maybe some explicit explanation overhere on how to do that. The idea is that students would have this application wich is a desktop based app and they could easily search what they want (i need this app to communicate directly with the server).
Later on i would put it on the mobile(windows phone, android) but that s not my question.

castajiz_2 35 Posting Whiz
  viewerlist.Lines = list.ToArray();

where does this come from?

castajiz_2 35 Posting Whiz
if (ts1.CompareTo(DateTime.Now) == -1 && ts2.CompareTo(DateTime.Now) == -1)
            {
                MessageBox.Show("....");
            }

the function asks for a object, i gave an object...

castajiz_2 35 Posting Whiz
            cmd = new SqlCommand
            ("select beggining_school,
            end_school FROM Student,student_weekend,Weekend WHERE
            Student.ID=student_weekend.studentID AND  
            student_weekend.WeekendID=Weekend.ID ", con);

I just want to say that i don't have any problem concerning my code functionality. I would just like the design to be like the above example.That is, I dont'want my whole sql expression to be on the same line. However if i want my expression to be on more than one line somehow the string get's lost and visual studio doesn't treat the expression as a string anymore.

castajiz_2 35 Posting Whiz

I have read pretty much about xml. I know that it is good to save data inside but i just can t get it why wouldn t I save my data into a .txt file once finished with my program tasks. Is it because xml offers a structural and more simple way of storing data (refering to the xml parent and child tags).I just can t see xml being a advanced technology for data saving and transportation. If you can give me a clearer view on xml because always when I investigate the net they always lack to provide an EXAMPLE WITH SOMETHING ELSE (for instance comparing xml with another technology).

castajiz_2 35 Posting Whiz

I m quite lazy to search all of the 128 pages, but if I do not find it using another approach I ll consider that one.

castajiz_2 35 Posting Whiz

There was a user named Mitja Bonca wich spent a lot of his time on the C# section. Before a year ago i ve seen a algorithm that he did for a guy providing him help in that way. This algorithm was tremendous (was then) and i can t locate this post from him. Is there a easy way that i can find this post(his reply to this guy). By the way i tried to contact him on facebook but facebook sorts the inbox in that way that he doesnt see the message. Any help would be appreciated.

castajiz_2 35 Posting Whiz

I ve always had a problem with this but never coped with it.
Let s say I bring a button to a form and click on it two times
a event will appeaer in the code section.
EXAMPLE:

private void button1_Click(object sender, EventArgs e)
        {

        }

Let s say i want to remove the BUTTON and the event by erasing them manually.
After that i get plenty of warnings wich is reasonable. Just wanted to ask how
do i do this safely or is there anything else i would have to erase in order to
avoid warnings...

castajiz_2 35 Posting Whiz

if anyone can give me a link or a hint on how to approach these queries, i m not asking for direct solutions. the only thing that i really don t know how to solve is the 1. query so this woulb be of imense help if you gave me a hint

castajiz_2 35 Posting Whiz
  1. For all the accounts that have authority="admin", set permision to modify all of the files (attribute changes is datatype YES/NO),,, so basically a user can set yes or no depends on his will.

  2. For each directory, print out his name, in which directory it is located, and how many subdirectories does it have. It is necessary to print out those directories which aren t found in a directory(don t have parentdirectories) and those whith no subdirectories

  3. Find 10% of the largest directories wich do not have subdirectories. The size of the directory without the subdirectory is equal to the sum of size of all directories wich are inside the directory. Write out directoryID, name of the directory and size.

This is what i have tried so far but i m really confused with this ones.

1) SELECT * FROM accounts WHERE  authorities="admin" ....

3) not sure about this one( i know that i should use count and group by,,, not sure about the location as well)

5) SELECT TOP 10 PERCENT direktoriID,name,size FROM direktori WHERE direktori.direktoriID= FILE.DIRECTORYid AND parentdirectoryID=NULL

So if you could please help out with that.
here is a picture of the ER model(using ms Access)

castajiz_2 35 Posting Whiz

yeah, i forgot to copy and paste the new string since i deleted my previous database..., tnx

castajiz_2 35 Posting Whiz
 private void Form1_Load(object sender, EventArgs e)
        {
            cn.Open();
        }

ERROR:Cannot open database "Persons" requested by the login. The login failed.
can anyone tell me how to fix this?

castajiz_2 35 Posting Whiz

If someone can provide a link with the use of Parameters instead of concatenation

castajiz_2 35 Posting Whiz

You don t need daniweb for that, you ve got google...

castajiz_2 35 Posting Whiz

Tnx Momerath for pointing things out. I tried again and it worked
this is the code:

 public void AccessPb()
     {
            foreach (Control gb in this.Controls)
            {
                if (gb.HasChildren)
                {
                    foreach (Control pb in gb.Controls)
                    {
                        if (pb is ProgressBar)
                        {
                            list.Add((ProgressBar)pb);
                        }
                    }
                }
            }
       }
castajiz_2 35 Posting Whiz

I would like to convert Control objects wich are in my array to progress bar Objects if possible. I know that the reverse conversion can be done explicitly without a problem but this one seems tricky. If impossible then please suggest something else instead. TNX

castajiz_2 35 Posting Whiz

Well I explained it to you. You have to create a method theButtonWasClicked and you attach it to your event button1.Click,button2.Click,button3.Click. You have to make an array yourself and put you variables button1, button2, button3 into you array manualy or by using a foreach(...) and collect your buttons from your form. Now i realise by looking the second time that i ve made a mistake because i copied your button event and put the code in it, it should be like this

private void thebButtonWasClicked(object sender, System.EventArgs e)
    {
                Button a = sender as Button;
                a.BackColor = Color.Blue;
                for (int i = 0; i < array.Length; i++) // erasing all button colors but not the one that was clicked
                {
                    if (!(sender.Equals(array[i]))) 
                    {
                        array[i].BackColor = Color.Silver;
                    }
                {
    }
            Button[] array; // bare in mind that you have to make an array of buttons
            private void Form1_Load(object sender, EventArgs e)
            {
                button1.Click += thebButtonWasClicked;
                button2.Click += thebButtonWasClicked;
                button3.Click += thebButtonWasClicked;
               array = new Button[3] { button1, button2, button3 };
            }

have a look at this link before doing anything it will help massively. Afer you watch the video, then you should understand what i was talking about.Concerning the database it depends on your knowledge, but if you look at my second previous post you should see how the import should be done. Your deadline is tomorrow i gues so you better hury up. You should have started your project earlier but still good luck, once again see the …

castajiz_2 35 Posting Whiz

Hi there, if i m correct you want to switch colors between buttons, erase previous color when you click another button, so try this

private void button1_Click(object sender, System.EventArgs e)
{
            Button a = sender as Button;
            a.BackColor = Color.Blue;
            for (int i = 0; i < array.Length; i++) // erasing all button colors but not the one that was clicked
            {
                if (!(sender.Equals(array[i]))) 
                {
                    array[i].BackColor = Color.Silver;
                }
            {
}
        Button[] array; // bare in mind that you have to make an array of buttons
        private void Form1_Load(object sender, EventArgs e)
        {

            button1.Click += thebButtonWasClicked;
            button2.Click += thebButtonWasClicked;
            button3.Click += thebButtonWasClicked;
           array = new Button[3] { button1, button2, button3 };

        }

i suggest that you loop through your form and find buttons on the form and populate those in a array rather than manually store them in the array like i did.

castajiz_2 35 Posting Whiz
 static void Main(string[] args)
        {
            string number = "12345";
            int counter = -1;
            string output="";
            int counter2 = 0;
            int pad = (2 * (number.Length-1)) + 1;
            List<string> list = new List<string>();

            for (int i = 0; i < number.Length; i++) // normal seqeuncial concatenation
            {
                output = output + number[i];
                if (i == 0)
                {
                    Console.WriteLine(output.PadLeft(pad));
                    list.Add(output);
                }

                for (int j = counter; j >=0 ; j--)//   reverse concatenation
                {
                    counter2 = output.Length;
                    output = output + number[j];

                    if (output[output.Length-1]==number[0])
                    {
                        Console.WriteLine(output.PadLeft(pad));
                        list.Add(output);
                        output=output.Remove(counter+2);
                    }
                }
                counter++;
            }
            list.RemoveAt(list.Count - 1);
            list.Reverse();
            foreach (var item in list)
            {
                Console.WriteLine(item.PadLeft(pad));
            }
            Console.ReadLine();
        }

I really wanted to avoid the list stuff but I was lazy to think how to reverse inside my loops.
By the way i would really want to see Ketsuekiame to post his code if ofcourse he s got the time for it. And i m also suprised that no one used recursion xd.

castajiz_2 35 Posting Whiz

What do you mean by single statement exactly?

castajiz_2 35 Posting Whiz

I must admit that i to google to find out about square and square root are possible for such a thing, i didn t notice that in the rising and falling sequence. But again tnx Ketsuekiame for letting me think a little bit more XD.

castajiz_2 35 Posting Whiz

Thanx for the response Ketsuekiame, you really put maximum effort in every of your post. I m little bit busy with some other stuff but as soon as i m done i l get to this again. Tnx for the suggestions.

castajiz_2 35 Posting Whiz

I think that this guy aint comming back, so it would be nice for Mike Askew to post his code, i m really interested on how he did it. I would definitly use here three loops one for normal concatenation second for reverse concatenation and third for removing digits. I ll give it a try in the evening.

castajiz_2 35 Posting Whiz

I think that i know what the problem is and i also think that you ll agree with me. The problem is that i don t know how to fix this. When i use the TranslateTransform method it automatically makes a new coordinate system starting from the given axes so it starts at (0,0), after that i rotate it and after rotation i draw my rectangle wich is ON THE NEW COORDINATE SYSTEM wich started a (0,0). I apply then the ResetTransform method wich puts it back to normal but that doesn t solve the problem. The conclusion is that I should avoid the translate transform by all means. Should i make a custom rotation rather the rotating it with a built in method or is there something wich would be easier to apply?

castajiz_2 35 Posting Whiz

Well, i made a mistake here but after fixing it didnt work either. I have a problem with my rotation here so if anyone can tell me why this isnt drawn, when debugging, it goes into the button event and inside the if codee but i can t see the drawing on the form i guess its drawn but at some weird position.

 private void button1_Click(object sender, EventArgs e)// (Button Create Object)
        {
            if (checkBox1.Checked) 
            {
                paper = this.CreateGraphics();

                paper.TranslateTransform((float)rect.Width / 2, (float)rect.Height / 2);

                paper.RotateTransform(75);

                paper.TranslateTransform(-(float)rect.Width / 2, -(float)rect.Height / 2);
                paper.DrawRectangle(new Pen(Brushes.Blue),x_cor, y_cor,  rec_width, rec_height);
                paper.ResetTransform();



                /*Image imagefile=Image.FromFile(@"C:\Users\eugen\Desktop\22200.png");
                Bitmap bms = new Bitmap(imagefile);
                rotateImage(bms, 45F);
                paper.DrawImage(bms, new Point(100, 100));*/
             }
        }
castajiz_2 35 Posting Whiz

It s a pretty long code...So the problem is that i can't get my mousedown event to work ONCE the rectangle is rotated.if a normal rectangle is drawn and if you then try to move it and drop it works fine but once the rotation occurs the thing get's stuck. Any help on that would be greatly apreciated.In the rotation mehtod i m not recording my rec coordinates since resettransform is here.

 public Form1()
        {
            InitializeComponent();

           rect = new Rectangle(x_cor, y_cor, rec_width, rec_height);
        }
        bool moving = false;
        Graphics paper;
        int rec_width = 10;
        int rec_height = 30;
        int x_cor = 100;
        int y_cor = 100;
        Rectangle rect;
        Point cursor;
        Bitmap btm;
        Graphics bmp;
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private bool InObjectArea(MouseEventArgs e)
        {
            if (rect.Contains(cursor))
            {
                return true;
            }
            else
                return false;
        }

        private void button1_Click(object sender, EventArgs e)// (Button Create Object)
        {
            if (checkBox1.Checked) 
            {
                paper = this.CreateGraphics();
                RotateImage(paper, 75);
             }
        }



        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (InObjectArea(e))
            {
                moving = true;
            }
            else
                moving = false; 
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (rect.Contains(cursor))
            {
                rect.X = e.X;
                rect.Y = e.Y;
            }


            moving = false; 
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            label6.Text = e.Location.ToString();
            cursor.X = e.X;
            cursor.Y = e.Y;

            if (moving)
            {
                rect.X = e.X;
                rect.Y = e.Y;
                paper.Clear(Color.Gray);


            } 
        }
        public void RotateImage(Graphics pape,int rtangle)  // method 0, main method
        {
            pape.TranslateTransform(x_cor, y_cor);
            pape.RotateTransform(rtangle);

            paper.DrawRectangle(new Pen(Brushes.Blue), -(float)rect.Width / 2, -(float)rect.Height / 2, rec_width, …
castajiz_2 35 Posting Whiz

I combined mouse events o move my drawn rectangle object. Everything was fine i could move it and when i released the mouse button it stopped moving and settled down. However after rotating that object and then trying to move it around I just could not perform the action again. I have used the ResetTransform method at the end but this didn't help eihter. I have an alternative way for this but i would like to stick with that(above mentioned). Any sugestions what's going on behind the graphic scene and why i m unable to move my rectangle when rotation is performed?

castajiz_2 35 Posting Whiz

Well onbuttonclick event you should definetly put this into the event

using (SqlConnection con = new SqlConnection(connectionString))
    {
          //connectionString should look like this:Data Source=pc3490ierf43;Initial Catalog=Persons;Integrated Security=True
          //then inside this block call sqlcommand class and sqlreader class
    }
castajiz_2 35 Posting Whiz

I think that by copy and pasting each of you errors onto google searchbox you should get pretty good information on what could be going on. It s hard to see what the issue is without any code. Maybe if you copy and paste you lines we could see the problem.

castajiz_2 35 Posting Whiz

I have not tought of that, going to check this right now.