Hi. Since you went with this approach to create your connection classs, in the OPEN method only open the connection if it is closed.
if (csCon.State == ConnectionState.Closed)
{
csCon.Open();
}
Hi. Since you went with this approach to create your connection classs, in the OPEN method only open the connection if it is closed.
if (csCon.State == ConnectionState.Closed)
{
csCon.Open();
}
It realy depends on how you call your action. If it's a normal http get request it loads the layout + view + every partial.
If you want only the partial view to be retunred do an ajax call and replace the content with the result.
Look through your code... there is a point when you actually do that, just the conditions don't get you there all the time.
It's because SelectedPiece is instantiated but it's properties are not. So SelectedPiece is just a new Piece qith nothing in it... no Moves, no name...
Just clicking the select button doesn't throw any exception for me. If you run the program from Visual Studio when it throws an uncaught exception the IDE jumps to the line of code where the exception occured. Check that line.
This line actually tells you that the Piece object has a Moves property of type Movement. It does not contain anything until you explicitly set it.
Pieces p = new Pieces();
Movement move = new Movement();
p.Moves = move;
Then you can set the Movement properties for that Pieces.
Same code I provided goes for showing movements. You just need to arrange the pieces (you could even have a graphical representation of a piece - image) and get the selected piece on button press instead of select button click.
Your while condition is wrong. It should be while ((line = sr.ReadLine()) != null)
part this is a piece object used when you select one from the radio button list. There is a global Pieces called "SelectedPiece" which gets initialized when you click the select button. The piece has a name (king, queen...), a Movement object (which in turn has the properties from the 2 part you asked about) and a StartingPosition (which i did not use eventually :))
part these are the properties of a movement. It has a list of directions (up, down...) where a piece can move, a maximum number of steps it can take (1 for king) and a complex direction which you can use to simulate the knight movement (2 verticaly, 1 horizontaly).
The code is pretty much self explanatory... you have one chess piece which has a movement option. the movement has direction and max limit.
Check out btn_selectClick to see how I defined the king and queen.
I made some changes to your code to get you started. First of all you have to think of a chess board/piece. A piece has directions of movement, movement pattern and maximum moves. I added a class that simulates these three attributes of a chess piece. So once you load the program, select one piece and it will give it the right attributes. Then if you click on a chess board button it shows where it can go.
Now for the not so good part for you :)
- I have only defined king and queen movements but this should be enough as an example. You have to define the other pieces
- the movement class has a ComplexMovement... you could use this for the Knight piece which has a complex pattern... it's your job to figure out how to simulate it
Let me know if you have any questions
public partial class Form1 : Form
{
public Pieces SelectedPiece;
public class Position
{
private int X, Y;
public Position(int x,int y)
{
X = x;
Y = y;
}
public Position() { }
public int getX()
{
return X;
}
public int getY()
{
return Y;
}
}
public class Pieces
{
public string …
Sounds great. Where are you stuck?
as an addition to C#Jaap. if you want to then compare to another string (lets say username and password stored in database) and the char is not all upper/lower case use this:
string username = textbox1.text;
if (username.Equals("string from database", StringComparison.CurrentCultureIgnoreCase))
{
}
if you're using string in languages with special characters use InvariantCultureIgnoreCase
if you need to disable your internet connection the simplest way is to change your gateway
to some ip that doesn't provide the functionality.
ex:
your curent settings:
your modified setting:
this method still lets u use the local network. if you want to disable that too just change your ip address too.
sample code to change ip address
public void setIP(string ip_address, string subnet_mask)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setIP;
ManagementBaseObject newIP =
objMO.GetMethodParameters("EnableStatic");
newIP["IPAddress"] = new string[] { ip_address };
newIP["SubnetMask"] = new string[] { subnet_mask };
setIP = objMO.InvokeMethod("EnableStatic", newIP, null);
}
catch (Exception)
{
throw;
}
}
}
}
sample code to change gateway
public void setGateway(string gateway)
{
ManagementClass objMC = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection objMOC = objMC.GetInstances();
foreach (ManagementObject objMO in objMOC)
{
if ((bool)objMO["IPEnabled"])
{
try
{
ManagementBaseObject setGateway;
ManagementBaseObject newGateway =
objMO.GetMethodParameters("SetGateways");
newGateway["DefaultIPGateway"] = new string[] { gateway };
newGateway["GatewayCostMetric"] = new int[] { 1 };
setGateway = objMO.InvokeMethod("SetGateways", newGateway, null);
}
catch (Exception)
{
throw;
}
}
}
}
this is not the best practice but it gets the job done if you need it fast.
ArrayList ar1 = new ArrayList();
ArrayList ar2 = new ArrayList();
ArrayList ar3 = new ArrayList();
ArrayList ar4 = new ArrayList();
ArrayList ar5 = new ArrayList();
ArrayList ar6 = new ArrayList();
string filePath = "file.txt";
StreamReader sr = new StreamReader(filePath);
while (sr.ReadLine() != null)
{
string[] line = sr.ReadLine().Split("\t".ToCharArray());
for(int i = 0; i < line.Length; i++)
{
ar1.Add(line[i]);
ar2.Add(line[i + 1]);
ar3.Add(line[i + 2]);
ar4.Add(line[i + 3]);
ar5.Add(line[i + 4]);
break;
}
}
sr.Close();
This assumes you know the number of columns in the text file. If you later need to use the values from the array as integers just use Convert.ToInt32(ar1[0])
and so on.
[B]Book mybook = new Book();[/B]
public void checkRatio()
{
const double RATE = .10;
// The price-to-pages ratio is determined by checking the following: price > RATE * pages where RATE = 0.10
if (Price > (RATE * NumPages))
{
[B]mybook[/B].validRatio = true;
}
// Throw a BookException if a book object is created that has a price that is more than 10 cents per page
else
{
[B]mybook[/B].validRatio = false;
BookException be = new BookException();
/* Create an error message that is passed to the Exception class constructor for the Message property
* when a book does not meet the price-to-pages ratio. */
Console.WriteLine("Ratio for {0} is invalid. Price is {1} for {2} pages.", Title, Price, NumPages);
throw(be);
}
}
} //End Book Class
you are creating an instance of class book inside the class declaration. remove the line in bold, and inside the checkRatio() method just use the cariable names (without the preceding object)... c# is clever enough to use the object you created in main.