IEnumerator webGetDepartments(int id)
    {
        WWWForm form = new WWWForm();

        form.AddField("UserID", PollsConfig.netUserID);
        form.AddField("Token", PollsConfig.netUserToken);
        form.AddField("HospitalID", id);
        WWW www = new WWW("http://47.106.71.112/api/getdepartments.aspx", form);

        yield return(www);

        if (www.isDone && www.error == null)
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            retWithoutData ret = JsonConvert.DeserializeObject <retWithoutData>(www.text, settings);
            if (ret.ret == 1)
            {
                getDepRetWithData configs = JsonConvert.DeserializeObject <getDepRetWithData>(www.text, settings);
                foreach (DepartmentListParser c in configs.data)
                {
                    int result = PollsConfig.AddDepartment(c.vcDepartmentName, c.iDepartmentID);
                    if (result == -1)
                    {
#if UNITY_ANDROID
                        Toast.ShowToast("科室名已存在");
#endif
                    }
                    else if (result == -2)
                    {
#if UNITY_ANDROID
                        Toast.ShowToast("创建科室失败");
#endif
                    }
                    else if (result == -3)
                    {
#if UNITY_ANDROID
                        Toast.ShowToast("未选择医院");
#endif
                    }
                    else
                    {
                        DepartmentCell dc = AddNewCell(c.vcDepartmentName);
                        if (dc != null)
                        {
                            yield return(StartCoroutine(webGetQuestionsID(dc, c.iDepartmentID)));
                        }
                    }
                }
            }
            else
            {
                Toast.ShowToast(ret.info);
            }
            //loadingPanel.SetActive(false);
            www.Dispose();
        }
    }
    IEnumerator webGetQuestionsID(DepartmentCell dc, int departmentid)
    {
        WWWForm form = new WWWForm();

        form.AddField("UserID", PollsConfig.netUserID);
        form.AddField("Token", PollsConfig.netUserToken);
        form.AddField("DepartmentID", departmentid);
        WWW www = new WWW("http://47.106.71.112/api/getquestionnaires.aspx", form);

        yield return(www);

        if (www.isDone && www.error == null && www.text != "")
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            retWithoutData ret = JsonConvert.DeserializeObject <retWithoutData>(www.text, settings);
            if (ret.ret == 1)
            {
                getQidRetWithData data = JsonConvert.DeserializeObject <getQidRetWithData>(www.text, settings);
                //get dci by name
                PollsConfig.DepartmentCellInfo dci = PollsConfig.GetDepartmentCellInfoByName(data.data[0].vcDepartmentName);
                if (dci != null)
                {
                    dci.title = data.data[0].Title;
                    if (!PollsConfig.QuestionMap.ContainsKey(data.data[0].iQuestionnaireID.ToString()))
                    {
                        needDownload++;
                        loadingPanel.SetActive(true);
                        yield return(StartCoroutine(webLoadQuestions(dc, data.data[0].vcDepartmentName, data.data[0].iQuestionnaireID)));
                    }
                    else
                    {
                        //PollsConfig.DepartmentCellInfo dci = PollsConfig.GetDepartmentCellInfoByName(data.data[0].vcDepartmentName);
                        dci.questions      = PollsConfig.QuestionMap[data.data[0].iQuestionnaireID.ToString()];
                        dci.qusetionLoaded = true;
                        dci.questionID     = data.data[0].iQuestionnaireID.ToString();
                        dc.SetToReadyStage();
                        PollsConfig.SerializeData();
                    }
                }
                else
                {
                    Toast.ShowToast("获取科室绑定问卷失败.");
                    Debug.LogError("webGetQuestionsID failed. " + data.data[0].vcDepartmentName);
                }
            }
            else
            {
                Toast.ShowToast(ret.info);
            }
            www.Dispose();
        }
        else
        {
            Debug.Log("There no questions in department " + departmentid);
        }
    }
    IEnumerator webLoadQuestions(DepartmentCell dc, string departmentname, int id)
    {
        WWWForm form = new WWWForm();

        form.AddField("UserID", PollsConfig.netUserID);
        form.AddField("Token", PollsConfig.netUserToken);
        form.AddField("QuestionnaireID", id);
        WWW www = new WWW("http://47.106.71.112/api/getquestionnaire.aspx", form);

        yield return(www);

        if (www.isDone && www.error == null)
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            retWithoutData ret = JsonConvert.DeserializeObject <retWithoutData>(www.text, settings);
            if (ret.ret == 1)
            {
                needDownload--;
                if (needDownload == 0)
                {
                    loadingPanel.SetActive(false);
                }
                getQRetWithData data = JsonConvert.DeserializeObject <getQRetWithData>(www.text, settings);
                parseJson(id.ToString(), data.data);
                PollsConfig.DepartmentCellInfo dci = PollsConfig.GetDepartmentCellInfoByName(departmentname);
                dci.questions      = PollsConfig.QuestionMap[id.ToString()];
                dci.qusetionLoaded = true;
                dci.questionID     = id.ToString();
                dc.SetToReadyStage();
                PollsConfig.SerializeData();
            }
            else
            {
                Toast.ShowToast(ret.info);
            }
            www.Dispose();
        }
    }
Exemplo n.º 4
0
    IEnumerator webPostAnswer(string edstring, List <string> pics, string key, string guid)
    {
        WWWForm form = new WWWForm();

        form.AddField("UserID", PollsConfig.netUserID);
        form.AddField("Token", PollsConfig.netUserToken);
        form.AddField("Data", edstring);
        form.AddField("Version", Application.version.ToString());
        if (pics.Count >= 1)
        {
            form.AddField("Pic1", pics[0]);
        }
        if (pics.Count >= 2)
        {
            form.AddField("Pic2", pics[1]);
        }
        if (pics.Count >= 3)
        {
            form.AddField("Pic3", pics[2]);
        }
        if (pics.Count >= 4)
        {
            form.AddField("Pic4", pics[3]);
        }
        WWW www = new WWW("http://47.106.71.112/api/importuseranswer.aspx", form);

        yield return(www);

        if (www.isDone && www.error == null && www.text != "")
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            retWithoutData ret = JsonConvert.DeserializeObject <retWithoutData>(www.text, settings);
            if (ret.ret == 1)
            {
                //Toast.ShowToast("导入数据库成功");
                removeList.Add(key);
                if (removeListEx.ContainsKey(key))
                {
                    removeListEx[key].Add(guid);
                }
                else
                {
                    List <string> _list = new List <string>();
                    removeListEx.Add(key, _list);
                    removeListEx[key].Add(guid);
                }
                Debug.Log(ret.info);
            }
            else
            {
                Debug.LogError(ret.info);
                Toast.ShowToast(ret.info);
            }
            www.Dispose();
        }
        else
        {
            Debug.Log("导出错误,请稍后再试");
        }
    }