darkagn 315 Veteran Poster Featured Poster

Check out the FileInfo class. This gives access to creation, access and modified dates. Not sure about tags and the like, possibly the FileInfo.GetAttributes method might return these (and SetAttributes to modify them?)

darkagn 315 Veteran Poster Featured Poster

I have never used the WebBrowser control, but my understanding of it was that it was simply a frame for viewing web pages. I believe you need to implement other controls such as a Back button and call the browser's GoBack function when the button is pressed.

darkagn 315 Veteran Poster Featured Poster

Your SQL is attempting to put the value 'False' (as in the string) into a tinyint (which is numeric) column. You need to check the boolean value and assign it to a 0 or a 1. You are converting it to a string by setting it the way that you are. Hint: A more efficient and accurate way to run SQL queries in C# is to use parameters.

darkagn 315 Veteran Poster Featured Poster

I believe that it doesn't (although I could be wrong). However you can extend the class and override those operators to suit your needs.

darkagn 315 Veteran Poster Featured Poster

The only encryptions worth using are one-way encryptions. C# has a few classes that can do this, the only one I have used is the System.Security.Cryptography.Rijndael class, however you should use AES instead if you need a more secure algorithm. There is lots of sample code on the MSDN website in the documentation for the System.Security.Cryptography namespaces.

darkagn 315 Veteran Poster Featured Poster

Don't get too hung up on which languages you need to learn. It's more about learning problem solving skills, design patterns, data structures and algorithms. I learned Java at university and about 1% of the commercial code I have written has been in Java. Once you know one language, subsequent languages are easily picked up.

.NET is a windows framework that several languages are based on, including C# .NET and Visual Basic (VB) .NET. I had only read a few lines of C# before entering the workforce, now much of the code I write is in C# .NET, but again I must stress that it is not important which language(s) you learn.

As for the detailed architecture of a computer, I think so long as you have a general understanding of how a computer works you will be fine. Unless you wish to work for Intel designing new components, then you might need a more expert depth of knowledge, but for software development a general understanding should suffice. That's not to say that it would hurt to know what's going on under the hood...

I'm not sure what you are trying to ask about the general structure of an OS? Since each OS differs I think that learning the theory behind how an OS operates can't hurt, but I wouldn't stress if you only have a general understanding when you complete your degree.

Personally I think that your degree should teach you skills in design, logic, …

ddanbe commented: Nice explanation. +9
darkagn 315 Veteran Poster Featured Poster

You can traverse child nodes quite easily in C#.
Example:

// assume here I have a DataSource node called node
foreach (XmlNode childNode in node.ChildNodes)
{
  string nodeValue = String.Empty;
  // use a case insensitive search on the node name
  string childNodeName = childNode.Name.ToLowerInvariant();
  if (childNodeName == "name")
  {
    nodeValue = childNode.Value;
    // do something meaningful with the value of the node...

  }
  else if (childNodeName == "property")
  {
    nodeValue = childNode.Value;
    // do some other meaningful thing with the value of the node...

  }
  else
  {
    // error - invalid node so do some error handling here...

  }
}

Hope this helps.

arjunpk commented: thank you.. :) +1
darkagn 315 Veteran Poster Featured Poster

Try C# using Visual Studio for a windows solution to your needs. C# uses the .NET framework and allows you to design forms and use a code-behind method to handle events, data etc. If you need cross-platform Java has similar capabilities using NetBeans design mode. C++, C# and Java are all based on C-style syntax, so each are similar in terms of syntax.

darkagn 315 Veteran Poster Featured Poster

The easiest way is to store the arrays as properties of a class, then set the data source of your DataGridView to an instance of the class and add columns with the DataPropertyName set to the two properties that you created.

Example:

public class MyContainer
{
  public string[] Items
  {
    get;
    set;
  }

  public string[] Locations
  {
    get;
    set;
  }
}

