⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 utilities.cs

📁 这是一个基于asp.net的网上气球店
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

/// <summary>
/// Utilities 的摘要说明
/// 包含杂项,如发送电子邮件...
/// </summary>
public class Utilities
{
	public Utilities()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    public static void SendMail(string from ,string to,string subject,string body) 
    {
        //configure mail client(may need additional code for authenticated SMIP servers)
       // SmtpClient mailClient = new SmtpClient(BalloonShopConfiguration.MailServer);
        //create the mail message
        //MailMessage mailMessage = new MailMessage(from, to, subject, body);
       // mailClient.Send(mailMessage);
    }
    public static void LogError(Exception ex) 
    {
        string dateTime = DateTime.Now.ToLongDateString() + "at" + DateTime.Now.ToShortTimeString();
        string errorMessage = "Exception generated on" + dateTime;
        System.Web.HttpContext context = System.Web.HttpContext.Current;
        errorMessage += "\n\n Page location:" + context.Request.RawUrl;
        errorMessage += "\n\n Message:" + ex.Message;
        errorMessage += "\n\n Source:" + ex.Source;
        errorMessage += "\n\n Method:" + ex.TargetSite;
        errorMessage += "\n\n Stack Trace: \n\n" + ex.StackTrace;
        if(BalloonShopConfiguration.EnableErrorLogEmail)
        {
            string from = "localhost";
            string to = BalloonShopConfiguration.ErrorLogEmail;
            string subject = BalloonShopConfiguration.SiteName + "error report";
            string body = errorMessage; SendMail(from,to,subject,body);
        }
    }
    // Configures what button to be clicked when the uses presses Enter in a 
    // textbox. The text box doesn't have to be a TextBox control, but it must 
    // be derived from either HtmlControl or WebControl, and the HTML control it 
    // generates should accept an 'onkeydown' attribute. The HTML generated by 
    // the button must support the 'Click' event
    public static void TieButton(Page page, Control TextBoxToTie, Control ButtonToTie)
    {
        // Init jscript
        string jsString = "";

        // Check button type and get required jscript
        if (ButtonToTie is LinkButton)
        {
            jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"
                + page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;";
        }
        else if (ButtonToTie is ImageButton)
        {
            jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"
                + page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":", "$") + ";return false;} else return true;";
        }
        else
        {
            jsString = "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {document."
                + "forms[0].elements['" + ButtonToTie.UniqueID.Replace(":", "_") + "'].click();return false;} else return true; ";
        }

        // Attach jscript to the onkeydown attribute - we have to cater for HtmlControl or WebControl
        if (TextBoxToTie is HtmlControl)
        {
            ((HtmlControl)TextBoxToTie).Attributes.Add("onkeydown", jsString);
        }
        else if (TextBoxToTie is WebControl)
        {
            ((WebControl)TextBoxToTie).Attributes.Add("onkeydown", jsString);
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -