当前位置:编程学习 > C#/ASP.NET >>

common javascript 类库(日记管理)

function ShouYe()
{
    document.getElementById("curPage").value = 1;
    QueryData();
}

function ShangYe(previousPage)
{
    if(previousPage <= 0 )
    {
        document.getElementById("curPage").value = 1;
    }
    else 
    {
        document.getElementById("curPage").value = previousPage;
    }
    QueryData();
}

function XiaYe(nextPage, pageCount)
{
    if(nextPage > pageCount)
    {
        document.getElementById("curPage").value = pageCount;
    }
    else{
        document.getElementById("curPage").value = nextPage;
    }
    QueryData();
}

function MoYe( pageCount )
{
    document.getElementById("curPage").value = pageCount;
    QueryData();
}

function Zhuan()
{
    var z = document.getElementById("zhuan").value;
    if(z==null || z=="")
    {
        return;
    }
    else
    {
        document.getElementById("curPage").value = z;
    }
    QueryData();
}

function ChooseAll(e ,itemName)
{
    var items = document.getElementsByName(itemName);
    if(items[0].checked == false)
    {
        for(var i = 0; i < items.length; i++)
        {
            items[i].checked = true;
        }
    }
    else
    {
        for(var i = 0; i < items.length; i++)
        {
            items[i].checked = false;
        }
    }
}

 function UpdatItem(itemName)
        {
            var items = document.getElementsByName(itemName);
            var count = 0;
            var index;
            
            
            if(items.length > 0)
            {
                    for(var i = 0; i < items.length; i++)
                    {
                        if(items[i].checked == true)
                        {
                            index = items[i].value;
                            count++;
                        }
                    }
                    if(count==1)
                    {
                        return index;
                    }
                    else if(count > 1)
                    {
                        alert("请仅选择一条进行修改!");
                        return null;
                    }
                    else
                    {
                        alert("请选择一条进行修改!");
                        return null;
                    }
            }            
            else
            {
                alert("请选择一条进行修改!");
                return null;
            }
        }
        
function GetDeleteItems(itemName)
{
    var items = document.getElementsByName(itemName);
    var array = '';
    if(items.length < 1 )
    {
        alert("请选择要删除的项!");
        return null;
    }
    else
    {
        var check = confirm("删除项不可恢复!确定要删除吗?");
        if(check == true)
        {
            for(var i=0; i < items.length; i++)
            {
                if(items[i].checked == true )
                {
                    array += items[i].value+',';
                }
            }
            
            return array;
        }
        else
        {
            return null;
        }
    }
}


//window 操作类
function winOpen(url,width,height,left,top)
{
    window.open(url,"","menubar=no,易做图=no,location=no,directories=no,status=no,width="+width+",height="+ height +",left="+ left +",top=" + top + ",scrollbars=no,resizable=no");
}

function winOpen1(url,width,height,left,top)
{
    window.open(url,"", "menubar=no, 易做图=no, location=no,directories=no, status=no, width="+width+",height="+height+", left="+left+",top="+top+", scrollbars=no, resizable=no ");
}

function winClose()
{
    try
    {
        window.opener.QueryData();
    }
    catch(e)
    {
    }
    finally
    {
        window.close();
    }
}

function winClose1()
{
    try{window.opener.QueryData();}
    catch(e)
    {
    
    }
    finally{window.close();}
}

function winOpenScroll(url,width,height,left,top)
{
    window.open(url,"","menubar=no,易做图=no,location=no,directories=no,status=no,width="+width+",height="+ height +",left="+ left +",top=" + top + ",scrollbars=yes,resizable=no");
}

