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 hqgl.dept;
using WebMessageBox;
using System.Xml;
using hqgl.user;
public partial class general_dept_dept_edit : System.Web.UI.Page
{
    public deptinfo dinfo=new deptinfo();
    protected void Page_Load(object sender, EventArgs e)
    {
        userchuli uch = new userchuli();
        //uch.user_yanzheng();
        string id = Request.QueryString["id"];
        if (string.IsNullOrEmpty(id))
            MessageBox.Show("无效请求，页面已关闭", true);
        if(!Page.IsPostBack)
            DataLoad(id);
    }
    public void DataLoad(string id)
    {
        deptchuli dch=new deptchuli();
        dinfo=dch.Dept_GetByID(id);
        if(dinfo==null)
            MessageBox.Show("无效请求，页面已关闭", true);
        ListItemCollection lic = dch.Make_DropList();
        foreach (ListItem li in lic)
        {
            if (li.Value == dinfo.DEPT_PARENT)
                li.Selected = true;
            Select1.Items.Add(li);
        }
        if (dinfo == null)
            MessageBox.Show("数据加载失败", true);
    }
    protected void Submit1_ServerClick(object sender, EventArgs e)
    {
        deptinfo dinfo = new deptinfo();
        dinfo.dept_no = Request["DEPT_NO"];
        dinfo.dept_name = Request["DEPT_NAME"];
        dinfo.tel_no = Request["TEL_NO"];
        dinfo.fax_no = Request["FAX_NO"];
        dinfo.DEPT_PARENT = Request["Select1"];
        dinfo.DEPT_FUNC = Request["DEPT_FUNC"];
        dinfo.dept_id = Request["DEPT_ID"];
        deptchuli dch = new deptchuli();
        int res= dch.Dept_Edit(dinfo);
        if (res != 1)
            MessageBox.Show("修改失败", "dept_edit.aspx?id=" + dinfo.dept_id);
        else
        {
            UpDate();
            MessageBox.Show("修改成功", "dept_edit.aspx?id=" + dinfo.dept_id);            
        }
    }
    protected void Button1_ServerClick(object sender, EventArgs e)
    {
        string id = Request["DEPT_ID"];
        deptchuli dpc = new deptchuli();
        int res=dpc.Dept_Delete(id);
        if (res != 1)
            MessageBox.Show("删除失败", "default.aspx");
        else
        {
            UpDate();
            MessageBox.Show("删除成功", "default.aspx");            
        }
    }
    public void UpDate()
    {
        Response.Write("<script>parent.document.getElementById(\"left\").src=\"./dept/tree.aspx\"</script>");
    }
}
