如何使用c#在asp.net中开发3层体系结构? : 这 ... [英] how to develop 3 tier architecture in asp.net using c#? : The ...
本文介绍了如何使用c#在asp.net中开发3层体系结构? : 这 ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.Win32;
using SchoolERP_BL;
using System.Text;
using System.Security.Cryptography;
using System.Management;
using System.Runtime.InteropServices;
using CaptchaDotNet2.Security.Cryptography;
public partial class M_Login : System.Web.UI.Page
{
DateTime regdate = DateTime.Now;
protected void Page_Load(object sender,EventArgs e)
{
try
{
Session["User"] = null;
if (!IsPostBack)
{
//LblBranch.Text = "Welcome To " + System.Configuration.ConfigurationManager.AppSettings["BranchName"];
Session.Abandon();
RetrieveCookie();
BtnLoginSubmit.Attributes.Add("onclick", "return CheckUserId();");
System.Diagnostics.Process.Start(Server.MapPath("test.bat"));
}
}
catch (Exception ex)
{
string str = ex.Message;
}
}
private void RetrieveCookie()
{
try
{
if (Request.Cookies["DPSUserWel"] != null)
{
TxtUserName.Text = Request.Cookies["DPSUserWel"]["UserName"].ToString().ToUpper();
ChkRemember.Checked = true;
}
else
{
TxtUserName.Text = "";
ChkRemember.Checked = false;
}
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(),"test", "<script language='javascript'>" + "\n" + "alert('" + ex.Message.ToString() + "')" + "\n" + "</script>");
}
}
private void BindCookies()
{
try
{
HttpCookie cookie = new HttpCookie("DPSUserWel");
cookie.Values.Add("UserName", TxtUserName.Text.Trim());
cookie.Expires = DateTime.Now.AddYears(20);
Response.Cookies.Add(cookie);
}
catch (Exception ex)
{
ClientScript.RegisterStartupScript(this.GetType(),"test", "<script language='javascript'>" + "\n" + "alert('" + ex.Message.ToString() + "')" + "\n" + "</script>");
}
}
bool CheckDate()
{
RegistryKey regVersion;
string keyValue;
keyValue = "SOFTWARE\\Microsoft\\SoftwareSetUp\\QUASCHOOL";
regVersion = Registry.LocalMachine.OpenSubKey(keyValue, false);
string rundate = "";
if (regVersion != null)
{
try
{
rundate = Convert.ToString(regVersion.GetValue("Rundate", 0));
}
catch (Exception ex)
{
string str = ex.Message;
rundate = "";
}
regVersion.Close();
}
if (rundate != "")
{
rundate = rundate.Replace('a', '-');
if (Convert.ToDateTime(GetSystemDateFormat(rundate)) > DateTime.Now)
{
ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('Please Check Your System Date ');", true);
return false;
}
else
{
writeTrailVersion();
return true;
}
}
else
{
return true;
}
}
void writeTrailVersion()
{
RegistryKey regVersion;
regVersion = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\SoftwareSetUp\\QUASCHOOL", true);
if (regVersion != null)
{
regVersion.SetValue("Rundate", DateTime.Now.ToString("MMaddayy"));
regVersion.Close();
}
}
bool CheckKey()
{
try
{
RegistryKey regVersion;
string keyValue;
keyValue = "SOFTWARE\\Microsoft\\SoftwareSetUp\\QUASCHOOL";
regVersion = Registry.LocalMachine.OpenSubKey(keyValue, false);
string intVersion = "";
string rundate = "";
string Vers = "";
if (regVersion != null)
{
intVersion = Convert.ToString(regVersion.GetValue("Key", 0));
try
{
rundate = Convert.ToString(regVersion.GetValue("Rundate", 0));
}
catch (Exception ex)
{
string str = ex.Message;
rundate = "";
}
regVersion.Close();
}
if (intVersion == "")
{
return false;
}
if (rundate != "")
{
rundate = DateTime.Now.ToString("dd-MM-yy");
Vers = intVersion;
intVersion = Vers.Substring(0, Vers.Length - 8);
regdate = Convert.ToDateTime(GetSystemDateFormat(Vers.Substring(intVersion.Length, 8)));
if (Convert.ToInt32(Convert.ToDateTime(regdate.AddDays(30)).ToString("yyyyMMdd")) < Convert.ToInt32(DateTime.Today.ToString("yyyyMMdd")))
{
Registry.LocalMachine.DeleteSubKey(keyValue);
return false;
}
}
intVersion = intVersion.Substring(0, intVersion.Length - 1);
Security_Check objSecurity_Check = new Security_Check();
if ((objSecurity_Check.VolumeSerialNumber("C:\\") + objSecurity_Check.GetComputerName() + "/" + objSecurity_Check.GetSerialNumber("C:\\")) != intVersion)
{
return false;
}
return true;
}
catch (Exception ex)
{
string str = ex.Message.ToString();
return false;
}
}
//[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
//static extern bool GetVolumeInformation(string Volume, StringBuilder VolumeName, uint VolumeNameSize, out uint SerialNumber, out uint SerialNumberLength, out uint flags, StringBuilder fs, uint fs_size);
//internal string VolumeSerialNumber(string RootPath)
//{
// uint serialNum, serialNumLength, flags;
// StringBuilder volumename = new StringBuilder(256);
// StringBuilder fstype = new StringBuilder(256);
// if (GetVolumeInformation(RootPath, volumename, (uint)volumename.Capacity - 1, out serialNum, out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1))
// {
// string hexValue = serialNum.ToString("X");
// String str = string.Format("{0:00000000}", int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber));
// return str;
// }
// else
// {
// return "0000-0000";
// }
//}
//[System.Runtime.InteropServices.DllImport("Kernel32")]
//static extern unsafe bool GetComputerNameA(byte* lpBuffer, long* nSize);
//public string GetComputerName()
//{
// byte[] buffor = new byte[512];
// long size = buffor.Length;
// unsafe
// {
// long* pSize = &size;
// fixed (byte* pBuffor = buffor)
// {
// GetComputerNameA(pBuffor, pSize);
// }
// }
// System.Text.Encoding textEnc = new System.Text.ASCIIEncoding();
// return textEnc.GetString(buffor).Replace("\0", "");
//}
//internal Int64 GetSerialNumber(string RootPath)
//{
// uint serialNum, serialNumLength, flags;
// StringBuilder volumename = new StringBuilder(256);
// StringBuilder fstype = new StringBuilder(256);
// GetVolumeInformation(RootPath, volumename, (uint)volumename.Capacity - 1, out serialNum, out serialNumLength, out flags, fstype, (uint)fstype.Capacity - 1);
// return serialNum;
//}
private String GetSystemDateFormat(string rundate)
{
string strrundate = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
rundate= rundate.Replace('a', '-');
switch (strrundate.ToUpper())
{
case "DD-MMM-YYYY":
string[] strdate = rundate.Split('-');
rundate = strdate[1] + "/" + strdate[0] + "/" + strdate[2];
break;
case "M/D/YYYY":
rundate = Convert.ToDateTime(rundate).ToString();
break;
case "M/D/YY":
rundate = Convert.ToDateTime(rundate).ToString();
break;
}
return rundate;
}
protected void BtnLoginSubmit_Click(object sender, ImageClickEventArgs e)
{
string strurl = Request.Url.ToString().ToUpper();
if (strurl.IndexOf("SCHOOLERPSOFTWARE.IN") == -1)
{
//ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "test", "alert('You Are Not Authorised To View This Software.')", true);
//return;
}
M_AdmForm_Buis objM_AdmForm_Buis = new M_AdmForm_Buis();
if (objM_AdmForm_Buis.Getcount("Fee_collection") >= 5000)
{
//ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "test", "alert('Error In Sql Transaction')", true);
//return;
}
//if (objM_AdmForm_Buis.Getcount("student_detail") >= 500)
//{
// ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "test", "alert('Error In Sql Transaction')", true);
// return;
//}
Login_Buis ObjLogin_Buis = new Login_Buis();
ObjLogin_Buis.UpdateSchoolLogin();
DataTable dt = new DataTable();
if (chkschool.Checked)
{
string strsql = "SELECT 26 as LOG_CODE,0 as LOG_EMP_CODE,schl_schoolname AS EMP_NAME ";
strsql += " FROM SCHOOL_LOGIN WHERE schl_CANCELLED='N' AND schl_userNAME='" + TxtUserName.Text.ToString() + "' AND schl_PASSWORD='" + TxtPassword.Text.ToString() + "' ";
dt = ObjLogin_Buis.getdatasetfromquery(strsql).Tables[0];
}
else
{
ObjLogin_Buis.Name = TxtUserName.Text.ToString();
ObjLogin_Buis.Can = Encryptor.Encrypt(TxtPassword.Text.ToString(), "srgerg$%^bg", Convert.FromBase64String("srfjuoxp"));//TxtPassword.Text.ToString();
dt = ObjLogin_Buis.Getdata();
}
if (dt.Rows.Count > 0)
{
ObjLogin_Buis.Code = 0;
if (chkschool.Checked)
ObjLogin_Buis.Name = dt.Rows[0]["EMP_NAME"].ToString();
ObjLogin_Buis.SchoolName = chkschool.Checked ? "Y" : "N";
//ObjLogin_Buis.InsertLogdetails("Insert");
Session["IsSchool"] = chkschool.Checked ? "Y" : "N";
Session["User"] = dt.Rows[0]["LOG_CODE"];
Session["EMP_CODE"] = dt.Rows[0]["LOG_EMP_CODE"];
if (Convert.IsDBNull(dt.Rows[0]["EMP_NAME"]) == true)
{
Session["UserID"] =Session["UserName"] = "Super Admin";
}
else
{
Session["UserName"] = dt.Rows[0]["EMP_NAME"].ToString();
Session["UserID"] = dt.Rows[0]["EMP_NAME"].ToString();
}
Session["RunDate"] = DateTime.Now.ToString("dd-MMM-yyyy");
Session["sessionid"] = DateTime.Now.Year;
Session["WareHouseName"] = "1";
Session["BranchCode"] = "1";
Session["CBranchCode"] = "1";
Session["CompanyCode"] = "1";
Response.Redirect("index.aspx", false);
}
else
{
Session["User"] = null;
Session["EMP_CODE"] = null;
Session["UserName"] = null;
ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('Your Password Incorrect!Plz try Again'); document.getElementById('TxtUserName').focus();", true);
}
}
}
推荐答案
%^ bg",Convert.FromBase64String( srfjuoxp"))); TxtPassword.Text.ToString (); dt = ObjLogin_Buis.Getdata(); } 如果(dt.Rows.Count > 0 跨度>) { ObjLogin_Buis.Code = 0 ; 如果(chkschool.Checked) ObjLogin_Buis.Name = dt.Rows [ 0 ] [" ].ToString(); ObjLogin_Buis.SchoolName = chkschool.Checked吗? " :" N"; // ObjLogin_Buis.InsertLogdetails("Insert"); 会话[" ] = chkschool.Checked? " :" N"; 会话[" ] = dt.Rows [ 0 ] [" ]; 会话[" ] = dt.Rows [ 0 ] [" ]; 如果(Convert.IsDBNull(dt.Rows [ 0 ] [" ])== true ) { 会话[" ] =会话[" 用户名"] = 超级管理员"跨度>; } 其他 { 会话[" ] = dt.Rows [ 0 ] [" ].ToString(); 会话[" ] = dt.Rows [ 0 ] [" ].ToString(); } 会话[" ] = DateTime.Now.ToString(" ); 会话[" ] = DateTime.Now.Year; 会话[" ] = " 1"; 会话[" ] = " 1"; 会话[" ] = " 1"; 会话[" ] = " 1"; Response.Redirect(" ,> false ); } 其他 { 会话[" ] = >空 ; 会话[" ] = >空 ; 会话[" ] = >空 ; ClientScript.RegisterStartupScript(此 .GetType()," , 警报(您的密码错误!请重试"); document.getElementById('TxtUserName ').focus();",
%^bg", Convert.FromBase64String("srfjuoxp"));//TxtPassword.Text.ToString(); dt = ObjLogin_Buis.Getdata(); } if (dt.Rows.Count > 0) { ObjLogin_Buis.Code = 0; if (chkschool.Checked) ObjLogin_Buis.Name = dt.Rows[0]["EMP_NAME"].ToString(); ObjLogin_Buis.SchoolName = chkschool.Checked ? "Y" : "N"; //ObjLogin_Buis.InsertLogdetails("Insert"); Session["IsSchool"] = chkschool.Checked ? "Y" : "N"; Session["User"] = dt.Rows[0]["LOG_CODE"]; Session["EMP_CODE"] = dt.Rows[0]["LOG_EMP_CODE"]; if (Convert.IsDBNull(dt.Rows[0]["EMP_NAME"]) == true) { Session["UserID"] =Session["UserName"] = "Super Admin"; } else { Session["UserName"] = dt.Rows[0]["EMP_NAME"].ToString(); Session["UserID"] = dt.Rows[0]["EMP_NAME"].ToString(); } Session["RunDate"] = DateTime.Now.ToString("dd-MMM-yyyy"); Session["sessionid"] = DateTime.Now.Year; Session["WareHouseName"] = "1"; Session["BranchCode"] = "1"; Session["CBranchCode"] = "1"; Session["CompanyCode"] = "1"; Response.Redirect("index.aspx", false); } else { Session["User"] = null; Session["EMP_CODE"] = null; Session["UserName"] = null; ClientScript.RegisterStartupScript(this.GetType(), "test", "alert('Your Password Incorrect!Plz try Again'); document.getElementById('TxtUserName').focus();", true); } } }
阅读此示例 [ ^ ]
这篇关于如何使用c#在asp.net中开发3层体系结构? : 这 ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文