public class MyForm: Form
{
  public MyForm()
  {
    InitializeComponents();
    MyContainer container = new MyContainer();
    container.Items = InitialiseItems();
    container.Locations = InitialiseLocations();
    myDataGridView.DataSource = container;
    myDataGridView.Columns[0].HeaderText = "Item";
    myDataGridView.Columns[0].DataPropertyName = "Items";
    myDataGridView.Columns[1].HeaderText = "Location";
    myDataGridView.Columns[1].DataPropertyName = "Locations";
  }
}
darkagn 315 Veteran Poster Featured Poster

I think the easiest way to stop your thread would be to break out of your while loop in the Reader method on a certain condition.

while (true)
{
  if (shouldIStop())
     break;
  msg = sr.ReadLine() + Environment.NewLine;
  allMessages += msg;
  Invoke(new Action(Output));
  Invoke(new Action(AddNameList));
}

private bool shouldIStop()
{
  // write some code here for the conditions when you want to stop your thread
}

EDIT: Also, once you break out of the while-loop you should probably do a graceful disconnect from the TCP connection.

darkagn 315 Veteran Poster Featured Poster

I think we might be over-complicating things. From your original post I thought you were after just the total of the record plus the one that came before it in sequence. If you are after a sum total of all sequences for the record, you can just use the SUM function as I have written in my second post of this thread. There is no need to use subqueries or other functions, the SUM function will give you totals for each record, and you can exclude specific sequenceID's in your where clause if you need to.

darkagn 315 Veteran Poster Featured Poster

Use a left outer join instead of an inner join. Inner joins only return results if both sides return values, left join works so long as the first part returns results, a right join works so long as the second part returns results.

darkagn 315 Veteran Poster Featured Poster

All totals is much simpler. MSSQL provides a SUM function which can be used to sum groups of totals like so:

SELECT A.PolicyID, B.CompanyID, SUM(B.Total) AS GrandTotal
FROM Table1 A
INNER JOIN Table2 B ON A.RecordID = B.RecordID
GROUP BY PolicyID, CompanyID

Note that this will give you totals by policy id and company id, sequence number is not referenced but I don't think it needs to be?

darkagn 315 Veteran Poster Featured Poster

There are a couple of ways to approach this kind of problem but I prefer to use a subquery in this case. Your query will be the subquery for the larger query, and we will select totals from that based on the SequenceID.

I suspect your query looks something like this:

SELECT A.PolicyID, A.RecordID, A.SequenceID, B.CompanyID, B.Total
FROM Table1 A
INNER JOIN Table2 B ON A.RecordID = B.RecordID

Here is how we can use that as a subquery:

SELECT C.RecordID, C.CompanyID, C.Total + D.Total AS GrandTotal
FROM
(
  -- subquery to get the first total
  SELECT A.PolicyID, A.RecordID, A.SequenceID, B.CompanyID, B.Total
  FROM Table1 A
  INNER JOIN Table2 B ON A.RecordID = B.RecordID
) C
INNER JOIN
(
  -- subquery to get the second total
  SELECT A.PolicyID, A.RecordID, A.SequenceID, B.CompanyID, B.Total
  FROM Table1 A
  INNER JOIN Table2 B ON A.RecordID = B.RecordID
) D ON C.RecordID = D.RecordID AND C.SequenceID = D.SequenceID - 1

This should at least give you something to go on. Good luck :)

darkagn 315 Veteran Poster Featured Poster

I would have one table, Visitor, then have a VistorType column that determines whether you are dealing with a student, employee or volunteer. This way you only have to join to one table from other tables that need to know about visitor information, rather than trying to join to the other three or create some sort of union statement.

darkagn 315 Veteran Poster Featured Poster

Is the CHM file on the PC running the application or in a network location? A security issue exists where windows will block CHM content when served over a network.

darkagn 315 Veteran Poster Featured Poster

1. A static method belongs to the class, not to an instance of the class, so the instance variables have no meaning in a static context. You need to create an instance of your class in the static method, then access any public instance variables, properties or methods of the instance.

2. I don't really understand what you are trying to do sorry. Without access to your answerReturned method or the Promotion method, I can't really see what you are doing.

NewOrder commented: Thank you +0
darkagn 315 Veteran Poster Featured Poster

Here is a link to the MSDN docs for the System.Math class. Take a look and see if there is any method in there that can help.

