mfiroozi66
عضو جدید
دوستان من برای فرم لاگینی که طراحی می کنم از این کد استفاده می کنم.گفتم توی این تایپیک قرار بدم شاید بدردتون بخوره و اینکه عیب هاشو بگید تا بتونیم به کمک هم به یه کد حرفه ای برسیم
ابتدا یه کلاس ایجاد کردم و تابع checkuser را درونش نوشتم
بعد در رویداد کلیک دکمه فراخوانیش می کنیم
ابتدا یه کلاس ایجاد کردم و تابع checkuser را درونش نوشتم
کد:
[COLOR=blue][FONT='inherit']public[/FONT][/COLOR][FONT='inherit'] [COLOR=blue]bool[/COLOR] checkuser([COLOR=blue]string[/COLOR] st1, [COLOR=blue]string[/COLOR] st2)[/FONT]
[FONT='inherit'] {[/FONT]
[FONT='inherit'][COLOR=#2B91AF]user[/COLOR] u = [COLOR=blue]new[/COLOR] [COLOR=#2B91AF]user[/COLOR]();[/FONT]
[FONT='inherit'][COLOR=blue]int[/COLOR] n=db.user.Where(p => p.id == st1 && p.pass == st2).Count();[/FONT]
[FONT='inherit'][COLOR=blue]if[/COLOR] (n == 0)[/FONT]
[FONT='inherit'][COLOR=blue]return[/COLOR] [COLOR=blue]false[/COLOR];[/FONT]
[FONT='inherit'][COLOR=blue]else[/COLOR][/FONT]
[FONT='inherit'][COLOR=blue]return[/COLOR] [COLOR=blue]true[/COLOR];[/FONT]
}
کد:
[COLOR=blue][FONT='inherit']string[/FONT][/COLOR][FONT='inherit'] st1 = textBox1.Text;[/FONT]
[FONT='inherit'][COLOR=blue]string[/COLOR] st2 = textBox2.Text;[/FONT]
[FONT='inherit'][COLOR=blue]if[/COLOR] (st1 == [COLOR=#A31515]""[/COLOR] || st2 == [COLOR=#A31515]""[/COLOR])[/FONT]
[FONT='inherit']{[/FONT]
[FONT='inherit']label3.Text = [COLOR=#A31515]"لطفا اطلاعات کامل وارد کنید"[/COLOR];[/FONT]
[FONT='inherit'][COLOR=blue]return[/COLOR];[/FONT]
[FONT='inherit'] }[/FONT]
[FONT='inherit'][COLOR=#2B91AF]user[/COLOR] u=[COLOR=blue]new[/COLOR] [COLOR=#2B91AF]user[/COLOR]();[/FONT]
[FONT='inherit'][COLOR=blue]if[/COLOR] (u.checkuser(st1, st2))[/FONT]
[FONT='inherit']{[/FONT]
[FONT='inherit'][COLOR=blue]this[/COLOR].Close(); [/FONT]
[FONT='inherit'][COLOR=#2B91AF]Form1[/COLOR].flag = [COLOR=blue]true[/COLOR];[/FONT]
[FONT='inherit']}[/FONT]
[FONT='inherit'] [COLOR=blue]else[/COLOR][/FONT]
[FONT='inherit']{[/FONT]
[FONT='inherit']label3.Text = [COLOR=#A31515]"نام کاربری و پسور اشتباه شد"[/COLOR];[/FONT]
[FONT='inherit'][COLOR=#2B91AF]Form1[/COLOR].flag = [COLOR=blue]false[/COLOR];[/FONT]
[FONT='inherit']}[/FONT]