private void LoadKnowledge()
 {
     KnowledgePet knowledge = new KnowledgePet();
     List<CTKnowledgePet> list = new List<CTKnowledgePet>();
     list=knowledge.GetKnowledgePetList();
     DropDownList1.DataSource = list;
     DropDownList1.DataTextField = "KnowledgeTitle";
     DropDownList1.DataValueField = "KnowledgeID";
     DropDownList1.DataBind();
 }
        protected void Button3_Click(object sender, EventArgs e)
        {
            int pageNumb =int.Parse( TextBox2.Text.Trim().ToString());
            int pagePerPage = CPetCareConfiguration.PetPerPageNumbers;

            List<CVKnowledgePet> list = new List<CVKnowledgePet>();
            KnowledgePet knowleget = new KnowledgePet();
            int howmanyPages = 0;
            list = knowleget.GetPetKnowledgePerPageList(pageNumb, pagePerPage,out howmanyPages);
            GridView1.DataSource = list;
            GridView1.DataBind();
        }
 //单机删除按钮
 protected void BtnDelete_Click(object sender, EventArgs e)
 {
     KnowledgePet knowledgePet = new KnowledgePet();
     int selectNumber = 0;
     for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
     {
         CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxs");
         if (cbox.Checked == true)
         {
             string sqlstr = GridView1.DataKeys[i].Value.ToString();
             knowledgePet.DeleteKnowledgePet(sqlstr);
             selectNumber++;
         }
     }
     BindGridNew(1);
 }
 //
 // GET: /Knowledge/
 /// <summary>
 /// 获取宠物知识的信息
 /// </summary>
 /// <param name="pageIndex">当前页码</param>
 /// <param name="limit">每页的显示条数</param>
 /// <returns></returns>
 public JsonResult Index(int pageIndex,int limit)
 {
     KnowledgePet knowledge = new KnowledgePet();
     PagingModel<WebCommonModel> _pageKnowledge = new PagingModel<WebCommonModel>();
     List<WebCommonModel> commonList = new List<WebCommonModel>();
     List<CVKnowledgePet> knowledgeList = new List<CVKnowledgePet>();
     //获取总页数
     int count = 0;
     try
     {
         knowledgeList = knowledge.GetPetKnowledgePerPageList(pageIndex,limit,out count);
         commonList = CommonDao.DataTransferToKnowledgeWebCommonModelList(knowledgeList);
         _pageKnowledge.total = count;
         _pageKnowledge.records = commonList;
     }
     catch (Exception ex)
     {
         throw ex;
     }
     return Json(_pageKnowledge, JsonRequestBehavior.AllowGet);
 }
 protected void BtnAdd_Click(object sender, EventArgs e)
 {
     //获取本机IP
     IPHostEntry ipe = Dns.GetHostEntry(Dns.GetHostName());
     IPAddress ipa = ipe.AddressList[0];
     string userID = dpUsers.SelectedValue.ToString();
     string knowledgeID =Guid.NewGuid().ToString();
     string addressID = dpAddress.SelectedValue.ToString();
     string petcategoryID = dpCategory.SelectedValue.ToString();
     string weiboID = "";
     string knowledgeTitle = tbKnowLedgeTitle.Text.Trim().ToString();
     string knowledgeTime = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
     string ip = ipa.ToString();
     string content = tbContent.Text.Trim().ToString();
     CTKnowledgePet knowledge = new CTKnowledgePet();
     knowledge.UserID = userID;
     knowledge.KnowledgeID = knowledgeID;
     knowledge.AddressID = addressID;
     knowledge.PetCategoryID = petcategoryID;
     knowledge.WeiBoID = weiboID;
     knowledge.KnowledgeTitle = knowledgeTitle;
     knowledge.KnowledgeTime = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
     knowledge.PriorityScore = 0;
     knowledge.IP = ip;
     knowledge.IsVisible = true;
     knowledge.LastEditTime = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss");
     knowledge.KnowledgeInfo = content;
     knowledge.FocusNum = 0;
     KnowledgePet knowledgePet = new KnowledgePet();
     int insertStatus=knowledgePet.InsertKnowledgePet(knowledge);
     if (insertStatus == 1)
     {
         Response.Write("<script>alert('添加成功!')</script>");
     }
     else
     {
         Response.Write("<script>alert('添加失败!')</script>");
     }
 }
 protected void BtnEdit_Click(object sender, EventArgs e)
 {
     int selectNumber = 0;
     string sqlstr = string.Empty;
     for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
     {
         CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBoxs");
         if (cbox.Checked == true)
         {
             sqlstr = GridView1.DataKeys[i].Value.ToString();
             selectNumber++;
         }
     }
     if (selectNumber > 1 || selectNumber < 1)
     {
         Response.Write("<script>alert('请选择一个!')</script>");
     }
     else
     {
         KnowledgePet knowledgePet = new KnowledgePet();
         CTKnowledgePet knowledgetable = new CTKnowledgePet();
         knowledgetable = knowledgePet.GetKnowledgePetByKnowledgeID(sqlstr);
         TextBox_KnowledgeID.Text = knowledgetable.KnowledgeID;
         TextBox_MissIDInfo.Text = knowledgetable.KnowledgeInfo;
         TextBox_AddressID.Text = knowledgetable.AddressID;
         TextBox_KnowledgeTime.Text = knowledgetable.KnowledgeTime.ToString();
         TextBox_KnowledgeTitle.Text = knowledgetable.KnowledgeTitle.ToString();
         TextBox_FocusNum.Text = knowledgetable.FocusNum.ToString();
         TextBox_IP.Text = knowledgetable.IP.ToString();
         TextBox_PetCategoryID.Text = knowledgetable.PetCategoryID.ToString();
         TextBox_PriorityScore.Text = knowledgetable.PriorityScore.ToString();
         TextBox_UserID.Text = knowledgetable.UserID.ToString();
         TextBox_WeiBoID.Text = knowledgetable.WeiBoID.ToString();
     }
 }
        private void BindGridNew(int pageNumber)
        {
            int perPage = CPetCareConfiguration.PetPerPageNumbers;
            List<CVKnowledgePet> list = new List<CVKnowledgePet>();
            KnowledgePet knowleget = new KnowledgePet();
            int howmany = 0;
            list = knowleget.GetPetKnowledgePerPageList(pageNumber, perPage, out howmany);
            GridView1.DataSource = list;
            GridView1.DataKeyNames = new string[] { "KnowledgeID"};
            GridView1.DataBind();
            int howmanyPages = 0;

            howmanyPages = int.Parse(Math.Ceiling((double)howmany / (double)perPage).ToString());
            List<int> listPage = new List<int>();
            for (int b = 1; b <= howmanyPages; b++)
            {
                listPage.Add(b);
            }
            ddPage.DataSource = listPage;
            ddPage.DataBind();
        }
 protected void Btn_Save_Click(object sender, EventArgs e)
 {
     if (TextBox_KnowledgeID.Text == "")
     {
         Response.Write("<script>alert('请选择一个编辑!')</script>");
     }
     else
     {
         CTKnowledgePet knowledgetable = new CTKnowledgePet();
         knowledgetable.KnowledgeID = TextBox_KnowledgeID.Text;
         knowledgetable.KnowledgeInfo = TextBox_MissIDInfo.Text;
         knowledgetable.AddressID = TextBox_AddressID.Text;
         knowledgetable.KnowledgeTime = TextBox_KnowledgeTime.Text.ToString();
         knowledgetable.KnowledgeTitle = TextBox_KnowledgeTitle.Text.ToString();
         knowledgetable.FocusNum = int.Parse(TextBox_FocusNum.Text.ToString());
         knowledgetable.IP = TextBox_IP.Text.ToString();
         knowledgetable.PetCategoryID = TextBox_PetCategoryID.Text.ToString();
         knowledgetable.PriorityScore = int.Parse(TextBox_PriorityScore.Text.ToString());
         knowledgetable.UserID = TextBox_UserID.Text.ToString();
         knowledgetable.WeiBoID = TextBox_WeiBoID.Text.ToString();
         knowledgetable.LastEditTime = DateTime.Now.ToShortDateString();
         KnowledgePet knowledgepet = new KnowledgePet();
         int editStatus = 0;
         editStatus = knowledgepet.EditKnowledgePet(knowledgetable);
         if (editStatus == 1)
         {
             Response.Write("<script>alert('Edit成功!')</script>");
         }
         else
         {
             Response.Write("<script>alert('Edit失败!')</script>");
         }
     }
 }
 private void LoadKnowledgeList()
 {
     List<CTKnowledgePet> knowledgeList = new List<CTKnowledgePet>();
     KnowledgePet knowledgePet = new KnowledgePet();
     knowledgeList = knowledgePet.GetKnowledgePetList();
     ddKnowledgeManageList.DataSource = knowledgeList;
     ddKnowledgeManageList.DataTextField = "KnowledgeTitle";
     ddKnowledgeManageList.DataValueField = "KnowledgeID";
     ddKnowledgeManageList.DataBind();
     ddKnowledgeList.DataSource = knowledgeList;
     ddKnowledgeList.DataTextField = "KnowledgeTitle";
     ddKnowledgeList.DataValueField = "KnowledgeID";
     ddKnowledgeList.DataBind();
 }
        private void GridViewBind(int pageNumb,string knowledgeID)
        {
            KnowledgePet knowledgepet = new KnowledgePet();
            List<CVKnowledgePetComment> list = new List<CVKnowledgePetComment>();
            int perPage = CPetCareConfiguration.PetPerPageNumbers;
            int howmany;
            list = knowledgepet.GetPetKnowledgeCommentPerPageList(knowledgeID, pageNumb, perPage, out howmany);
            int howmanyPages = 0;
            howmanyPages = int.Parse(Math.Ceiling((double)howmany / (double)perPage).ToString());
            List<int> listPage = new List<int>();
            for (int a = 1; a <= howmanyPages; a++)
            {
                listPage.Add(a);
            }
            ddPages.DataSource = listPage;
            ddPages.DataBind();

            GridView1.DataSource = list;
            GridView1.DataKeyNames = new string[] { "CommentID" };
            GridView1.DataBind();
        }