266 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			266 lines
		
	
	
		
			6.9 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Data; | |||
|  | using System.Web.UI; | |||
|  | using System.Web.UI.WebControls; | |||
|  | using DeiNiu.Utils; | |||
|  | using DeiNiu.wms.Logical; | |||
|  | 
 | |||
|  | public partial class PublicNewsMain : PageBase | |||
|  | { | |||
|  |     private LPublicNews _logic; | |||
|  |     protected void Page_Load(object sender, EventArgs e) | |||
|  |     { | |||
|  |    | |||
|  |         if (!IsPostBack) | |||
|  |         { | |||
|  |             _logic = new LPublicNews(); | |||
|  |             Databound(); | |||
|  |         } | |||
|  |         SessionSeting(); | |||
|  |     } | |||
|  |   | |||
|  |     /*****************************************   private methods   ******************************************/ | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// bound the query list. | |||
|  |     /// </summary> | |||
|  |     private void Databound() | |||
|  |     { | |||
|  |           | |||
|  |          | |||
|  |         //װ<><D7B0>ѡ<EFBFBD><D1A1><EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | |||
|  |         DataView dv = new DataView(_logic.QueryPublicInfomation()); | |||
|  |          | |||
|  |         TreeAuth.SelectedNode.ChildNodes.Clear(); | |||
|  |         BindTree(TreeAuth.SelectedNode.Value, TreeAuth.SelectedNode, dv); | |||
|  |         //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>ѡ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> | |||
|  |          | |||
|  |         GridView1.DataSource = _logic.QueryNews(Convert.ToInt32(TreeAuth.SelectedValue)); | |||
|  |         GridView1.DataBind(); | |||
|  | 
 | |||
|  |        //  GVFiles.DataSource = null; | |||
|  |        // GVFiles.DataBind(); | |||
|  |         UpdateSession(); | |||
|  |         ClearDetail(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void SessionSeting() | |||
|  |     { | |||
|  |         if (IsPostBack) | |||
|  |         { | |||
|  |             _logic = (LPublicNews)Session[appScope.PagelevelObj]; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     private void UpdateSession() | |||
|  |     { | |||
|  |         Session[appScope.PagelevelObj] = _logic; | |||
|  |     } | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// set data from shift object to page | |||
|  |     /// </summary> | |||
|  |     private void DetailDataBind() | |||
|  |     { | |||
|  | 
 | |||
|  |         DataDetail.Visible = true; | |||
|  |         txtTitle.Text = _logic.GetPublicNews.news_title; | |||
|  |         txtDesc.Text = _logic.GetPublicNews.news_content;  | |||
|  |     } | |||
|  | 
 | |||
|  |     /************************************** protected methods (event listeners) ********************************/ | |||
|  | 
 | |||
|  |     protected void btnAddnew_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(true); | |||
|  |         _logic.Initialize(); | |||
|  |        | |||
|  |         GridView1.SelectedIndex = -1; | |||
|  |         Databound(); | |||
|  |         DetailDataBind(); | |||
|  |        //todo bind attached files infomationsss\\ | |||
|  | 
 | |||
|  | 
 | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void DetailsView1_PageIndexChanging(object sender, DetailsViewPageEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(false); | |||
|  |         if (GridView1.DataKeys != null) | |||
|  |         { | |||
|  |             string id = GridView1.DataKeys[e.NewEditIndex].Value.ToString(); | |||
|  |             _logic.Initialize(int.Parse(id)); | |||
|  |         } | |||
|  |         Databound(); | |||
|  |         DetailDataBind(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void btnSubmit_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         SetDataBack(); | |||
|  |         //shifts id eq 0 means this is new one,to add; else an old one, to update | |||
|  |      | |||
|  |         int oper = 0; | |||
|  |         oper = _logic.GetPublicNews.ID > 0 ? _logic.GetPublicNews.Update() : _logic.GetPublicNews.Add(); | |||
|  |         ClearDetail(); | |||
|  |         Databound(); | |||
|  |         lbEdit.Text = ""; | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e) | |||
|  |     { | |||
|  |          | |||
|  |         if (GridView1 != null) | |||
|  |         { | |||
|  |             if (GridView1.DataKeys != null) | |||
|  |             { | |||
|  |                 string id = GridView1.DataKeys[e.RowIndex].Value.ToString(); | |||
|  |                 _logic.Initialize(int.Parse(id)); | |||
|  |             } | |||
|  |         } | |||
|  |         /* | |||
|  |         _logic.GetRole.dr = false; | |||
|  |         _logic.GetRole.Update(); | |||
|  |          | |||
|  |        */ | |||
|  |         _logic.GetPublicNews.Delete(); | |||
|  |         ClearDetail(); | |||
|  |         Databound(); | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_PageIndexChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) | |||
|  |     { | |||
|  |         GridView1.PageIndex = e.NewPageIndex; | |||
|  |         Databound(); | |||
|  | 
 | |||
|  |         //GridView1.DataSource = shiftLgc.getAllShifts().Tables[0]; | |||
|  |         //     GridView1.DataBind();     | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_DataBinding(object sender, EventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |      | |||
|  |     protected void GridView1_Sorting(object sender, GridViewSortEventArgs e) | |||
|  |     { | |||
|  |     } | |||
|  | 
 | |||
|  |     //reset the page | |||
|  |     protected void btnCancel_Click(object sender, EventArgs e) | |||
|  |     { | |||
|  |         _logic.Initialize(); | |||
|  |         Page_Load(this, e); | |||
|  |     } | |||
|  | 
 | |||
|  |     /***************************************** internal methods ********************************************/ | |||
|  | 
 | |||
|  |     /// <summary> | |||
|  |     /// set data from page to shift object | |||
|  |     /// </summary> | |||
|  |     private void SetDataBack() | |||
|  |     { | |||
|  |         //    _logic.GetRole.operater = Session["CurrentUserID"].ToString();  todo: write a public method to handle operater,createtime,lastmodfied ... log info. | |||
|  | 
 | |||
|  |         if (!(_logic.GetPublicNews.ID > 0))  | |||
|  |        { | |||
|  |            //_logic.GetPublicNews.last_modified  = DateTime.Now.ToString(); | |||
|  |            _logic.GetPublicNews.news_authority = Convert.ToInt32(TreeAuth.SelectedValue); | |||
|  |        } | |||
|  | 
 | |||
|  |        _logic.GetPublicNews.news_title = txtTitle.Text; | |||
|  |        _logic.GetPublicNews.news_content = txtDesc.Text;  | |||
|  |         | |||
|  |         //todo bind files | |||
|  |     } | |||
|  | 
 | |||
|  |     private void chgOperTxt(bool addNew) | |||
|  |     { | |||
|  |         DataDetail.Visible = true; | |||
|  |         lbEdit.Text = addNew ? "<22><><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>¼" : "<22><EFBFBD><DEB8><EFBFBD><EFBFBD>м<EFBFBD>¼"; | |||
|  |         btnSubmit.Enabled = true; | |||
|  |     } | |||
|  | 
 | |||
|  |     private void ClearDetail() | |||
|  |     { | |||
|  |         txtTitle.Text = "";  | |||
|  |         txtDesc.Text = ""; | |||
|  |         | |||
|  |         DataDetail.Visible = false; | |||
|  |     } | |||
|  | 
 | |||
|  |     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) | |||
|  |     { | |||
|  |         chgOperTxt(false); | |||
|  |         if (GridView1.DataKeys != null) | |||
|  |         { | |||
|  |             string id = GridView1.DataKeys[GridView1.SelectedIndex].Value.ToString(); | |||
|  |             _logic.Initialize(int.Parse(id)); | |||
|  |         } | |||
|  |         Databound(); | |||
|  |         DetailDataBind(); | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     public void BindTree(string id, TreeNode pNode, DataView dv) | |||
|  |     { | |||
|  | 
 | |||
|  |         dv.RowFilter = "auth_uplevel = '" + id + "'"; | |||
|  |         foreach (DataRowView row in dv) | |||
|  |         { | |||
|  |             TreeNode node = new TreeNode(); | |||
|  |             node.Text = row["auth_name"].ToString(); | |||
|  |             node.Value = row["ID"].ToString(); | |||
|  |             if (pNode == null) | |||
|  |                 //˵<><CBB5><EFBFBD>Ǹ<EFBFBD><C7B8>ڵ<EFBFBD> | |||
|  |             { | |||
|  |              | |||
|  |                 TreeAuth.Nodes.Add(node); | |||
|  |                 node.Expanded = true; | |||
|  |        | |||
|  |             } | |||
|  |             else | |||
|  |             { | |||
|  |                 pNode.ChildNodes.Add(node); | |||
|  |                 node.Expanded = true; | |||
|  |                  | |||
|  |             } | |||
|  |             BindTree(node.Value, node, new DataView(dv.Table)); | |||
|  | 
 | |||
|  |         } | |||
|  |     } | |||
|  |     | |||
|  |     protected void TreeAuth_SelectedNodeChanged1(object sender, EventArgs e) | |||
|  |     { | |||
|  |         GridView1.SelectedIndex = -1; | |||
|  |         DataView dv = new DataView(_logic.QueryNews(Convert.ToInt32(TreeAuth.SelectedValue)));  | |||
|  |         GridView1.DataSource = dv; | |||
|  |         GridView1.DataBind();  | |||
|  |         ClearDetail(); | |||
|  |     } | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  | 
 | |||
|  |     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) | |||
|  |     { | |||
|  | 
 | |||
|  |           | |||
|  |         switch (e.Row.RowType) | |||
|  |         { | |||
|  |             case DataControlRowType.DataRow: | |||
|  |                 if (e.Row.Cells[2].Text.Trim().Length > 30) e.Row.Cells[2].Text = e.Row.Cells[2].Text.Substring(0,30)+"...."; | |||
|  |                  | |||
|  |                 break; | |||
|  |         } | |||
|  |     } | |||
|  | } |