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 }
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 bt_Save_Click(object sender, EventArgs e) { if (ViewState["WorkingPlanData"] != null) { DataTable dt = (DataTable)ViewState["WorkingPlanData"]; DateTime begindate = (DateTime)ViewState["BeginDate"]; DateTime enddate = (DateTime)ViewState["EndDate"]; #region 将界面中已选择的日志放入IList中 IList <JN_Journal> NewJournals = new List <JN_Journal>(); for (int i = 0; i < dt.Rows.Count; i++) { JN_Journal jn = null; DateTime day = begindate; while (day <= enddate) { if ((bool)dt.Rows[i]["J" + day.ToString("MMdd")]) { #region 新增日志 if (jn == null) { jn = new JN_Journal(); jn.Title = (string)dt.Rows[i]["Description"]; jn.OrganizeCity = new Org_StaffBLL((int)ViewState["PlanStaff"]).Model.OrganizeCity; jn.JournalType = 1; jn.Staff = (int)ViewState["PlanStaff"]; jn.BeginTime = day.AddHours(8.5); jn.EndTime = day.AddHours(17.5); jn.WorkingClassify = (int)dt.Rows[i]["WorkingClassify"]; if (jn.WorkingClassify == 1) { jn.RelateClient = (int)dt.Rows[i]["RelateClient"]; jn.Title = "[客户拜访]" + dt.Rows[i]["RelateClientName"] + jn.Title; } if (jn.WorkingClassify == 2) { jn.RelateStaff = (int)dt.Rows[i]["RelateStaff"]; jn["CCSynergeticStaff"] = "N"; jn.Title = "[协同拜访]" + dt.Rows[i]["RelateStaffName"] + jn.Title; } jn.OfficialCity = (int)dt.Rows[i]["OfficialCity"]; jn["IPAddress"] = Request.UserHostAddress; jn["IPLocation"] = Const_IPLocationBLL.FindByIP(Request.UserHostAddress).Location; jn.ApproveFlag = 2; jn.InsertStaff = (int)Session["UserID"]; NewJournals.Add(jn); //如果每天都生成一条独立的日志,则启用这一行 jn = null; } else { jn.EndTime = day.AddHours(17); } #endregion } else { jn = null; } day = day.AddDays(1); } } #endregion #region 将数据库中已存的计划与IList作比较,相同的从List中移除,不存在于List中的从数据中移除 JN_WorkingPlanBLL bll = new JN_WorkingPlanBLL((int)ViewState["PlanID"]); string con = "Staff = " + bll.Model.Staff.ToString() + " AND BeginTime BETWEEN '" + bll.Model.BeginDate.ToString("yyyy-MM-dd") + "' AND '" + bll.Model.EndDate.ToString("yyyy-MM-dd 23:59:59") + "' " + " AND JournalType = 1"; IList <JN_Journal> OrgJournals = JN_JournalBLL.GetModelList(con); foreach (JN_Journal orgitem in OrgJournals) { JN_Journal m = null; if (orgitem.WorkingClassify == 1) { m = NewJournals.FirstOrDefault(p => p.WorkingClassify == orgitem.WorkingClassify && p.RelateClient == orgitem.RelateClient && p.BeginTime.Date == orgitem.BeginTime.Date && p.EndTime.Date == orgitem.EndTime.Date); } else if (orgitem.WorkingClassify == 2) { m = NewJournals.FirstOrDefault(p => p.WorkingClassify == orgitem.WorkingClassify && p.RelateStaff == orgitem.RelateStaff && p.BeginTime.Date == orgitem.BeginTime.Date && p.EndTime.Date == orgitem.EndTime.Date); } else { m = NewJournals.FirstOrDefault(p => p.WorkingClassify == orgitem.WorkingClassify && p.OfficialCity == orgitem.OfficialCity && p.Title == orgitem.Title && p.BeginTime.Date == orgitem.BeginTime.Date && p.EndTime.Date == orgitem.EndTime.Date); } if (m == null) { new JN_JournalBLL(orgitem.ID).Delete(); //删除日志 } else { NewJournals.Remove(m); } } #endregion #region 将剩余下来的计划,新增到数据库中 foreach (JN_Journal item in NewJournals) { JN_JournalBLL jnbll = new JN_JournalBLL(); jnbll.Model = item; jnbll.Add(); } #endregion BindGrid(); MessageBox.ShowAndRedirect(this, "与该计划相关联的实际工作日志填报保存成功!", "JournalOnWorkingPlan.aspx?PlanID=" + ViewState["PlanID"].ToString()); } }