Bruce Xiao 的程序生活

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

<%@ Register TagPrefix="nicklee" Namespace="NickLee.Web.UI" Assembly="NickLee.Web.UI" %>
<%@ Register TagPrefix="iewc" Namespace="Microsoft.Web.UI.WebControls" Assembly="Microsoft.Web.UI.WebControls" %>
<%@ Register TagPrefix="uc1" TagName="ucCopyRight" Src="../../uControls/ucCopyRight.ascx" %>
<%@ Page language="c#" Codebehind="pubProductPhase.aspx.cs" AutoEventWireup="false" Inherits="CQS.MasterData.Project.pubProductPhase" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>Product Phase</title>
  <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
  <LINK href="../../CSS/style1.css" type="text/css" rel="stylesheet">
  <LINK href="../../CSS/style2.css" type="text/css" rel="stylesheet">
  <script language="javascript" src="../../JavaScript/meizz2.js"></script>
  <script language="javascript" src="../../JavaScript/CommonFunction.js"></script>
  <script language="javascript" src="../../AjaxFunction/ajaxfunc.js"></script>
  <script language="javascript">
   function ToolbarConfirm()
   {
    var oItem=event.srcNode;
    switch (oItem.getAttribute("ID"))
    {
    //欲打開的頁面中一定要加入下面的話,這樣才能正常關閉
    //  <base target="_self">
     case "ibtnAdd":
      var openWnd;
      openWnd=window.open("pubProductPhase_Edit.aspx?state=Add&F_SysCode="+getUrlParam("F_SysCode"),'ProductPhase','height=500,width=700,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes',null);
      openWnd.moveTo((parseInt(screen.width)-700)/2,(parseInt(screen.height)-500)/2);
      break;
     case "ibtnBack":
      window.history.back();
      break;
    }
   }
  </script>
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <table class="tblouter" cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
     <td>
      <TABLE class="titletbl" id="Table1" cellSpacing="0" cellPadding="0" width="100%" border="0">
       <TR>
        <td class="title1_L">&nbsp;</td>
        <TD class="td_title1"><asp:label id="lbUseInfo" runat="server" CssClass="f_title"></asp:label></TD>
        <td class="title1_R">&nbsp;</td>
       </TR><tr>
        <td colspan="3"><iewc:toolbar id="Toolbar1" runat="server" DefaultStyle='background:url("../../images/mmu1.gif")'
          border="0" borderWidth="1px" CssClass="noticeDH" HoverStyle="border-right:1px solid #666666;border-left:1px solid #FFFFFF;border-top:1px solid #FFFFFF;border-bottom:1px solid #666666;cursor:hand;padding-left:4px;padding-right:4px;"
          SelectedStyle="border-right:1px solid #FFFFFF;border-left:1px solid #666666;border-top:1px solid #666666;border-bottom:1px solid #FFFFFF;cursor:hand;padding-left:4px;padding-right:4px;">
          <iewc:ToolbarLabel ImageUrl="../../images/toolbarstar.gif" DefaultStyle="padding-left:10px;padding-right:4px;height:18px;border:0px;"></iewc:ToolbarLabel>
          <iewc:ToolbarButton Text="Add" ImageUrl="../../images/NewP.gif" DefaultStyle="border:0px;padding:2px 5px 2px 5px;"
           ID="ibtnAdd" HoverStyle="cursor:hand;padding:2px 10px 2px 10px;" SelectedStyle="border:0px;padding:2px 6px 2px 10px;"></iewc:ToolbarButton>
          <iewc:ToolbarSeparator DefaultStyle="padding-left:10px;padding-right:1px; border:0px;"></iewc:ToolbarSeparator>
          <iewc:ToolbarButton Text="Back" ImageUrl="../../images/back.gif" DefaultStyle="border:0px;padding:2px 0px 2px 10px;"
           ID="ibtnBack" HoverStyle="cursor:hand;padding:2px 10px 2px 10px;" SelectedStyle="border:0px;padding:2px 0px 2px 10px;"></iewc:ToolbarButton>
         </iewc:toolbar></td>
       </tr>
      </TABLE>
     </td>
    </tr>
    
    <tr>
     <td class="pL20" height="40"><asp:dropdownlist id="ddlQuery" runat="server" Width="128px"></asp:dropdownlist><asp:textbox id="tbQuery" runat="server" Width="136px"></asp:textbox><asp:button id="btnQuery" CssClass="search2" Runat="server" Text="Query"></asp:button></td>
    </tr>
    <tr>
     <td class="td3">&nbsp;</td>
    </tr>

   </table>
   
   <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
     <td width="2%" align="left" valign="bottom" class="topBg1"><IMG src="../../images/innertabtrip/topleft1.gif" alt="" width="22" height="33"></td>
     <td width="92%" class="topBg1">
      <div class="tblpage">
          <asp:label id="Label1" runat="server">Record Total:</asp:label>&nbsp;
          <asp:label id="lbRecords" runat="server" CssClass="fred" Width="20px"></asp:label><asp:label id="Label2" runat="server">Page Current: </asp:label>&nbsp;
          <asp:label id="lbPage" runat="server" CssClass="fred" Width="10px"></asp:label>/
          <asp:label id="lbPages" runat="server" CssClass="fred" Width="10px"></asp:label><asp:label id="Label3" runat="server">Page  </asp:label>&nbsp;&nbsp;&nbsp;
          <asp:textbox id="tbpage" runat="server" CssClass="inputs"></asp:textbox><asp:button id="btnpage" runat="server" CssClass="go" Width="32px" Text=""></asp:button></div>
     </td>
     <td width="6%" align="right" class="topBg1"><IMG src="../../images/innertabtrip/topRight1.gif" alt="" width="22" height="33"></td>
    </tr>
    <tr>
     <td colspan="3">
      <TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" width="100%" align="center">
       <TR>
        <TD class="bgL1">&nbsp;</TD>
        <TD class=DGtd1><asp:datagrid id="dgDataType" runat="server" CssClass="DBGrid" AllowSorting="True" PageSize="20"
       AllowPaging="True" BorderColor="#eeeeee" BorderWidth="1px" AutoGenerateColumns="False" DataKeyField="ID"
       width="100%" HeaderStyle-Font-Size="10pt" HeaderStyle-Font-Name="Arial" ItemStyle-Font-Size="9pt"
       ItemStyle-Font-Name="Arial">
                                  <AlternatingItemStyle CssClass="ais_1"></AlternatingItemStyle>
                                  <ItemStyle Font-Size="9pt" Font-Names="Arial" CssClass="is_1"></ItemStyle>
                                  <HeaderStyle Font-Size="10pt" Font-Names="Arial" CssClass="hs_1"></HeaderStyle>
                                  <Columns>
                                  <asp:BoundColumn Visible="False" DataField="ID" ReadOnly="True"></asp:BoundColumn>
                                  <asp:BoundColumn DataField="Value" SortExpression="Value" HeaderText="Product life cycle"></asp:BoundColumn>
                                  <asp:BoundColumn DataField="Text" SortExpression="Text" HeaderText="Description"></asp:BoundColumn>
                                  <asp:BoundColumn DataField="ModifyBy" SortExpression="ModifyBy" HeaderText="Modify By" ItemStyle-Width="80"></asp:BoundColumn>
                                  <asp:BoundColumn DataField="ModifyOn" SortExpression="ModifyOn" HeaderText="Modify On" DataFormatString="{0:yyyy-MM-dd HH:mm:ss}"
         ItemStyle-Width="120"></asp:BoundColumn>
                                  <asp:TemplateColumn ItemStyle-Width="80">
                                    <ItemTemplate> <A id=LinkEdit href='<%# "javascript:OpenEditWindow("+DataBinder.Eval(Container.DataItem, "ID")+")" %>' runat="server"> Edit</A>&nbsp;&nbsp;&nbsp;
                                        <asp:LinkButton id="lkDelete" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
                                    </ItemTemplate>
                                  </asp:TemplateColumn>
                                  </Columns>
                                  <PagerStyle Visible="False" NextPageText="Next" PrevPageText="Previous" HorizontalAlign="Right"></PagerStyle>
                                </asp:datagrid>
        </TD>
        <TD class="bgR1">&nbsp;</TD>
       </TR>
      </TABLE>
      <TABLE style="BORDER-COLLAPSE: collapse" cellSpacing="0" cellPadding="0" width="100%" align="center"
       border="0">
       <tbody>
        <TR>
         <TD width="29"><IMG src="../../images/innertabtrip/footerLeft.gif" alt="" width="32" height="26"></TD>
         <TD class="footer_Bg1"><nicklee:datagridnavigator id="dgNav" runat="server" DataGridName="dgDataType" FirstButtonText="First" LastButtonText="Last"
           NextButtonText="Next" PrevButtonText="Previous" PageButtonCount="10"></nicklee:datagridnavigator>
           </TD>
         <TD align="right" class="footer_Bg1"><uc1:uccopyright id="UcCopyRight1" runat="server" width="100%"></uc1:uccopyright>
         </TD>
         <TD align="right" width="24"><IMG src="../../images/innertabtrip/footerRight.gif" alt="" width="24" height="26"></TD>
        </TR>
       </tbody>
      </TABLE>
     </td>
    </tr>
   </table>
  </form>
 </body>
