using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Text;

public partial class Ajax_Ajax_Personnel : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            Response.Write(InitWorkOrPersonnel());
        }
    }
    #region 绑定职位或人员
    /// <summary>
    /// 绑定职位或人员
    /// </summary>
    /// <returns></returns>
    public string InitWorkOrPersonnel()
    {
        if (!string.IsNullOrEmpty(Request["departmentIds"]))//部门id不为空
        {
            string work = "";
            DataSet ds = SqlHelper.GetDataSet("SELECT WorkId,WorkName FROM dbo.tabP_Work WHERE DepartmentId=" + ConvertHelper.GetInteger(Request["departmentIds"]) + " AND State=1", "constring");
            if (ds.Tables[0].Rows.Count > 0)
            {
                StringBuilder stb = new StringBuilder();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    stb.Append(ds.Tables[0].Rows[i]["WorkName"]);//职位名
                    stb.Append(",");
                    stb.Append(ds.Tables[0].Rows[i]["WorkId"]);//职位id
                    stb.Append(",");
                }
                work = ConvertHelper.GetString(stb).TrimEnd(',');
            }
            return work;
        }
        else if (!string.IsNullOrEmpty(Request["workIds"]))//职位不为空
        {
            string personnel = "";
            DataSet ds = SqlHelper.GetDataSet("SELECT Pid,PersonnelName FROM dbo.tabP_Personnel WHERE WorkId=" + ConvertHelper.GetInteger(Request["workIds"]) + " AND State=1", "constring");
            if (ds.Tables[0].Rows.Count > 0)
            {
                StringBuilder stb = new StringBuilder();
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    stb.Append(ds.Tables[0].Rows[i]["PersonnelName"]);//人员名
                    stb.Append(",");
                    stb.Append(ds.Tables[0].Rows[i]["Pid"]);//职位id
                    stb.Append(",");
                }
                personnel = ConvertHelper.GetString(stb).TrimEnd(',');
            }
            return personnel;
        }
        else
        {
            return "";
        }
    }
    #endregion
}