توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : کدهای مفید asp.net
در این تاپیک قصد دارم کدهای مفید ASP.net رو قرار بدم که وجود آنها در هر پروژه ای لازم میشه اما و وقت ما رو در انجام پروژه های بزرگ به خودش اختصاص میده این کدها رو میتوانید در پروژه های خود بصورت کپی و آماده قرار دهید تا در وقت خود نیز صرفه جویی کنید و زمان تحویل پروژه رو جلو بندازید .
نابع تبدبل تاریخ میلادی به شمسی
using System;
using System.Collections.Generic;
using System.Text;
namespace DateConverter
{
class datecl
{
/*public datecl()
{
//
// TODO: Add constructor logic here (chi! bih!)
//
}*/
/// <summary>
/// GetShamsiDate.
/// Its name is so clear!
/// </summary>
public static string GetSystemShamsiDate()
{
int Year = System.DateTime.Now.Year;
int Month = System.DateTime.Now.Month;
int Day = System.DateTime.Now.Day ;
return GetShamsiDate(Year, Month, Day);
}
/// <summary>
/// GetShamsiDate.
/// Converts the specified date to shamsi.
/// </summary>
public static string GetShamsiDate(int Year, int Month, int Day)
{
int[] A ={0,10, 11, 9, 11, 10, 10, 9, 9, 9, 8, 9, 9};
int[] B ={0,30, 30, 29, 31, 31, 31, 31, 31, 31, 30, 30, 30};
int YY;
int MM;
int DD;
string CHm,CHd ;
// Get current Date values
YY = Year - 621;
if ((Year % 4 == 0) && (Month == 3) && (Day <= 21))
{
A[3]++;
B[3]++;
}
MM = Month + 9;
DD = Day + A[Month];
if (DD > B[Month])
{
DD -= B[Month];
MM++;
}
if (MM > 12)
MM -= 12;
if (MM == 10 && DD > 10)
YY--;
if (MM == 11 || MM == 12)
YY--;
if (MM < 10)
CHm = "0" + MM.ToString() ;
else
CHm = MM.ToString() ;
if (DD < 10)
CHd = "0" + DD.ToString() ;
else
CHd = DD.ToString() ;
return YY.ToString() + '/' + CHm + '/' + CHd;
}
public static string systemDayOfWeek()
{
string res="";
switch( System.DateTime.Now.DayOfWeek.ToString() )
{
case "Saturday" :
res = "شنبه";
break;
case "Sunday" :
res = "یک شنبه" ;
break;
case "Monday":
res = "دوشنبه";
break;
case "Tuesday":
res = "سه شنبه";
break;
case "Wednesday":
res = "چهار شنبه";
break;
case "Thursday":
res = "پنج شنبه";
break;
case "Friday":
res = "جمعه" ;
break;
}
return res ;
}
public static string systemShamsiDatTime()
{
return
GetSystemShamsiDate() + " اکنون " +"\n"+
System.DateTime.Now.ToLongTimeString() +"\n"+
System.DateTime.Now.ToLongDateString() + " " +"\n"+
System.DateTime.Now.DayOfWeek + " "+
systemDayOfWeek() ;
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace fileattr
{
class cs_fileattr
{
public string getattr(ref bool isreadonly, ref bool isarchive, ref bool ishidden, ref bool issystem , string filesource)
{
if (filesource != "")
{
try
{
FileAttributes fattr = File.GetAttributes(filesource);
if ((fattr & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
isreadonly = true;
if ((fattr & FileAttributes.Archive) == FileAttributes.Archive)
isarchive = true;
if ((fattr & FileAttributes.System) == FileAttributes.System)
issystem = true;
if ((fattr & FileAttributes.Hidden) == FileAttributes.Hidden)
ishidden = true;
return "Success";
}
catch(IOException e)
{
return e.Message;
}
}
else
return "File Source Is Empty";
}
public string setattr(bool isreadonly, bool isarchive, bool ishidden, bool issystem, string filesource)
{
if (filesource != "")
{
try
{
FileAttributes fattr = new FileAttributes();
if (isarchive)
fattr = fattr | FileAttributes.Archive;
if (ishidden)
fattr = fattr | FileAttributes.Hidden;
if (isreadonly)
fattr = fattr | FileAttributes.ReadOnly;
if (issystem)
fattr = fattr | FileAttributes.System;
File.SetAttributes(filesource, fattr);
return "Success";
}
catch (IOException e)
{
return e.Message;
}
}
else
return "File Source Is Empty";
}
}
}
هر زمانی که بخواهید یک delegate را از یک رویداد حذف کنید این کار رو می کنیم .
برای حذف delegate
TextBox.TextChanged -= TextBox_TextChanged;
برای اضافه کردن Delegate
TextBox.TextChanged += TextBox_TextChanged;
با این کلاس شما می توانید به راحتی رجیستری رو دستکاری کنید .
منبع : [Only registered and activated users can see links]
برای صفحه بندی DataList در ASP.NET از کدی که ضمیمه شده می تونید استفاده کنید .
این کد در یک تابع نوشته شده است که یک پارامتر تاریخ را دریافت می کند و یک رشته را برمی گرداند که این رشته همان تاریخ شمسی می باشد.
ابتدا فضای نام Globalization را به صفحه خود اضاف کنید .
Imports System.Globalization
و حالا یک پارامتر از نوع تاریخ به تابع وارد کنید .
Protected Function PersianDate(ByVal k As Date)
Dim Per As String
Dim ps As PersianCalendar
Per = ps.GetDayOfMonth(k) & "/" & ps.GetMonth(k) & "/" & ps.GetYear(k)
Return Per
End Function
public static void CompactAccessDB(string connectionString, string mdbfilename)
{
object[] oParams;
object objJRO =
Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
oParams = new object[] {
connectionString,
"Provider=Microsoft.Jet.OLEDB.4.0;Data" +
" Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5"};
objJRO.GetType().InvokeMember("CompactDatabase",
System.Reflection.BindingFlags.InvokeMethod,
null,
objJRO,
oParams);
System.IO.File.Delete(mdbfilename);
System.IO.File.Move("C:\\tempdb.mdb", mdbfilename);
System.Runtime.InteropServices.Marshal.ReleaseComO bject(objJRO);
objJRO = null;
}
در رویداد control_keypres کد زیر را وارد کنید
if (!char.IsNumber(e.KeyChar))
{
e.Handled = true;
MessageBox.Show("insert Number","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
در رویداد control_keyup کد زیر را وارد کنید.
if (e.KeyCode == Keys.F1)
{
Point point1 = new Point(textBox1.Right+this.Left+35, textBox1.Bottom+this.Top+35);
Help.ShowPopup(textBox1, "Help String", point1);
}
string dir = string.Empty;
dir =Environment.GetFolderPath( Environment.SpecialFolder.DesktopDirectory);
string tic = string.Empty;
tic = Convert.ToString((Environment.TickCount / 1000)/60))
حتما شده که برین و یه سری کد گیر بیاری ولی به زبان vb.net یا بالعکس باشه ، اگه بخواهی اونو استفاده کنی یا باید به یه زبان دیگه آشنایی کامل داشته باشی یا اینکه اونو تبدیل کنی به DLL و بعد استفاده کنی .
ولی اگه بخواهی یه قسمتی از اون رو به دلخواه خودت عوض کنی تازه اول گرفتاریته ............!
با این ابزاری که امروز می خواهم معرفی کنم شما می تونید به صورت آنلاین کدهاتون رو تبدیل کنید.
تبدیل vb.net به C# [Only registered and activated users can see links]
تبدیل C# به vb.net [Only registered and activated users can see links]
-ابتدا از آدرس زیر فایل مورد نظر را دریافت کنید.
[Only registered and activated users can see links]
2-در ویژوال استودیو dll مربوطه را تولید کنید.
3-dll مورد نطر را به پروژه اضافه کنید.
4-یک کنترل login به صفحه اضافه و بر روی گزینه Convert to template کلیک کنید تا قالب این کنترل قابل ویرایش باشد.
5-یک کنترل captcha به این قلب اضافه کنید.
6-سپس در روال رخداد Authenticate کنترل login دستورات زیر را اضافه کنید.
protected void Login2_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login2.UserName;
string password = Login2.Password;
WebControlCaptcha.CaptchaControl logincaptcha = (WebControlCaptcha.CaptchaControl)Login2.FindContr ol("Captcha");
if (!logincaptcha.UserValidated)
{
Login2.FailureText = "The code you entered did not match up with image provider";
e.Authenticated = false;
}
else
{
if (Membership.ValidateUser(username, password))
{
e.Authenticated = true;
Server.Transfer("Default.aspx");
}
else
{
e.Authenticated = false;
Login2.FailureText = "Your UserName or Password Are Invalid.";
}
}
7- در نهایت دستورات زیر را به web.config اضافه کنید.
<[Only registered and activated users can see links]>
<add verb="GET" path="CaptchaImage.aspx" type="WebControlCaptcha.CaptchaImageHandler, WebControlCaptcha"/>
</[Only registered and activated users can see links]>
خاموش کردن سیستم
System.Diagnostics.Process.Start("Shutdown", "-s-f-t0");
ریستارت کردن سیستم:
System.Diagnostics.Process.Start("Shutdown", "-r-f-t0");
لوگاف کردن سیستم
System.Diagnostics.Process.Start("Shutdown", "-l-f-t0");
OleDbConnection conn = new OleDbConnection("Conection String");
OleDbDataAdapter dadt= new OleDbDataAdapter("Command Text", conn);
DataSet Ds = new DataSet();
dadt.Fill(Ds, "TableName");
Ds.WriteXml("XmlAddress");
conn.Close();
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.