|
I am trying to verify some domain names from our internal customer list. I am using Dns.GetHostAddresses but it doesn't seem to find half of the domains - many I can type into IE and up pops the web page. Is GetHostAddresses broken (I have tried the deprecated methods too and they don't seem to work either)
|
|
|
|
|
Do you not want to use GetHostByName?
Regards,
Rob Philpott.
|
|
|
|
|
That doesn't seem to work either - I get "The requested name is valid, but no data of the requested type was found" on even some quite well known domain names
|
|
|
|
|
That's strange, as my understanding is that's what Internet Explorer etc. will call behind the scenes to resolve domain names. Sorry, as confused as you.
Regards,
Rob Philpott.
|
|
|
|
|
|
can't you just ping them?
ping[^]
|
|
|
|
|
I tried pinging some through the command console - some work, some don't.
So:
ping google.com works
ping microsoft.com doesn't
|
|
|
|
|
I trust one can create a server that only supports some protocols (do/don't respond to PING, do/don't respond to HTTP, HTTPS, FTP, etc). And then the server could try and ignore false clients, those with strange or no "user agent" for instance. So I expect browsers to try several things behind the scenes, before giving you a "404".
If ping doesn't work for you and your targets are HTTP oriented, I would go with http://msdn.microsoft.com/en-us/library/system.web.httprequest.aspx[^]. You can ask for the HEAD only, without the BODY.
|
|
|
|
|
Hi,
Summary: I need to draw lines between items in two DataGridViews to give a visual indication of source to target column mapping.
Details: First of all, I'm fairly new to DotNet and C# programming, but an experienced developer in other languages and technologies. This is my first post to CodeProject. I've read the FAQs, searched the articles, searched Google, and skimmed several forums before deciding on this one. If this is the incorrect forum, please gently and politely point me in the right direction and correct an honest mistake.
I need to write an application that will allow the user to map source columns to target columns, then generate syntactically correct SQL. For the UI, I was thinking of using two DataGridViews, plus the "dictionary tables" to populate the DataGridViews. For the SQL, I intend to use NVelocity or something similar.
My vision is the user will select a column from the source DataGridView and drag it to the target column in the target DataGridView.
What I can't work out is how to draw lines between the source and target columns to give the user a visual indication of the column mapping. This is especially true for columns mapped that are scrolled off the DataGridView, either top or bottom.
Picture another scenario: an online quiz. Questions on the left, answers on the right, drag the question to the correct answer to map the two.
Is there any example code in the public domain that does this, or something similar? Otherwise any design ideas are greatly appreciated.
Finally, I'm not married to using a DataGridView, so if there's a better UI element to use, please let me know.
Kind Regards,
Scott
|
|
|
|
|
I'm making Yahtzee but I've 1 question:
I've 5 stones which must be generated randomly between 1 and 6.
If I've a 1,2,3,4 and 5 in this 5 stones it need's to display "GOOD" otherwise "LOST"
SO 2,1,3,5,4 is "GOOD"
SO 1,1,3,4,5 is "LOST"
How can I do this can somebody help me please with it So I can go further. I must work with array'sin my opinion but didn't have much knowledge of them
Hope somebody can improve my code or say how I must do it. (I'm learning)
My Code:
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace W1<br />
{<br />
public partial class w1 : Form<br />
{<br />
public w1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void w1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void exitToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
Application.Exit();<br />
}<br />
<br />
private void btnDrop_Click(object sender, EventArgs e)<br />
{<br />
Random random = new Random();<br />
<br />
int randomNumber1C = random.Next(1, 7);<br />
int randomNumber2C = random.Next(1, 7);<br />
int randomNumber3C = random.Next(1, 7);<br />
int randomNumber4C = random.Next(1, 7);<br />
int randomNumber5C = random.Next(1, 7);<br />
lblDice1C.Text = "Dropped: " + randomNumber1C.ToString();<br />
lblDice2C.Text = "Dropped: " + randomNumber2C.ToString();<br />
lblDice3C.Text = "Dropped: " + randomNumber3C.ToString();<br />
lblDice4C.Text = "Dropped: " + randomNumber4C.ToString();<br />
lblDice5C.Text = "Dropped: " + randomNumber5C.ToString();<br />
if (randomNumber1C == 1 && randomNumber2C == 2 && randomNumber3C == 3 && randomNumber4C == 4 && randomNumber5C == 5 || randomNumber1C == 2 && randomNumber2C == 3 && randomNumber3C == 4 && randomNumber4C == 5 && randomNumber5C == 6)<br />
{<br />
lblDroppedC.ForeColor = System.Drawing.Color.Green;<br />
lblDroppedC.Text = "WON";<br />
}<br />
else<br />
{<br />
lblDroppedC.ForeColor = System.Drawing.Color.Red;<br />
lblDroppedC.Text = "LOST";<br />
}<br />
<br />
int randomNumber1 = random.Next(1, 7);<br />
int randomNumber2 = random.Next(1, 7);<br />
int randomNumber3 = random.Next(1, 7);<br />
int randomNumber4 = random.Next(1, 7);<br />
int randomNumber5 = random.Next(1, 7);<br />
lblDice1.Text = "Dropped: " + randomNumber1.ToString();<br />
lblDice2.Text = "Dropped: " + randomNumber2.ToString();<br />
lblDice3.Text = "Dropped: " + randomNumber3.ToString();<br />
lblDice4.Text = "Dropped: " + randomNumber4.ToString();<br />
lblDice5.Text = "Dropped: " + randomNumber5.ToString();<br />
if (randomNumber1 == 1 && randomNumber2 == 2 && randomNumber3 == 3 && randomNumber4 == 4 && randomNumber5 == 5 || randomNumber1 == 2 && randomNumber2 == 3 && randomNumber3 == 4 && randomNumber4 == 5 && randomNumber5 == 6)<br />
{<br />
lblDropped.ForeColor = System.Drawing.Color.Green;<br />
lblDropped.Text = "WON";<br />
}<br />
else<br />
{<br />
lblDropped.ForeColor = System.Drawing.Color.Red;<br />
lblDropped.Text = "LOST";<br />
}<br />
}<br />
<br />
private void label1_Click(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
}<br />
}
Looks:
1 button
2x5 labels (1 Computer and 1 myself)
Both 5x stones need to be generated randomly each time you click on the button and then it's needs to check or you LOST OR LOSE
Dennis,
|
|
|
|
|
As a suggestion, firstly don't use 5 seperate integers, use an array with 5 elements.
You could do the test a couple of ways. Firstly, sort the array, then check that two neighbouring elements do not contain the same number. That guarantees uniqueness.
Or, create five booleans, all false originally, then set the appopriate one on each iteration of a loop over the array. All booleans being set would signal uniqueness too.
Regards,
Rob Philpott.
|
|
|
|
|
Changed my code, can I make it easier? TO read and write? I don't know much about C#...
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace W1<br />
{<br />
public partial class w1 : Form<br />
{<br />
public w1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void w1_Load(object sender, EventArgs e)<br />
{<br />
<br />
}<br />
<br />
private void exitToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
Application.Exit();<br />
}<br />
<br />
private void btnDrop_Click(object sender, EventArgs e)<br />
{<br />
Random random = new Random();<br />
<br />
int randomNumber1C = random.Next(1, 7);<br />
int randomNumber2C = random.Next(1, 7);<br />
int randomNumber3C = random.Next(1, 7);<br />
int randomNumber4C = random.Next(1, 7);<br />
int randomNumber5C = random.Next(1, 7);<br />
<br />
int randomNumber1 = random.Next(1, 7);<br />
int randomNumber2 = random.Next(1, 7);<br />
int randomNumber3 = random.Next(1, 7);<br />
int randomNumber4 = random.Next(1, 7);<br />
int randomNumber5 = random.Next(1, 7);<br />
<br />
List<int> randomList = new List<int>();<br />
randomList.Add(randomNumber1);<br />
randomList.Add(randomNumber2);<br />
randomList.Add(randomNumber3);<br />
randomList.Add(randomNumber4);<br />
randomList.Add(randomNumber5);<br />
randomList.Sort();<br />
<br />
int last = 0;<br />
foreach (int itemInRandomList in randomList)<br />
{<br />
if (itemInRandomList == last || itemInRandomList - last != 1)<br />
{<br />
last = 0;<br />
break;<br />
}<br />
last = itemInRandomList;<br />
}<br />
<br />
if (last == 0)<br />
{<br />
lblDropped.ForeColor = System.Drawing.Color.Red;<br />
lblDropped.Text = "LOST";<br />
}<br />
else<br />
{<br />
lblDropped.ForeColor = System.Drawing.Color.Green;<br />
lblDropped.Text = "WON";<br />
}<br />
<br />
List<int> randomListC = new List<int>();<br />
randomListC.Add(randomNumber1C);<br />
randomListC.Add(randomNumber2C);<br />
randomListC.Add(randomNumber3C);<br />
randomListC.Add(randomNumber4C);<br />
randomListC.Add(randomNumber5C);<br />
randomListC.Sort();<br />
<br />
int lastC = 0;<br />
foreach (int itemInRandomList in randomListC)<br />
{<br />
if (itemInRandomList == lastC || itemInRandomList - lastC != 1)<br />
{<br />
lastC = 0;<br />
break;<br />
}<br />
lastC = itemInRandomList;<br />
}<br />
<br />
if (lastC == 0)<br />
{<br />
lblDroppedC.ForeColor = System.Drawing.Color.Red;<br />
lblDroppedC.Text = "LOST";<br />
}<br />
else<br />
{<br />
lblDroppedC.ForeColor = System.Drawing.Color.Green;<br />
lblDroppedC.Text = "WON";<br />
}<br />
<br />
lblDice1C.Text = "Dropped: " + randomNumber1C.ToString();<br />
lblDice2C.Text = "Dropped: " + randomNumber2C.ToString();<br />
lblDice3C.Text = "Dropped: " + randomNumber3C.ToString();<br />
lblDice4C.Text = "Dropped: " + randomNumber4C.ToString();<br />
lblDice5C.Text = "Dropped: " + randomNumber5C.ToString();<br />
<br />
lblDice1.Text = "Dropped: " + randomNumber1.ToString();<br />
lblDice2.Text = "Dropped: " + randomNumber2.ToString();<br />
lblDice3.Text = "Dropped: " + randomNumber3.ToString();<br />
lblDice4.Text = "Dropped: " + randomNumber4.ToString();<br />
lblDice5.Text = "Dropped: " + randomNumber5.ToString();<br />
<br />
lblDice1.Visible = true;<br />
lblDice2.Visible = true;<br />
lblDice3.Visible = true;<br />
lblDice4.Visible = true;<br />
lblDice5.Visible = true;<br />
lblDice1C.Visible = true;<br />
lblDice2C.Visible = true;<br />
lblDice3C.Visible = true;<br />
lblDice4C.Visible = true;<br />
lblDice5C.Visible = true;<br />
lblDropped.Visible = true;<br />
lblDroppedC.Visible = true;<br />
w1.ActiveForm.Size = new Size(316, 256);<br />
}<br />
<br />
private void rulesToolStripMenuItem_Click(object sender, EventArgs e)<br />
{<br />
MessageBox.Show("Rules");<br />
}<br />
}<br />
}<br />
<br />
|
|
|
|
|
First as suggested previously you need a 5 long array of ints. The method described above (checking for uniqueness) won't work as (2,3,4,5,6) is unique but not winning.
You will also find your code improves vastly if you study OO and work out how to refactor. The two guidlines I try to live by [and often fail] are "Don't Repeat Yourself" "Keep It Simple Stupid" (DRY-KISS).
For example
int randomNumber1 = random.Next(1, 7);<br />
int randomNumber2 = random.Next(1, 7);<br />
int randomNumber3 = random.Next(1, 7);<br />
int randomNumber4 = random.Next(1, 7);<br />
int randomNumber5 = random.Next(1, 7);
Fails the DRY test.
I've separated out an example Yahtzee Roller class for you, this is one implementation of many possible and is not meant to be perfect. It contains an array of roll results, abd an array of winning values, these are compared. The amin program creates an instance of the roller, and proceeds to roll until a winning set is found.
The roller:
public class YahtzeeRoller
{
int[] rollResults = new int[]{0, 0, 0, 0, 0};
int[] WinningValues = new int[] { 1, 2, 3, 4, 5 };
Random random = new Random();
public bool IsWinning
{
get
{
return WinningValues.Except(rollResults).Count() == 0;
}
}
public string CurrentRoll
{
get
{
string result = "Roll =";
foreach (int rollResult in rollResults)
result += " " + rollResult;
return result;
}
}
public void Roll()
{
for (int i = 0; i < rollResults.Length; i++)
rollResults[i] = random.Next(1, 7);
}
}
Calling Program:
class Program
{
static void Main(string[] args)
{
YahtzeeRoller yahtzeeRoller = new YahtzeeRoller();
while (!yahtzeeRoller.IsWinning)
{
yahtzeeRoller.Roll();
Console.Write(yahtzeeRoller.CurrentRoll);
if (yahtzeeRoller.IsWinning)
Console.WriteLine(" Yahtzee!");
else
Console.WriteLine(" Not Yahtzee !");
}
Console.ReadKey();
}
}
Notice a few things. The re-factored code is shorter (and hopefully clearer) than the original. Additionally, it separates out the rolling functionality from the display [mostly] the use of CurrentRole property is debatable. You can now call Roll as many times as needed (it is not hard-coded), and if desired, easily change what constitutes a winning set of rolls.
I hope this helps!
CCC solved so far: 2 (including a Hard One!)
37!?!! - Randall, Clerks
|
|
|
|
|
Hi,
- you have a single random generator, that is good.
- you don't need five or ten Labels, its much easier to show all five numbers in a single Label.
- you want to recognize not only "12345" but also all permutations thereof. Sorting the numbers is one way, but is unnecessary. The smart way to do this is by using a bit collection. Have a look at this:
int all=0;
all = all | (1<<number);
...
if (all==goodValue) output("WON");
Now try to use that to your advantage; the end result will be less than half the code you have now.
BTW: please use PRE tags, not CODE tags.
|
|
|
|
|
But this isn't working at any computer?
|
|
|
|
|
dennis_max27 wrote: this
what?
dennis_max27 wrote: isn't working
what gives?
dennis_max27 wrote: any computer?
huh?
if you can't communicate what it is you want or try or experience, nobody can help you.
|
|
|
|
|
Ha! Use a System.Collections.Generic.HashSet!
Are you only looking for a large straight?
Clear the HashSet.
Generate the numbers (into an array).
Iterate the array, putting each value in the HashSet. (Or you could eliminate the array if you're only interested in large straights.)
Check how many values are in the HashSet -- if there are five and 1 or 6 is not present, then you have a large straight!
To also check for small straights, you can track the min and max values.
Large straight := Five values, max - min == 4
Small straight := Four values, max - min == 3
Also, if the HashSet contains only one value, you have a Yahtzee.
If only two, you might have a full house.
|
|
|
|
|
I have this problem with a SQL query that is executed through a c# program.
it occurs in the following query:
string strSql = "SELECT 2010Forms.Task_ID_PK, 2010Forms.isMainOutcome, 2010Forms.Outcome, ";
strSql += " 2010Outcome.InProg, 2010Forms.OutcomeType, ";
strSql += " 2010Outcome.TraineeStatus, 2010Outcome.ReviewerStatus ";
strSql += " FROM 2010Outcome INNER JOIN 2010Forms ON ";
strSql += " 2010Outcome.2010Outcome_ID_FK = 2010Forms.Task_ID_PK";
strSql += " where (2010Outcome.Review_ID_FK = '" + StringRevID "')";
strSql += " and (2010Outcome.Trainee_ID_FK = '" + StringTraineeID + "')";
strSql += " and (2010Forms.isFinal = 0)";
strSql += " order by 2010Forms.OutcomeOrder asc ";
I cannot see any missing operators, but is anyone can assist me, I will be very greatful.
|
|
|
|
|
Two things:
1) Shouldn't you have a space between ".Outcome" and "Order"?
AlucardCode wrote: strSql += " order by 2010Forms.OutcomeOrder asc ";
2) You realy should use Parameters.AddWithValue rather than encoding IDs directly. Even if they are numeric it is good practice - avoid SQl injection problems!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
Maybe using table names starting with a number can be a problem: identifiers starting with a number has a special meaning in SQL server (documentation here[^]).
Try enclosing the identifiers inside square brakets (eg [2010Outcome].InProg ). I'm not sure this is your problem through.
|
|
|
|
|
Cool Thanx, I will give it a try
|
|
|
|
|
missing plus sign
strSql += " where (2010Outcome.Review_ID_FK = '" + StringRevID "')";
strSql += " where (2010Outcome.Review_ID_FK = '" + StringRevID + "')";
|
|
|
|
|
when can we use begin invoke
suresh
|
|
|
|
|
|
sureshhi wrote: when can we use begin invoke
Any time you like!
|
|
|
|
|