function winOpenScroll1(url,width, height, left,top)
{
    window.open(url,"","menubar=no,易做图=no,location=no,directories=no,status=no,width="+width+",height="+ height +",left="+ left +",top=" + top + ",scrollbars=yes,resizable=no");
} --------------------编程问答--------------------   #region 执行SQL语句

    #region 查询数据

    /// <summary>
    /// 不带参数的查询
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>数据表</returns>
    public static DataTable SQL_ExecuteDataTable(string selectSql, string conString)
    {
        if (string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(conString))
            return null;
        DataTable dt = new DataTable();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = conn;
                command.CommandType = CommandType.Text;
                command.CommandText = selectSql;
                try
                {
                    conn.Open();
                    using (SqlDataReader sr = command.ExecuteReader())
                    {
                        dt.Load(sr);
                    }
                    return dt;
                }
                catch
                {
                    return null;
                }
            }
        }
    }

    /// <summary>
    /// 带参的查询
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="parms">参数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>数据表</returns>
    public static DataTable SQL_ExecuteDataTable(string selectSql, SqlParameter[] parms, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(conString);
        if (isNull)
            return null;
        DataTable dt = new DataTable();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(selectSql, conn))
            {
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                using (SqlDataAdapter adpter = new SqlDataAdapter(command))
                {
                    try
                    {
                        adpter.Fill(dt);
                        return dt;
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
        }
    }

    /// <summary>
    /// 不带参数的查询
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>查询结果</returns>
    public static DataSet SQL_ExecuteDataSet(string selectSql, string conString)
    {
        if (string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(conString))
            return null;
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlDataAdapter adpter = new SqlDataAdapter(selectSql, conn))
            {
                try
                {
                    adpter.Fill(ds);
                    return ds;
                }
                catch
                {
                    return null;
                }
            }
        }
    }

    /// <summary>
    /// 不带参数的查询
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="tbName">内存表表名</param>
    /// <param name="conString">数据库连接字符串</param>
    /// <returns>查询结果</returns>
    public static DataSet SQL_ExecuteDataSet(string selectSql, string tbName, string conString)
    {
        if (string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(conString) || string.IsNullOrEmpty(tbName))
            return null;
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlDataAdapter adpter = new SqlDataAdapter(selectSql, conn))
            {
                try
                {
                    adpter.Fill(ds, tbName);
                    return ds;
                }
                catch
                {
                    return null;
                }
            }
        }
    }

    /// <summary>
    /// 带参查询数据
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>查询结果集</returns>
    public static DataSet SQL_ExecuteDataSet(string selectSql, SqlParameter[] parms, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(conString);
        if (isNull)
            return null;
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(selectSql, conn))
            {
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                using (SqlDataAdapter adpter = new SqlDataAdapter(command))
                {
                    try
                    {
                        adpter.Fill(ds);
                        return ds;
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
        }
    }

    /// <summary>
    /// 带参查询数据
    /// </summary>
    /// <param name="selectSql">查询语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="tbName">内存表表名</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>查询结果集</returns>
    public static DataSet SQL_ExecuteDataSet(string selectSql, SqlParameter[] parms, string tbName, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(selectSql) || string.IsNullOrEmpty(tbName) || string.IsNullOrEmpty(conString);
        if (isNull)
            return null;
        DataSet ds = new DataSet();
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(selectSql, conn))
            {
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                using (SqlDataAdapter adpter = new SqlDataAdapter(command))
                {
                    try
                    {
                        adpter.Fill(ds, tbName);
                        return ds;
                    }
                    catch
                    {
                        return null;
                    }
                }
            }
        }
    }

    #endregion

    #region 插入数据、更新数据、删除数据

    /// <summary>
    ///  执行插入、删除、更新操作
    /// </summary>
    /// <param name="opSql">执行操作的SQL语句</param>
    /// <param name="eCount">影响的行数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQuery(string opSql, out int eCount, string conString)
    {
        if (string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString))
        {
            eCount = -2;
            return false;
        }
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                try
                {
                    conn.Open();
                    eCount = command.ExecuteNonQuery();
                    return true;
                }
                catch
                {
                    eCount = -1;
                    return false;
                }
            }
        }
    } --------------------编程问答--------------------     /// <summary>
    ///  执行插入、删除、更新操作(附带事务)
    /// </summary>
    /// <param name="opSql">执行操作的SQL语句</param>
    /// <param name="eCount">影响的行数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string opSql, out int eCount, string conString)
    {
        if (string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString))
        {
            eCount = -2;
            return false;
        }
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    eCount = command.ExecuteNonQuery();
                    transaction.Commit();
                    return true;
                }
                catch
                {
                    if (transaction != null)
                        transaction.Rollback();
                    eCount = -1;
                    return false;
                }
            }
        }
    }

    /// <summary>
    /// 执行插入、删除、更新操作
    /// </summary>
    /// <param name="opSql">执行操作的sql语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="eCount">影响的行数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQuery(string opSql, SqlParameter[] parms, out int eCount, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString);
        if (isNull)
        {
            eCount = -2;
            return false;
        }
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                command.CommandType = CommandType.Text;
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                try
                {
                    conn.Open();
                    eCount = command.ExecuteNonQuery();
                    return true;
                }
                catch
                {
                    eCount = -1;
                    return false;
                }
            }
        }
    }

    /// <summary>
    /// 执行插入、删除、更新操作(附带事务)
    /// </summary>
    /// <param name="opSql">执行操作的sql语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="eCount">影响的行数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string opSql, SqlParameter[] parms, out int eCount, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString);
        if (isNull)
        {
            eCount = -2;
            return false;
        }
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                command.CommandType = CommandType.Text;
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    eCount = command.ExecuteNonQuery();
                    transaction.Commit();
                    return true;
                }
                catch
                {
                    eCount = -1;
                    transaction.Rollback();
                    return false;
                }
            }
        }
    }

    /// <summary>
    /// 执行多次不同插入、删除、更新操作(附带事务)
    /// </summary>
    /// <param name="opSqls">执行操作的sql语句数组</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string[] opSqls, string conString)
    {
        bool isNull = ArrayIsNullOrEmpty(opSqls) || string.IsNullOrEmpty(conString);
        if (isNull)
            return false;
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = conn;
                command.CommandType = CommandType.Text;
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    foreach (string opSql in opSqls)
                    {
                        command.CommandText = opSql;
                        command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch
                {
                    if (transaction != null)
                        transaction.Rollback();
                    return false;
                }
            }
            return true;
        }
    }

    /// <summary>
    /// 执行多次不同插入、删除、更新操作
    /// </summary>
    /// <param name="opSqls">执行操作的sql语句数组</param>
    /// <param name="effectRowCout">影响的行数</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string[] opSqls, out int effectRowCout, string conString)
    {
        bool isNull = ArrayIsNullOrEmpty(opSqls) || string.IsNullOrEmpty(conString);
        if (isNull)
        {
            effectRowCout = -1;
            return false;
        }
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand())
            {
                command.Connection = conn;
                command.CommandType = CommandType.Text;
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    effectRowCout = 0;
                    foreach (string opsql in opSqls)
                    {
                        command.CommandText = opsql;
                        effectRowCout += command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
                catch
                {
                    effectRowCout = -1;
                    if (transaction != null)
                        transaction.Rollback();
                    return false;
                }
            }
            return true;
        }

    }

    /// <summary>
    /// 执行插入、删除、更新操作
    /// </summary>
    /// <param name="opSql">执行操作的sql语句</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQuery(string opSql, string conString)
    {
        if (string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString))
            return false;
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                try
                {
                    conn.Open();
                    command.ExecuteNonQuery();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }
