zoukankan      html  css  js  c++  java
  • PageComm.cs

    using System;
    using System.Data;
    using System.Configuration;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    /// <summary>
    /// 页内输入输出格式转化,基本逻辑验证
    /// Summary description for PageCommon
    /// </summary>
    public class PageCommon
    {
        public PageCommon()
        {
            //
            // TODO: Add constructor logic here
            //
        }
      
        /// <summary>
        /// 输出分页格式
        /// </summary>
        /// <param name="currentindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="recordcount"></param>
        /// <returns></returns>
        public static string GetCustomInfoHtml(int currentindex, int pagesize, int recordcount)
        {
            int begin = (currentindex - 1) * pagesize + 1;
            if (recordcount == 0) begin = 0;
            int end = (currentindex - 1) * pagesize + pagesize > recordcount ? recordcount : (currentindex - 1) * pagesize + pagesize;
            return "第" + begin.ToString() + "-" + end.ToString() + "条,共" + recordcount + " 条信息";
        }
        /// <summary>
        /// 对一个table 搜索关键字,返回结果集
        /// </summary>
        /// <param name="sdt"></param>
        /// <param name="key"></param>
        /// <param name="p"></param>
        /// <returns></returns>
        public static DataTable SelectTable(DataTable sdt,string key,params int[] p)
        {
            DataTable  ndt = sdt.Clone();
            if (p != null && !string.IsNullOrEmpty(key))
            {
                int maxCol = sdt.Columns.Count;
                bool b = false;
                for (int j = 0; j < sdt.Rows.Count; j++)
                {
                    b = false;
                    DataRow drw = sdt.Rows[j];
                    for (int i = 0; i < p.Length; i++)
                    {
                        if (p < maxCol)
                        {
                            if (drw[p].ToString().Contains(key))
                            {
                                b = true;
                            }
                        }
                    }
                    if (b)
                    {
                        ndt.ImportRow(drw);
                    }
                }
                return ndt;
            }
            else
            {
                return sdt;
            }
          
        }
        //弹出提示框后转URL
        public static void Redirect(string word, string url)
        {
            string str = "<script>alert(\"" + word + "\");location.replace('" + url + "');</script>";
            HttpContext.Current.Response.Write(str);
            HttpContext.Current.Response.End();
        }
        public override string ToString()
        {
            return base.ToString();
        }
        #region 基本 对类的输入输出格式转化 Get开头
        /// <summary>
       /// 将一个Object转化为字符串输出
       /// </summary>
       /// <param name="obj"></param>
       /// <returns></returns>
        public static String GetAcString(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return "";
            }
            else
            {
                return obj.ToString().Trim();
            }
        }    
        /// <summary>
        /// 将一个Object转化为int输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static int GetAcInt(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return 0;
            }
            else
            {
                return int.Parse(obj.ToString().Trim());
            }
        }
        /// <summary>
        /// 将一个Object转化为decimal 2位输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static decimal GetAcDecimal(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return 0;
            }
            else
            {
                decimal d=Convert.ToDecimal(obj.ToString().Trim());
                return decimal.Round(d, 2);
            }
        }
        /// <summary>
        /// 扩大100 将一个Object转化为decimal 2位输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static decimal GetDecimalExp100(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return 0;
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString().Trim());
                return d * 100;
            }
        }
        /// <summary>
        /// 缩小100 将一个Object转化为decimal 2位输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static decimal GetDecimalDiv100(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return 0;
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString().Trim())/100;
                return decimal.Round(d,2);
            }
        }  
        /// <summary>
        /// 将一个Object转化为decimal 2位输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static decimal GetAdChinaNum(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return 0;
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString().Trim());
                return d/100;
            }
        }
        #endregion
        #region 基本页面 web 格式设置 Shw开头
        /// <summary>
        /// 将一个Object转化为货币输出 不要小数点
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object ShwCurrencyNoPoint(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return "0.00";
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString());
                String str = String.Format("{0:c2}", d);
                if (str.Contains("¥") || str.Contains("$"))
                {
                    if (d < 0) { str = str.Substring(2); str = "-" + str; }
                    else str = str.Substring(1);
                }
                return str;
            }
        }
        /// <summary>
        /// 将一个Object转化为货币输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>1
        public static object GetCurrency(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return "0.00";
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString());
                String str = String.Format("{0:c2}", d);
                if (str.Contains("¥") || str.Contains("$"))
                {
                    if (d < 0) { str = str.Substring(2); str = "-" + str; }
                    else  str = str.Substring(1);
                }
                return str;
            }
        }
        /// <summary>
        /// 将一个Object转化为货币输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>1
        public static string GetCurrency(decimal d1)
        {
            if (d1==0)
            {
                return "0.00";
            }
            else
            {
                decimal d = Convert.ToDecimal(d1.ToString());
                String str = String.Format("{0:c2}", d);
                if (str.Contains("¥") || str.Contains("$"))
                {
                    if (d < 0) { str = str.Substring(2); str = "-" + str; }
                    else str = str.Substring(1);
                }
                return str;
            }
        }
        /// <summary>
        /// 将一个Object转化为货币输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static object GetCurrency(String obj)//
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return "0.00";
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString());
                String str = String.Format("{0:c2}", d);
                if (str.Contains("¥") || str.Contains("$"))
                {
                    if (d < 0) { str = str.Substring(2); str = "-" + str; }
                    else str = str.Substring(1);
                }
                return str;
            }
        }
        /// <summary>
        /// 缩小100 将一个Object转化为货币输出
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>2
        public static String GetCurrencyDiv100(object obj)
        {
            if (obj == null || String.IsNullOrEmpty(obj.ToString().Trim()))
            {
                return "0.00";
            }
            else
            {
                decimal d = Convert.ToDecimal(obj.ToString()) / 100;
                String str = String.Format("{0:c2}", d);
                if (str.Contains("¥") || str.Contains("$"))
                {
                    if (d < 0) { str = str.Substring(2); str = "-" + str; }
                    else str = str.Substring(1);
                }
                return str;
            }
        }
      
        #endregion
        #region 基本逻辑验证
        /// <summary>
        /// 判断object对象是否为空
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>是空 为true</returns>
        public static bool CheckNull(object obj)
        {
            if (obj == null ||obj==DBNull.Value||string.IsNullOrEmpty(obj.ToString()))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        public static string GetNullOfLine(object obj)
        {
            if (obj == null || obj == DBNull.Value || string.IsNullOrEmpty(obj.ToString()))
            {
                return "--";
            }
            else
            {
                return obj.ToString();
            }
        }
        public static String GetDateTime(object obj)
        {
            if (obj == null || obj == DBNull.Value || string.IsNullOrEmpty(obj.ToString()))
            {
                return String.Empty;
            }
            else
            {
                String uda = string.Empty;
                try
                {
                    uda = Convert.ToDateTime(obj).ToString("yyyy-MM-dd");
                }
                catch
                {

                }
                return uda.ToString();
            }
        }
        #endregion
    }
  • 相关阅读:
    spring mvc技术
    转 easyUI的iframe子页面操作父页面元素
    DG
    SqlServer数据库分离附加操作
    SqlServer2008系统数据库的作用和特点
    Oracle基础学习记录1.0
    聚集索引与非聚集索引
    苹果官方 Crash文件分析方法 (iOS系统Crash文件分析方法)
    iOS Crash文件的解析
    在同一台电脑上使用两个github账户
  • 原文地址:https://www.cnblogs.com/MySpace/p/1599773.html
Copyright © 2011-2022 走看看