코드 코드 코드 코드

14218 단어 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");

        }







    }

}




좋은 웹페이지 즐겨찾기