예제 #1
0
    private void OnEnable()
    {
        if (gridOriginHeight == 0)
        {
            gridOriginHeight = grid.GetComponent <RectTransform>().sizeDelta.y;
        }
        BtnMgrPwd.gameObject.SetActive(PollsConfig.isOfflineMode);
        if (PollsConfig.isOfflineMode)
        {
            if (PollsConfig.Password == "")
            {
                TextPwd.text                = "创建密码";
                BtnExport.interactable      = false;
                BtnQuestionMgr.interactable = false;
                Invoke("OnSetupPwd", 0.1f);
            }
            else
            {
                TopicText.text              = "";
                TextPwd.text                = "管理密码";
                BtnExport.interactable      = true;
                BtnQuestionMgr.interactable = true;
            }
        }
        else
        {
            BtnExport.interactable      = true;
            TopicText.text              = "";
            BtnQuestionMgr.interactable = true;
        }

        for (int i = 0; i < grid.transform.childCount; i++)
        {
            Destroy(grid.transform.GetChild(i).gameObject);
        }
        //fill list
        foreach (KeyValuePair <string, List <PollsConfig.AnswerStorge> > pair in PollsConfig.Answers)
        {
            PollsConfig.AnswerStorge _ans = pair.Value[0];
            AddNewCell(_ans.department.name, pair.Value.Count);
        }
    }
예제 #2
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);
    }