Exemplo n.º 1
0
        public AdminAwardsResp Awards([FromBody] AdminAwardsReq req)
        {
            AdminAwardsResp resp = new AdminAwardsResp();

            try
            {
                if (Fun.ExistSMID(req.smid))
                {
                    Fun.GetSqlConn().Execute($"update student_match set is_awards = true, awards = '{req.awards}' where id={req.smid}");
                    resp.status = 0;
                    resp.msg    = "ok";
                }
                else
                {
                    resp.status = -1;
                    resp.msg    = "参数错误";
                }
            }
            catch (Exception ex)
            {
                resp.msg    = "未知错误" + ex.ToString();
                resp.status = -2;
                Console.WriteLine(resp.msg);
            }

            return(resp);
        }
Exemplo n.º 2
0
        public AdminAwardsResp Awards(int smid)
        {
            AdminAwardsResp resp = new AdminAwardsResp();

            try
            {
                var result     = Fun.GetSqlConn().Query($"select sid, mid, awards from student_match where  id = {smid}");
                var sm_obj     = result.Single();
                var m_result   = Fun.GetSqlConn().Query($"select title from `match` where id = {sm_obj.mid}");
                var m_obj      = m_result.Single();
                var stu_result = Fun.GetSqlConn().Query($"select name from student where id = {sm_obj.sid}");
                var stu_obj    = stu_result.Single();

                // 生成证书
                string       unique_file_name = Guid.NewGuid().ToString() + ".docx";
                string       file_path        = Path.Combine("wwwroot", "awards", unique_file_name);
                XWPFDocument doc = new XWPFDocument();
                // 添加段落
                XWPFParagraph gp = doc.CreateParagraph();
                gp.Alignment = ParagraphAlignment.CENTER;//水平居中
                XWPFRun gr = gp.CreateRun();
                gr.GetCTR().AddNewRPr().AddNewRFonts().ascii    = "黑体";
                gr.GetCTR().AddNewRPr().AddNewRFonts().eastAsia = "黑体";
                //gr.GetCTR().AddNewRPr().AddNewRFonts().hint = ST_Hint.eastAsia;
                gr.GetCTR().AddNewRPr().AddNewSz().val    = (ulong)44; //2号字体
                gr.GetCTR().AddNewRPr().AddNewSzCs().val  = (ulong)44;
                gr.GetCTR().AddNewRPr().AddNewB().val     = true;      //加粗
                gr.GetCTR().AddNewRPr().AddNewColor().val = "red";     //字体颜色
                gr.SetText("荣誉证书");
                gr.SetText("——————");
                gr.SetText($"恭喜{stu_obj.name}同学在{m_obj.title}比赛中获得{sm_obj.awards},特发此证,予以鼓励!");
                FileStream fs = new FileStream(file_path, FileMode.OpenOrCreate, FileAccess.Write);
                doc.Write(fs);
                doc.Close();

                resp.status = 0;
                resp.msg    = "ok";
                resp.data   = Path.Combine("awards", unique_file_name);
            }
            catch (Exception ex)
            {
                resp.msg    = "未知错误" + ex.ToString();
                resp.status = -2;
                Console.WriteLine(resp.msg);
            }

            return(resp);
        }