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 System.Data.SqlClient;

public partial class WTOSYSadmin_news_wordlinkedit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
            switch (Request.QueryString["doing"])
            {
                case "del":
                    if (Doadmin.Exec("delete from jobmag where id=" + Request.QueryString["id"]))
                    {
                        Response.Write("<script>alert('删除成功');location.href('job.aspx')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('此次操作失败');</script>");
                    }
                    break;
                case "open":
                    if (Doadmin.Exec("update jobmag set isfp='y' where id=" + Request.QueryString["id"]))
                    {
                        Response.Write("<script>alert('操作成功');location.href('job.aspx')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('此次操作失败');</script>");
                    }
                    break;
                case "close":
                    if (Doadmin.Exec("update jobmag set isfp='n' where id=" + Request.QueryString["id"]))
                    {
                        Response.Write("<script>alert('操作成功');location.href('job.aspx')</script>");
                    }
                    else
                    {
                        Response.Write("<script>alert('此次操作失败');</script>");
                    }
                    break;
                case "edit":
                    if (!IsPostBack)
                    {
                        SqlConnection conn = CDatabase.wtoconn();
                        conn.Open();
                        SqlCommand smd = new SqlCommand("select * from jobmag where id=" + Request.QueryString["id"], conn);
                        SqlDataReader sdr = smd.ExecuteReader();
                        sdr.Read();
                        if (sdr.GetString(7).ToString().Trim() == "y")
                        {
                            this.y.Checked = true;
                        }
                        else
                        {
                            this.n.Checked = true;
                        }
                        this.jobtitle.Text = sdr.GetString(1);
                        this.jobcount.Text =Convert.ToString(sdr.GetInt32(2));
                        this.jobbm.Text = sdr.GetString(3);
                        this.cont.Text = sdr.GetString(5);
                    }
                    this.LinkButton3.Visible = false;
                    this.LinkButton1.Visible = true;
                    this.LinkButton1.Click += new EventHandler(LinkButton3_Click);
                    break;
            }
        
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string isfp, jobtitle, jobcount, jobbm, cont;
        if(y.Checked)
        {
            isfp="y";
        }
        else
        {
             isfp="n";
        }

        jobtitle=this.jobtitle.Text;
        jobcount=this.jobcount.Text;
        jobbm=this.jobbm.Text;
        cont=this.cont.Text;

        if (Doadmin.Exec("insert into jobmag(jobtitle,jobcount,jobbm,jobaddtime,cont,isfp) values ('"+jobtitle+"',"+jobcount+",'"+jobbm+"','"+DateTime.Now.ToString()+"','"+cont+"','"+isfp+"')"))
        {
            Response.Write("<script>alert('添加成功');location.href('job.aspx')</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败');</script>");
        }
    }
    protected void LinkButton3_Click(object sender, EventArgs e)
    {
        string isfp, jobtitle, jobcount, jobbm, cont;
        if (y.Checked)
        {
            isfp = "y";
        }
        else
        {
            isfp = "n";
        }

        jobtitle = this.jobtitle.Text;
        jobcount = this.jobcount.Text;
        jobbm = this.jobbm.Text;
        cont = this.cont.Text;
        if (Doadmin.Exec("update jobmag set jobtitle='" + jobtitle + "',jobcount='" + jobcount + "',jobbm='" + jobbm + "',jobaddtime='" + DateTime.Now.ToString() + "',cont='" + cont + "',isfp='" + isfp + "' where id="+Request.QueryString["id"]))
        {
            Response.Write("<script>alert('发布成功');location.href('job.aspx')</script>");
        }
        else
        {
            Response.Write("<script>alert('此次操作失败');</script>");
        }
    }

}
