Ejemplo n.º 1
0
        /// <summary>
        /// 保存按钮点击事件执行方法
        /// </summary>
        protected void PageSave()
        {
            //ajax返回信息
            string resultmsg = "";
            //实例化工作计划实体
            MWorkPlan modelMWorkPlan = new MWorkPlan();
            //实例化业务层
            BIndividual bllBIndividual = new BIndividual();

            if (!string.IsNullOrEmpty(Utils.GetFormValue(hidId.UniqueID)))
            {
                //修改状态根据id获取计划实体
                modelMWorkPlan = bllBIndividual.GetWorkPlan(Utils.GetFormValue(hidId.UniqueID));
            }
            else
            {
                //计划时间
                modelMWorkPlan.IssueTime = DateTime.Now;
                //最后修改时间
                modelMWorkPlan.UpdateTime = DateTime.Now;
            }
            #region 显性属性(页面直接和用户交互)
            //计划标题
            string title = Utils.GetFormValue(txtTitle.UniqueID);
            //计划人
            string userName = Utils.GetFormValue(txtUserName.UniqueID);
            //部门id
            string departID = Utils.GetFormValue(this.SelectSection1.SelectIDClient);
            //部门名称
            string departName = Utils.GetFormValue(this.SelectSection1.SelectNameClient);
            //计划预计完成时间
            string dateTime = Utils.GetFormValue(txtDateTime.UniqueID);
            //计划内容
            string content = Utils.GetFormValue(txtContent.UniqueID);
            //附件上传
            string strUploadUrl = Utils.GetFormValue(UploadControl1.ClientHideID);

            #region  审批人列表
            //审批人
            string   strapprover = Utils.GetFormValue(this.SelectSection2.SellsNameClient);
            string[] approver    = { "" };
            if (strapprover != null && strapprover.Contains(','))
            {
                approver = strapprover.Split(',');
            }
            else
            {
                approver[0] = strapprover;
            }
            //审核人id
            string   strapproverId = Utils.GetFormValue(this.SelectSection2.SellsIDClient);
            string[] approverId    = { "" };
            if (strapproverId != null && strapproverId.Contains(','))
            {
                approverId = strapproverId.Split(',');
            }
            else
            {
                approverId[0] = strapproverId;
            }
            List <MWorkPlanCheck> list = new List <MWorkPlanCheck>();
            if (approver.Length > 0)
            {
                for (int i = 0; i < approver.Length; i++)
                {
                    MWorkPlanCheck modelMWorkPlanCheck = new MWorkPlanCheck();
                    if (approverId[i] != null)
                    {
                        //审批人id
                        modelMWorkPlanCheck.ApproverId = approverId[i];
                    }
                    //审批人姓名
                    modelMWorkPlanCheck.Approver = approver[i];
                    list.Add(modelMWorkPlanCheck);
                }
            }
            #endregion

            #region 实体赋值
            modelMWorkPlan.Title         = title;
            modelMWorkPlan.OperatorName  = userName;
            modelMWorkPlan.OperatorId    = "";
            modelMWorkPlan.DeptId        = Utils.GetInt(departID);
            modelMWorkPlan.Department    = departName;
            modelMWorkPlan.ScheduledTime = Utils.GetDateTime(dateTime);
            modelMWorkPlan.Remark        = content;

            #region 附件
            if (!string.IsNullOrEmpty(strUploadUrl))
            {
                //验证数据
                string[] strUploadList = strUploadUrl.Split('|');
                if (strUploadList.Length == 2)
                {
                    strUploadUrl = strUploadList[0] + "|" + strUploadList[1];
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(Utils.GetFormValue("hideOtherFile")))
                {
                    strUploadUrl = Utils.GetFormValue("hideOtherFile");
                }
            }

            modelMWorkPlan.UploadUrl = strUploadUrl;
            modelMWorkPlan.list      = list;
            #endregion
            #endregion
            #endregion

            #region 隐性属性(id之类)
            //系统公司id
            string companyid = SiteUserInfo.CompanyId;
            modelMWorkPlan.CompanyId = companyid;
            //计划人编号
            modelMWorkPlan.OperatorId = SiteUserInfo.UserId;
            #endregion
            //操作之后返回结果
            bool result = false;
            if (!string.IsNullOrEmpty(hidId.Value))
            {
                result = bllBIndividual.UpdWorkPlan(modelMWorkPlan);
                if (result)
                {
                    resultmsg = UtilsCommons.AjaxReturnJson("true", "修改成功");
                }
                else
                {
                    resultmsg = UtilsCommons.AjaxReturnJson("false", "修改失败,检查选用的数据是否正确");
                }
            }
            else
            {
                result = bllBIndividual.AddWorkPlan(modelMWorkPlan);
                if (result)
                {
                    resultmsg = UtilsCommons.AjaxReturnJson("true", "添加成功");
                }
                else
                {
                    resultmsg = UtilsCommons.AjaxReturnJson("false", "添加失败,检查选用的数据是否正确");
                }
            }
            Response.Clear();
            Response.Write(resultmsg);
            Response.End();
        }