--------------------编程问答--------------------
    /// <summary>
    /// 执行插入、删除、更新操作(附带事务)
    /// </summary>
    /// <param name="opSql">执行操作的sql语句</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string opSql, string conString)
    {
        if (string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString))
            return false;
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    command.ExecuteNonQuery();
                    transaction.Commit();
                    return true;
                }
                catch
                {
                    if (transaction != null)
                        transaction.Rollback();
                    return false;
                }
            }
        }
    }

    /// <summary>
    /// 执行插入、删除、更新操作
    /// </summary>
    /// <param name="opSql">执行操作的SQL语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQuery(string opSql, SqlParameter[] parms, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString);
        if (isNull)
            return false;
        using (SqlConnection conn = new SqlConnection(conString))
        {
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                command.CommandType = CommandType.Text;
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                try
                {
                    conn.Open();
                    command.ExecuteNonQuery();
                    return true;
                }
                catch
                {
                    return false;
                }
            }
        }
    }

    /// <summary>
    /// 执行插入、删除、更新操作(附带事务)
    /// </summary>
    /// <param name="opSql">执行操作的SQL语句</param>
    /// <param name="parms">参数数组</param>
    /// <param name="conString">连接字符串</param>
    /// <returns>执行结果:true or false</returns>
    public static bool SQL_ExecuteNonQueryWithTrans(string opSql, SqlParameter[] parms, string conString)
    {
        bool isNull = SqlParameterIsNullOrEmpty(parms) || string.IsNullOrEmpty(opSql) || string.IsNullOrEmpty(conString);
        if (isNull)
            return false;
        using (SqlConnection conn = new SqlConnection(conString))
        {
            SqlTransaction transaction = null;
            using (SqlCommand command = new SqlCommand(opSql, conn))
            {
                command.CommandType = CommandType.Text;
                foreach (SqlParameter parm in parms)
                    command.Parameters.Add(parm);
                try
                {
                    conn.Open();
                    transaction = conn.BeginTransaction();
                    command.Transaction = transaction;
                    command.ExecuteNonQuery();
                    transaction.Commit();
                    return true;
                }
                catch
                {
                    if (transaction != null)
                        transaction.Rollback();
                    return false;
                }
            }
        }
    }


    #endregion

    #endregion
--------------------编程问答-------------------- 友情帮顶。 --------------------编程问答-------------------- 太长了,有没有打包的?
补充:.NET技术 ,  非技术区
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,