private string ProcessData(string data) { context context = JsonConvert.DeserializeObject <context>(data); if (context.Mode == "Post") { if (context.Function == "Insertreport") { DataModel dm = JsonConvert.DeserializeObject <DataModel>(context.Content.ToString()); //var dm = context.Content as DataModel; bool res = false; try { ReportDal rd = new ReportDal(); res = rd.Insertreport(dm.name, dm.content, dm.path, dm.timeCreate, dm.timeModify, dm.timeAccess); } catch (Exception e) { File.AppendAllLines(path, new string[] { $"{DateTime.Now.ToLongTimeString()}:操作数据库 Insertreport 异常:{e.ToString()} ." }); //throw; } context.Content = res ? "Success" : "Failure"; string restr = JsonConvert.SerializeObject(context); return(restr); } return(""); } if (context.Mode == "Get") { if (context.Function == "GetReportSingleContent") { var name = context.Content as string; //object res = null; byte[] bytes = null; try { ReportDal rd = new ReportDal(); var res = rd.GetReportSingleContent(name); bytes = res as byte[]; } catch (Exception e) { File.AppendAllLines(path, new string[] { $"{DateTime.Now.ToLongTimeString()}:操作数据库 GetReportSingleContent 异常:{e.ToString()} ." }); //throw; } string restr2 = JsonConvert.SerializeObject(bytes); context.Content = restr2; string restr = JsonConvert.SerializeObject(context); return(restr); } else if (context.Function == "GetReportSingle") { var name = context.Content as string; DataSet res = null; try { ReportDal rd = new ReportDal(); res = rd.GetReportSingle(name); } catch (Exception e) { File.AppendAllLines(path, new string[] { $"{DateTime.Now.ToLongTimeString()}:操作数据库 GetReportSingle 异常:{e.ToString()} ." }); //throw; } string restr2 = JsonConvert.SerializeObject(res); context.Content = restr2; string restr = JsonConvert.SerializeObject(context); return(restr); } else if (context.Function == "GetreportLimitN") { var dm = Convert.ToInt32(context.Content); DataSet res = null; try { ReportDal rd = new ReportDal(); res = rd.GetreportLimitN(dm); } catch (Exception e) { File.AppendAllLines(path, new string[] { $"{DateTime.Now.ToLongTimeString()}:操作数据库 GetreportLimitN 异常:{e.ToString()} ." }); //throw; } string restr2 = JsonConvert.SerializeObject(res); context.Content = restr2; string restr = JsonConvert.SerializeObject(context); return(restr); } return(""); } throw new NotImplementedException(); }