using
		 TestWeb.HR.BusinessLogicLayer;
 using
		 TestWeb.HR.DataAccessLayer;
		using
		 TestWeb.HR.DataAccessLayer;
 public
		 
		partial
		 
		class
		 HR_CompanyView : System.Web.UI.UserControl
		public
		 
		partial
		 
		class
		 HR_CompanyView : System.Web.UI.UserControl

 ...
		
				{
		...
		
				{
 protected
				 
				void
				 Page_Load(
				object
				 sender, EventArgs e)
    
				protected
				 
				void
				 Page_Load(
				object
				 sender, EventArgs e)

 ...
				
						{
    
				...
				
						{
 if
						 (
						!
						this
						.IsPostBack)
        
						if
						 (
						!
						this
						.IsPostBack)

 ...
						
								{
        
						...
						
								{
 GetAllCompanies(); 
								//
								初试加载所有公司
            GetAllCompanies(); 
								//
								初试加载所有公司
								
										
										 }
								
								        }
						
						
								
								 }
}
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 返回所有公司
    
						///
						 返回所有公司
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
						
				
				
				 private
				 
				void
				 GetAllCompanies()
				    
				private
				 
				void
				 GetAllCompanies()

 ...
				
						{
    
				...
				
						{
 try
        
						try
						
								
								 
								 ...
						
								{
        
						...
						
								{
 List
								<
								Company
								>
								 companyList 
								=
								 
								new
								 List
								<
								Company
								>
								();
            List
								<
								Company
								>
								 companyList 
								=
								 
								new
								 List
								<
								Company
								>
								();
 companyList 
								=
								 Company.GetAllCompanies();
            companyList 
								=
								 Company.GetAllCompanies();
 if
								 (companyList 
								!=
								 
								null
								)
            
								if
								 (companyList 
								!=
								 
								null
								)

 ...
								
										{
            
								...
								
										{
 this
										.GridView1.DataSource 
										=
										 companyList;
                
										this
										.GridView1.DataSource 
										=
										 companyList;
 this
										.GridView1.DataBind();
                
										this
										.GridView1.DataBind();
 }
            }
								
								
										
										 }
        }
						
						
								
								 catch
						 (Exception ex)
        
						catch
						 (Exception ex)

 ...
						
								{
        
						...
						
								{
 ShowMessage.ErrorMessage(
								this
								.Page, ex.Message);
            ShowMessage.ErrorMessage(
								this
								.Page, ex.Message);
 }
        }
						
						
								
								 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 编辑公司
    
						///
						 编辑公司
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_RowEditing(
				object
				 sender, GridViewEditEventArgs e)
				    
				protected
				 
				void
				 GridView1_RowEditing(
				object
				 sender, GridViewEditEventArgs e)

 ...
				
						{
    
				...
				
						{
 this
						.GridView1.EditIndex 
						=
						 e.NewEditIndex;
        
						this
						.GridView1.EditIndex 
						=
						 e.NewEditIndex;
 GetAllCompanies();
        GetAllCompanies();
 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 取消编辑
    
						///
						 取消编辑
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_RowCancelingEdit(
				object
				 sender, GridViewCancelEditEventArgs e)
				    
				protected
				 
				void
				 GridView1_RowCancelingEdit(
				object
				 sender, GridViewCancelEditEventArgs e)

 ...
				
						{
    
				...
				
						{
 this
						.GridView1.EditIndex 
						=
						 
						-
						1
						;
        
						this
						.GridView1.EditIndex 
						=
						 
						-
						1
						;
 GetAllCompanies();
        GetAllCompanies();
 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 更新公司
    
						///
						 更新公司
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_RowUpdating(
				object
				 sender, GridViewUpdateEventArgs e)
				    
				protected
				 
				void
				 GridView1_RowUpdating(
				object
				 sender, GridViewUpdateEventArgs e)

 ...
				
						{
    
				...
				
						{
 GridViewRow uprow 
						=
						 
						this
						.GridView1.Rows[e.RowIndex];
        GridViewRow uprow 
						=
						 
						this
						.GridView1.Rows[e.RowIndex];
 TextBox text1 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox1
						"
						);
        TextBox text1 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox1
						"
						);
 TextBox text2 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox2
						"
						);
        TextBox text2 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox2
						"
						);
 TextBox text3 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox3
						"
						);
        TextBox text3 
						=
						 (TextBox)uprow.Cells[
						0
						].FindControl(
						"
						TextBox3
						"
						);
 HyperLink hlk 
						=
						 (HyperLink)uprow.Cells[
						0
						].FindControl(
						"
						HyperLink1
						"
						);
        HyperLink hlk 
						=
						 (HyperLink)uprow.Cells[
						0
						].FindControl(
						"
						HyperLink1
						"
						);
 int
						 companyId 
						=
						 Convert.ToInt32(
						this
						.GridView1.DataKeys[e.RowIndex].Value);
        
						int
						 companyId 
						=
						 Convert.ToInt32(
						this
						.GridView1.DataKeys[e.RowIndex].Value);
 //
						直接调用存储过程进行更新
        
						//
						直接调用存储过程进行更新
						
								
								 string
						 connectionstring 
						=
						 ConfigurationManager.ConnectionStrings[
						"
						TESTDB_Database_Connection
						"
						].ConnectionString;
						
						        
						string
						 connectionstring 
						=
						 ConfigurationManager.ConnectionStrings[
						"
						TESTDB_Database_Connection
						"
						].ConnectionString;
 SqlCommand upcmd 
						=
						 
						new
						 SqlCommand();
        SqlCommand upcmd 
						=
						 
						new
						 SqlCommand();
 upcmd.CommandType 
						=
						 CommandType.StoredProcedure;
        upcmd.CommandType 
						=
						 CommandType.StoredProcedure;
 upcmd.CommandText 
						=
						 
						"
						UPCompany
						"
						;
        upcmd.CommandText 
						=
						 
						"
						UPCompany
						"
						;
 upcmd.Parameters.Add(
						"
						@CompanyName
						"
						, SqlDbType.VarChar, 
						50
						);
        upcmd.Parameters.Add(
						"
						@CompanyName
						"
						, SqlDbType.VarChar, 
						50
						);
 upcmd.Parameters[
						"
						@CompanyName
						"
						].Value 
						=
						 text1.Text.Trim();
        upcmd.Parameters[
						"
						@CompanyName
						"
						].Value 
						=
						 text1.Text.Trim();
 upcmd.Parameters.Add(
						"
						@Phone
						"
						, SqlDbType.VarChar, 
						50
						);
        upcmd.Parameters.Add(
						"
						@Phone
						"
						, SqlDbType.VarChar, 
						50
						);
 upcmd.Parameters[
						"
						@Phone
						"
						].Value 
						=
						 text2.Text.Trim();
        upcmd.Parameters[
						"
						@Phone
						"
						].Value 
						=
						 text2.Text.Trim();
 upcmd.Parameters.Add(
						"
						@Fax
						"
						, SqlDbType.VarChar, 
						50
						);
        upcmd.Parameters.Add(
						"
						@Fax
						"
						, SqlDbType.VarChar, 
						50
						);
 upcmd.Parameters[
						"
						@Fax
						"
						].Value 
						=
						 text3.Text.Trim();
        upcmd.Parameters[
						"
						@Fax
						"
						].Value 
						=
						 text3.Text.Trim();
 upcmd.Parameters.Add(
						"
						@WebSite
						"
						, SqlDbType.VarChar, 
						50
						);
        upcmd.Parameters.Add(
						"
						@WebSite
						"
						, SqlDbType.VarChar, 
						50
						);
 upcmd.Parameters[
						"
						@WebSite
						"
						].Value 
						=
						 hlk.Text.Trim();
        upcmd.Parameters[
						"
						@WebSite
						"
						].Value 
						=
						 hlk.Text.Trim();
 upcmd.Parameters.Add(
						"
						@CompanyId
						"
						, SqlDbType.Int, 
						4
						);
        upcmd.Parameters.Add(
						"
						@CompanyId
						"
						, SqlDbType.Int, 
						4
						);
 upcmd.Parameters[
						"
						@CompanyId
						"
						].Value 
						=
						 companyId;
        upcmd.Parameters[
						"
						@CompanyId
						"
						].Value 
						=
						 companyId;
 SqlConnection con 
						=
						 
						new
						 SqlConnection(connectionstring);
        SqlConnection con 
						=
						 
						new
						 SqlConnection(connectionstring);
 upcmd.Connection 
						=
						 con;
        upcmd.Connection 
						=
						 con;
 con.Open();
        con.Open();
 upcmd.ExecuteNonQuery();
        upcmd.ExecuteNonQuery();
 con.Close();
        con.Close();

 this
						.GridView1.EditIndex 
						=
						 
						-
						1
						;
        
						this
						.GridView1.EditIndex 
						=
						 
						-
						1
						;
 GetAllCompanies();
        GetAllCompanies();
 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 删除公司
    
						///
						 删除公司
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_RowDeleting(
				object
				 sender, GridViewDeleteEventArgs e)
				    
				protected
				 
				void
				 GridView1_RowDeleting(
				object
				 sender, GridViewDeleteEventArgs e)

 ...
				
						{
    
				...
				
						{
 int
						 companyId 
						=
						 Convert.ToInt32(
						this
						.GridView1.DataKeys[e.RowIndex].Value);
        
						int
						 companyId 
						=
						 Convert.ToInt32(
						this
						.GridView1.DataKeys[e.RowIndex].Value);
 string
						 connectionstring 
						=
						 ConfigurationManager.ConnectionStrings[
						"
						TESTDB_Database_Connection
						"
						].ConnectionString;
        
						string
						 connectionstring 
						=
						 ConfigurationManager.ConnectionStrings[
						"
						TESTDB_Database_Connection
						"
						].ConnectionString;
 SqlCommand delcmd 
						=
						 
						new
						 SqlCommand();
        SqlCommand delcmd 
						=
						 
						new
						 SqlCommand();
 delcmd.CommandType 
						=
						 CommandType.StoredProcedure;
        delcmd.CommandType 
						=
						 CommandType.StoredProcedure;
 delcmd.CommandText 
						=
						 
						"
						HR_DeleteCompanyByCompanyId
						"
						;
        delcmd.CommandText 
						=
						 
						"
						HR_DeleteCompanyByCompanyId
						"
						;
 delcmd.Parameters.Add(
						"
						@CompanyId
						"
						, SqlDbType.Int, 
						4
						);
        delcmd.Parameters.Add(
						"
						@CompanyId
						"
						, SqlDbType.Int, 
						4
						);
 delcmd.Parameters[
						"
						@CompanyId
						"
						].Value 
						=
						 companyId;
        delcmd.Parameters[
						"
						@CompanyId
						"
						].Value 
						=
						 companyId;
 SqlConnection _Con 
						=
						 
						new
						 SqlConnection(connectionstring);
        SqlConnection _Con 
						=
						 
						new
						 SqlConnection(connectionstring);
 delcmd.Connection 
						=
						 _Con;
        delcmd.Connection 
						=
						 _Con;
 _Con.Open();
        _Con.Open();
 delcmd.ExecuteNonQuery();
        delcmd.ExecuteNonQuery();
 _Con.Close();
        _Con.Close();
 GetAllCompanies();
        GetAllCompanies();
 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 允许分页
    
						///
						 允许分页
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_PageIndexChanging(
				object
				 sender, GridViewPageEventArgs e)
				    
				protected
				 
				void
				 GridView1_PageIndexChanging(
				object
				 sender, GridViewPageEventArgs e)

 ...
				
						{
    
				...
				
						{
 this
						.GridView1.PageIndex 
						=
						 e.NewPageIndex;
        
						this
						.GridView1.PageIndex 
						=
						 e.NewPageIndex;
 GetAllCompanies();
        GetAllCompanies();
 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 焦点行颜色变化
    
						///
						 焦点行颜色变化
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 GridView1_RowDataBound(
				object
				 sender, GridViewRowEventArgs e)
				    
				protected
				 
				void
				 GridView1_RowDataBound(
				object
				 sender, GridViewRowEventArgs e)

 ...
				
						{
    
				...
				
						{
 if
						 (e.Row.RowType 
						==
						 DataControlRowType.DataRow)
        
						if
						 (e.Row.RowType 
						==
						 DataControlRowType.DataRow)

 ...
						
								{
        
						...
						
								{
 //
								当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色
            
								//
								当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
								
										
										 e.Row.Attributes.Add(
								"
								onmouseover
								"
								, 
								"
								currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';
								"
								);
								
								            e.Row.Attributes.Add(
								"
								onmouseover
								"
								, 
								"
								currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';
								"
								);
 //
								当鼠标离开的时候 将背景颜色还原的以前的颜色
            
								//
								当鼠标离开的时候 将背景颜色还原的以前的颜色 
								
										
										 e.Row.Attributes.Add(
								"
								onmouseout
								"
								, 
								"
								this.style.backgroundColor=currentcolor,this.style.fontWeight='';
								"
								);
								
								            e.Row.Attributes.Add(
								"
								onmouseout
								"
								, 
								"
								this.style.backgroundColor=currentcolor,this.style.fontWeight='';
								"
								);
 }
        }
						
						
								
								 //
						单击行改变行背景颜色
        
						//
						单击行改变行背景颜色 
						
								
								 if
						 (e.Row.RowType 
						==
						 DataControlRowType.DataRow)
						
						        
						if
						 (e.Row.RowType 
						==
						 DataControlRowType.DataRow)

 ...
						
								{
        
						...
						
								{
 e.Row.Attributes.Add(
								"
								onclick
								"
								, 
								"
								this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';
								"
								);
            e.Row.Attributes.Add(
								"
								onclick
								"
								, 
								"
								this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';
								"
								);
 }
        }
						
						
								
								 }
    }
				
				
						
						 
						 /**/
				
						///
						 
						<summary>
    
				/**/
				
						///
						 
						<summary>
						
								
								 ///
						 根据ID获取公司详细信息
    
						///
						 根据ID获取公司详细信息
 ///
						 
						</summary>
    
						///
						 
						</summary>
						
								
								 ///
						 
						<param name="sender"></param>
    
						///
						 
						<param name="sender"></param>
						
								
								 ///
						 
						<param name="e"></param>
    
						///
						 
						<param name="e"></param>
						
						
				
				
				 protected
				 
				void
				 Button1_Click(
				object
				 sender, EventArgs e)
				    
				protected
				 
				void
				 Button1_Click(
				object
				 sender, EventArgs e)

 ...
				
						{
    
				...
				
						{
 Response.Redirect(
						"
						~/CompanyDetails.aspx
						"
						);
        Response.Redirect(
						"
						~/CompanyDetails.aspx
						"
						);
 }
    }
				
				 
 }
}
		
	posted on 2006-10-30 14:44 
圣域飞侠 阅读(545) 
评论(0)  编辑  收藏