Esempio n. 1
0
        internal bool AddQPapers(QPaper model)
        {
            bool result = false;

            try
            {
                string     query = "INSERT INTO papers (title, subject, description, path, status, facultyid, datetime, deptid) VALUES(@title, @subject, @description, @path, @status, @facultyid, @datetime, @deptid)";
                SqlCommand cmd   = new SqlCommand(query, Conn);

                cmd.Parameters.Add(new SqlParameter("title", model.Title));
                cmd.Parameters.Add(new SqlParameter("subject", model.Subject));
                cmd.Parameters.Add(new SqlParameter("description", model.Description));
                cmd.Parameters.Add(new SqlParameter("path", model.Path));
                cmd.Parameters.Add(new SqlParameter("status", model.Status));
                cmd.Parameters.Add(new SqlParameter("facultyid", model.FacultyID));
                cmd.Parameters.Add(new SqlParameter("datetime", model.DateTime));
                cmd.Parameters.Add(new SqlParameter("deptid", model.DeptID));

                Conn.Open();

                int rows = cmd.ExecuteNonQuery();
                if (rows > 0)
                {
                    result = true;
                }
            }
            catch (Exception exp)
            {
            }
            finally
            {
                Conn.Close();
            }
            return(result);
        }
Esempio n. 2
0
        /* Leaves operations ends here */

        internal List <QPaper> QPapers(bool View = true, int DeptID = 0, int FacultyID = 0)
        {
            DataTable     td   = new DataTable();
            List <QPaper> list = new List <QPaper>();

            try
            {
                string sqlquery = string.Empty;
                if (View) // View All
                {
                    sqlquery = $"SELECT * FROM papers ORDER BY paperid DESC";
                }
                else // View Specific
                {
                    string FaculQuery = string.Empty;
                    if (FacultyID > 0)
                    {
                        FaculQuery = "AND facultyid = " + FacultyID;
                    }
                    sqlquery = $"SELECT * FROM papers WHERE deptid = {DeptID} {FaculQuery} ORDER BY paperid DESC";
                }

                SqlCommand     cmd = new SqlCommand(sqlquery, Conn);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                Conn.Open();
                adp.Fill(td);
                Conn.Close();
                PrinciUtil princiUtil = new PrinciUtil();
                foreach (DataRow row in td.Rows)
                {
                    QPaper obj = new QPaper
                    {
                        ID          = Convert.ToInt32(row["paperid"]),
                        Title       = Convert.ToString(row["title"]),
                        Subject     = Convert.ToString(row["subject"]),
                        Description = Convert.ToString(row["description"]),
                        Path        = Convert.ToString(row["path"]),
                        Status      = Convert.ToInt32(row["status"]),
                        FacultyID   = Convert.ToInt32(row["facultyid"]),
                        DateTime    = Convert.ToDateTime(row["datetime"]),
                        DeptID      = Convert.ToInt32(row["deptid"])
                    };
                    obj.FacultyName = princiUtil.GetFacultyByID(obj.FacultyID).Name;
                    obj.DeptName    = princiUtil.GetDeptByID(obj.DeptID).Name;
                    list.Add(obj);
                }
            }
            catch (Exception)
            { }
            return(list);
        }
Esempio n. 3
0
        public ActionResult AddQuestionPapers(QPaper qPaper)
        {
            SetFacultyDetails();
            qPaper.Status    = 0;
            qPaper.FacultyID = FacultyDetails.ID;
            qPaper.DeptID    = FacultyDetails.DeptID;
            qPaper.DateTime  = DateTime.Now;
            string ImgUrl = string.Empty;

            try
            {
                string uniqueFileName = Guid.NewGuid().ToString() + "_" + qPaper.Image.FileName;
                if (qPaper.Image != null)
                {
                    string path = Server.MapPath("/Images/QPapers/");
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    qPaper.Image.SaveAs(path + uniqueFileName);
                    ImgUrl = "/Images/QPapers/" + uniqueFileName;
                }
            }
            catch
            { }

            qPaper.Path = ImgUrl;

            Common common = new Common();

            if (common.AddQPapers(qPaper))
            {
                Session["Notification"] = 1;
            }
            else
            {
                Session["Notification"] = 2;
            }
            return(RedirectToAction("QuestionPapers"));
        }
        /// <summary>
        /// 保存问卷信息
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public override async Task <RpcResult <SaveQPaperRsp> > SaveQPaperAsync(SaveQPaperReq req)
        {
            var res = new RpcResult <SaveQPaperRsp>();

            if (req.Questions.Count == 0)
            {
                res.Code = ErrorCodes.PARAMS_VALIDATION_FAIL;
                return(res);
            }
            res.Data = new SaveQPaperRsp();

            using (TransScope scope = this._qpaperRepo.BeginTransScope())
            {
                int paperId = 0;

                var qpaper = new QPaper();
                qpaper.QpaperId    = req.QpaperId;
                qpaper.Description = req.Description;
                //数据校验
                if (!string.IsNullOrEmpty(req.StartTime))
                {
                    qpaper.StartTime = Convert.ToDateTime(req.StartTime);
                }

                if (!string.IsNullOrEmpty(req.EndTime))
                {
                    qpaper.EndTime = Convert.ToDateTime(req.EndTime);
                }
                qpaper.Subject    = req.Subject;
                qpaper.UpdateTime = DateTime.Now;
                if (req.QpaperId > 0) // 更新
                {
                    paperId = req.QpaperId;

                    //更新时需判断是否存在答卷
                    bool hasAPaper = await this._qpaperRepo.CheckHasAPaper(paperId);

                    if (hasAPaper)
                    {
                        res.Code = ErrorCodes.INVALID_OPERATION;
                        res.Data.ReturnMessage = "该问卷已存在答卷,不能修改了!";
                        return(res);
                    }

                    var t1 = this._qpaperRepo.UpdateAsync(qpaper);
                    //删除旧题目
                    var t2 = this._qpaperRepo.DeleteQuestionsByPId(paperId);

                    await Task.WhenAll(t1, t2); //两个任务可以并行
                }
                else
                {
                    qpaper.CreateUserId = req.Identity;
                    var newId = await this._qpaperRepo.InsertAsync(qpaper);

                    paperId = (int)newId;
                }

                if (paperId <= 0)
                {
                    //Internal error;
                    res.Code = ErrorCodes.INTERNAL_ERROR;
                    res.Data.ReturnMessage = "操作失败,请稍后重试";
                    return(res);
                }
                res.Data.QpaperId = paperId;
                //重新保存问题
                int i     = 0;
                var qlist = new List <Question>();
                foreach (var q in req.Questions)
                {
                    var question = new Question();
                    question.Id           = q.Id;
                    question.PaperId      = paperId;
                    question.Sequence     = ++i;
                    question.ExtendInput  = q.ExtendInput;
                    question.ItemDetail   = q.ItemDetail;
                    question.QuestionType = (sbyte)q.QuestionType.GetHashCode();
                    question.Topic        = q.Topic;
                    qlist.Add(question);
                }
                await this._qpaperRepo.AddQuestions(qlist);

                scope.Complete();// 提交事务
            }
            return(res);
        }