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

📄 gencity.aspx.cs

📁 本程序基于 asp.net 2.0 +sql server 2
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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.Data.SqlClient;
using lalablog;
public partial class admin_genCity : System.Web.UI.Page
{
    public SqlDataReader dr;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["admin"] == null)
            Response.Redirect("adminLogin.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        button(1);
    }

    private void button(int x)
    {
        string sql;
        if(x==1)
         sql = "select userid ,loginip from users ";
        else 
         sql = "select userid ,loginip from users where cityid=0 or cityid is null";
        string strconn = ConfigurationManager.ConnectionStrings["dsn"].ToString();
        SqlConnection cn = new SqlConnection(strconn);
        cn.Open();

        SqlCommand cm = new SqlCommand(sql, cn);

        try
        {
            this.dr = cm.ExecuteReader();
            if (this.dr.HasRows)
            {
                while (this.dr.Read())
                    setUserCity(Convert.ToInt32(this.dr["userid"].ToString()), this.dr["loginip"].ToString());
            }

        }
        catch (Exception ex)
        {
            myfunc m1 = new myfunc(ex.Message);
            Response.Write(m1.JavaMsgOnlyAlert());
        }
        finally
        {
            cn.Close();
        }
    }

    private void setUserCity(int userid,string loginip)
    { 
        int cityid=setCity(loginip );
        string sql = "update users set cityid=" + cityid + " where userid=" + userid;
        openDb o1 = new openDb(sql);
        o1.update();

    }


    private int setCity(string loginip)
    {
        int x1 = loginip.IndexOf(".");
        int x2 = loginip.IndexOf( ".",x1+1);
        int x3 = loginip.IndexOf( ".",x2+1);

        string  ip1 = loginip.Substring(0, x1+1);
        string ip2 = loginip.Substring(0, x2+1);
        string ip3 = loginip.Substring(0,x3+1);

        string sql = "select top 1 id from cityip ";
        sql += " where ipseg='" + ip1+"'";
        sql += " or ipseg='" + ip2 + "'";
        sql += " or ipseg='" + ip3 + "'";
        sql += " order by ipseg desc";

        string strconn = ConfigurationManager.ConnectionStrings["dsn"].ToString();
        SqlConnection cn = new SqlConnection(strconn);
        cn.Open();

        SqlCommand cm = new SqlCommand(sql, cn);

        try
        {
            SqlDataReader drIp = cm.ExecuteReader();
            if (drIp.Read())
                return Convert.ToInt32(drIp[0].ToString());
            else
                return 0;
        }
        catch (SqlException ex)
        {
            return 0;
        }
        finally
        {
            cn.Close();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        button(0);
    }
}

⌨️ 快捷键说明

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