public void OnDepartmentInputNameEnd()
    {
        HoldPanel.gameObject.SetActive(false);
        if (nameInput.text == "")
        {
            return;
        }
        string pattern = @"^[^ ]{2,16}$";
        Regex  regex   = new Regex(pattern);

        if (!regex.IsMatch(nameInput.text))
        {
#if UNITY_ANDROID
            Toast.ShowToast("科室名称为2-16个字符,且不能存在空格");
#endif
            Debug.LogWarning("科室名称为2-16个字符,且不能存在空格");
            return;
        }
        pattern = @"^[^\/\:\*\?\""\<\>\|\,\.\。\,\?\、\;\“\”]+$";
        regex   = new Regex(pattern);
        if (!regex.IsMatch(nameInput.text))
        {
#if UNITY_ANDROID
            Toast.ShowToast("科室名称仅能使用汉字,英文字母,数字");
#endif
            Debug.LogWarning("科室名称仅能使用汉字,英文字母,数字");
            return;
        }
        string name   = nameInput.text;
        int    result = PollsConfig.AddDepartment(name, 0);
        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
        {
            AddNewCell(name);
        }
    }
 public void ConfirmDelHospital()
 {
     if (HospitalCellMap.ContainsKey(hotHospitalCell))
     {
         PollsConfig.DelHospital(HospitalCellMap[hotHospitalCell].name);
         DestroyImmediate(hotHospitalCell.gameObject);
         hotHospitalCell        = null;
         textSelected.text      = "未选择医院";
         btnDelete.interactable = false;
         btnNext.interactable   = false;
         PollsConfig.SerializeData();
         Invoke("_refreshList", 0.1f);
     }
 }
    private DepartmentCell AddNewCell(string name, bool load = false)
    {
        PollsConfig.DepartmentCellInfo dci = PollsConfig.GetDepartmentCellInfoByName(name);
        if (selectMode && !dci.qusetionLoaded)
        {
            return(null);
        }
        GameObject newone = Instantiate(Resources.Load("ui/DepartmentCell") as GameObject);

        if (newone != null)
        {
            newone.transform.SetParent(grid.transform);
            newone.transform.localScale = Vector3.one;
            newone.transform.position   = Vector3.zero;
            RectTransform rti = newone.GetComponent <RectTransform>();
            rti.anchoredPosition3D = new Vector3(rti.anchoredPosition3D.x, rti.anchoredPosition3D.y, 0);


            if (dci != null)
            {
                DepartmentCell dc = newone.GetComponent <DepartmentCell>();
                dc.controller    = this;
                dc.textName.text = dci.name;
                if (dci.qusetionLoaded)
                {
                    dc.SetToReadyStage();
                }
                else
                {
                    dc.SetToNormalStage();
                }
                DepartmentCellMap.Add(dc, dci);
                if (!load)
                {
                    PollsConfig.SerializeData();
                }
                Invoke("_refreshList", 0.1f);
                return(dc);
            }
            return(null);
        }
        else
        {
            Debug.Log("Instantiate DepartmentCell failed.");
#if UNITY_ANDROID
            Toast.ShowToast("未知错误,请退出后重试");
#endif
            return(null);
        }
    }
    IEnumerator webGetAllHospital()
    {
        WWWForm form = new WWWForm();

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

        yield return(www);

        if (www.isDone && www.error == null)
        {
            var settings = new JsonSerializerSettings {
                TypeNameHandling = TypeNameHandling.All
            };
            getAllHRetWithoutData ret = JsonConvert.DeserializeObject <getAllHRetWithoutData>(www.text, settings);
            if (ret.ret == 1)
            {
                getAllHRetWithData data = JsonConvert.DeserializeObject <getAllHRetWithData>(www.text, settings);
                foreach (HospitalListParser c in data.data)
                {
                    int result = PollsConfig.AddHospitals(c.vcHospitalName, c.iHospitalID);
                    if (result == -1)
                    {
#if UNITY_ANDROID
                        Toast.ShowToast("医院名已存在");
#endif
                    }
                    else if (result == -2)
                    {
#if UNITY_ANDROID
                        Toast.ShowToast("创建项目失败");
#endif
                    }
                    else
                    {
                        AddNewCell(c.vcHospitalName);
                    }
                }
            }
            else
            {
                Toast.ShowToast(ret.info);
            }
            loadingPanel.SetActive(false);
            www.Dispose();
        }
    }
 public void ConfirmDelDepartment()
 {
     if (DepartmentCellMap.ContainsKey(hotDepartmentCell))
     {
         textNumPeople.text = "";
         PollsConfig.DelDepartment(DepartmentCellMap[hotDepartmentCell].name);
         DestroyImmediate(hotDepartmentCell.gameObject);
         hotDepartmentCell            = null;
         textDepartmentSelected.text  = "未选择科室";
         textDepartmentSelected.color = Color.red;
         btnDelete.interactable       = false;
         btnStart.interactable        = false;
         btnLoad.interactable         = false;
         btnPreview.interactable      = false;
         PollsConfig.SerializeData();
         Invoke("_refreshList", 0.1f);
     }
 }
 public void RefleshDepartments()
 {
     PollsConfig.DelAllDepartment();
     PollsConfig.ClearQuestionMap();
     for (int i = 0; i < grid.transform.childCount; i++)
     {
         Destroy(grid.transform.GetChild(i).gameObject);
     }
     hotDepartmentCell              = null;
     btnNew.interactable            = selectMode ? false : true;
     btnDelete.interactable         = false;
     btnStart.interactable          = false;
     btnPreview.interactable        = false;
     btnLoad.interactable           = false;
     PollsConfig.selectedDepartment = null;
     loadingPanel.gameObject.SetActive(true);
     needDownload = 0;
     StartCoroutine(webGetDepartments(PollsConfig.selectedHospital.hospitalID));
 }
    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();
        }
    }
    IEnumerator webLoadQuestions(QuestionBlockCell qbc)
    {
        WWW www = new WWW("http://47.106.71.112:8080/api/Questions?questionname=" + qbc.questionGuid);

        yield return(www);

        if (www.isDone && www.error == null)
        {
            downloaded++;
            if (downloaded == grid.transform.childCount)
            {
                loadingPanel.SetActive(false);
            }
            parseJson(qbc.questionGuid, www.text);
            //add hospital
            PollsConfig.AddHospitals(qbc.hospitalNameText.text, 0);
            PollsConfig.AddDepartment(qbc.departmentNameText.text, 0, PollsConfig.GetHospitalCellInfoByName(qbc.hospitalNameText.text));
            PollsConfig.DepartmentCellInfo dci = PollsConfig.GetDepartmentCellInfoByName(qbc.departmentNameText.text, PollsConfig.GetHospitalCellInfoByName(qbc.hospitalNameText.text));
            dci.questions      = PollsConfig.QuestionMap[qbc.questionGuid];
            dci.qusetionLoaded = true;
            www.Dispose();
        }
    }
    void AddNewCell(string name, bool load = false)
    {
        GameObject newone = Instantiate(Resources.Load("ui/HospitalCell") as GameObject);

        if (newone != null)
        {
            newone.transform.SetParent(grid.transform);
            newone.transform.localScale = Vector3.one;
            newone.transform.position   = Vector3.zero;
            RectTransform rti = newone.GetComponent <RectTransform>();
            rti.anchoredPosition3D = new Vector3(rti.anchoredPosition3D.x, rti.anchoredPosition3D.y, 0);

            PollsConfig.HospitalCellInfo hci = PollsConfig.GetHospitalCellInfoByName(name);
            if (hci != null)
            {
                HospitalCell hc = newone.GetComponent <HospitalCell>();
                hc.controller          = this;
                hc.textName.text       = hci.name;
                hc.textTime.text       = "创建时间 : " + hci.createTime.ToShortDateString() + " " + hci.createTime.ToShortTimeString();
                hc.imgSelected.enabled = false;
                HospitalCellMap.Add(hc, hci);
                if (!load)
                {
                    PollsConfig.SerializeData();
                }
                Invoke("_refreshList", 0.1f);
            }
        }
        else
        {
            Debug.Log("Instantiate HospitalCell failed.");
#if UNITY_ANDROID
            Toast.ShowToast("未知错误,请退出后重试");
#endif
        }
    }
