统一绑定下拉框控件;设置同一类型的控件的属性;自定义错误处理类


1 // 统一绑定控制下拉框
public static int SetDDL(ref DropDownList ddl,string sql)
 {
   int nErr=0;
   try
     {
       DataSet ds=new DataSet();
       nErr=DBProcess.FillDataSet(sql,new string[]{"table"},out ds);
       if(nErr!=0)
         {
           return nErr;
         }
        for(i=0;i<ds.Tables[0].Rows.Count;i++)
          {
             string UserName=ds.Tables[0].Rows[0]["name"].Tostring();
             string UserPwd =ds.Tables[0].Rows[0]["pwd"].ToString();
             ListItem li;
             li=new ListItem(UserName,UserPwd);
             ddl.Items.Add(li);
          }
     }
   catch(Exception ex)
     {
        nErr=-1;
     }
    while(dd.Items.FindByText("")!=null)
      {
        ddl.Items.Remove(ddl.Items.FindByText(""));
      }
    while(dd.Items.FindByValue(-1)!=null)
      {
        ddl.Items.Remove(ddl.Items.FindByValue(-1));
      }
    return nErr;
 }

2 // 设置同一类型的控件的属性(文本框,下拉框,按钮等常用控件)
public static int ChangeControlPropertyValue(ref TextBox[] myTextBox,string property,string propertyValue)
{
   try
   {
     for(i=0;i<myTextBox.Length;i++)
      {
         switch(property)
           {
             case "Enable":
                  myTextBox.Enable=Conver.ToBoolean(propertyValue);
                  break;
             case "Text":
                  myTextBox.Text =propertyValue.ToString();
                  break;
           }
       }
    }
    catch(Exception ex)
    {
     return -1;
    }
    return 0;
}

3 //自定义错误处理类,继承SystemExcetpion类
   1 自定义错误处理号errNumber,错误信息errMessage,模块名称errModele
   2 设置get,set属性;
   3 自定义错误处理方法;
     public cuException(int errorNumber,string errorMessage,string moduleName)
     {
       this.errNumber=errorNumber;
       this.errMessage=errorMessage;
       this.errModele=moduleName;
     }
   4 捕获错误(也就是生成一个错误对象)
     throw new BE_NET.HandleException.CuException(2002,"Wrong username or password!","User Login");


原文地址:https://www.cnblogs.com/csj007523/p/1153043.html