private void BindData()
    {
        JN_Journal m = new JN_JournalBLL((int)ViewState["ID"]).Model;

        Org_StaffBLL staff = new Org_StaffBLL(m.Staff, true);
        select_Staff.SelectValue = m.Staff.ToString();
        select_Staff.SelectText = staff.Model.RealName;
        select_Staff.Enabled = false;
        Org_PositionBLL position = new Org_PositionBLL(staff.Model.Position);
        lbl_Position.Text = position.Model.Name;

        ddl_JournalType.SelectedValue = m.JournalType.ToString();
        ddl_JournalType_SelectedIndexChanged(null, null);
        ddl_JournalType.Enabled = false;

        tbx_begindate.Text = m.BeginTime.ToString("yyyy-MM-dd");
        tbx_enddate.Text = m.EndTime.ToString("yyyy-MM-dd");
        try
        {
            ddl_BeginHour.SelectedValue = m.BeginTime.Hour.ToString("d2");
            ddl_BeginMinute.SelectedValue = m.BeginTime.Minute.ToString("d2");
            ddl_EndHour.SelectedValue = m.EndTime.Hour.ToString("d2");
            ddl_EndMinute.SelectedValue = m.EndTime.Minute.ToString("d2");
        }
        catch { }

        ddl_WorkingClassify.SelectedValue = m.WorkingClassify.ToString();
        ddl_WorkingClassify_SelectedIndexChanged(null, null);
        ddl_WorkingClassify.Enabled = false;

        pl_detail.BindData(m);

        rbl_HasSynergeticStaff_SelectedIndexChanged(null, null);

        select_RelateClient_SelectChange(null, null);
        if (ddl_RelateLinkMan.Items.FindByValue(m.RelateLinkMan.ToString()) != null)
            ddl_RelateLinkMan.SelectedValue = m.RelateLinkMan.ToString();

        if (m.WorkingClassify == 1 && m.RelateLinkMan > 0)
        {
            //客户拜访
            bt_AddNewClient.OnClientClick = "javascript:OpenClientInput(" + m.ID.ToString() + "," + m.RelateLinkMan + ",0)";
            bt_AddNewClient.Enabled = true;
        }
        else if (m.WorkingClassify == 3 && !string.IsNullOrEmpty(m["RelateActivity"]))
        {
            //活动举办
            bt_AddNewClient.OnClientClick = "javascript:OpenClientInput(" + m.ID.ToString() + ",0," + m["RelateActivity"] + ")";
            bt_AddNewClient.Enabled = true;
        }
        else
        {
            bt_AddNewClient.Enabled = false;
        }
        #region 显示日志填报时的IP地址
        TextBox tbx_IPAddress = (TextBox)pl_detail.FindControl("JN_Journal_IPAddress");
        if (m["IPAddress"] != "" && m["IPLocation"] == "")
        {
            TextBox tbx_IPLocation = (TextBox)pl_detail.FindControl("JN_Journal_IPLocation");
            userAddress = Const_IPLocationBLL.FindByIP(Request.UserHostAddress);
            if (tbx_IPLocation != null) tbx_IPLocation.Text = userAddress != null ? userAddress.Location : "";
        }
        #endregion

        Label lbl_InsertStaff = (Label)pl_detail.FindControl("JN_Journal_InsertStaff");

        if (lbl_InsertStaff != null)
        {
            Org_StaffBLL _staff = new Org_StaffBLL(m.InsertStaff, true);
            Org_PositionBLL _position = new Org_PositionBLL(_staff.Model.Position);
            lbl_InsertStaff.Text = lbl_InsertStaff.Text + "(职位:" + _position.Model.Name + ")";
        }

        if (m.InsertStaff != (int)Session["UserID"] || m.ApproveFlag == 1 || (DateTime.Today - m.InsertTime.Date).Days > 7)
        {
            ddl_JournalType.Enabled = false;
            tbx_begindate.Enabled = false;
            ddl_WorkingClassify.Enabled = false;
            ddl_BeginHour.Enabled = false;
            ddl_BeginMinute.Enabled = false;
            ddl_EndHour.Enabled = false;
            ddl_EndMinute.Enabled = false;

            pl_detail.SetControlsEnable(false);
            TextBox tbx_remark = pl_detail.FindControl("JN_Journal_Remark") != null ?
                (TextBox)pl_detail.FindControl("JN_Journal_Remark") : null;
            if (tbx_remark != null)
            {
                tbx_remark.Enabled = true;
                tbx_remark.ReadOnly = true;
            }
            UploadFile1.CanDelete = false;
            UploadFile1.CanUpload = false;
            bt_OK.Visible = false;
            bt_Delete.Visible = false;
        }

        if ((DateTime.Today - m.InsertTime.Date).Days > 0) bt_Delete.Visible = false;       //只能删除当日填写的日志

        #region 展示附件
        UploadFile1.RelateID = (int)ViewState["ID"];
        UploadFile1.RelateType = 90;
        UploadFile1.BindGrid();
        #endregion

        int commentcounts = JN_JournalCommentBLL.GetModelList("JournalID=" + ViewState["ID"].ToString()).Count;
        lb_CommentCounts.Text = commentcounts.ToString();
        if (commentcounts > 0)
        {
            table_comment.Visible = true;
            BindGridList();
            btn_LookComment.Visible = false;
        }
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        #region 初始化页面控件
        Page.ClientScript.RegisterClientScriptInclude("meizzDate", Page.ResolveClientUrl("~/App_Themes/basic/meizzDate.js"));

        select_RelateClient = (MCSSelectControl)pl_detail.FindControl("JN_Journal_RelateClient");
        if (select_RelateClient != null)
            select_RelateClient.SelectChange += new SelectChangeEventHandler(select_RelateClient_SelectChange);

        ddl_RelateLinkMan = (DropDownList)pl_detail.FindControl("JN_Journal_RelateLinkMan");
        if (ddl_RelateLinkMan != null)
        {
            ddl_RelateLinkMan.DataTextField = "Name";
            ddl_RelateLinkMan.DataValueField = "ID";
        }

        rbl_HasSynergeticStaff = (RadioButtonList)pl_detail.FindControl("JN_Journal_HasSynergeticStaff");
        if (rbl_HasSynergeticStaff != null)
        {
            rbl_HasSynergeticStaff.AutoPostBack = true;
            rbl_HasSynergeticStaff.SelectedIndexChanged += new EventHandler(rbl_HasSynergeticStaff_SelectedIndexChanged);
        }

        ddl_RelateActivity = (DropDownList)pl_detail.FindControl("JN_Journal_RelateActivity");
        if (ddl_RelateActivity != null)
        {
            ddl_RelateActivity.DataTextField = "Topic";
            ddl_RelateActivity.DataValueField = "ID";
            ddl_RelateActivity.AutoPostBack = true;
            ddl_RelateActivity.SelectedIndexChanged += new EventHandler(ddl_RelateActivity_SelectedIndexChanged);
        }
        #endregion

        // 在此处放置用户代码以初始化页面
        if (!Page.IsPostBack)
        {
            #region 获取页面参数
            ViewState["ID"] = Request.QueryString["ID"] != null ? Int32.Parse(Request.QueryString["ID"]) : 0;
            #endregion

            BindDropDown();

            if ((int)ViewState["ID"] != 0)
            {
                if (rbl_HasSynergeticStaff != null) rbl_HasSynergeticStaff.SelectedValue = "2";    //默认非协同拜访
                BindData();
            }
            else
            {

                if (Request.QueryString["Day"] != null && Request.QueryString["Day"] != "0")
                    tbx_begindate.Text = DateTime.Today.AddDays(int.Parse(Request.QueryString["Day"]) - DateTime.Today.DayOfYear).ToString("yyyy-MM-dd");
                else
                    tbx_begindate.Text = DateTime.Today.ToString("yyyy-MM-dd");

                #region 获取日志填报人信息
                Org_StaffBLL staff = new Org_StaffBLL((int)Session["UserID"], true);
                select_Staff.SelectText = staff.Model.RealName;
                select_Staff.SelectValue = Session["UserID"].ToString();
                Org_PositionBLL position = new Org_PositionBLL(staff.Model.Position);
                lbl_Position.Text = position.Model.Name;

                MCSTreeControl tr_OfficialCity = pl_detail.FindControl("JN_Journal_OfficialCity") != null ? (MCSTreeControl)pl_detail.FindControl("JN_Journal_OfficialCity") : null;
                if (tr_OfficialCity != null) tr_OfficialCity.SelectValue = staff.Model.OfficialCity.ToString();
                #endregion

                #region 获取本机IP

                TextBox tbx_IPAddress = pl_detail.FindControl("JN_Journal_IPAddress") != null ? (TextBox)pl_detail.FindControl("JN_Journal_IPAddress") : null;
                if (tbx_IPAddress != null)
                {
                    tbx_IPAddress.Text = Request.UserHostAddress;

                    TextBox tbx_IPLocation = pl_detail.FindControl("JN_Journal_IPLocation") != null ? (TextBox)pl_detail.FindControl("JN_Journal_IPLocation") : null;
                    userAddress = Const_IPLocationBLL.FindByIP(Request.UserHostAddress);
                    if (tbx_IPLocation != null) tbx_IPLocation.Text = userAddress != null ? userAddress.Location : "";
                }
                #endregion

                #region 新增日志时,联系人字段不可编辑
                if (ddl_RelateLinkMan != null)
                {
                    ddl_RelateLinkMan.Items.Clear();
                    ddl_RelateLinkMan.Enabled = false;
                }
                #endregion

                pl_detail.SetPanelVisible("Panel_OA_JournalDetail_02", false);
                pl_detail.SetPanelVisible("Panel_OA_JournalDetail_03", false);
                pl_detail.SetPanelVisible("Panel_OA_JournalDetail_04", false);

                #region 默认无领导协同拜访
                if (rbl_HasSynergeticStaff != null)
                {
                    rbl_HasSynergeticStaff.SelectedValue = "2";    //默认非协同拜访
                    rbl_HasSynergeticStaff_SelectedIndexChanged(null, null);
                }
                #endregion

                bt_AddNewClient.Visible = false;
                bt_Delete.Visible = false;
                tbl_comment.Visible = false;
                UploadFile1.Visible = false;
                bt_ToEvectionRoute.Visible = false;
            }
        }
        #region 注册脚本
        string script = "function OpenClientInput(Journalid,OfferMan,Activityid){\r\n";
        script += "window.open('../../CSO/CSO_SampleOfferDetail.aspx?JournalID='+Journalid+'&OfferMan='+OfferMan+'&ActivityID='+Activityid);}";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "OpenClientInput", script, true);
        #endregion
    }