</HTML>



using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace CQS.MasterData.Project
{
 /// <summary>
 /// pubProductPhase 的摘要描述。
 /// </summary>
 public class pubProductPhase : PageCommon
 {
  protected System.Web.UI.WebControls.Label lbUseInfo;
  protected Microsoft.Web.UI.WebControls.Toolbar Toolbar1;
  protected System.Web.UI.WebControls.DropDownList ddlQuery;
  protected System.Web.UI.WebControls.TextBox tbQuery;
  protected System.Web.UI.WebControls.Button btnQuery;
  protected System.Web.UI.WebControls.Label lbRecords;
  protected System.Web.UI.WebControls.Label lbPage;
  protected System.Web.UI.WebControls.Label lbPages;
  protected System.Web.UI.WebControls.TextBox tbpage;
  protected System.Web.UI.WebControls.Button btnpage;
  protected System.Web.UI.WebControls.DataGrid dgDataType;
  protected System.Web.UI.WebControls.Label Label1;
  protected System.Web.UI.WebControls.Label Label2;
  protected System.Web.UI.WebControls.Label Label3;
  protected NickLee.Web.UI.DataGridNavigator dgNav;
 
  #region Web Form 設計工具產生的程式碼
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
  /// 這個方法的內容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.btnQuery.Click += new System.EventHandler(this.btnQuery_Click);
   this.btnpage.Click += new System.EventHandler(this.btnpage_Click);
   this.dgDataType.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgDataType_SortCommand);
   this.dgDataType.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgDataType_UpdateCommand);
   this.dgDataType.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgDataType_DeleteCommand);
   this.dgDataType.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgDataType_ItemDataBound);
   this.dgNav.Command += new System.Web.UI.WebControls.CommandEventHandler(this.dgNav_Command);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion
  CommClass.PubFunction func= new CommClass.PubFunction();

  void dgbind(){
   //綁定并顯示數據
   DataSet ds=func.GetDataTable("select * from cqsParameter where "+ getcond());
   DataView dv;
   dv=ds.Tables[0].DefaultView;
   dv.Sort=ViewState["sortitem"]+" "+ViewState["sortdir"];
   this.dgDataType.DataSource=dv;
   //防止頁碼超出範圍時出錯
   if (dgDataType.CurrentPageIndex>=func.GetDGPageCount(ds.Tables[0],dgDataType)){
    dgDataType.CurrentPageIndex=0;
   }
   this.dgDataType.DataBind();
   //顯示頁碼及資料筆數
   lbRecords.Text=ds.Tables[0].Rows.Count.ToString();
   lbPages.Text=this.dgDataType.PageCount.ToString();
   lbPage.Text=(this.dgDataType.CurrentPageIndex + 1).ToString();

   //設置刪除
   this.SetDelBound();
  }

  string getcond(){
   string con;
   con = func.GetFieldStr("cqsParameter",ddlQuery.SelectedValue,tbQuery.Text) + " and Category='ProductPhase' ";
   return con;
  }

  //=======================================================================================================================
  private void dgDataType_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
  {
   //恢復資料,將Active標示成 A
   int ID;
   ID=(int)this.dgDataType.DataKeys[e.Item.ItemIndex];  

   if (func.ExecuteSQL("update cqsParameter set Active='A' where ID="+ ID)==false)
   {
    Response.Write("<script language=javascript>alert('Resume data fail!');</script>");
   } 
   else
   {
    Response.Write("<script language=javascript>alert('Resume data successfully!');</script>");
    this.dgbind();
   }
  }

  private void SetDelBound()
  {
   //設置顯示已刪除記錄最後一列
   DataGrid dg =  this.dgDataType;
   int i=0;   
   while(i<dg.Items.Count)
   {
    LinkButton DelButton=(LinkButton)(dg.Items[i].FindControl("lkDelete"));    
    string flg = getDesc("cqsParameter", "Active", "ID=" + dg.DataKeys[dg.Items[i].ItemIndex].ToString());
    if(flg=="D")
    {                 
     dg.Items[i].BackColor = Color.LightGray;
     dg.Items[i].FindControl("LinkEdit").Visible = false;
     DelButton.Text = "Resume";
     DelButton.CommandName = "Update";
     DelButton.Attributes.Add("onclick", "return confirm('Are you sure resume this record?');");   
    }
    else if(flg=="I")
    {
     dg.Items[i].BackColor = Color.LightBlue;
    }

    i =i+1;
   }
   return; 
  }
  //=======================================================================================================================


  private void Page_Load(object sender, System.EventArgs e)
  {
   //登陸頁面時進行身份驗證和權限設定   
   Page_login("../../");
   //判斷用戶是否具有添加權限,如果沒有添加按鈕失效
   Toolbar1.Items[1].Enabled = func.GetMenuPermit(Session["uID"].ToString(), Request["F_SysCode"].ToString(), "Add");
   this.PagePath="pubProductPhase_Edit.aspx?state=Edit&F_SysCode="+Request["F_SysCode"].ToString()+"&ID=";
   this.PageName="ProductPhase";
   this.RegisterFunctionView();

   this.lbUseInfo.Text=func.GetPageMsg("pubProductPhase","M0001","Chinese");
   

   if (IsPostBack !=true){
    //綁定可以查詢的欄位
    func.FillDDL(ddlQuery,"select Description,FieldName from cqsQueryField where tablename='pubProductPhase' and Active='A'","Description","FieldName");
    func.FillDDL2(ddlQuery,"(all*)","(all*)","T");

    ViewState["sortitem"]="ID";
    ViewState["sortdir"]="asc";
    dgbind();
    //給Toolbar中的按鈕賦點擊事件
    Toolbar1.Attributes.Add("onbuttonclick","ToolbarConfirm();");
    Toolbar1.Attributes.Add("_submitting","true");
   }
  }

  private void dgDataType_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {
   //綁定數據時加上相關屬性
   LinkButton DelButton= new LinkButton(); 
   if(e.Item.ItemType==ListItemType.AlternatingItem || (e.Item.ItemType==ListItemType.Item)) {
    e.Item.Attributes.Add("onMouseover", "this.bgColor='#eeeeee'");
    e.Item.Attributes.Add("onmouseout", "this.bgColor='white'");
    e.Item.Attributes.Add("ID","dg_"+e.Item.Cells[0].Text);
    e.Item.Attributes.Add("onclick","SelectLine('dg_"+e.Item.Cells[0].Text+"')");
    e.Item.Attributes.Add("style","cursor:hand");

    DelButton=(LinkButton)(e.Item.FindControl("lkDelete"));
    DelButton.Attributes.Add("onclick", "return confirm('Are you sure delete this record?');"); 
    //判斷用戶是否具有編輯/刪除權限,如果沒有編輯/刪除按鈕隱藏,如果都沒有且方格沒有具它物件則方格隱藏
    dg_Permit(Session["uID"].ToString(),Request["F_SysCode"].ToString(),"LinkEdit","lkDelete",null,e,dgDataType);
   }  
  }

  private void dgDataType_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e) {
   //抓出要排序的欄位
   string sortitem=e.SortExpression;
   if (ViewState["sortitem"].ToString()==sortitem){
    if (ViewState["sortdir"].ToString()=="asc"){
     ViewState["sortdir"]="desc";
    }else{
     ViewState["sortdir"]="asc";
    }
   }else
    ViewState["sortitem"]=sortitem; 
   dgbind();
  }

  private void dgNav_Command(object sender, System.Web.UI.WebControls.CommandEventArgs e) {
   //利用NickLee控件組中的 DataNavigator 控件實現翻頁功能
   dgDataType.CurrentPageIndex = (int) e.CommandArgument;
   dgbind();
  }

  private void dgDataType_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) {
   //刪除資料
   int ID;
   ID=(int)this.dgDataType.DataKeys[e.Item.ItemIndex];  

   if (func.ExecuteSQL("update cqsParameter set Active='D' ,DeleteBy ='"+ Request.Cookies["LoginID"].Value +"',DeleteOn =getdate() where ID="+ ID)==false) {
    Response.Write("<script language=javascript>alert('Delete data fail!');</script>");
   } else{
    Response.Write("<script language=javascript>alert('Delete data successfully!');</script>");
    dgbind();
   }
  }

  private void btnpage_Click(object sender, System.EventArgs e) {
   //跳到指定的頁碼
   if (func.RegularNum(this.tbpage.Text,this.lbPages.Text) ==false){
    return;
   } else {
    this.dgDataType.CurrentPageIndex =Convert.ToInt32(this.tbpage.Text)-1;
    this.dgbind();
   }
  }

  private void btnQuery_Click(object sender, System.EventArgs e) {
   //按照指定的條件進行查找
   dgbind();
  }

 }
}

posted on 2007-01-02 16:38  Bruce Xiao  阅读(334)  评论(0编辑  收藏  举报