注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

一车,一房,一个温暖家

10万左右的车,80平方的房子,这是我奋斗的暖暖的家

 
 
 

日志

 
 

引用 stdb.cs   

2015-06-20 20:10:17|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
本文转载自yjdd005@126《stdb.cs》

using System;
using System.Data;
using System.Data.SqlClient;
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;

/// <summary>
/// STDB 的摘要说明
/// </summary>
public class STDB
{
    private string connstr;
    private SqlConnection conn;
    private DataSet ds;
    private SqlDataAdapter ad;
    private SqlCommand cmd;
 public STDB()
 {
        connstr = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
        conn = new SqlConnection(connstr);
 }
    public SqlConnection getconnection()
    {
        return conn;
    }
    public void open()
    {
        conn.Open();
    }
    public void close()
    {
        conn.Close();
    }
    public void fill(string sql)
    {
        ad = new SqlDataAdapter(sql, conn);
        ds = new DataSet();
        ad.Fill(ds);
    }
    public bool Excnosql(string sql)
    {
        conn.Close();
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        cmd = new SqlCommand(sql, conn);
        try
        {
            if (cmd.ExecuteNonQuery() > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch (SystemException error)
        {
            say(error.ToString());
            return false;
        }
        finally
        {
            close();
        }
    }
    public SqlDataReader ExcReadersql(string sql)
    {
        close();
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        cmd = new SqlCommand(sql, conn);
        SqlDataReader rd;
        rd = cmd.ExecuteReader();
        cmd.Dispose();
        return rd;
    }
    public void ExcDGridersql(string sql, DataGrid gd)
    {
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        fill(sql);
        gd.DataSource = ds.Tables[0].DefaultView;
        gd.DataBind();

    }
    public DataSet ExcDataSetsql(string sql)
    {
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        fill(sql);
        return ds;
    }
    public void BindDrplist(string sql, DropDownList drpcls, string fid, string va)
    {
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
        }
        fill(sql);
        drpcls.DataSource = ds.Tables[0].DefaultView;
        drpcls.DataTextField = fid;
        drpcls.DataValueField = va;
        drpcls.DataBind();

    }
    public void Goto(string url)
    {
        System.Web.HttpContext.Current.Response.Write("<script>location.href('" + url + "')</script>");
    }
    public void say(string url)
    {
        System.Web.HttpContext.Current.Response.Write("<script>alert('" + url + "')</script>");
    }
    public string htmlcode(string str)
    {

        //str含有HTML标签的文本

        str = str.Replace("<", "&lt;");

        str = str.Replace(">", "&gt;");

        str = str.Replace(" ", "&nbsp;");

        str = str.Replace("\n", "<br>");

        str = str.Replace("&", "&amp;");

        return str;

    }
    public string upfile(string strpath, HtmlInputFile File1)
    {
        string str1, filePath, fileExtName, str5, mPath;
        str5 = "";
        str1 = ConfigurationManager.AppSettings[strpath].ToString();
        filePath = File1.PostedFile.FileName;
        fileExtName = filePath.Substring(filePath.LastIndexOf(".") + 1);
        str5 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Ticks.ToString() + "." + fileExtName;
        try
        {
            mPath = System.Web.HttpContext.Current.Server.MapPath(str1);
            File1.PostedFile.SaveAs(mPath + "\\" + str5);
            return str5;
        }
        catch (SystemException error)
        {
            return error.ToString();
        }

    }
    public string webcode()
    {
        return DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Ticks.ToString();
    }
    public string webmd5(string pwd)
    {
        pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "MD5").ToString().ToLower().Substring(8, 16);
        return pwd;
    }
    public string FunStr(string str)
    {
        str = str.Replace("&", "&amp;");
        str = str.Replace("<", "&lt;");
        str = str.Replace(">", "&gt");
        str = str.Replace("'", "''");
        str = str.Replace("*", "");
        str = str.Replace("\n", "<br/>");
        str = str.Replace("\r\n", "<br/>");
        //str   =   str.Replace("?","");  
        str = str.Replace("select", "");
        str = str.Replace("insert", "");
        str = str.Replace("update", "");
        str = str.Replace("delete", "");
        str = str.Replace("create", "");
        str = str.Replace("drop", "");
        str = str.Replace("delcare", "");
        str = str.Replace("   ", "&nbsp;");

        str = str.Trim();
        if (str.Trim().ToString() == "")
            str = "无";
        return str;
    }
    public string GetUserIp()
    {
        string ip;
        string[] temp;
        bool isErr = false;
        if (System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"] == null)
            ip = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
        else
            ip = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_ForWARDED_For"].ToString();
        if (ip.Length > 15)
            isErr = true;
        else
        {
            temp = ip.Split('.');
            if (temp.Length == 4)
            {
                for (int i = 0; i < temp.Length; i++)
                {
                    if (temp[i].Length > 3) isErr = true;
                }
            }
            else
                isErr = true;
        }

        if (isErr)
            return "1.1.1.1";
        else
            return ip;
    }
    public string CutTitle(string str, int len)
    {
        int intLen = str.Length;
        int start = 0;
        int end = intLen;
        int single = 0;
        char[] chars = str.ToCharArray();
        for (int i = 0; i < chars.Length; i++)
        {
            if (Convert.ToInt32(chars[i]) > 255)
            {
                start += 2;
            }
            else
            {
                start += 1;
                single++;
            }
            if (start >= len)
            {

                if (end % 2 == 0)
                {
                    if (single % 2 == 0)
                    {
                        end = i + 1;
                    }
                    else
                    {
                        end = i;
                    }
                }
                else
                {
                    end = i + 1;
                }
                break;
            }
        }
        string temp = str.Substring(0, end);
        if (str.Length > end)
        {
            return temp + "...";
        }
        else
        {
            return temp;
        }
    }
}

  评论这张
 
阅读(11)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018