关闭

零散技术总结1

标签: stringexceptiontablejavascriptdatasetrandom
439人阅读 评论(0) 收藏 举报


  #region 检验用户昵称,过滤HTML非法字符
  public   bool   CheakUserNikeName(string userNikeName)  
  {  
   //检查文件名是否合法  
   bool result=true; 
   if(userNikeName.IndexOfAny(new char[]{'、','>','<','=','!','-','+','*','/','(',')','|','#','&','@','$'})>=0)
   {
    result = false;
   }
   return result;
  }
  #endregion

//单元格只能输入数字

  onKeyUp="value=value.replace(/[^0123456789]/g,'')"

onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace

(/[^0123456789]/g,''))" 

 

 #region 验证输入的字符数要大于30
  public   bool   CheakCodeNums(string str)
  {
   bool result = true;
   if(str.Length>=30)
   {
    result = true ;
   }
   else
   {
    result = false;
   }
   return result;
  }
  #endregion

 

#region 验证日期
  public bool ValidateDate(string input)
  {
   return Regex.IsMatch(input, "//b(?<year>//d{2,4})-(?<month>//d{1,2})-(?<day>//d{1,2})//b");
  }
  #endregion

 

#region 判断输入是否非数字
  protected bool IsNotNum(string num)
  {
   Regex r = new Regex(@"^([1-9][0-9]+|[0-9])(.[0-9]+|)$");
   if (r.Match(num).Success)
    return false;

   Response.Write("<script>alert('格式录入错误,请录入数字');</script>");
   return true;
  }
  #endregion

 

#region 将原记录值显示在页面上  DropDownList控件
  public void ShowFriendInfo( string friendID)
  {
   SqlDataReader result= (new FriendInfoFacade()).ShowFriendInfo(friendID);
   if( result.Read())
   {
    try
    {
     this.ddlCurArea.SelectedIndex = -1;
     this.ddlCurArea.Items.FindByText( result.GetString(0).Trim()).Selected = true;
     this.txtHeight.Text = result["UserHeight"].ToString();
     this.txtWeight.Text = result["UserWeight"].ToString();
     this.ddlDegree.Items.FindByText(result.GetString(3).ToString().Trim()).Selected = true;
//     this.txtSchool.Text = result["UserSchool"].ToString();
     this.ddlIncome.Items.FindByText(result.GetString(4).ToString().Trim()).Selected = true;
     this.ddlNation.Items.FindByText(result.GetString(5).ToString().Trim()).Selected = true;
     this.ddlUserBloodType.Items.FindByText(result.GetString(6).ToString().Trim()).Selected = true;
     this.ddlZodiac.Items.FindByText(result.GetString(7).ToString().Trim()).Selected = true;
     this.ddlLook.Items.FindByText(result.GetString(8).ToString().Trim()).Selected = true;
     this.ddlConstellation.Items.FindByText(result.GetString(9).ToString().Trim()).Selected = true;
    }
    catch(Exception error)
    {
     throw new Exception(error.Message,error);
    }
   }
   result.Close();
  }
  #endregion  

 

 

