|
Code Server :
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IPAddress[] localip = Dns.GetHostAddresses(Dns.GetHostName());
foreach (IPAddress address in localip)
{
if (address.AddressFamily == AddressFamily.InterNetwork)
{
textBox1.Text = address.ToString();
textBox2.Text = "8888";
}
}
}
private void button1_Click(object sender, EventArgs e)
{
TcpListener listenner = new TcpListener(IPAddress.Any, int.Parse(textBox2.Text));
listenner.Start();
tcpclient = listenner.AcceptTcpClient();
}
Code client :
namespace CLIENT
{
public partial class Form1 : Form
{
private TcpClient tcpclient;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
labelmessage.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
tcpclient = new TcpClient();
IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(textBox1.Text), int.Parse(textBox2.Text));
try
{
tcpclient.Connect(ipe);
if (tcpclient.Connected)
{
labelmessage.Visible = true;
labelmessage.Text = "Conected...";
}
}
catch
{
}
}
}
}
|
|
|
|
|
And what exactly is your question?
|
|
|
|
|
hi all,
i was searching an article on how to implement roles system in my winform c# application, so i find the same question: user roles management in c# windows application[^]
I understand from this article that I can use Membership and Role provider so I revise this course specific to ASP .NET :
ASP.NET Membership and Role Provider[^]
I want an article/course/code/explanation on how to use this into my winform application (app.config)
I use MySql and C#
|
|
|
|
|
I apologize for my bad english (google translate),
With this code, I can see the dates for this week : but I do not see next week and the previous week, please help
DateTime dt = DateTime.Now;
int a = (int)dt.DayOfWeek;
if (a == 0) a = 7;
DateTime monday_day = dt.AddDays(1 - a);
DateTime tuesday_day = dt.AddDays(2 - a);
DateTime wednesday_day = dt.AddDays(3 - a);
DateTime thursday_day = dt.AddDays(4 - a);
DateTime friday_day = dt.AddDays(5 - a);
DateTime saturday_day = dt.AddDays(6 - a);
DateTime sunday_day = dt.AddDays(6);
monday_lbl.Text = monday_day.ToShortDateString();
tuesday_lbl.Text = tuesday_day.ToShortDateString();
wednesday_lbl.Text = wednesday_day.ToShortDateString();
thursday_lbl.Text = thursday_day.ToShortDateString();
friday_lbl.Text = friday_day.ToShortDateString();
saturday_lbl.Text = saturday_day.ToShortDateString();
sunday_lbl.Text = sunday_day.ToShortDateString();
----------------------
|
|
|
|
|
|
ty man, I guess I was looking for this code, but there are a lot of code I don't understand
|
|
|
|
|
It's all pretty simple, I thought. What parts are difficult? I may be able to explain them, or change the tip to be clearer to others.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I just next to the label and I want you to write the history of the previous week, but these mixed. ty
|
|
|
|
|
Sorry, but I don't understand what you are saying.
Could you try saying that again, but in a different way?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
Not too complex:
Next week (starting Saturday) is Next Saturday (there is a method for that in the link).
From that, as a DateTime, you can work out the whole of the week by using teh standard DateTime.AddDays method.
From the Saturday, you can also work out last week: Next Saturday and use AddDays again, with -14 as the add on value. You can then use AddDays again to work through the week.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
yes, I can see it with code dates next week, how can I make the loop, but how,
DateTime dt = DateTime.Now;
int a = (int)dt.DayOfWeek;
if (a == 0) a = 14;
DateTime pazartesigun = dt.AddDays(8 - a);
DateTime saligun = dt.AddDays(9 - a);
DateTime carsambagun = dt.AddDays(10- a);
DateTime persembegun = dt.AddDays(11- a);
DateTime cumagun = dt.AddDays(12 - a);
DateTime cumartesigun = dt.AddDays(13 - a);
DateTime songun = dt.AddDays(14-a);
pazartesilbl.Text = pazartesigun.ToShortDateString();
salilbl.Text = saligun.ToShortDateString();
carsambalbl.Text = carsambagun.ToShortDateString();
persembelbl.Text = persembegun.ToShortDateString();
cumalbl.Text = cumagun.ToShortDateString();
cumartesilbl.Text = cumartesigun.ToShortDateString();
pazarlbl.Text = songun.ToShortDateString();
|
|
|
|
|
This may be a translation problem, but you can't make that code into a loop, unless you create an array of labels - containing pazartesilbl, salilbl ... in the order you want to display them.
Which I think you know...so what is it you are trying to get help with?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Can I send the program solves the problem?
|
|
|
|
|
No - but if it's solved, why would I need it anyway?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
I'm not looking at that: I don't download and run EXE files from unknown websites!
And particularly when they are "download managers"...
I'm not surprised it doesn't change any dates when you press a button - you are using DateTime.Now, so at best it will be a week before anything changes!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
area code next week dates this. now you need the area code of the previous week dates
DateTime strtdt = DateTime.ParseExact(mondaylbl.Text, "dd/MM/yyyy", null);
GregorianCalendar cal = new GregorianCalendar(GregorianCalendarTypes.Localized);
int week = cal.GetWeekOfYear(strtdt, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
int year = strtdt.Year;
DayOfWeek day = DayOfWeek.Monday;
DateTime startOfYear = new DateTime(year, 1, 1);
int daysToFirstCorrectDay = (((int)day - (int)startOfYear.DayOfWeek) + 7) % 7;
DateTime FirstDay = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay);
DateTime sonrakiikincigun = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(1);
DateTime sonrakiucuncugun = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(2);
DateTime sonrakidorduncugun = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(3);
DateTime sonrakibesincigun = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(4);
DateTime sonrakialtincigun = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(5);
DateTime Endaday = startOfYear.AddDays(7 * (week - 1) + daysToFirstCorrectDay).AddDays(6);
mondaylbl.Text=FirstDay.ToString("dd/MM/yyyy");
tuesdaylbl.Text = sonrakiikincigun.ToString("dd/MM/yyyy");
wednesdaylbl.Text = sonrakiucuncugun.ToString("dd/MM/yyyy");
thursdaylbl.Text = sonrakidorduncugun.ToString("dd/MM/yyyy");
fridaylbl.Text = sonrakibesincigun.ToString("dd/MM/yyyy");
saturdaylbl.Text = sonrakialtincigun.ToString("dd/MM/yyyy");
sundaylbl.Text=Endaday.ToString("dd/MM/yyyy");
|
|
|
|
|
OK - a quick check says that works. I put a date in monday, press the button, I get a monday, and so forth.
What's the problem?
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
problem, can not list the previous week
|
|
|
|
|
I'd probably do it something like this:
DateTime strtdt = DateTime.ParseExact(mondaylbl.Text, "dd/MM/yyyy", null);
DateTime thisWeekMonday = strtdt.AddDays(1 - (int) strtdt.DayOfWeek );
DateTime nextWeekMonday = thisWeekMonday.AddDays(7);
DateTime lastWeekMonday = thisWeekMonday.AddDays(-7);
mondaylbl.Text = lastWeekMonday.ToString("dd/MM/yyyy");
tuesdaylbl.Text = lastWeekMonday.AddDays(1).ToString("dd/MM/yyyy");
wednesdaylbl.Text = lastWeekMonday.AddDays(2).ToString("dd/MM/yyyy");
thursdaylbl.Text = lastWeekMonday.AddDays(3).ToString("dd/MM/yyyy");
fridaylbl.Text = lastWeekMonday.AddDays(4).ToString("dd/MM/yyyy");
saturdaylbl.Text = lastWeekMonday.AddDays(5).ToString("dd/MM/yyyy");
sundaylbl.Text = lastWeekMonday.AddDays(6).ToString("dd/MM/yyyy");
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I've solved the problem, thank u OriginalGriff
|
|
|
|
|
It seems to me these three things are very quite similar. Can someone explain why you would use one over the others in given situations. Here I wrote a silly console app in which I was able to get all three types of methods to perform a simple math expression.
Are there advantages / disadvantages to using one over another?
class Program
{
delegate int GimmeTwoInts(int x, int y);
static void Main(string[] args)
{
GimmeTwoInts addThemUp = delegate(int x, int y)
{ return x + y; };
Console.WriteLine(addThemUp(5, 5));
GimmeTwoInts addAgain = (c, d) => { return c + d; };
Console.WriteLine(addAgain(10, 10));
Console.WriteLine(Program.AddingMachine(20, 20));
Console.ReadLine();
}
public static int AddingMachine(int f, int g)
{
return f + g;
}
}
|
|
|
|
|
Anonymous has it's own obvious advantages and would be used for a specific requirement but I don't see any benefit either way on the other 2. I would always use the "static" method but then I don't normally consider linq by default.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The three aren't "very quite similar" - the static method is a different animal altogether from the other two. Anonymous and Lambda methods cannot be static: they are always instance related.
A static method is not instance related: you cannot use the this reference inside a static method explicitly or implicitly - which means you can't access non-static class properties, fields, or methods at all. So you can't do this:
private int myInt = 666;
public static void MyStaticMethod()
{
Console.WriteLine(myInt);
} Because the compiler will complain that "An object reference is required for the non-static field, method, or property '... .myInt'"
And there is no way to find the object reference because it is never, ever provided for a static method.
If you remove the keyword static from your example, then the three calls become equivalent.
But... you wouldn't normally do that!
The Lambda you use for a very simple method that you are going to do in one place only, and it is frequently used for Linq to process all the elements in a collection - outside that context it's a bit overkill (why not just do the code inline?)
Delegates are different: while you can use them the way you show, you would have to agree it's very "clumsy"! That's partly why Lambdas were introduced with Linq - to give a "cleaner" syntax to doing the same thing, and that's effectively what a Lambda is: an anonymous Delegate!
But Delegates are move powerful that that: you can use the delegate repeatedly, or pass it through to a method. This allows you to write code which calls the delegate to "do something" without knowing exactly what the delegate is going to do! For example, you could set up a method to list out a log from a DB, and give it a delegate which does the actual output - then call the same method to output to the console, a textbox, a file,... without changing the actual method in any way!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|