.NET技术支持者

  博客园 :: 首页 :: 博问 :: 闪存 :: :: 联系 :: 订阅 订阅 :: 管理 ::
/// <summary>
        
/// 清空指定页面上所有的控件内容,包括TextBox,CheckBox,CheckBoxList,RadioButton,RadioButtonList。但是不清
        
/// 除如ListBox,DropDownList,因为这样的控件值对当前页面来说还可以用,一般这些控件里都是保存的字典数据。
        
/// Author:Kevin
        
/// 日期:2004-12-02
        
/// </summary>
        
/// <param name="page"> 指定的页面</param> 

        public static void ClearAllContent(System.Web.UI.Control page)
        
{
            
int nPageControls = page.Controls.Count;
            
for (int i = 0; i < nPageControls; i++)
            
{
                
foreach (System.Web.UI.Control control in page.Controls[i].Controls)
                
{
                    
if (control.HasControls())
                    
{
                        ClearAllContent(control); 
                    }

                    
else
                    

                        
if (control is TextBox)
                            (control 
as TextBox).Text = "";

                        
if (control is CheckBox)
                            (control 
as CheckBox).Checked = false;

                        
if (control is RadioButtonList)
                            (control 
as RadioButtonList).SelectedIndex = -1;

                        
if (control is RadioButton)
                            (control 
as RadioButton).Checked = false;

                        
if (control is CheckBoxList)
                        
{
                            
foreach (ListItem item in (control as CheckBoxList).Items)
                            
{
                                item.Selected 
= false;
                            }

                        }

                    }
//if..else
                }
//foreach
            }
//for
        }
/// <summary>
        
/// 汉字转拼音缩写
        
/// Code By MuseStudio@hotmail.com
        
/// 
        
/// </summary>
        
/// <param name="str">要转换的汉字字符串</param>
        
/// <returns>拼音缩写</returns>

        public string GetPYString(string str)
        
{
            
string tempStr = "";
            
foreach(char c in str)
            
{
                
if((int)c >= 33 && (int)c <=126)
                
{//字母和符号原样保留
                    tempStr += c.ToString();
                }

                
else
                
{//累加拼音声母
                    tempStr += GetPYChar(c.ToString());
                }

            }

            
return tempStr;
        }


        
/// <summary>
        
/// 取单个字符的拼音声母
        
/// Code By MuseStudio@hotmail.com
        
/// 2004-11-30
        
/// </summary>
        
/// <param name="c">要转换的单个汉字</param>
        
/// <returns>拼音声母</returns>

        public string GetPYChar(string c)
        