示例#10
0
    IEnumerator _webExportData(/*exportDataBase64 edb64*/)
    {
        //StartCoroutine(webPostAnswer(edb64.answers, edb64.pics));
        removeList.Clear();
        removeListEx.Clear();
        foreach (KeyValuePair <string, List <PollsConfig.AnswerStorge> > pair in PollsConfig.Answers)
        {
            exportDataBase64         edb64 = new exportDataBase64();
            PollsConfig.AnswerStorge _ans  = pair.Value[0];

            //List<Question> qs = QuestionMap[pair.Value[0].department.questionPath];
            exportData ed = null;
            for (int row = 0; row < pair.Value.Count; row++)
            {
                for (int col = 0; col < pair.Value[0].answers.Count + 6; col++)
                {
                    switch (col)
                    {
                    case 0:
                        ed         = new exportData();
                        ed.Answers = new List <answerExportData>();
                        break;

                    case 1:
                        if (Application.platform == RuntimePlatform.WindowsEditor)
                        {
                            ed.UserID = pair.Value[row].guid + "_" + "a87f814a75bf11dd" + "_" + pair.Value[row].answers[pair.Value[row].answers.Count - 1].endTime.ToString();
                        }
                        else
                        {
                            ed.UserID = pair.Value[row].guid + "_" + AndroidDeviceInfo.GetAndroidId() + "_" + pair.Value[row].answers[pair.Value[row].answers.Count - 1].endTime.ToShortTimeString();
                        }
                        Debug.Log("length " + ed.UserID + "\n" + ed.UserID.Length);
                        break;

                    case 2:
                        break;

                    case 3:
                        System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
                        ed.timestart = (pair.Value[row].answers[0].startTime.Ticks - startTime.Ticks) / 10000;
                        break;

                    case 4:
                        System.DateTime endTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
                        ed.timeend = (pair.Value[row].answers[pair.Value[row].answers.Count - 1].endTime.Ticks - endTime.Ticks) / 10000;
                        break;

                    case 5:
                        break;

                    default:
                        if (pair.Value[row].answers[col - 6].type != 2)
                        {
                            answerExportData aed = new answerExportData();
                            aed.id  = pair.Value[row].answers[col - 6].id;
                            aed.aid = pair.Value[row].answers[col - 6].aid;
                            if (aed.aid == null || aed.aid == "")
                            {
                                aed.aid = "-1";
                            }
                            ed.Answers.Add(aed);
                        }
                        else
                        {
                            UInt32 t = 0;
                            for (int i = 0; i < PollsConfig.MAX_ANS_COUNT; ++i)
                            {
                                if (pair.Value[row].answers[col - 6].answers[i] == 1)
                                {
                                    t += (UInt32)Math.Pow(2, i);
                                }
                            }
                            answerExportData aed = new answerExportData();
                            aed.id  = pair.Value[row].answers[col - 6].id;
                            aed.aid = pair.Value[row].answers[col - 6].aid;
                            if (aed.aid == null || aed.aid == "")
                            {
                                aed.aid = "-1";
                            }
                            ed.Answers.Add(aed);
                        }
                        break;
                    }
                }
                var settings = new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                };
                ed.QuestionnaireID = Int32.Parse(_ans.department.questionID);
                //_ans.department.numPeople = 0;
                ed.HospitalID   = _ans.hospital.hospitalID;
                ed.DepartmentID = _ans.department.departmentID;
                string json  = JsonConvert.SerializeObject(ed);
                byte[] bytes = Encoding.GetEncoding("utf-8").GetBytes(json);
                edb64.answers = Convert.ToBase64String(bytes);
                edb64.pics    = new List <string>();
                for (int i = 0; i < pair.Value[row].photos.Count; ++i)
                {
                    string imgstring;
                    if (departmentPageController.CaptureData != null && i == 0)
                    {
                        imgstring = "data:image / jpg; base64," + Convert.ToBase64String(departmentPageController.CaptureData);
                    }
                    else
                    {
                        imgstring = "data:image / jpg; base64," + Convert.ToBase64String(pair.Value[row].photos[i]);
                    }
                    edb64.pics.Add(imgstring);
                }
                yield return(StartCoroutine(webPostAnswer(edb64.answers, edb64.pics, pair.Key, pair.Value[row].guid)));
            }
        }

        foreach (string key in removeList)
        {
            PollsConfig.Answers[key][0].department.numPeople = 0;
            //
        }
        List <PollsConfig.AnswerStorge> _removeAstList = new List <PollsConfig.AnswerStorge>();

        foreach (KeyValuePair <string, List <string> > pair in removeListEx)
        {
            foreach (string guid in pair.Value)
            {
                for (int i = PollsConfig.Answers[pair.Key].Count - 1; i >= 0; i--)
                {
                    if (PollsConfig.Answers[pair.Key][i].guid == guid)
                    {
                        PollsConfig.Answers[pair.Key].RemoveAt(i);
                    }
                }
            }
            if (PollsConfig.Answers[pair.Key].Count == 0)
            {
                PollsConfig.Answers.Remove(pair.Key);
            }
        }

        if (PollsConfig.Answers.Count == 0)
        {
            Toast.ShowToast(string.Format("导入{0:d}条记录", removeList.Count));
            if (File.Exists(Application.persistentDataPath + "/answer.bin"))
            {
                File.Delete(Application.persistentDataPath + "/answer.bin");
            }
        }
        else
        {
            Toast.ShowToast(string.Format("导入{0:d}条记录, 剩余{1:d}条记录", removeList.Count, PollsConfig.Answers.Count));
            FileStream      fs = new FileStream(Application.persistentDataPath + "/" + "answer.bin", FileMode.OpenOrCreate);
            BinaryFormatter bf = new BinaryFormatter();
            bf.Serialize(fs, PollsConfig.Answers);
            fs.Close();
        }
        PollsConfig.SerializeData();
        loadingPanel.gameObject.SetActive(false);
    }