darkagn 315 Veteran Poster Featured Poster

This statement is a LINQ statement which selects all members of the list (or enumerable) named patchFiles which meet the condition of the method TryReadPatch (I don't know this method sorry) into an array named allPatches. I'm not sure if C++ makes use of LINQ, try a google search to see what you can come up with.

darkagn 315 Veteran Poster Featured Poster

Not if all of your methods are static. What I would do is make your methods non-static and pass the form to the constructor of the MathLogic class, then in your form add the property as suggested above and create a MathLogic instance.

darkagn 315 Veteran Poster Featured Poster

Can you pass the text box as a parameter to your Start method?

public static void Start(string e, TextBox answerBox)
{
  Entry = e;
  //Determine what to do to the entry. In this case 2 + 2
  // ...
  // update the text box with the answer
  try
  {
    answerBox.Text += Add(x, y).ToString();
  }
  catch
  {
    answerBox.Text += "SYNTAX ERROR";
  }
}
darkagn 315 Veteran Poster Featured Poster

In your form add a property like so:

public decimal Answer
{
  get
  {
    return Convert.ToDecimal(AnswerBox.Text);
  }
  set
  {
    AnswerBox.Text = value.ToString();
  }
}

Then in your other class add a reference to the form and set the Answer property accordingly.

class Calculator
{
  private MyForm form;
  public Calculator (MyForm aForm)
  {
    form = aForm;
  }
  public void Calculate()
  {
    // work out the answer
    //...
    // now set it in the form
    form.Answer = answer;
  }
}
darkagn 315 Veteran Poster Featured Poster

I see two potential issues with your code:

// first call to ReadLine() advances the stream
foreach (string record in reader.ReadLine().Split('|'))
{
  // first time will read the second line because of first call
  while ((line = reader.ReadLine()) != null)
  {
    if (Regex.IsMatch(line, searchText, RegexOptions.IgnoreCase))
    {
      // the text here will be overwritten on each pass, try += instead
      rtbRecord.Text = line;
    }
  }
}
darkagn 315 Veteran Poster Featured Poster

You need to join to the tblRespondentsChildren table twice, once for each child.
Something like this should give you a start:

SELECT r.FirstName, r.Surname FROM tblRespondents r
INNER JOIN tblRespondentsChildren rc1 ON r.RespondentID = rc1.RespondentID
INNER JOIN tblRespondentsChildren rc2 ON r.RespondentID = rc2.RespondentID
WHERE rc1.DOB BETWEEN ('1998-09-01') AND ('1999-08-31')
AND rc2.DOB BETWEEN ('1995-09-01') AND ('1995-12-08')
AND rc1.SexID = 1
AND rc2.SexID = 1
Gdyson commented: Spot on +0
darkagn 315 Veteran Poster Featured Poster

Try this:

protected readonly int ID = ID.GetNextID();
darkagn 315 Veteran Poster Featured Poster

You could use the String.Split function to split each line according to where each space is. Then you could just substring from the = signs to get the digits. Something like this (untested but should give you an idea):

while ((s = sr.ReadLine()) != null)
{
  string[] chunks = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  foreach (string part in chunks)
  {
    int i = part.IndexOf("=");
    if (i != -1)
    {
       int digit = Convert.ToInt32(part.Substring(i+1));
       // do something with digit...

    }
  }
}
darkagn 315 Veteran Poster Featured Poster

Hilarious post, thanks for sharing almostbob :)

And all you lot, come to Australia and visit us eh?

darkagn 315 Veteran Poster Featured Poster

That ContextMenuStrip is not standard for a TextBox (which defaults to a null ContextMenuStrip) so either you are using a different control to System.Windows.Forms.TextBox or you have added that strip yourself. You can't have two ContextMenuStrips on a single control, however you could switch between two different strips if you need to.

Alternatively, you could add a ContextMenu (as opposed to a ContextMenuStrip) and this will take precedence over the strip in a right-click operation. What you can then do is listen to the Opening event for your ContextMenu and cancel it from opening if you want the strip to open instead.

darkagn 315 Veteran Poster Featured Poster

