zoukankan      html  css  js  c++  java
  • 一段代码Code

    后台aspx.cs Code 

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using SubjectData.BLL;
    using SubjectData.Common;
    
    namespace SubjectManager.Disease
    {
        public partial class SubjectList : System.Web.UI.Page
        {
            DiseaseSubject dal_sub = new DiseaseSubject();
            public string Nothing;
    
            #region My Init
            /// <summary>
            /// 层次分割符
            /// Hyey.wl
            /// 2010-03-18
            /// </summary>
            const string STR_TREENODE = "┆┄";
            /// <summary>
            /// Data View Source.
            /// Hyey.wl
            /// 2010-03-18
            /// </summary>
            DataView dv;
            /// <summary>
            /// ID
            /// </summary>
            const string STR_ID = "SubID";
            /// <summary>
            /// Parent ID
            /// </summary>
            const string STR_PARENTID = "parentId";
            /// <summary>
            /// Type Name 
            /// </summary>
            const string STR_DISPLAYNAME = "SubTypeName";
            #endregion
    
            protected void Page_Load(object sender, EventArgs e)
            {
                string schar = STR_TREENODE;
    
                if (!IsPostBack)
                {
                    //绑定专题类型
                    bindSubType(-1, ref schar);
                    if (this.ddlSubType.Items.FindByValue("-1") == null)
                        this.ddlSubType.Items.Insert(0, new ListItem("--请选择--", "-1"));
                    BindDate(1, 10);
                }
            }
    
            #region   查询参数
            //专题名称
            protected string Query_Name
            {
                get
                {
                    if (Request.QueryString["q_name"] != null && Request.QueryString["q_name"].ToString() != String.Empty)
                    {
                        string query_name = this.Request.QueryString["q_name"].Trim();
    
                        return query_name.Replace("'", "").Replace(";", "");
                    }
                    else
                    {
                        return null;
                    }
                }
            }
    
            //相关药物
            protected string Query_ConDrugs
            {
                get
                {
                    if (Request.QueryString["q_cdrug"] != null && Request.QueryString["q_cdrug"].ToString() != String.Empty)
                    {
                        string query_cdrug = this.Request.QueryString["q_cdrug"].Trim();
    
                        return HyeyClass.Web.PageValidate.ReplaceStr(query_cdrug);
    
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            //学科ID
            protected string Query_KiID
            {
                get
                {
                    if (Request.QueryString["q_kn"] != null && Request.QueryString["q_kn"].ToString() != String.Empty)
                    {
                        string query_kiID = this.Request.QueryString["q_kn"].Trim();
                        return HyeyClass.Web.PageValidate.ReplaceStr(query_kiID);
    
                    }
                    else
                    {
                        return null;
                    }
                }
            }
    
            #endregion
    
    
            #region  组织查询where条件
    
            string Org_where() //---------------------------------------------组织where条件
            {
                System.Text.StringBuilder strBuilder = new System.Text.StringBuilder();
                strBuilder.Append("1=1");
    
                if (this.Query_Name != null)
                {
                    strBuilder.Append(" and ");
                    strBuilder.Append("SubName like '%" + this.Query_Name + "%'");
                    TxtSubName.Text = Query_Name;
    
                }
                if (this.Query_ConDrugs != null)
                {
                    strBuilder.Append(" and ");
                    strBuilder.Append("ConDrugs like  '%" + this.Query_ConDrugs + "%'");
                    TxtConDrugs.Text = this.Query_ConDrugs;
    
                }
                if (this.Query_KiID != null)
                {
                    strBuilder.Append(" and ");
                    strBuilder.Append("kiID = " + this.Query_KiID);
    
                    for (int i = 0; i < ddlSubType.Items.Count; i++)
                    {
                        if (ddlSubType.Items[i].Value == Query_KiID)
                        {
                            ddlSubType.Items[i].Selected = true;
                        }
                    }
                }
    
               
                return strBuilder.ToString();
    
            }
    
    
            #endregion
    
            /// <summary>
            /// Binds the type of the sub.
            /// Hyey.wl
            /// 2010-03-18
            /// 绑定树集目录列表.
            /// </summary>
            /// <param name="schar">The schar is tree split string.</param>
            void bindSubType(int pid ,ref string schar)
            {
                string url = "XMLData/SubjectType.xml";
                string strXmlFile = Server.MapPath(url);
                EditXML xmlDal = new EditXML(strXmlFile);
                DataSet ds = xmlDal.GetTable();
    
                dv = ds.Tables[0].DefaultView;
    
                dv.Sort = STR_PARENTID;
    
                if (pid == -1)
                {
                    foreach (DataRow row in dv.Table.Rows)
                    {
                        if (Convert.ToInt32(row[STR_PARENTID]) == 0)
                        {
                            this.ddlSubType.Items.Add(new ListItem(schar + row[STR_DISPLAYNAME].ToString(), row[STR_ID].ToString()));
                            bindSubType(Convert.ToInt32(row[STR_ID]), ref schar);
                        }
                    }
                }
                else
                {
                    DataRowView[] rows = dv.FindRows(pid);
                    foreach (DataRowView row in rows)
                    {
                        if (Convert.ToInt32(row[STR_ID]) != Convert.ToInt32(row[STR_PARENTID]))
                        {
                            schar += STR_TREENODE;
                            this.ddlSubType.Items.Add(new ListItem(schar + row[STR_DISPLAYNAME].ToString(), row[STR_ID].ToString()));
                            bindSubType(Convert.ToInt32(row[STR_ID]), ref schar);
                        }
    
                    }
                    schar = STR_TREENODE;
                }
    
            }
    
            void BindDate(int PageIndex, int PageSize)
            {
                string strWhere = Org_where();
    
                #region
                //显示的字段
                string strFld = "SubID,SubName,kiID,Knowledge,ConDrugs,Op,AddTime";
    
                int RecordCount = 0;
                int PageCount = 0;
    
    
                //			if( HiddenRecordCount.Value == "" )
                //			{
                string Count_sql = "select count(*) from DiseaseSubject where " + strWhere;
                HiddenRecordCount.Value = HyeyClass.DALFactory.DataAccess.CreateComm().ExecScalar(Count_sql);  //取出记录总数
                //			}
    
                RecordCount = Convert.ToInt32(HiddenRecordCount.Value);
    
                if (RecordCount % PageSize == 0)
                {
                    PageCount = RecordCount / PageSize;
    
                }
                else
                {
                    PageCount = RecordCount / PageSize + 1;
    
                }
    
    
                if (PageIndex > PageCount)
                    PageIndex = PageCount;
    
    
                if (PageIndex == PageCount && PageCount == 1)
                {
    
                    this.LinkFirst1.Enabled = false;
                    this.LinkPrev1.Enabled = false;
    
                    this.LinkNext1.Enabled = false;
                    this.LinkEnd1.Enabled = false;
    
    
                }
                else if (PageIndex == 1)
                {
                    this.LinkFirst1.Enabled = false;
                    this.LinkPrev1.Enabled = false;
    
                    this.LinkNext1.Enabled = true;
                    this.LinkEnd1.Enabled = true;
    
                }
                else if (PageIndex == PageCount)
                {
                    this.LinkFirst1.Enabled = true;
                    this.LinkPrev1.Enabled = true;
    
                    this.LinkEnd1.Enabled = false;
                    this.LinkNext1.Enabled = false;
    
                }
                else if (PageIndex != 1 && PageIndex != PageCount)
                {
                    this.LinkFirst1.Enabled = true;
                    this.LinkPrev1.Enabled = true;
    
                    this.LinkEnd1.Enabled = true;
                    this.LinkNext1.Enabled = true;
    
                }
    
    
                this.HiddenIndex.Value = PageIndex.ToString();//当前页的值,放入隐藏控件中
                this.TextIndex1.Text = PageIndex.ToString();
                this.txtNum.Text = PageSize.ToString();
                this.LabelPageSow1.Text = "<font color='red'>" + PageIndex.ToString() + "</font>" + "/" + PageCount.ToString();
                this.LabNum1.Text = RecordCount.ToString();
    
                //-------------------------------------------------------------------------------------
    
                if (PageIndex <= 0)
                    return;
    
                #endregion
    
    
    
                DataSet ds = dal_sub.GetList(strFld, strWhere, PageIndex, PageSize, "subId", "subid desc", 0);
    
    
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    Nothing = "没有数据";
                    return;
                }
               
    
                this.Repeater1.DataSource = ds;
                this.Repeater1.DataBind();
    
                ds.Dispose();
            }
    
            #region 页面跳转
    
            int getPageSize()
            {
                if (txtNum.Text == String.Empty || txtNum.Text == "0" || !HyeyClass.Web.PageValidate.IsNumber(txtNum.Text.Trim()))
                {
                    return 0;
                }
                else
                {
                    return Convert.ToInt32(txtNum.Text.Trim());
                }
            }
    
            protected void LinkFirst1_Click(object sender, System.EventArgs e)
            {
                FirstPage();
            }
    
            protected void LinkPrev1_Click(object sender, System.EventArgs e)
            {
                PrevPage();
            }
    
            protected void LinkNext1_Click(object sender, System.EventArgs e)
            {
                NextPage();
            }
    
            protected void LinkEnd1_Click(object sender, System.EventArgs e)
            {
                LastPage();
            }
            private void ImageButton1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
            {
                goPage();
            }
    
            void FirstPage()  //第一页
            {
    
                BindDate(1, 20);
    
            }
    
            void PrevPage() //上一页
            {
    
                int CurrentIndex = Convert.ToInt32(this.HiddenIndex.Value.ToString());
                int PrevIndex = CurrentIndex - 1;
    
                BindDate(PrevIndex, getPageSize());
    
    
            }
    
            void NextPage()  //下一页
            {
    
                int CurrentIndex = Convert.ToInt32(this.HiddenIndex.Value.ToString());
                int NextIndex = CurrentIndex + 1;
    
                BindDate(NextIndex, getPageSize());
    
    
            }
    
            void LastPage()  //最后一页
            {
    
                int pagesize = getPageSize();
                int RecordCount = Convert.ToInt32(this.HiddenRecordCount.Value.ToString());
                int EndIndex = 0;
    
                if (RecordCount % pagesize == 0)
                {
                    EndIndex = RecordCount / pagesize;
    
                }
                else
                {
                    EndIndex = RecordCount / pagesize + 1;
    
                }
    
                BindDate(EndIndex, pagesize);
    
    
    
    
            }
    
            void goPage()   //跳转
            {
    
    
                if (this.TextIndex1.Text == String.Empty || this.TextIndex1.Text == "0" || !HyeyClass.Web.PageValidate.IsNumber(this.TextIndex1.Text.Trim()))
                {
                    HyeyClass.Web.MessageBox.Show(this, "页面索引无效");
                    return;
    
                }
                if (getPageSize() > 0)
                {
                    int pagesize = getPageSize();
                    int RecordCount = Convert.ToInt32(this.HiddenRecordCount.Value.ToString());
                    int EndIndex = 0;
    
                    if (RecordCount % pagesize == 0)
                    {
                        EndIndex = RecordCount / pagesize;
    
                    }
                    else
                    {
                        EndIndex = RecordCount / pagesize + 1;
    
                    }
    
                    if (Convert.ToInt32(this.TextIndex1.Text.Trim()) > EndIndex)
                    {
                        HyeyClass.Web.MessageBox.Show(this, "索引值超出范围,最大页面索引为:" + EndIndex.ToString());
                        return;
    
                    }
    
                    BindDate(Convert.ToInt32(this.TextIndex1.Text.Trim()), getPageSize());
                }
                else if (getPageSize() > Convert.ToInt32(HiddenRecordCount.Value.ToString()))
                {
                    HyeyClass.Web.MessageBox.Show(this, "超出页面的总记录数!");
                    return;
                }
                else
                {
                    HyeyClass.Web.MessageBox.Show(this, "页面显示的医生个数无效!");
                    return;
                }
    
    
            }
    
    
    
    
            #endregion
    
            //搜索
            protected void imgBtnSearch_Click(object sender, ImageClickEventArgs e)
            {
                Response.Redirect("SubjectList.aspx?q_name=" + TxtSubName.Text + "&q_cdrug=" + TxtConDrugs.Text + "&q_kn=" + ddlSubType.SelectedValue.ToString() );
            }
    
            protected void imgBtnAdd_Click(object sender, ImageClickEventArgs e)
            {
                Response.Redirect("AddSubject.aspx");
            }
    
    
    
        }
    }
    
    
  • 相关阅读:
    AndRodi Strudio中的按钮时件
    Intent(三)向下一个活动传递数据
    Intent(二)隐式调用intent
    用PopupWindow做下拉框
    环形进度条
    Android Studio分类整理res/Layout中的布局文件(创建子目录)
    Android无需申请权限拨打电话
    使用ViewPager切换Fragment时,防止频繁调用OnCreatView
    定制 黑色描边、白色背景、带圆角 的背景
    Android 底部弹出Dialog(横向满屏)
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1689799.html
Copyright © 2011-2022 走看看