|
Hi
i need to create a windows service which can run continuously
i have some ms sql qureys which i would like to run can any one help me i don't have any idea on c# if any one can help it will be great full.
Thank
Sharm
|
|
|
|
|
Have a look at Topshelf or Cinchoo for getting started with a service - when you have a running service then add the ability to connect and query a database to it - you might like to think about how you're going to 'schedule' the execution of your queries - some sort of timing mechanism - its not too hard to use Quartz.Net with Topshelf to provide this ability
have fun
|
|
|
|
|
int a = 0;
int inputvalue = 0;
for (int i = 0; i < 1; i++)
{
Console.WriteLine("Give me a number");
inputvalue = Convert.ToInt16(Console.ReadLine());
if (i == 0)
a = inputvalue;
while ()
}
Console.ReadLine();
Hi guys, this is what I have so far. I am trying to learn this but i cant even understand the basics and i am really frustrated. Heres what im trying to do. Im trying to have a loop repeat certain code before it exits out. So in this example, I want to be able to write a nested loop where if I dont meet a certain condition, it continues to repeat until the condition is met. For example,
Give me a number greater than 50.
If the condition is met then loop out of the nested loop and ask for another number, if condition is not met, ask again until condition is met.
Am I close? do I have to use a loop at all or will an if statement suffice?
|
|
|
|
|
Nearly, but I would likely do the inner loop more like this:
do
{
Console.Write("Give me a number");
}
while (!System.Int16.TryParse(Console.ReadLine() , out inputvalue ) || (inputvalue <= 50 ) ) ;
|
|
|
|
|
Nested Loop defines as create the new loop inside the already existing loop. e.g.
for(int i =0;i<5;i++)
{
for(int j=0;j<i;j++)
{
Console.Write("*");
}
Console.WriteLine("");
}
Here is the example of nested for loop. You may also include the while or do-while loop inside or outside the loop.
Happy Coding
|
|
|
|
|
Your code here ... the for-loop ... suggests you want to get a certain number of numbers from the user, but I don't see you storing those numbers for future use.
PieBald's response here shows you how to use 'TryParse, and you should definitely be using that.
Do you need to preserve the user's entries ?
Also, what about letting the user quit the loop when they enter something like "quit" ?
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
I did it the tryparse way and its good but I guess im just doing this to exercise my mind and think in a logical manner. Granted, this is the more complex way but im trying different ways to program the same thing.
|
|
|
|
|
Hi, Nothing wrong with exercising the mind and trying out different things ! Experimenting is, imho, a vital part of getting the "feel" of the language ... I'm addicted to it cheers, Bill
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Hi,
I have a winform application that is a simple form with three textboxes, submit button, and cancel button. When a user is entering data, I would like the application to detect if the Enter key is pressed and "click" the Submit button when the key press is detected without regard to which control currently has focus.
Does this require a key press event for each control or is there a way to globally detect the key press?
Thanks,
Rob
|
|
|
|
|
It's very simple. Just look at the AcceptButton property of your form. Set it to the button that will be clicked when the user hits [Enter]. That's all you have to do.
|
|
|
|
|
Note that to use this with the standard Ms TextBox you will have to set the 'AcceptsReturn Property to 'true.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Actually, you don't have to do that at all. The AcceptsReturn property is only for Multiline textboxes.
What does have to happen, which I forgot about, is that you have to handle the Click event for the button you set as the AcceptButton and set the forms DialogResult property to whatever you want it to be in order for the AcceptButton property to work. The CancelButton property sets this for you, but the AcceptButton doesn't.
|
|
|
|
|
Rob, Open the properties of the required control (eg textBox), click on the event button. here you will see the keydown property. Double click on it and code here.
private void textBox2_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode.ToString() == "Return")
{
}
}
|
|
|
|
|
tarun1991,
Do I need to do this for each textbox? Your example refers to textBox2 only. I have 3 textboxes total.
-Rob
|
|
|
|
|
Rob, it depends on you. At which point you are creating its object, you need to create its event.
If you create the control inside the loop, you have to declare its location and size. Here you will call it as :
for(int i =0;i<3;i++)
{
TextBox textBox = new TextBox();
textBox.Text .....
textBox.Location....
textBox.size....
textBox.KeyDown += (press TabButton) //whole next coding will automatically generated.
}
//This part will generate automatically.
public void textBox_KeyDown(Object sender,Eventargs e)
{
// here you need to code you statement part.
}
Regards
Tarun
|
|
|
|
|
Rob, There is also an another way. You need to write the code one time and set the all textboxes event name as textBox_Keydown. This can be done, if all the textbox performs same function with same behavior.
|
|
|
|
|
In addition to the method that Dave shows, you can also set the Form's KeyPreview property to 'true, and catch the Enter Key in a KeyUp EventHandler:
private void Form1_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Console.WriteLine("enter key seen");
}
} If you have both an 'AcceptButton defined for the Form, and KeyPreview set to 'true, and a KeyUp EventHandler: both Events will fire, with the Button getting a "virtual click" first.
However, I think using either of these two techniques is (almost always) a mistake because most applications are going to need to perform some kind of validation on user entry before "submit."
With either of these two techniques, you won't know where the Enter key Event came from (okay, there is a work-around for that using 'ActiveControl, but I'll skip over that).
imho a much better technique is something like this:
private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine("button click ... active Control is {0}", ActiveControl.Name);
}
private void TextBoxes_KeyUp(object sender, KeyEventArgs e)
{
if (! (e.KeyCode == Keys.Enter)) return;
button1.Enabled = false;
TextBox activeTextBox = sender as TextBox;
string currentText = activeTextBox.Text;
if(currentText.Where(ch => Char.IsDigit(ch)).ToList().Count > 3)
{
Console.WriteLine("fail: TextBox{0} has more than 3 digits", activeTextBox);
activeTextBox.Focus();
e.Handled = true;
return;
}
switch (activeTextBox.Name)
{
case "textBox1":
if (! (currentText.Where(ch => Char.IsLetter(ch)).ToList().Count == 4))
{
Console.WriteLine("fail: TextBox1 does not have 4 letters");
activeTextBox.Focus();
e.Handled = true;
return;
}
break;
case "textBox2":
break;
case "textBox3":
break;
}
button1.Enabled = true;
button1.PerformClick();
} Note that you need to wire-up the KeyUp EventHandler to each of the TextBoxes you wish to validate.
Also, note that the decision to disable the Button used for "submit" reflects my own conviction that it is better to have UI controls that do not function if using them would have unknown side-effects, or allow errors.
While disabling the Button may not quite make sense in this example; my choice would be to enable the Button only when all 3 TextBoxes have validated content. Your Application design may not require this.
Writing code to keep track of which TextBoxes are currently validated, and to evaluate whether all TextBoxes have valid content is not difficult.
Validation is a good thing !
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
Bill,
In your example you use TextBoxes_KeyUp. When you use the name "TextBoxes" are you suggesting that each textbox requires this treatment? I wasn't sure if I used the KeyPress event for the form if it would work for all controls.
I used my newly acquired regex skills that I learned from CodeProject to perform the validation and it exactly meets the specifications for the project. Works great.
In testing this app, I seem to have a habit of pressing the enter key when the form is filled out. Since it feels natural to press the enter key to submit the form, I thought it would be a good idea to add this feature. That is where I'm at with this app at the moment. After submit is clicked, the heart of the program will begin to take place. That could spark a few discussions as I continue to develop the app.
-Rob
|
|
|
|
|
I am using Custom Featured MessageBox taken from codeproject developed by Xmen WK
while using this i am unable to change font size of the messagebox
|
|
|
|
|
There are many MessageBox realted articles on CodeProject; you don't tell us which one you are referring to.
Consider posting a message on the article with your question.
«OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. » Alan Kay's clarification on what he meant by the term "Object" in "Object-Oriented Programming."
|
|
|
|
|
If you downloded the MessageBox source from CP .You can also look for what actualy the author has made with that hope you can find the solution from the source to change the font size.If you cont find it you can also request the same message to the author at the comment section of that article.
Can you paste the article link so that it will be check for the possible ways to change the font size .
|
|
|
|
|
PLease elaborate your requirement?
hi
|
|
|
|
|
If you mean this one: Custom Featured MessageBox[^], then don't post this here - if you got the code from an article, then there is a "new message" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
The original author appears to be still logging in, so he may respond - even to a 6 and a half year old article!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hi,
I have fromOptions and I am showing a user control for every option using this code:
ucOptionsBarcode options_barcode = new ucOptionsBarcode();
options_barcode.Left = 270;
options_barcode.Top = 12;
options_barcode.Width = 500;
options_barcode.Height = 300;
this.Controls.Add(options_barcode);
I would like to change the code to loop through all user controls on the form, if the user control was already added earler then just BringToFront, otherwise Controls.Add it?
How can I do this please?
Technology News @ www.JassimRahma.com
|
|
|
|
|
Try:
Control found = null;
foreach (Control c in Controls)
{
if (c is ucOptionsBarcode)
{
found = c;
break;
}
}
if (found == null)
{
}
else
{
found.BringToFront();
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
modified 25-Dec-14 2:05am.
|
|
|
|