I think you are talking about the TextBox.ContextMenuStrip property? You can simply create a ContextMenuStrip (in Designer or in Code) and assign it to this property. If the property is not set, there is no ContextMenuStrip for the TextBox, that is there is no "inbuilt" ContextMenuStrip.

Example:

ContextMenuStrip cms = new ContextMenuStrip();
// add some items here...
// ...
myTextBox.ContextMenuStrip = cms;
darkagn 315 Veteran Poster Featured Poster

Hi AndreiZ3 and welcome to DaniWeb :)

You need to cast the tag back to a datarow, then you can access each part by their names, using the methods in the Convert class to convert to the datatype required. For example,

ListViewItem lvi = lvProductsOrdered.Items[lvProductsOrdered.SelectedIndices[0]];
if (lvi.Tag.GetType() == typeof(DataRow))
{
  DataRow dr = (DataRow)(lvi.Tag);
  int qtyOrdered = Convert.ToInt32(dr["QuantityOrdered"]);
  // and so on...
}
darkagn 315 Veteran Poster Featured Poster

Directory.EnumerateFiles is one of many ways to do this.

darkagn 315 Veteran Poster Featured Poster

You need to quote your string N like so:

WHERE p.DATE IS NULL and p.TRUE = 'N'
darkagn 315 Veteran Poster Featured Poster

You can use class properties to do this. A simple example:

public class MyClass
{
  public string MyProperty
  {
    get;
    set;
  }
}
public partial class MyForm: Form
{
  private MyClass myObject;

  public MyForm()
  {
    InitializeComponents();
    myObject = new MyClass();
  }
  
  public void PassString(string str)
  {
    myObject.MyProperty = str;
  }
}
darkagn 315 Veteran Poster Featured Poster

Hi reemhatim and welcome to DaniWeb :)

There are some pretty strict rules at DaniWeb - we aren't allowed to just do it for you. Have a try yourself and feel free to post questions on specific problems you are having with your algorithm or code and we will try to point you in the right direction.

Good luck :)

darkagn 315 Veteran Poster Featured Poster

Instead of:

object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox))

and the like, you can just do:

ctrControl.GetType() == typeof(TextBox)

Also, where you call your function recursively, I would probably make that inside an else-if rather than a second if-statement. Like so:

if (object.ReferenceEquals(ctrControl.GetType(), typeof(TextBox)))
{
  ((TextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(RichTextBox)))
{
  ((RichTextBox)ctrControl).Text = string.Empty;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(ComboBox)))
{
  ((ComboBox)ctrControl).SelectedIndex = -1;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(CheckBox)))
{
  ((CheckBox)ctrControl).Checked = false;
}
else if (object.ReferenceEquals(ctrControl.GetType(), typeof(RadioButton)))
{
  ((RadioButton)ctrControl).Checked = false;
}
else if (ctrControl.Controls.Count > 0)
{
  ClearForm(ctrControl);
}

Not sure if these small fixes will help fix your problem, as everyone else said it's hard to find the problem with no error message to guide us.

darkagn 315 Veteran Poster Featured Poster

The default application for handling the http protocol is stored in the following registry key:
HKEY_CLASSES_ROOT\http\shell\open\command

You may also need to set the application for other protocols, such as https, perhaps doing some exploration using regedit.exe might provide some answers.

To write to the registry key(s) you will need to look at the Microsoft.Win32 namespace. This tutorial might help to work it out.

darkagn 315 Veteran Poster Featured Poster

In Visual Studio, when you add a class file for your project the access identifier is not specified, but you can (and should) add it. If it isn't specified, it defaults to internal access, which is public within the namespace but private outside it. Java actually does something similar when access modifiers aren't explicitly specified - it's called package access and it makes the class/method/variable public throughout the package but private outside it.

In C# we often use properties for our instance variables that require getter and/or setter methods to give a consistent way of accessing a class's underlying data. There isn't really an equivalent in Java, although other languages, such as Delphi, do have properties. Properties are basically shortcuts to accessing member variables, and there are a number of ways in which they can be used. Consider the following code:

public bool Visible
{
  get;
  set;
}

This is the "pure" form of a property, with public getter and setter method. The equivalent code in Java would be something like:

private bool visible;

public bool isVisible()
{
  return this.visible;
}

public void setVisible(bool isVisible)
{
  this.visible = isVisible;
}

And in fact, that is exactly what the C# code does behind the scenes, but for readablility and conciseness of code I think you would agree that C# is better.

Another way we can use Properties:

private bool visible;

public bool Visible
{
  get
  {
    return visible;
  }
  set
  {
    // value is the key …
darkagn 315 Veteran Poster Featured Poster

In C# there is the concept of namespaces, which (roughly) correlates to a package in Java, although in Java the naming convention matches the folder structure of the compiled .jar file whereas the C# namespace does not have to. Similarly, there is no hard and fast naming rule in C# class-file relationships, but most conventions follow this trend for ease of use. One big difference is the way get__ and set__ methods are written in C# - often properties are used instead. Another difference in syntax (but not really behaviour) is the way in which interfaces are implemented or base classes extended.

Your Java example might look something like this in C#:

using System;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.Common;

namespace Example
{
  // the : indicates extends and/or implements
  public class MyFrame: Form
  {
    private string name = "C# the son of Java";

    // the : here indicates that the constructor "inherits" the base class constructor
    public MyFrame() : base()
    {
      // ...
    }

    // C# convention - methods and properties start with capital letter
    // instead of Java's camel case of lowercase first letter but capitalises second word, third word etc
    public void PrintMe(string name)
    {
      //...
    }

    private string GetName()
    {
      // although this is legal, in C# you would probably use a property (see below)
      return this.name;
    }

    // Property - outside this class use MyFrame.Name to access the name variable.
    public string Name
    {
      get
      {
        return this.name;
      } …
darkagn 315 Veteran Poster Featured Poster

I'm afraid I'm no C++ guru, but I can probably compare C# and Java:

Some similarities:
- both have system garbage collection (C++ does not - you have to allocate and deallocate memory for objects).
- both have strict compiler conditions which are checked such as array indexes, initialisation of variables before use etc (I believe that C++ only checks syntax, resulting in many run-time errors).
- both have large API's and documentation (Java - http://download.oracle.com/javase/6/docs/api/ , C# - http://msdn.microsoft.com/en-us/library/hfa3fa08.aspx).
- both can perform reflection.
- both have excellent exception handling.

Some differences:
- C# (and C++ for that matter) allows operator overloading, Java does not.
- Java has primitive types such as int, char, double etc. Although C# has a similar syntax, the "primitive types" are actually objects and behave in the same manner in terms of memory usage and referencing.
- In Java, all method parameters are called by value, that is that the values of the parameter variables are copied into method local variables. C# allows call by value by default, but can also pass a parameter by reference, allowing the properties or values of parameters to be mutated. C# also allows an "out" variable, which is a means of returning more than one value from a method.

There are more similarities and differences between the languages. C# and Java are very similar in their syntax, C++ is more like C in …

ddanbe commented: Good answer! +7
Stefano Mtangoo commented: Well explained! +6
darkagn 315 Veteran Poster Featured Poster

If the $instance variable is null, it is created then returned. If it is not null, it is simply returned without being re-created. Your example is equivalent however. Note that my code does not have curly braces for the if-statement, so only the first line after the condition is skipped if the condition is false.

darkagn 315 Veteran Poster Featured Poster

public static function: this declaration indicates that the function is public so can be called from outside the class (for example, you can call the getInstance function from the session class. The static part of the declaration indicates that it is not called directly by a MYSQLDB instance variable. Instead, you call it like so:

$database = MYSQLDB::getInstance();

Because the constructor and clone functions have been made private, they can't be called from outside the class. This means that the only way to get an object of type MYSQLDB is by calling the getInstance function. This function creates an instance if it hasn't yet been created but if it has it is simply returned. Therefore there can only ever be one instance of the object.

Sorry, there are a couple of errors in my code for the MYSQLDB class, I was getting confused with C# syntax. The corrections are:

// this instantiates a class variable called $instance to a null value
private static $instance = null;
//...
public static function getInstance()
{
  // what we are doing here is checking whether the instance has been created
  // if it hasn't it is created
  if (MYSQLDB::instance == null)
    MYSQLDB::instance = new MYSQLDB();
  // now we return it
  return MYSQLDB::instance;
}

I hope this has helped, please let us know if you are still unsure of what I have described.

darkagn 315 Veteran Poster Featured Poster

Personally I think the best implementation is to use the Singleton design pattern and not the global keyword in this instance. So your code for MYSQLDB class would be:

class MYSQLDB
{
  private static instance = null;
  // private constructor and clone methods
  private __construct()
  {
    // initialise any variables here
  }
  private __clone()
  {
  }
  public static function getInstance()
  {
    // this code ensures there is only ever at most one instance of this class
    if (instance == null)
        instance = new MYSQLDB();
    return instance;
  }
  public function validateLogin($member, $password)
  {
     // check the member/password details in the database...
  }
}

Then in your session class you call the getInstance method to initialise your database accessor like so:

class session
{
  private $database;
  public __constuct()
  {
    $this->database = MYSQLDB::getInstance();
  }
  function login($member, $password)
  {
    // now you can use your database variable like so:
    $this->database->validateLogin($member, $password);
  }
}

I believe this method is cleaner than the global approach, but I'll leave it up to you to decide what's best for your application.

darkagn 315 Veteran Poster Featured Poster

Interfaces are extremely useful, and there are many examples why.

Taking your example one step further, you can then have another class that does this:

public class Copier
{
private ICopy copy;

public Copier(ICopy copy)
{
  this.copy = copy;
}

public void MakeCopy()
{
  copy.CopyMethod();
}
}

Now the Copier class doesn't care how the CopyMethod is implemented. This means that you can decide what gets passed to your Copier object via the constructor, and it could be a FileManipulation object or a MakePrankCalls object, or some other implementation of ICopy interface.

This is just a simple example, but as your classes get more complex, this is extremely useful.

darkagn 315 Veteran Poster Featured Poster

Not sure if there is an easier way, but you can use Convert.ToInt32(string) method to convert your string to an integer. Here is a link to the MSDN docs on this method which should provide some insight.

darkagn 315 Veteran Poster Featured Poster

Your code looks ok to me, except I think you need to override the paintComponent method in the Tooopi class with the code you have in the tupi method? I can't see where the tupi method is being called at the moment...

darkagn 315 Veteran Poster Featured Poster

Nope, it's not optional. If it were optional in Java another method would be defined, insertString(int, String).

darkagn 315 Veteran Poster Featured Poster

Not sure, but I think you need a third parameter in your call to insertString. The Java API says that insertString takes an int, a String and an AttributeSet parameter, so I would check that first.

darkagn 315 Veteran Poster Featured Poster

The LIKE statement might prove useful.

SELECT * FROM Discriptions
WHERE Description LIKE '%paint%' or Description LIKE '%red%'

The above statement will find any description where one or both of the words paint or red appear anywhere in the string. The % is a wildcard character that represents any set of characters, another is the _ (underscore) character that is used to indicate any single character.

Example:

SELECT * FROM Discriptions
WHERE Description LIKE 'r_d'

will return any three character string it finds with r as the first character and d as the third character.

These are just suggestions, not sure if it will help but was the first thing I thought of when I read your post. Good luck :)

darkagn 315 Veteran Poster Featured Poster

Make sure that line 7 (and all lines for that matter) in your csv don't have more than 19 commas. That will give you 20 values in a csv file. This line in a csv file:

1,,2,,3

actually has 5 values, it's just that 2 of the values are null/blank.

darkagn 315 Veteran Poster Featured Poster

Your problem is with this line:

for(x=0;x<sample.length();x++)

If you enter something that is less than 52 characters (because sample.length() = 52 in your code), then when you do the enter.charAt for something past the end of what has been entered, you will receive an error. You need to change the condition of the for-loop so that you don't go past the end of what has been entered, and you also don't exceed the length of sample (which you already have checked for).

HTH,
darkagn.