#region 将原记录值显示在页面上 
  public void ShowFriendStyleInfo( string friendID)
  {
   SqlDataReader result= new BusinessFacade.FriendFacade.FriendLifeStyleFacade().ShowFriendStyleInfo(friendID);
   if( result.Read())
   {
    try
    {
      this.txtPosition.Text = result["Position"].ToString();
     
    // this.ddlHouse.SelectedIndex = -1;
     
      this.ddlHouse.SelectedIndex = this.ddlHouse.Items.IndexOf(this.ddlHouse.Items.FindByValue(result["IsHousing"].ToString()));
      this.ddlHouse.Items.FindByText( result.GetString(1)).Selected = true;
     
      this.ddlCar.SelectedIndex = this.ddlCar.Items.IndexOf(this.ddlCar.Items.FindByValue(result["IsCar"].ToString()));
      this.ddlCar.Items.FindByText(result.GetString(2).Trim()).Selected = true;

      this.ddlMarry.SelectedIndex = this.ddlMarry.Items.IndexOf(this.ddlCar.Items.FindByValue(result["IsMarring"].ToString()));
      this.ddlMarry.Items.FindByText(result.GetString(3).Trim()).Selected = true;

      this.ddlIsChild.SelectedIndex = this.ddlIsChild.Items.IndexOf(this.ddlIsChild.Items.FindByValue(result["IsChild"].ToString()));
      this.ddlIsChild.Items.FindByText(result.GetString(4).Trim()).Selected = true;

      this.ddlWantToChild.SelectedIndex = this.ddlWantToChild.Items.IndexOf(this.ddlWantToChild.Items.FindByValue(result["IsWantToChild"].ToString()));
      this.ddlWantToChild.Items.FindByText(result.GetString(5).Trim()).Selected = true;
     
      this.ddlSmoke.SelectedIndex = this.ddlSmoke.Items.IndexOf(this.ddlSmoke.Items.FindByValue(result["IsSmoking"].ToString()));
      this.ddlSmoke.Items.FindByText(result.GetString(6).Trim()).Selected = true;
     
      this.ddlDrink.SelectedIndex = this.ddlDrink.Items.IndexOf(this.ddlDrink.Items.FindByValue(result["IsDrinking"].ToString()));
      this.ddlDrink.Items.FindByText(result.GetString(7).Trim()).Selected = true;
 
      this.ddlReligious.SelectedIndex = this.ddlReligious.Items.IndexOf(this.ddlReligious.Items.FindByValue(result["IsReligious"].ToString()));
      this.ddlReligious.Items.FindByText(result.GetString(8).Trim()).Selected = true;
    }
    catch(Exception error)
    {
     throw new Exception(error.Message ,error);
    }
   }
   result.Close();
  }
  #endregion

 

 #region 上传图片的事件
  private void btnSend_Click(object sender, System.EventArgs e)
  {
   string filePath  = string.Empty;
   string fileExtName = string.Empty;
   string mFileName = string.Empty;
   string mPath = string.Empty;

   System.Text.StringBuilder strMsg = new System.Text.StringBuilder("");
   if("" != FileUpload1.PostedFile.FileName)
   {
    filePath=FileUpload1.PostedFile.FileName;   //获取文件在客户端上的完全限定名
    fileExtName = (System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName)).ToString( ).ToLower( ); //文件扩展名称
    string []IMG = {".jpg",".bmp",".gif"};//上传图片的类型
    bool isValid = false;
    for (int i=0;i<IMG.Length;i++)
    {
     if (fileExtName == IMG[i]) isValid = true;
     /*-----------取图片大小------------*/
     System.Drawing.Image image = System.Drawing.Image.FromStream(FileUpload1.PostedFile.InputStream );
     int height = image.Height;
     int width = image.Width;

     if( height>100 || height<90 || width<75 || width>85 )
     {
      //大小不合适
      isValid = false;
     }

     int size = FileUpload1.PostedFile.ContentLength;
     isValid = isValid&&(size<512000);
     /*----------------------------------*/
    }
    if(isValid)
    {
     try
     {
      DateTime CurTime = DateTime.Now;
      string UpLoadImagesSaveUrl = "uploadImg/";
      string PhotoImageUrl = "";
      mPath    = Server.MapPath(UpLoadImagesSaveUrl);   //服务器上传路径
      mFileName   = filePath.Substring(filePath.LastIndexOf("//")+1,filePath.LastIndexOf(".")-filePath.LastIndexOf("//")-1);  //上传文件名称
      Random randomsize = new Random();
      mFileName   = "uploadImg"+CurTime.Year.ToString()+CurTime.DayOfYear.ToString()+"-"+UserCode.ToString()+fileExtName; //DateTime.Now.ToShortDateString()+" "+size+fileExtName;

      FileUpload1.PostedFile.SaveAs(mPath+mFileName);
      if(PageBase.UrlBase.ToLower().IndexOf(":85/web")>0)
      {
       PhotoImageUrl = PageBase.UrlBase+"/friend/uploadImg/"+mFileName;
      }
      else
      {
       PhotoImageUrl = "Http://my.7clive.com/StarPhotoes/"+mFileName;
      }
      this.imgPhoto.ImageUrl = PhotoImageUrl;
      ExeEvent(this.lblMsg.Text,mFileName,this.txtPhotoNote.Text.Trim());
     }
     catch(Exception error)
     {
      throw new Exception( error.Message , error );
     }
     this.lblMessage.Text="上传成功,图片名称为:"+mFileName;
    }
    else
    {
     Response.Write("<script>alert('您上传的图片大小或类型有误!');</script>");
    }
   }
   else
   {
    Response.Write("<script>alert('请上传的图片!');</script>");
   }
    
  }
  #endregion

  #region 执行方法
  public void ExeEvent(string FriendID , string mFileName , string PhotoNote)
  {
   Common.FriendCommon.FriendPhoto friendPhoto = new Common.FriendCommon.FriendPhoto();
   DataTable friendPhotoTable = friendPhoto.Tables[ Common.FriendCommon.FriendPhoto.FRIENDINFO_TABLE];
   DataRow friendPhotoRow = friendPhotoTable.NewRow();
   
   friendPhotoRow[ Common.FriendCommon.FriendPhoto.FRIENDID_FIELD] =FriendID;
   friendPhotoRow[ Common.FriendCommon.FriendPhoto.FRIENDPHOTO_FIELD] = mFileName;
   friendPhotoRow[ Common.FriendCommon.FriendPhoto.FRIENDPHOTONOTE_FIELD] = PhotoNote;
   friendPhotoTable.Rows.Add( friendPhotoRow );
   bool result = (new BusinessFacade.FriendFacade.FriendInfoFacade()).InsertPhoto( friendPhoto );
   if(result)
   {
    Response.Redirect("FriendRegSuccess.aspx?FriendID="+FriendID);
   }
  }
  #endregion

