Ejemplo n.º 1
0
        /// <summary>
        /// 添加批次
        /// </summary>
        public void savePlan()
        {
            //获取参数
            string planName  = Context.Request["planName"].ToString(),
                   startTime = Context.Request["startTime"].ToString(),
                   endTime   = Context.Request["endTime"].ToString(),
            //college = Context.Request["college"].ToString(),
                   planstate = Context.Request["state"].ToString();

            try
            {
                //获取院系id
                Teacher    teacher    = (Teacher)Session["user"];
                string     account    = teacher.TeaAccount;
                TeacherBll teacherBll = new TeacherBll();
                loginUser = teacherBll.GetModel(account);
                College ColID = loginUser.college;

                if (planName != "" && startTime != "" && endTime != "" && state.ToString() != "")
                {
                    //int collegeId = int.Parse(college),
                    int state = int.Parse(planstate);
                    //字符串转日期
                    string   start   = Convert.ToDateTime(startTime).ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime startdt = Convert.ToDateTime(start);
                    string   end     = Convert.ToDateTime(endTime).ToString("yyyy-MM-dd HH:mm:ss");
                    DateTime enddt   = Convert.ToDateTime(end);

                    //判断当开始时间在结束时间之后时,不能执行添加
                    TimeSpan ts = enddt - startdt;
                    if (ts.Days >= 1)
                    {
                        Plan plan = new Plan()
                        {
                            PlanName  = planName,
                            StartTime = startdt,
                            EndTime   = enddt,
                            State     = state,
                            college   = ColID
                        };
                        PlanBll pBll   = new PlanBll();
                        Result  result = pBll.Insert(plan);
                        if (result == Result.添加成功)
                        {
                            LogHelper.Info(this.GetType(), loginUser.TeaAccount + loginUser.TeaName + "-添加批次");
                            Response.Write("添加成功");
                            Response.End();
                        }
                        else
                        {
                            Response.Write("添加失败");
                            Response.End();
                        }
                    }
                    else
                    {
                        Response.Write("开始与结束时间间隔必须大于1天");
                        Response.End();
                    }
                }
                else
                {
                    Response.Write("以上内容不能出现未填项");
                    Response.End();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(this.GetType(), ex);
            }
        }