{
            
byte[] array = new byte[2];
            array 
= System.Text.Encoding.Default.GetBytes(c);
            
int i = (short)(array[0- '\0'* 256 + ((short)(array[1- '\0'));

            
if ( i < 0xB0A1return "*";
            
if ( i < 0xB0C5return "a";
            
if ( i < 0xB2C1return "b";
            
if ( i < 0xB4EEreturn "c";
            
if ( i < 0xB6EAreturn "d";
            
if ( i < 0xB7A2return "e";
            
if ( i < 0xB8C1return "f";
            
if ( i < 0xB9FEreturn "g";
            
if ( i < 0xBBF7return "h";
            
if ( i < 0xBFA6return "g";
            
if ( i < 0xC0ACreturn "k";
            
if ( i < 0xC2E8return "l";
            
if ( i < 0xC4C3return "m";
            
if ( i < 0xC5B6return "n";
            
if ( i < 0xC5BEreturn "o";
            
if ( i < 0xC6DAreturn "p";
            
if ( i < 0xC8BBreturn "q";
            
if ( i < 0xC8F6return "r";
            
if ( i < 0xCBFAreturn "s";
            
if ( i < 0xCDDAreturn "t";
            
if ( i < 0xCEF4return "w";
            
if ( i < 0xD1B9return "x";
            
if ( i < 0xD4D1return "y";
            
if ( i < 0xD7FAreturn "z";

            
return "*";
        }
//作用:把ListBox中的全部内容转换成一个字符串,各个字段间用,分隔
  
//
  
//参数:Lists,需要转换的ListBox.items
  
//
  
//返回值:转换好的字符串
  
//
  public string ListToString(ListItemCollection Lists)
  
{
   
string result="";
   
for(int i=0;i<Lists.Count;i++)
   
{
    
if (i==0)
    
{
     result
=Lists[i].Text;
    }

    
else
    
{
     result
=result+","+Lists[i].Text;
    }

   }

   
return result;
  }
 

  
//
  
//作用:把string中的全部内容转换成ListItemCollection从而绑定到Listbox
  
//
  
//参数:str,需要转换的字符串
  
//
  
//返回值:转换好的ListItemCollection
  
//
  public ListItemCollection StringToList(string str)
  
{
   ListItemCollection lists
=new ListItemCollection();
   
if(str=="")                                        //字符串为空
   {
    errPosition
="ListItemCollection";
    errMsg
="字符串为空";
   }

   
else if(str.IndexOf(",")==0)                        //首位为","
   {
    errPosition
="ListItemCollection";
    errMsg
="首位为,";
   }

   
else if(str.Substring(str.Length-1,1)==",")        //尾位为","
   {
    errPosition
="ListItemCollection";
    errMsg
="尾位为,";
   }

   
else
   
{
    
while (str.IndexOf(",")>0)
    
{
     
int position=str.IndexOf(",") ;
     lists.Add(str.Substring(
0,position));
     str
=str.Remove(0,position+1);
    }

    lists.Add(str);
   }

   
return lists;
  }


  
//
  
//作用:把源ListBox中的选中数据移动到目标ListBox
  
//
  
//参数:FromLists,源ListBox
  
//
  public static void MoveListBoxSelectedItem
   (ListItemCollection FromLists,ListItemCollection ToLists)
  
{
   
for(int i=FromLists.Count-1;i>=0;i--)
   
{
    
if (FromLists[i].Selected)
    
{
     FromLists[i].Selected
=false;
     ToLists.Add(FromLists[i]);
     FromLists.Remove(FromLists[i]);
    }

   }

  }


  
//
  
//作用:把源ListBox中的全部数据移动到目标ListBox
  
//
  
//参数:FromLists,源ListBox
  
//
  public static void MoveListBoxAllItem
   (ListItemCollection FromLists,ListItemCollection ToLists)
  
{
   
for(int i=FromLists.Count-1;i>=0;i--)
   
{
    FromLists[i].Selected
=false;
    ToLists.Add(FromLists[i]);
    FromLists.Remove(FromLists[i]);
   }

  }


  
//
  
//作用:输入年月返回月份的天数的集合
  
//
  
//参数:YYYY年,MM月
  
//
  
//返回值:本月的天数的ArrayList
  
//
  public static ArrayList GetDaysInMonth(int YYYY,int MM)
  
{
   
int day=DateTime.DaysInMonth(YYYY,MM);
   ArrayList days
=new ArrayList();
   
for (int i=1;i<=day;i++)
   
{
    days.Add(i);
   }

   
return days;
  }



  
//
  
//作用:输入选中天数的集合,返回其中的最小和最大的天数
  
//
  
//参数:dates,把Calendar.SelectedDates传入即可
  
//
  
//返回值:两个数值的ArrayList,第一个为最小天数,第二个为最大天数
  
//
  public static ArrayList GetMinMaxDate(SelectedDatesCollection dates)
  
{
   ArrayList Result
=new ArrayList();
   DateTime min
=new DateTime();
   DateTime max
=new DateTime();
   
for(int i=0;i<dates.Count;i++)
   
{
    
if (i>0)
    
{
     
if(dates[i]<min)
     
{
      min
=dates[i];
     }

     
if(dates[i]>max)
     
{
      max
=dates[i];
     }

    }

    
else
    
{
     min
=dates[i];
     max
=dates[i];
    }

   }

   Result.Add(min);
   Result.Add(max);
   
return Result;
  }


调用函数是碰到ListItemCollection 使用ListBox.Items做参数

posted on 2005-10-12 14:12  LDAR泄漏检测与修复  阅读(1122)  评论(1编辑  收藏  举报