//注销

private void lnkExit_Click(object sender, System.EventArgs e)
  {
   Session.Clear() ;
   Session.Abandon() ;
   //LoginCheck( CheckedUserCode( new PageBase().UserCode ) ) ;
   Response.Redirect("FirendLoginInfo.aspx");
  }

 

#region 登陆判断
  private void LoginCheck( string rv )
  {
   if( ( new PageBase() ).UserCode != 0 )
   {
    if( rv == "0" || rv == "" )
     Response.Redirect( "FriendAccountInfo.aspx" ) ;
    else
     this.lblloginname.Text =rv ;
    //this.lbllogin.Visible = false ;
    this.lnkExit.Visible = true ;
   }
   else
   {
//    this.lblloginname.Text = "您尚未登录" ;
//    this.lbllogin.Visible = true ;
//    this.lbllogin.Text  = "<a href = /"FirendLoginInfo.aspx/">登录</a>" ;
//    this.lnkExit.Visible = false ;
    //Response.Redirect( "FirendLoginInfo.aspx" ) ;
   }
  }
  #endregion

 function firm()
    {
        
//利用对话框返回的值 (true 或者 false)

        if(confirm("你确信要转去 天轰穿的博客?"))
        {
             
//如果是true ,那么就把页面转向thcjp.cnblogs.com

             location.href="http://thcjp.cnblogs.com";
         }
        
else

        {
             
//否则说明下了,赫赫
             alert("你按了取消,那就是返回false");
         }
    }
    
function
 prom()
    {
        
var name=prompt("请输入您的名字","");//将输入的内容赋给变量 name ,

        //这里需要注意的是,prompt有两个参数,前面是提示的话,后面是当对话框出来后,在对话框里的默认值
        if(name)//如果返回的有内容
        {
             alert(
"欢迎您:"+
 name)
         }
    }

//不能后退

<script language="JavaScript">
javascript:window.history.forward(1);
</script>

TEXTAREA rows="15" readOnly cols="70" wrap="soft"  //输入协议框

 

内存表:

using System;
using System.Data;

namespace Common.FriendCommon
{
 /// <summary>
 /// FriendAccount 的摘要说明。
 /// 创建人:朱保健 创建时间:20070820
 /// </summary>
 public class FriendAccount:DataSet
 {
  #region 交友帐号信息常量表
  public const string FRIENDINFO_TABLE    = "FriendInfoTab";
  public const string FRIENDID_FIELD     = "FriendID";
  public const string USERNIKENAME_FIELD    = "UserNikeName";
  public const string USEREMAIL_FIELD     = "UserEmail";
  #endregion

  public FriendAccount()
  {
   BuildDataTables();
  }

  private void BuildDataTables()
  {
   DataTable table = new DataTable(FRIENDINFO_TABLE);
   DataColumnCollection columns = table.Columns;

   columns.Add( FRIENDID_FIELD,typeof(System.String) );
   columns.Add( USERNIKENAME_FIELD,typeof(System.String) );
   columns.Add(USEREMAIL_FIELD,typeof(System.String) );
   this.Tables.Add(table);
  }
 }
}

 

Acess:

#region 添加交友帐号信息
  public bool InsertFriendAccountInfo(FriendAccount friendAccountInfo)
  {
   if ( sqlDataAdapter == null )
   {
    throw new System.ObjectDisposedException( GetType().FullName );
   }

   sqlDataAdapter.InsertCommand = GetInsertAccountCommand();

   sqlDataAdapter.Update(friendAccountInfo ,FriendAccount.FRIENDINFO_TABLE);
   if ( friendAccountInfo.HasErrors )
   {
    friendAccountInfo.Tables[FriendInfo.FRIENDINFO_TABLE].GetErrors()[0].ClearErrors();
    return false;
   }
   else
   {
    friendAccountInfo.AcceptChanges();
    return true;
   }
  }

 

 #region 获得帐户添加命令,返回添加命令
  public SqlCommand GetInsertAccountCommand()
  {
   if ( insertCommand == null )
   {
    insertCommand = new SqlCommand("ProcFriendAccountAdd",dataConn);
    insertCommand.CommandType = CommandType.StoredProcedure;
    SqlParameterCollection sqlParams = insertCommand.Parameters;

    //sqlParams.Add(new SqlParameter(paramChg(FriendAccount.FRIENDID_FIELD) , SqlDbType.Int));
    sqlParams.Add(new SqlParameter(paramChg(FriendAccount.USERNIKENAME_FIELD) , SqlDbType.NVarChar));
    sqlParams.Add(new SqlParameter(paramChg(FriendAccount.USEREMAIL_FIELD),SqlDbType.NVarChar));

    //sqlParams[paramChg(FriendInfo.FRIENDID_FIELD)].SourceColumn = FriendAccount.FRIENDID_FIELD; 
    sqlParams[paramChg(FriendAccount.USERNIKENAME_FIELD)].SourceColumn = FriendAccount.USERNIKENAME_FIELD; 
    sqlParams[paramChg(FriendAccount.USEREMAIL_FIELD)].SourceColumn = FriendAccount.USEREMAIL_FIELD; 

    //用户标识
    sqlParams.Add(new SqlParameter(paramChg(FriendAccount.FRIENDID_FIELD),SqlDbType.NVarChar));
    sqlParams[paramChg(FriendAccount.FRIENDID_FIELD)].SourceColumn = FriendAccount.FRIENDID_FIELD; 

   }
   return insertCommand;
  }
  #endregion

  onKeyUp="value=value.replace(/[^0123456789]/g,'')" onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^0123456789]/g,''))"  单元格只能输入数字

 