示例#11
0
    void SetupPwd(string pwd)
    {
        HoldInputPanel.SetActive(false);
        if (pwd == null || pwd == "")
        {
            return;
        }
        TopicText.text = "";
        string pattern = @"^[^ ]{6,6}$";
        Regex  regex   = new Regex(pattern);

        if (!regex.IsMatch(pwd))
        {
#if UNITY_ANDROID
            Toast.ShowToast("密码为6位字符,且不能存在空格");
#endif
            Debug.LogWarning("密码为6位字符,且不能存在空格");
            return;
        }
        if (pwd.Length != 6)
        {
#if UNITY_ANDROID
            Toast.ShowToast("密码长度为6位");
#endif
            return;
        }
        if (pwdStage == PWD_STAGE.NEW_PWD)
        {
            TmpPwd         = PollsConfig.GetMD5(pwd);
            TopicText.text = "请再次输入管理员密码";
            Invoke("InputNewPwd", 0.5f);
            pwdStage = PWD_STAGE.CONFIRM_PWD;
        }
        else if (pwdStage == PWD_STAGE.CONFIRM_PWD) //
        {
            if (TmpPwd == PollsConfig.GetMD5(pwd))
            {
#if UNITY_ANDROID
                Toast.ShowToast("管理员密码设置成功");
#endif
                TmpPwd = "";
                PollsConfig.Password        = pwd;
                PwdText.text                = "Pwd is : " + PollsConfig.Password;
                TextPwd.text                = "管理密码";
                BtnExport.interactable      = true;
                BtnQuestionMgr.interactable = true;
                TopicText.text              = "";
            }
            else
            {
#if UNITY_ANDROID
                Toast.ShowToast("密码输入不一致,请重新再试");
#endif
                TmpPwd = "";
            }
        }
        else if (pwdStage == PWD_STAGE.VERIFY_PWD)
        {
            if (PollsConfig.GetMD5(pwd) == PollsConfig.Password)
            {
                TopicText.text = "请输入新的管理员密码";
                Invoke("InputNewPwd", 0.5f);
                pwdStage = PWD_STAGE.NEW_PWD;
            }
            else
            {
#if UNITY_ANDROID
                Toast.ShowToast("请输入正确的管理员密码");
#endif
                TopicText.text = "";
            }
        }
        else if (pwdStage == PWD_STAGE.VERIFY_QUESTION_PWD)
        {
            if (PollsConfig.GetMD5(pwd) == PollsConfig.Password)
            {
                this.gameObject.SetActive(false);
                hospitalPage.gameObject.SetActive(true);
            }
            else
            {
#if UNITY_ANDROID
                Toast.ShowToast("请输入正确的管理员密码");
#endif
                TopicText.text = "";
            }
        }
        else if (pwdStage == PWD_STAGE.VERIFY_EXPORT_PWD)
        {
            if (PollsConfig.GetMD5(pwd) == PollsConfig.Password)
            {
                if (PollsConfig.Answers.Count == 0)
                {
#if UNITY_ANDROID
                    Toast.ShowToast("目前无可导出数据");
#endif
                }
                else
                {
                    fileChooser.setup(FileChooser.OPENSAVE.OPEN, "");
                    fileChooser.openSaveButton.GetComponentInChildren <Text>().text = "选择";
                    fileChooser.TextTopic.text = "请选择需要导出至的位置";
                    fileChooser.callbackYes    = delegate(string filename, string fullname)
                    {
                        //first hide the filechooser
                        fileChooser.gameObject.SetActive(false);
                        Debug.Log("select " + fullname);
                        pollsConfig.ExportData(fullname);
                    };

                    fileChooser.callbackNo = delegate()
                    {
                        fileChooser.gameObject.SetActive(false);
                    };
                }
            }
            else
            {
#if UNITY_ANDROID
                Toast.ShowToast("请输入正确的管理员密码");
#endif
                TopicText.text = "";
            }
        }
    }
 private void OnEnable()
 {
     if (Application.version == "2.07.6")
     {
         if (webcamTexture != null)
         {
             webcamTexture.Stop();
         }
         webcamTexture = null;
         OpenWebCamera();
     }
     textNumPeople.text           = "";
     textQuestion.text            = "";
     textHospitalSelected.text    = PollsConfig.selectedHospital.name;
     textDepartmentSelected.text  = "未选择科室";
     textDepartmentSelected.color = Color.red;
     if (gridOriginHeight == 0)
     {
         gridOriginHeight = grid.GetComponent <RectTransform>().sizeDelta.y;
     }
     for (int i = 0; i < grid.transform.childCount; i++)
     {
         Destroy(grid.transform.GetChild(i).gameObject);
     }
     hotDepartmentCell = null;
     UpdateList();
     btnNew.interactable     = selectMode ? false : true;
     btnDelete.interactable  = false;
     btnStart.interactable   = false;
     btnPreview.interactable = false;
     btnLoad.interactable    = false;
     btnNew.gameObject.SetActive(PollsConfig.isOfflineMode);
     btnDelete.gameObject.SetActive(PollsConfig.isOfflineMode);
     btnLoad.gameObject.SetActive(PollsConfig.isOfflineMode);
     btnReflesh.gameObject.SetActive(!PollsConfig.isOfflineMode);
     btnReflesh.interactable        = !selectMode;
     PollsConfig.selectedDepartment = null;
     needDownload = 0;
     if (!PollsConfig.isOfflineMode)
     {
         if (PollsConfig.GetDepartmentCellInfoCount(PollsConfig.selectedHospital) == 0)
         {
             RefleshDepartments();
         }
     }
     if (Application.version == "2.07.6")
     {
         if (selectMode)
         {
             ReadyPanel.gameObject.SetActive(true);
             DOTween.To(x =>
             {
             }, 0, 1, 5.0f).OnComplete(() =>
             {
                 webcamTexture.Play();
                 Invoke("CaptureWebCamTexture", 1.5f);
                 ReadyPanel.gameObject.SetActive(false);
             });
         }
     }
 }