[HttpGet] //定义访问方式(Post或Get方法) public object Get() //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。 { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.Limit(300); query.WhereEqualTo("courseId", courseId); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Examination>("Examination", query); try { examinationList = future.Result.results; foreach (var e in examinationList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Examination_View examination_View = new Examination_View(); examination_View.objectId = e.objectId; examination_View.name = e.name; examination_View.questionList = e.questionList; examination_View.id = e.id.Get(); examination_View.difficulty = e.difficulty.Get(); examination_View.courseId = e.courseId.Get(); eList.Add(examination_View); } } catch { } return(ResultToJson.toJson(eList)); //返回数据需要json格式 }
[HttpGet] //定义访问方式(Post或Get方法) public object GetKnowledge() //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。 { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.WhereEqualTo("courseId", courseId); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Knowledge>("Knowledge", query); try { knowledgeList = future.Result.results; foreach (var k in knowledgeList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Knowledge_View knowledge_view = new Knowledge_View(); knowledge_view.id = k.id.Get(); knowledge_view.name = k.name; knowledge_view.courseId = k.courseId.Get(); knowledge_view.unitId = k.unitId.Get(); kList.Add(knowledge_view); } }catch { } return(ResultToJson.toJson(kList)); //返回数据需要json格式 }
public object GetShowDetails(String examQuestionList) { string[] results = examQuestionList.Split(new[] { ';' }); int[] examQuestion = Array.ConvertAll <string, int>(results, s => int.Parse(s)); for (int i = 0; i < examQuestion.Length; i++) { var query = new BmobQuery(); query.WhereEqualTo("id", examQuestion[i]); HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String Id = cookie1["CourseId"]; int courseId = int.Parse(Id); var query2 = new BmobQuery(); query2.WhereEqualTo("courseId", courseId); query = query.And(query2); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Question>("Question", query); try { questionList = future.Result.results; foreach (var q in questionList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Question_View question_view = new Question_View(); question_view.id = q.id.Get(); question_view.difficulty = q.difficulty.Get(); question_view.question = q.question; question_view.courseId = q.courseId.Get(); question_view.unitId = q.unitId.Get(); question_view.knowledgeId = q.knowledgeId; qList.Add(question_view); } } catch { return("获取失败"); } } return(ResultToJson.toJson(qList)); }
public void QuestionInfo() //查询全部题目的函数 { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.Limit(300); query.WhereEqualTo("courseId", courseId); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Question>("Question", query); try { questionList = future.Result.results; foreach (var q in questionList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Question_View question_view = new Question_View(); question_view.objectId = q.objectId; question_view.id = q.id.Get(); question_view.difficulty = q.difficulty.Get(); question_view.totalNum = q.totalNum.Get(); question_view.rightNum = q.rightNum.Get(); question_view.question = q.question; question_view.a = q.a; question_view.b = q.b; question_view.c = q.c; question_view.d = q.d; question_view.answer = q.answer; question_view.analysis = q.analysis; question_view.courseId = q.courseId.Get(); question_view.unitId = q.unitId.Get(); question_view.knowledgeId = q.knowledgeId; qList.Add(question_view); } } catch { } //如果需要对其中一行数据进行处理,可以记录每以条记录的object值,方便对Bmob数据库进行操作。 }
[HttpGet] //定义访问方式(Post或Get方法) public object Get() //返回数据的函数,如果是Get方法则方法名为Get开头,若是Post则使用Post开头。 { HttpCookie cookie1 = HttpContext.Current.Request.Cookies["CurrentCourse"]; String id = cookie1["CourseId"]; int courseId = int.Parse(id); var query = new BmobQuery(); query.Limit(300); query.WhereEqualTo("courseId", courseId); query.OrderBy("id"); var future = Bmob.FindTaskAsync <Unit>("Unit", query); unitList = future.Result.results; foreach (var u in unitList) //由于BmobModel中有BmobInt类型不能直接显示到页面中,所以需要对字段的类型进行处理,变为相对应的ViewModel格式。 { Unit_View unit_view = new Unit_View(); unit_view.id = u.id.Get(); unit_view.name = u.name; unit_view.courseId = u.courseId.Get(); uList.Add(unit_view); } return(ResultToJson.toJson(uList)); //返回数据需要json格式 }
private void bomoToexcel() { DataTable _px = new DataTable(); var query = new BmobQuery(); query.WhereGreaterThan("indexID", 2651); //分数大于60岁 query.OrderBy("indexID"); query.Limit(600); var childfuture = Bmob.FindTaskAsync <computerTiKu>("computerTiKu", query); if (childfuture.Result.results.Count != 0) { _px = ToDataTable <computerTiKu>(childfuture.Result.results); // MessageBox.Show("总行数" + _px.Rows.Count); } //_dspx = AdDispatchManage.GetValue(sqlstr); int row; row = 2; int b; b = 0; string PathStr; string SourceFileName; string DestinationFileName; PathStr = Application.StartupPath.Trim(); // MakeBigWord.MakeBigWord.KillExcelProcess(); DestinationFileName = PathStr + @"\plantmp.xls"; SourceFileName = PathStr + @"\yhygzpx.xls"; try { File.Delete(DestinationFileName); File.Copy(SourceFileName, DestinationFileName); } catch (Exception ee) { MessageBox.Show(ee.Message); return; } Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application(); Microsoft.Office.Interop.Excel.Workbook xlBook = xlApp.Workbooks.Add(DestinationFileName); Microsoft.Office.Interop.Excel.Worksheet xlSheet = xlBook.Worksheets[1]; xlSheet.Activate(); xlSheet.Application.Visible = true; try { for (int i = 0; i < _px.Rows.Count; i++) { if (_px.Rows[i]["titleSubject"].ToString() != null) { xlSheet.Cells[i + row, 1] = _px.Rows[i]["titleSubject"].ToString(); } else { MessageBox.Show(i + "titleSubject"); } if (_px.Rows[i]["titleSubject"].ToString() != null) { xlSheet.Cells[i + row, 1] = _px.Rows[i]["titleSubject"].ToString(); } else { MessageBox.Show(i + "titleSubject"); } if (_px.Rows[i]["optionA"].ToString() != null && _px.Rows[i]["optionB"].ToString() != null && _px.Rows[i]["optionC"].ToString() != null && _px.Rows[i]["optionD"].ToString() != null) { Choice[] student = new Choice[4]; student[0] = new Choice(); student[0].key = "A"; student[0].content = _px.Rows[i]["optionA"].ToString(); student[1] = new Choice(); student[1].key = "B"; student[1].content = _px.Rows[i]["optionB"].ToString(); student[2] = new Choice(); student[2].key = "C"; student[2].content = _px.Rows[i]["optionC"].ToString(); student[3] = new Choice(); student[3].key = "D"; student[3].content = _px.Rows[i]["optionD"].ToString(); string aa = Newtonsoft.Json.JsonConvert.SerializeObject(student); xlSheet.Cells[i + row, 2] = aa; //设置一个Person类 //Choice p = new Choice(); //p.key = _px.Rows[i]["optionA"].ToString(); //p.content = _px.Rows[i]["optionB"].ToString(); //p.C = _px.Rows[i]["optionC"].ToString(); //p.D = _px.Rows[i]["optionD"].ToString(); //string json1 = JsonConvert.SerializeObject(p); //Console.WriteLine(json1 + "\n"); ////缩进输出 //string json2 = JsonConvert.SerializeObject(p, Formatting.Indented); //Console.WriteLine(json2 + "\n"); // {"A":"+价格发现功能+","B":"+套利功能+","C":"+投机功能+","D":"+套期保值功能"} } else { MessageBox.Show(i + "A=" + _px.Rows[i]["optionA"].ToString() + "B=" + _px.Rows[i]["optionB"].ToString() + "C=" + _px.Rows[i]["optionC"].ToString() + "D=" + _px.Rows[i]["optionD"].ToString()); } xlSheet.Cells[i + row, 3] = "3RcsJ77J"; if (_px.Rows[i]["answer"].ToString() != null) { String title = _px.Rows[i]["answer"].ToString().Substring(4, _px.Rows[i]["answer"].ToString().Length - 4); ///去掉两个字符串 xlSheet.Cells[i + row, 4] = "[\"" + title + "\"]"; } else { MessageBox.Show(i + "answer"); } if (_px.Rows[i]["explain"].ToString() != null) { xlSheet.Cells[i + row, 5] = _px.Rows[i]["explain"].ToString(); } else { MessageBox.Show(i + "explain"); } xlSheet.Cells[i + row, 6] = 500 + i; xlSheet.Cells[i + row, 7] = "P0Vm666E"; b = i; //xlSheet.Cells[i + row, 2] = _px.Rows[i]["indexID"].ToString(); //xlSheet.Cells[i + row, 3] = _px.Rows[i]["titleSubject"].ToString(); //xlSheet.Cells[i + row, 4] = _px.Rows[i]["answer"].ToString(); //xlSheet.Cells[i + row, 5] = _px.Rows[i]["optionA"].ToString(); //xlSheet.Cells[i + row, 6] = _px.Rows[i]["chapterflag"].ToString(); //xlSheet.Cells[i + row, 7] = _px.Rows[i]["core"].ToString(); //xlSheet.Cells[i + row, 8] = _px.Rows[i]["answerCode"].ToString(); //xlSheet.Cells[i + row, 9] = "'" + _px.Rows[i]["optionB"].ToString() + "/" + _px.Rows[i]["optionC"].ToString(); //xlSheet.Cells[i + row, 10] = _px.Rows[i]["optionD"].ToString(); //xlSheet.Cells[i + row, 11] = _px.Rows[i]["questiontype"].ToString(); //xlSheet.Cells[i + row, 12] = _px.Rows[i]["subjectType"].ToString() + "/" + _px.Rows[i]["explain"].ToString(); } } catch { } try { Microsoft.Office.Interop.Excel.Range r1 = xlSheet.Range[xlSheet.Cells[3, 1], xlSheet.Cells[b + row + 4, 6]]; r1.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeBottom].LineStyle = 7; r1.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeRight].LineStyle = 7; r1.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlEdgeLeft].LineStyle = 7; r1.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = 7; r1.Borders[Microsoft.Office.Interop.Excel.XlBordersIndex.xlInsideVertical].LineStyle = 7; } catch { } }