#region 加@方法
  public string paramChg(string str)
  {
   str = "@"+str;
   return str;
  }
  #endregion

 

Session["Sex"] = this.ddlSex.SelectedValue;
                   string Value1 =this.Check_Form(Request.Form["ddlBirthProvince"]);
                   string Value2 =this.Check_Form(Request.Form["ddlBirthCity"]);
                   Common.FriendCommon.FriendInfo friendInfo = new Common.FriendCommon.FriendInfo();
                   DataTable friendInfoTable = friendInfo.Tables[ Common.FriendCommon.FriendInfo.FRIENDINFO_TABLE];
                   DataRow friendInfoRow = friendInfoTable.NewRow();
   
                   friendInfoRow[ Common.FriendCommon.FriendInfo.FRIENDID_FIELD]   =this.lblMessage.Text;
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERSEX_FIELD]   = this.ddlSex.SelectedValue.ToString(); //用户性别
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERBIRTHDATE_FIELD]  = this.txtBirthDate.Text.Trim();  //出生日期
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERCURAREA_FIELD]  = this.ddlCurArea.SelectedValue.ToString();  //当前区域
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERHEIGHT_FIELD]   = this.txtHeight.Text.Trim();   //用户身高
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERWEIGHT_FIELD]   = this.txtWeight.Text.Trim();   //用户体重
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERDEGREE_FIELD]   = this.ddlDegree.SelectedValue.ToString();  //最高学历
                   friendInfoRow[ Common.FriendCommon.FriendInfo.UERSCHOOL_FIELD]   = this.txtSchool.Text.Trim();   //毕业学校
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERINCOME_FIELD]   = this.ddlIncome.SelectedValue.ToString();  //年收入
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERBIRTHAREAPRO_FIELD] = Value1.ToString();//出生区域省
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERBIRTHAREACITY_FIELD] = Value2.ToString();//出生区域市
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERNATION_FIELD]   = this.ddlNation.SelectedValue.ToString();//民族
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERBLOODTYPE_FIELD]  = this.ddlUserBloodType.SelectedValue.ToString();//血型
                   friendInfoRow[ Common.FriendCommon.FriendInfo.GOODLOOKING_FIELD]  = this.ddlZodiac.SelectedValue.ToString();//生肖
                   friendInfoRow[ Common.FriendCommon.FriendInfo.USERSELFINFO_FIELD]  = this.ddlLook.SelectedValue.ToString();//相貌  
                   friendInfoRow[ Common.FriendCommon.FriendInfo.CONSTELLATION_FIELD]  = this.ddlConstellation.SelectedValue.ToString();//星座  
                 
   
                   //添加
                   friendInfoTable.Rows.Add( friendInfoRow );
                   bool result = (new BusinessFacade.FriendFacade.FriendInfoFacade()).Insert( friendInfo );

public static String UrlBase
  {
   get
   {
    return @"http://" + UrlSuffix;
   }
  }

/// <summary>
  /// 获得主机与虚拟目录的根路径
  /// </summary>
  private static string UrlSuffix
  {
   get
   {
    string urlSuf ;
    if(HttpContext.Current.Request.ApplicationPath=="/")
    {
     urlSuf = "";
    }
    else
    {
     urlSuf = HttpContext.Current.Request.ApplicationPath;
    }
    return HttpContext.Current.Request.Url.Host+":"+HttpContext.Current.Request.Url.Port+urlSuf;
    
   }
  }

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:134424次
    • 积分:2472
    • 等级:
    • 排名:第14948名
    • 原创:113篇
    • 转载:6篇
    • 译文:0篇
    • 评论:14条
    文章分类
    最新评论