系統常用操作

來源:互聯網
上載者:User

public class SysOperation
{
   public SysOperation() {}

   public static string OpenDialog(string msg)
   {
     return ("<script>alert('"+ msg +"')</script>");
   }

   public static bool StringNullChecked(string str)
   {
 if (str == null || str == "" || str.Length < 1)
        { return false; }
 return true;
   }

   public static void SetListSelected(DropDownList list,string value)
   {
 if(list.Items.Count < 0 )
        {
  list.SelectedIndex = -1;
                return;
   }
 for(int i=0; i < list.items.Count; i++)
 {
  if(list.Items[i].Value == value)
  {
   list.SelectedIndex = i;
   return;
  }
 }
 list.SelectedIndex = -1;
   }

   public static void SetListSelected(ListBox list,string value)
   {
 if(list.Items.Count <= 0)
        {
  list.SelectedIndex  = -1;
  return;
  }
 for(int i=0; i < list.Items.Count; i++)
 {
  if(list.Items[i].Value == value)
  {
  list.SelectedIndex = i;
  return; }
 }
 list.SelectedIndex = -1;
   }

   public static string FormatErrorUrl(string url)
   {
 if(url.IndexOf("?")>0)
 { return (url.Substring(0,url,IndexOf("?")))}
 return (url);
   }

   public static string FormatErrorPageUrl(string url,string msg)
   {
 return ("~/Portal/ErrorPage.aspx?ErrorMsg="+msg
         + "&ErrorUrl="+url.Replace("/n","").Replace("/t",""));
   }

   public static DataSet CacheCatalogData()
{
 ICatalog catalog = new Catalog();
 DataSet ds = (DataSet)SQLHelper.CacheData.GetCacheValue(SystemConst.Catalog_Cache_Value_Key);
if(ds==null)
{
  ds = new DataSet();
  catalog.GetCatalogDS(ref ds);
  SQLHelper.CacheData.CacheObjectValue(SystemConst.Catalog_Cache_Value_Key,(object)ds);
}
return ds;
}

public static string CreateFileNameByDateTime()
{
DateTime now = DateTime.Now;
string fileName =now.Year.ToString()
+now.Month.ToString()
+now.Day.ToString()
+now.Hour.ToString()
+now.Minute.ToString()
+now.Second.ToString()
+now.Millisecond.ToString();
return (fileName);
}

public static string FormatStringLength(string str,int length)
{
if(SysOperation.StringNullChecked(str) == false)
{
return string.Empty;
}
if(Encoding.UTF8.GetByteCount(str) > str.Length)
{
 length = length/2;
}
if(str.Length > length)
{
return str.Substring(0,length)+"...";
}
return str;
}

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.