//创建药物按钮 void createDrugBtn(Vector2 minpos, Vector2 maxpos, string name, Operation.Drugs drug) { GameObject instance = Instantiate(Resources.Load <GameObject>("toggle")); instance.name = name; instance.transform.parent = parentDialogBtn.transform; instance.GetComponent <RectTransform>().anchorMin = minpos; instance.GetComponent <RectTransform>().anchorMax = maxpos; instance.GetComponent <RectTransform>().offsetMin = new Vector2(0, 0); instance.GetComponent <RectTransform>().offsetMax = new Vector2(0.0f, 0.0f); instance.GetComponentInChildren <Text>().text = drug.d_concentration + drug.d_name + drug.d_dose; instance.GetComponent <Toggle>().onValueChanged.AddListener( delegate(bool ison) { if (ison) { currentDrugArry.Add(drug); } else { currentDrugArry.Remove(drug); } } ); currentDialogBtnArry.Add(instance); }
//获取药物并将药物填写在对话框中 void getDrug(string groupId, string groupName) { DbAccess db = new DbAccess("data source = " + Application.dataPath + "/ModelData/NDtreatmentnew.db"); string sqlstr = "select * from NT_drug"; SqliteDataReader result = db.ExecuteQuery(sqlstr); float i = 0.03f, j = 0.93f; int k = 0; while (result.Read()) { string tempid = result.GetString(result.GetOrdinal("NC_id")); string tempname = result.GetString(result.GetOrdinal("NC_name")); string tempclass = result.GetString(result.GetOrdinal("NC_class")); string tempconcentration = result.GetString(result.GetOrdinal("NC_concentration")); string tempdose = result.GetString(result.GetOrdinal("NC_dose")); Operation.Drugs temp = new Operation.Drugs(tempid, tempname, tempclass, tempconcentration, tempdose); if (k < 3) { createDrugBtn(new Vector2(i, j - 0.05f), new Vector2(i + 0.27f, j), "btnDialog", temp); i = i + 0.3f; k++; } else { k = 0; i = 0.03f; j = j - 0.05f; createDrugBtn(new Vector2(i, j - 0.05f), new Vector2(i + 0.27f, j), "btnDialog", temp); i = i + 0.3f; k++; } } result.Close(); db.CloseSqlConnection(); CustomView.SCButton sumitbtn = new CustomView.SCButton(5, "submit", parentDialogBtn.transform.parent, delegate() { onSubmitBtn(groupId, groupName); }, btnImage, new Vector2(0.0f, 0.9f), new Vector2(0.93f, 1.0f), new Vector2(0, 0), new Vector2(0, 0)// new Vector2(0, 0.92f), new Vector2(0.166f, 1.0f) ); CustomView.SCText text = new CustomView.SCText(5, "text", sumitbtn._btn.transform, "提交", textFont, FontStyle.Normal, new Color(0, 0, 0, 1), TextAnchor.MiddleCenter, new Vector2(0, 0), new Vector2(1, 1), new Vector2(0, 0), new Vector2(0, 0)); currentDialogBtnArry.Add(sumitbtn._btn); }
void onSubmitBtn(string groupId, string groupName) { gameObject.GetComponent <AudioSource>().Play(); string drugstr = ""; string drugnamestr = ""; currentDrugArry.Sort(); for (int ii = 0; ii < currentDrugArry.Count; ii++) { Operation.Drugs it = currentDrugArry[ii]; if (ii != currentDrugArry.Count - 1) { drugstr = drugstr + it.d_id + "|"; drugnamestr = drugnamestr + it.d_name + "、"; } else { drugstr = drugstr + it.d_id; drugnamestr = drugnamestr + it.d_name; } } DbAccess db2 = new DbAccess("data source = " + Application.dataPath + "/ModelData/NDtreatmentnew.db"); string sqlstr2 = "select * from NT_operation where NC_drug like '" + drugstr + "'" + "AND NC_groupid = '" + groupId + "'"; SqliteDataReader result2 = db2.ExecuteQuery(sqlstr2); if (!result2.HasRows) { result2.Close(); db2.CloseSqlConnection(); Debug.Log("没有此药品"); operationList.Add(groupName + drugnamestr + ":×"); return; } else { result2.Read(); string tempname = result2.GetString(result2.GetOrdinal("NC_name")); string tempid = result2.GetString(result2.GetOrdinal("NC_id")); string tempgid = result2.GetString(result2.GetOrdinal("NC_groupid")); string tempgname = result2.GetString(result2.GetOrdinal("NC_groupname")); string tempdescribe = result2.GetString(result2.GetOrdinal("NC_oprationdescribe")); string temporgan = result2.GetString(result2.GetOrdinal("NC_organ")); string tempdrug = result2.GetString(6); string tempother = result2.GetString(result2.GetOrdinal("NC_other")); Operation.SChandle temp = new Operation.SChandle(tempid, tempname, tempgid, tempgname, tempdescribe, temporgan, tempdrug, tempother); //教学模式中判断本操作是否是当前要求的操作并对要求操作做更新 if (isTeacher) { gameObject.GetComponent <SCTeacher>().isAccord(temp); } int nextstate = temp.stateChange(currentState); if (nextstate != 0) { operationList.Add(temp.h_name + drugnamestr + ":√"); stateGetAndShow(nextstate); } else { operationList.Add(temp.h_name + drugnamestr + ":×"); } result2.Close(); db2.CloseSqlConnection(); } }