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;

          namespace zj123.UI.images.News
          {
              public partial class NewsManage:zj123.BLL.AdminPage
              {
                  protected void Page_Load(object sender, EventArgs e)
                  {
                      this.BtShanChu.Attributes.Add("onclick","return confirm('確定要刪除么?')");
                      if (!Page.IsPostBack)
                      {
                          DoAjax();
                          this.LoadType(this.DdlType, this.Db.GetTable("select * from NewsSort where Column_Depth=1"));
                          BindData();
                      }
                  }
                  public void LoadType(DropDownList ddl, DataTable dt)
                  {
                      if (dt != null)
                      {
                          if (dt.Rows.Count > 0)
                          {
                              for (int i = 0; i < dt.Rows.Count; i++)
                              {
                                  ddl.Items.Add(new ListItem(GetSpace(Convert.ToInt32(dt.Rows[i]["Column_Depth"]) - 1) + Convert.ToString(dt.Rows[i]["Column_Name"]), Convert.ToString(dt.Rows[i]["Column_ID"])));
                                  DataTable dtTemp = this.Db.GetTable("select * from NewsSort where Parent_ID=@Parent_ID", new System.Data.SqlClient.SqlParameter("@Parent_ID", Convert.ToString(dt.Rows[i]["Column_ID"])));
                                  if (dtTemp != null)
                                  {
                                      if (dtTemp.Rows.Count > 0)
                                      {
                                          LoadType(DdlType, dtTemp);
                                      }
                                  }
                              }

                          }
                      }
                  }
                  public string GetSpace(int tempint)
                  {
                      string s = "";
                      for (int i = 0; i < tempint; i++)
                      {
                          s += "";
                      }
                      return s;
                  }
                  public void DoAjax()
                  {

                      string state = "0";
                      string isAjax = this.GetRequest("isAjax").ToLower();

                      if (isAjax == "true")
                      {
                          string action = this.GetRequest("action").ToString();
                          string values = this.GetRequest("values").ToString();
                          switch (action)
                          {
                              case "tuijian":
                                  state = this.Db.GetState("update News set IsCommand=case IsCommand when 1 then 0 else 1 end,CommandTime=getdate() where Gid=@Gid", new System.Data.SqlClient.SqlParameter("@Gid", values)) ? ("1") : ("0");
                                  break;
                              case "zhiding":
                                  state = this.Db.GetState("update News set IsTop=case IsTop when 1 then 0 else 1 end,TopTime=getdate() where Gid=@Gid", new System.Data.SqlClient.SqlParameter("@Gid", values)) ? ("1") : ("0");
                                  break;
                              case "toutiao":
                                  state = this.Db.GetState("update News set IsHead=case IsHead when 1 then 0 else 1 end,HeadTime=getdate() where Gid=@Gid", new System.Data.SqlClient.SqlParameter("@Gid", values)) ? ("1") : ("0");
                                  break;
                              default:
                                  break;
                          }
                          Response.Clear();
                          Response.Write(state);
                          Response.End();
               
                  }
                  }
                  public void BindData()
                  {
                      string Key_Word = this.GetRequest("idKeyWord");
                      this.TbKeyword.Text = Key_Word;
                      string typeid = this.GetRequest("typeid");
                      if (typeid.Length > 0)
                      {
                          this.DdlType.SelectedValue = typeid;
                      }
                      string isCommand = this.GetRequest("isCommand");
                      string isTop = this.GetRequest("isTop");
                      Key_Word = Key_Word.Length > 0 ? (" and Title like '%" + Key_Word + "%'") : ("");
                      isCommand = isCommand.Length > 0 ? (" and isCommand=" + isCommand) : ("");
                      typeid = typeid.Length > 0 ? (" and typeid='" + typeid+"'") : ("");
                      isTop = isTop.Length > 0 ? (" and isTop=" + isTop) : ("");
                      this.TableName = "News";
                      this.Pid = "Gid";
                      this.Columns = "Gid,(select Column_Name from NewsSort where Column_id=News.Typeid) TypeName,Title,IsCommand,IsTop,AddTime,isHead";
                      this.PageSize = 20;
                      this.Where = string.Format(" 1=1{0}{1}{2}{3}", Key_Word, isCommand, isTop, typeid);//, C_ID);
                      this.Order = "AddTime desc";
                      this.gvList.DataSource = this.PageData;
                      this.gvList.DataBind();
                      this.Pages1.NumCount = Convert.ToInt32(this.Db.GetOne(string.Format("select count(1) from {0} where{1}", TableName, Where)));
                      this.Pages1.PageSize = this.PageSize;
                      this.Pages1.CurrentPage = this.CurrentPage;
                  }

                  protected void gvList_RowDataBound(object sender, GridViewRowEventArgs e)
                  {
                      if (e.Row.RowIndex != -1)
                      {
                          DataRowView drv = e.Row.DataItem as DataRowView;
                          string isCommand = Convert.ToString(drv["IsCommand"]);
                          string isTop     = Convert.ToString(drv["IsTop"]);
                          string isHead = Convert.ToString(drv["isHead"]);               
                          //string.Format("<a href='NewsEdit.aspx?gid={0}'>修改</a>", Convert.ToString(drv["Gid"])) +
                          e.Row.Cells[0].Text = string.Format(this.CheckBoxString, Convert.ToString(drv["Gid"])) ;
                          //"string.Format(<a href='NewsEdit.aspx?gid={0}'>修改</a>", Convert.ToString(drv["Gid"]))+
                          // + "<a href=\"#\" onclick=\"new Ajax().getData('"+Request.Path.ToString()+"','isAjax=true&action=tuijian&values=" + Convert.ToString(drv["Gid"]) + "',function(obj){if(obj.responseText=='1'){alert('操作成功!');document.location=document.location;}else{alert('操作失敗!請重試!');}})\">"+isCommand=="1"?("推薦"):("取消推薦")+"</a>"+
                          string editString = string.Format("<a href='NewsEdit.aspx?gid={0}'>修改</a>", Convert.ToString(drv["Gid"])) + "&nbsp;&nbsp;" + "<a  onclick=\"new Ajax().getData('" + Request.Path.ToString() + "','isAjax=true&action=tuijian&values=" + Convert.ToString(drv["Gid"]) + "',function(obj){if(obj.responseText=='1'){alert('操作成功!');document.location=document.location;}else{alert('操作失敗!請重試!');}}) \" href=\"void(0)\">" + (isCommand == "1" ? ("取消推薦") : ("推薦")) + "</a>" + "&nbsp;&nbsp;" + ("<a href=\"void(0)\"  onclick=\"new Ajax().getData('" + Request.Path.ToString() + "','isAjax=true&action=zhiding&values=" + Convert.ToString(drv["Gid"]) + "',function(obj){if(obj.responseText=='1'){alert('操作成功!');document.location=document.location;}else{alert('操作失敗!請重試!');}})\">" + (isTop == "1" ? ("取消置頂 ") : ("置頂")) + "</a>") + "&nbsp;&nbsp;" + ("<a href=\"void(0)\"  onclick=\"new Ajax().getData('" + Request.Path.ToString() + "','isAjax=true&action=toutiao&values=" + Convert.ToString(drv["Gid"]) + "',function(obj){if(obj.responseText=='1'){alert('操作成功!');document.location=document.location;}else{alert('操作失敗!請重試!');}})\">" + (isHead == "1" ? ("取消頭條 ") : ("頭條")) + "</a>");
                          e.Row.Cells[4].Text = editString;
                      }
                  }

                  protected void BtShanChu_Click(object sender, EventArgs e)
                  {
                      ActionDo("delete from news where Gid={0}");
                  }
                  public void ActionDo(string sql)
                  {
                      ArrayList al = this.GetSqls(sql);
                      if (this.Db.GetTranState(al))
                      {
                          this.ShowMessage("操作成功!", "document.location=document.location");
                      }
                      else
                      {
                          this.ShowMessage("操作失敗!", "history.go(-1)");
                      }
                  }

                  protected void BtSearch_Click(object sender, EventArgs e)
                  {
                      Response.Redirect(Request.Path.ToString() + "?idKeyWord="+this.TbKeyword.Text.Trim()+"&typeid="+this.DdlType.SelectedValue.Trim());
                  }
              }
          }

          posted on 2009-06-10 18:18 sanmao 閱讀(53) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 资中县| 嘉义市| 渑池县| 新沂市| 葵青区| 彰化市| 霍城县| 台南县| 金阳县| 浙江省| 牙克石市| 惠州市| 望奎县| 吴川市| 故城县| 即墨市| 灵丘县| 邹平县| 陈巴尔虎旗| 诏安县| 双城市| 抚远县| 项城市| 永康市| 兴安盟| 元江| 肥东县| 台北市| 普兰县| 宁乡县| 铜陵市| 晋州市| 柳江县| 南部县| 平邑县| 绥化市| 田阳县| 通道| 马尔康县| 友谊县| 康马县|