コード例 #1
0
ファイル: RecordHandler.ashx.cs プロジェクト: TonyPod/MyIC
        //JSON数据格式
        //{
        //    Username: string
        //    Description:string
        //    Time:DateTime
        //    LocationStr string(四川_成都_郫县)
        //    Answers:string("010100")
        //    PicNames:string的JArray
        //}
        public void ProcessRequest(HttpContext context)
        {
            StreamReader reader     = new StreamReader(context.Request.InputStream, Encoding.UTF8);
            string       requestStr = reader.ReadToEnd();

            JObject  jObj        = JObject.Parse(requestStr);
            string   username    = jObj["Username"].ToString();
            string   description = jObj["Description"].ToString();
            DateTime time        = DateTime.Parse(jObj["Time"].ToString());
            string   locationStr = jObj["LocationStr"].ToString();
            string   answers     = jObj["Answers"].ToString();
            JArray   picNames    = JArray.Parse(jObj["PicNames"].ToString());

            //添加到自检记录
            RecordModel record = new RecordModel();

            record.Answers     = answers;
            record.Description = description;

            //如果locationStr为null,则返回"000000"(中国),否则解析并保存
            if (string.IsNullOrEmpty(locationStr))
            {
                record.Citycode = "000000";
            }
            else
            {
                record.Citycode = LocationDAL.GetLocalId(locationStr);
            }

            record.Time    = time;
            record.User_id = UserDAL.GetByUsername(username).User_id;
            long record_id = RecordDAL.Insert(record);

            //添加自检图片
            foreach (string picName in picNames)
            {
                PhotoModel photo = new PhotoModel();
                photo.Path      = picName;
                photo.Record_id = record_id;
                PhotoDAL.Insert(photo);
            }

            //返回Record_id给移动端
            JObject jObjSend = new JObject();

            jObjSend.Add("Record_id", record_id);

            byte[] buf = Encoding.UTF8.GetBytes(jObjSend.ToString());
            context.Response.OutputStream.Write(buf, 0, buf.Length);

            Thread thread = new Thread(() =>
            {
                List <CVResultModel> results = new List <CVResultModel>();

                //检查图片是否分析完成(是否Insert到CVResult中)
                const int WAIT_TIME = 240;   //等待时间(如果240秒某张图片都没有传输成功且分析完成,则放弃)
                foreach (string picName in picNames)
                {
                    //轮询
                    for (int i = 0; i < WAIT_TIME; i++)
                    {
                        if (null != CVResultDAL.GetById(picName))
                        {
                            results.Add(CVResultDAL.GetById(picName));
                            break;
                        }
                        Thread.Sleep(1000);
                    }
                }

                //计算分数并保存
                float score = ScoreUtil.GetScore(results);
                RecordDAL.UpdateScore(score, record_id);
            });

            thread.Start();
        }
コード例 #2
0
ファイル: RecordWebForm.aspx.cs プロジェクト: TonyPod/MyIC
        /// <summary>
        /// 窗口加载时:通过GET请求的"record_id"参数到数据库取得相应的自检信息并显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            long record_id;

            if (long.TryParse(Request.Params["record_id"], out record_id))
            {
                //调用数据库访问类查询该主键对应的自检记录
                RecordModel  record = RecordDAL.GetById(record_id);
                PhotoModel[] photos = PhotoDAL.GetAllByRecordId(record_id);

                //原图片
                List <string> srcUrls = new List <string>();
                List <string> dstUrls = new List <string>();
                foreach (var photo in photos)
                {
                    srcUrls.Add("~/ImageWebForm.aspx?fileType=src&picName=" + photo.Path);
                    dstUrls.Add("~/ImageWebForm.aspx?fileType=dst&picName=" + photo.Path);
                }

                //将图片绑定到控件上
                dl_srcImgs.DataSource = srcUrls;
                dl_srcImgs.DataBind();

                dl_dstImgs.DataSource = dstUrls;
                dl_dstImgs.DataBind();

                //取得该自检对应图片的所有处理结果
                List <CVResultModel> results = new List <CVResultModel>();
                foreach (var photo in photos)
                {
                    var result = CVResultDAL.GetById(photo.Path);
                    if (result != null)
                    {
                        results.Add(result);
                    }
                }

                //分析处理结果
                float score = ScoreUtil.GetScore(results);

                //结论
                StringBuilder builder = new StringBuilder();
                //builder.AppendFormat("系统分析得分:{0:f2}", score).AppendLine();
                var group = Severity.Group(score);
                switch (group)
                {
                case Severity.SeverityEnum.Normal:
                    builder.AppendLine("牙齿正常,请注意保持");
                    break;

                case Severity.SeverityEnum.Light:
                    builder.AppendLine("有少量龋齿或程度较轻");
                    break;

                case Severity.SeverityEnum.Medium:
                    builder.AppendLine("有一定龋齿或程度中等");
                    break;

                case Severity.SeverityEnum.Severe:
                    builder.AppendLine("有大量龋齿或龋坏严重");
                    break;

                default:
                    break;
                }

                if (group != Severity.SeverityEnum.Normal)
                {
                    builder.AppendLine("可能为色素沉着,牙石或牙垢,保持口腔清洁或前往正规医院洗牙可以让结果更准确");
                }
                lbl_conclusion.Text = builder.ToString().Replace(Environment.NewLine, "<br>");

                //医生意见
                DiagnosisModel[] diagnoses = DiagnosisDAL.GetAllByRecordId(record_id);
                List <string>    comments  = new List <string>();
                foreach (var diagnosis in diagnoses)
                {
                    string item = string.Format("{0} {1}", diagnosis.Time.ToString(), DoctorDAL.GetById(diagnosis.Doc_id).RealName)
                                  + Environment.NewLine + diagnosis.Result;
                    comments.Add(item);
                }
                dl_comments.DataSource = comments;
                dl_comments.DataBind();
            }
            else
            {
                //record_id出错
            }
        }