protected void btnRoleMemberAdd_Click(object sender ,EventArgs e)

{

  txtEmpID.Text=Coeno.utility.string.CleanUpInput(textEmpID.Text.Trim());     --命名空间,类、方法名

  if(string.IsNullorEmpty(DropRoles.SelectedValue.Trim()))

  {

    LabMsg.Text= “无法新增至数据库:请选择一个角色进行新增" ;

    LabMsg.ForeColor=System.Drawing.Color.Red;

    return;

  }

  //检查是否有输入员工工号

  if(txtEmpID.Text==" ")

  {

    LabMsg.Text= "请确认是否有输入员工工号!!!" ;

    LabMsg.ForeColor=System.Drawing.Color.Red;

  }

  //检查员工工号是否存在

  if(Coeno.Account.Users.IsEmpIDExist(txtEmpID.Text)==0)

  {

    LabMsg.Text= "员工工号不存在!!!" ;

    LabMsg.ForeColor=System.Drawing.Color.Red;

    return;

  }

  if(Coeno.Main.Roles.IsUserInRole(SystemID,txtEmpID.Text,DorpRoles.SelectedValue))

  {

    LabMsg.Text= "无法新增至数据库:可能您新增的数据已经存在" ;

    LabMsg.ForeColor=System.Drawing.Color.Red;

    Return;

  }

  try

  {

    Coeno.Main.Roles.AddUserInRole(SystemID,DropRoles.SelectedValue,txtEmpID.Text,LabCuser.Text);

    LabMsg.Text= "新增成功" ;

    LabMsg.ForeColor=System.Drawing.Color.Blue;

    return;

  }

  catch(Exception ex)

  {

    LabMsg.Text= "新增失败" ;

    LabMsg.ForeColor=System.Drawing.Color.Red;

    return;

  }

}

一、public static string CleanUpInput(string strInput)

{

  strInput=strInput+" ";

  strInput=strInput.Replace("["," ");

  strInput=strInput.Replace("]" ," ");

  strInput=strInput.Replace("{"," ");

  strInput=strInput.Reaplace("}"," ");

  strInput=strInput.Reaplace(";"," ");

  strInput=strInput.Reaplace("&"," ");

  strInput=strInput.Reaplace("<"," ");

  strInput=strInput.Reaplace(">"," ");

  strInput=strInput.Reaplace(" ' "," ");

  strInput=Coeno.Tools.SDBC.ToDBC(strInput);

  strInput=strInput.Trim();

  return strInput;

}

///全角转半角

///转半角的函数(DBC case)

///任意字符串

///半角字符串

///全角空格为12288,半角空格为32

///其他字符半角(32-126)与全角(65281-65374)的对应关系是:均相差65248

public static string ToDBC(string input)

{

  char[ ] c=input.ToCharArray();

  for(int i =0; i<c.length;i++)

  {

    if(c[i]==12288)

    {

      c[i]=(char)32;continue;

    }

    if(c[i]>65280&&c[i]<65375)

    c[i]=(char)(c[i]-65248);

  }

  return new string(c);

}

05-08 14:59