private void Txt_OnValueChanged(object sender, EventArgs e) { if (((Bunifu.Framework.UI.BunifuMetroTextbox)sender).Text != "" && loadedNode != null) { try { int numberOfTxt = int.Parse(((Bunifu.Framework.UI.BunifuMetroTextbox)sender).Tag.ToString()); var followFromTree = fromNodeToObject[loadedNode]; if (followFromTree.Followups.Count < numberOfTxt) { var nT = new TreeNode(((Bunifu.Framework.UI.BunifuMetroTextbox)sender).Text); loadedNode.Nodes.Add(nT); var nF = new Followup(); nF.PlayerResponse = nT.Text; followFromTree.Followups.Add(nF); fromNodeToObject.Add(nT, nF); if (!fromFollowToFather.ContainsKey(nF)) { fromFollowToFather.Add(nF, followFromTree); } if (numberOfTxt != 8) { answerTexts[numberOfTxt].Show(); } } else { followFromTree.Followups[numberOfTxt - 1].PlayerResponse = ((Bunifu.Framework.UI.BunifuMetroTextbox)sender).Text; loadedNode.Nodes[numberOfTxt - 1].Text = ((Bunifu.Framework.UI.BunifuMetroTextbox)sender).Text; } } catch { } } }
public int SaveRegularFollowUp(Followup followup) { int count = 0; try { for (int i = 0; i < followup.AFollowupList.Count; i++) { Query = "INSERT INTO tbl_PatientFollowUpRegular([FollowUPID],[PatientID],[FollowUpItemID],[Particulars],[ItemType],[DoctorID],[Shift],[Date])" + "VALUES(@FollowUPID,@PatientID,@FollowUpItemID, @Particulars, @ItemType,@DoctorID, @Shift,@Date)"; Command = new SqlCommand(Query, Connection); Command.CommandType = CommandType.Text; Command.Parameters.AddWithValue(@"FollowUPID", followup.SerialId); Command.Parameters.AddWithValue(@"PatientID", followup.OPID); Command.Parameters.AddWithValue(@"FollowUpItemID", followup.AFollowupList[i].FollowUPItemId); Command.Parameters.AddWithValue(@"DoctorID", followup.DocId); Command.Parameters.AddWithValue(@"Particulars", followup.AFollowupList[i].Particulars); Command.Parameters.AddWithValue(@"ItemType", followup.AFollowupList[i].ItemType); Command.Parameters.AddWithValue(@"Shift", followup.Shift); Command.Parameters.AddWithValue(@"Date", followup.Date); count += Command.ExecuteNonQuery(); } } catch (Exception) { } return(count); }
private void dfsInModel(Followup follow, ref TreeNode father) { var copyFather = father; var newNode = new TreeNode($"{follow.PlayerResponse}"); if (!fromNodeToObject.ContainsKey(father)) { fromNodeToObject.Add(father, follow); } father.Nodes.Add(newNode); father = newNode; if (!fromNodeToObject.ContainsKey(father)) { fromNodeToObject.Add(father, follow); } foreach (var followup in follow.Followups) { if (!fromFollowToFather.ContainsKey(followup)) { fromFollowToFather.Add(followup, follow); } dfsInModel(followup, ref father); } father = copyFather; }
public int SaveFollowUp(Followup followup) { int count = 0; if (followup.ListOfDrug != null) { foreach (DataRow value in followup.ListOfDrug.Rows) { Query = "INSERT INTO [tbl_PatientFollowup]([SerialFollowUp],[OPID],[Drug],[DoctorID],[Dous],[FollowupId],[BP],[ExtraNote],[ExtraNoteSpecial],[Date])" + "VALUES(@SerialFollowUp,@OPID,@Drug, @DoctorID, @Dous,@FollowupId, @BP,@ExtraNote,@ExtraNoteSpecial,@Date)"; Command = new SqlCommand(Query, Connection); Command.CommandType = CommandType.Text; Command.Parameters.AddWithValue(@"SerialFollowUp", followup.SerialId); Command.Parameters.AddWithValue(@"OPID", followup.OPID); Command.Parameters.AddWithValue(@"Drug", value["DrugId"]); Command.Parameters.AddWithValue(@"DoctorID", followup.DocId); Command.Parameters.AddWithValue(@"Dous", value["Dous"]); Command.Parameters.AddWithValue(@"FollowupId", ""); Command.Parameters.AddWithValue(@"BP", followup.Bp); Command.Parameters.AddWithValue(@"ExtraNote", value["ExtraNote"]); Command.Parameters.AddWithValue(@"ExtraNoteSpecial", value["ExtraNoteSpecial"]); Command.Parameters.AddWithValue(@"Date", followup.Date); count += Command.ExecuteNonQuery(); } } return(count); }
public MessageModel SaveRegularFollowUp(Followup followup) { MessageModel model = new MessageModel(); if (followup.DocId == "") { model.MessageBody = "Please select Doctor"; model.MessageTitle = "Warning"; } else if (followup.Shift == "") { model.MessageBody = "Please select Shift"; model.MessageTitle = "Warning"; } if (followup.OPID == "") { model.MessageBody = "Please select Patient"; model.MessageTitle = "Warning"; } else { int count = new MedicalGatway().SaveRegularFollowUp(followup); if (count > 0) { model.MessageBody = "Follow Up data Saved"; model.MessageTitle = "Success"; } } return(model); }
private void btnDelete_Click(object sender, EventArgs e) { MessageModel aMessageModel = new MessageModel(); if (!string.IsNullOrEmpty(cmbPid.Text)) { MessageBox.Show("Select a patient.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DialogResult dr = MessageBox.Show("Are you sure to delete row?", "Confirmation Message", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { Followup followup = new Followup(); followup.OPID = cmbPid.Text; followup.SerialId = txtFollowupSlNo.Text; aMessageModel = aMedicalManager.DeletePatientFollowup(followup); if (aMessageModel.MessageTitle == "Successfull") { MessageBox.Show(aMessageModel.MessageBody, aMessageModel.MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); GenerateFollowSerialNo(); Refresh(); } } } }
public IHttpActionResult PutFollowup(int id, Followup followup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != followup.ID) { return(BadRequest()); } db.Entry(followup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!FollowupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public int DeletePatientFollowupSheet(Followup followup) { Query = "DELETE tbl_PatientFollowUpRegular WHERE FollowUPID='" + followup.SerialId + "'"; Command = new SqlCommand(Query, Connection); int rowAffect = Command.ExecuteNonQuery(); return(rowAffect); }
public DataTable GetPatientFollowupByOpid(Followup followup) { DataTable data = new DataTable(); aMedicalGatway = new MedicalGatway(); data = aMedicalGatway.GetPatientFollowupByOpid(followup); return(data); }
private void gridViewFollowUp_DoubleClick(object sender, EventArgs e) { xtraTabPage1.Show(); Followup followup = new Followup(); string Department = gridViewFollowUp.GetFocusedRowCellValue("Deparment").ToString(); followup.OPID = gridViewFollowUp.GetFocusedRowCellValue("OPID").ToString(); cmbPid.Text = gridViewFollowUp.GetFocusedRowCellValue("OPID").ToString(); txtFollowupSlNo.Text = gridViewFollowUp.GetFocusedRowCellValue("SerialFollowUp").ToString(); followup.SerialId = txtFollowupSlNo.Text; txtShift.Text = gridViewFollowUp.GetFocusedRowCellValue("Shift").ToString(); txtName.Text = gridViewFollowUp.GetFocusedRowCellValue("PatientName").ToString(); //txtSuggetion.Text = gridViewFollowUp.GetFocusedRowCellValue("ExtraNoteSpecial").ToString(); //txtExtraNotes.Text = gridViewFollowUp.GetFocusedRowCellValue("ExtraNote").ToString(); cmbDoctor.Text = gridViewFollowUp.GetFocusedRowCellValue("DoctorName").ToString(); FolluwUpDate.Text = gridViewFollowUp.GetFocusedRowCellValue("Date").ToString(); cmbDept.Text = Department; aMedicalManager = new MedicalManager(); DataTable dt = aMedicalManager.UpdateFollowUpSheet(followup.OPID, txtFollowupSlNo.Text); //gridControl1.DataSource = dt; for (int i = 0; i < gridView1.RowCount; i++) { //string ItemID =gridView1.GetRowCellValue(i, "MasterId").ToString() ; foreach (DataRow row in dt.Rows) { if (row["FollowUpItemID"].ToString() == gridView1.GetRowCellValue(i, "MasterId").ToString()) { string values = row["Particulars"].ToString(); gridView1.SetRowCellValue(i, "Value", values); } } } //dgvServices.DataSource = null; //drugTable.Rows.Clear(); DataTable dataTable = new DataTable(); dataTable = new MedicalManager().GetPatientFollowupByOpid(followup); drugTable.Rows.Clear(); for (int i = 0; i < dataTable.Rows.Count; i++) { DataRow rows1 = drugTable.NewRow(); rows1["DrugId"] = dataTable.Rows[i]["Drug"]; rows1["Drug"] = dataTable.Rows[i]["ProductName"]; rows1["Dous"] = dataTable.Rows[i]["Dous"]; rows1["ExtraNote"] = dataTable.Rows[i]["ExtraNote"]; rows1["ExtraNoteSpecial"] = dataTable.Rows[i]["ExtraNoteSpecial"]; drugTable.Rows.Add(rows1); } dgvServices.DataSource = drugTable; btnSave.Enabled = false; btnUpdate.Enabled = true; btnDelete.Enabled = true; }
private void btn_new_click(object sender, EventArgs e) { rootConversation = new Followup(); rootConversation.Reply = "start"; rootConversation.PlayerResponse = "start"; locationOpened = ""; UpdateTreeView(); }
private async void OpenDetails(object sender, SelectedItemChangedEventArgs e) { var ailment = (FollowupAilment)e.SelectedItem; int ailment_id = ailment.id; Followup followup = await App.Database.GetFollowupByAilmentID(ailment_id); await Navigation.PushAsync(new FollowupDetails(followup, ailment)); }
public DataTable GetPatientFollowupByOpid(Followup followup) { Query = "SELECT * FROM ViewGetAllPatientFollowup WHERE OPID='" + followup.OPID + "'"; Command = new SqlCommand(Query, Connection); Command.CommandType = CommandType.Text; Reader = Command.ExecuteReader(); DataTable data = new DataTable(); data.Load(Reader); return(data); }
public IHttpActionResult GetFollowup(int id) { Followup followup = db.Followups.Find(id); if (followup == null) { return(NotFound()); } return(Ok(followup)); }
public Task <FollowupResponse> Handle(Request request, CancellationToken cancellationToken) { var user = request.GetUser(); var followup = new Followup { UserId = user.Id, ActivityDate = request.ActivityDate, JobApplicationId = request.JobApplicationId, FollowupDescription = request.FollowupDescription }; using var connection = _connectionFactory(); connection.Save(followup); return(Task.Run(() => FollowupResponse.MapFrom(followup), cancellationToken)); }
public IHttpActionResult PostFollowup(Followup followup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Followups.Add(followup); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = followup.ID }, followup)); }
public MessageModel UpdateFollowUp(Followup followup) { MessageModel model = new MessageModel(); int count = new MedicalGatway().UpdateFollowUp(followup); if (count > 0) { model.MessageBody = "FollowUp data Updated"; model.MessageTitle = "Success"; } return(model); }
public static FollowupResponse MapFrom(Followup followup) { if (followup == null) { return(null); } var response = new FollowupResponse { Id = followup.Id, ActivityDate = followup.ActivityDate, JobApplicationId = followup.JobApplicationId, FollowupDescription = followup.FollowupDescription }; return(response); }
public IHttpActionResult DeleteFollowup(int id) { Followup followup = db.Followups.Find(id); if (followup == null) { return(NotFound()); } db.Followups.Remove(followup); db.SaveChanges(); return(Ok(followup)); }
public MessageModel SaveFollowUp(Followup followup) { MessageModel model = new MessageModel(); if (followup.DocId == "") { model.MessageBody = "Please select Doctor"; model.MessageTitle = "Warning"; return(model); } else if (followup.Shift == "") { model.MessageBody = "Please select Shift"; model.MessageTitle = "Warning"; return(model); } if (followup.OPID == "") { model.MessageBody = "Please select Patient"; model.MessageTitle = "Warning"; return(model); } else { int count = new MedicalGatway().SaveRegularFollowUp(followup); if (count > 0) { count = new MedicalGatway().FOllowUpmaster(followup); } if (count > 0) { int count1 = new MedicalGatway().SaveFollowUp(followup); if (count1 > 0) { } } else { model.MessageBody = "Please Input FollowUp Sheet"; model.MessageTitle = "Warning"; } if (count > 0) { model.MessageBody = "Follow Up Saved Successfully"; model.MessageTitle = "Success"; } } return(model); }
public FollowupDetails(Followup followup, FollowupAilment ailment) { InitializeComponent(); this.Title = ailment.ailment; var advicePage = new NavigationPage(new FollowupAdvicePage(followup.advice)); advicePage.Title = "Advice"; var treatmentPage = new NavigationPage(new FollowupTreatmentPage(followup.treatment)); treatmentPage.Title = "Treatment"; Children.Add(advicePage); Children.Add(treatmentPage); }
public void SaveItemValue() { Followup followup = new Followup(); followup.OPID = cmbPid.Text; followup.SerialId = txtFollowupSlNo.Text; followup.Bp = txtBP.Text; followup.DocId = cmbDoctor.SelectedValue.ToString(); followup.Shift = txtShift.Text; followup.Date = FolluwUpDate.Value; followup.Date = FolluwUpDate.Value; followup.AFollowupList = GetFollowUP(); MessageModel message = new MedicalManager().SaveRegularFollowUp(followup); MessageBox.Show(message.MessageBody, message.MessageTitle); }
private void btnUpdate_Click(object sender, EventArgs e) { MessageModel aMessageModel = new MessageModel(); Followup followup = new Followup(); followup.OPID = cmbPid.Text; followup.SerialId = txtFollowupSlNo.Text; aMessageModel = aMedicalManager.DeletePatientFollowup1(followup); if (aMessageModel.MessageTitle == "Successfull") { Save(); // MessageBox.Show("Updated Successfully.", aMessageModel.MessageTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); GenerateFollowSerialNo(); Refresh(); } }
public int FOllowUpmaster(Followup followup) { int count = 0; Query = "INSERT INTO [tbl_PatientFollowUPMaster]([PatientId],[FollowUPId],[Date],[ExtraNote],[Doctor],[Shift],[Department])" + "VALUES(@PatientId,@FollowUPId,@Date, @ExtraNote, @Doctor,@Shift, @Department)"; Command = new SqlCommand(Query, Connection); Command.CommandType = CommandType.Text; Command.Parameters.AddWithValue(@"PatientId", followup.OPID); Command.Parameters.AddWithValue(@"FollowUPId", followup.SerialId); Command.Parameters.AddWithValue(@"Date", followup.Date); Command.Parameters.AddWithValue(@"ExtraNote", ""); Command.Parameters.AddWithValue(@"Doctor", followup.DocId); Command.Parameters.AddWithValue(@"Shift", followup.Shift); Command.Parameters.AddWithValue(@"Department", followup.Department); count += Command.ExecuteNonQuery(); return(count); }
public MessageModel DeletePatientFollowup1(Followup followup) { MessageModel aMessageModel = new MessageModel(); aMedicalGatway = new MedicalGatway(); int count = aMedicalGatway.DeletePatientFollowup(followup); if (count > 0) { count = aMedicalGatway.DeletePatientFollowupMaster(followup); } if (count > 0) { count = aMedicalGatway.DeletePatientFollowupSheet(followup); } if (count > 0) { aMessageModel.MessageTitle = "Successfull"; // aMessageModel.MessageBody = "Patient Followup deleted successfully."; } return(aMessageModel); }
public List <Followup> GetFollowUP() { aFollowups.Clear(); for (int i = 0; i < gridView1.RowCount; i++) { Followup followup = new Followup(); var ItemValue = gridView1.GetRowCellValue(i, "Value").ToString(); if (ItemValue != "") { followup.SerialId = txtFollowupSlNo.Text; followup.OPID = cmbPid.Text; followup.FollowUPItemId = gridView1.GetRowCellValue(i, "MasterId").ToString(); followup.Particulars = gridView1.GetRowCellValue(i, "Value").ToString(); followup.ItemType = gridView1.GetRowCellValue(i, "Item").ToString(); followup.DocId = cmbDoctor.SelectedValue.ToString(); followup.Shift = txtShift.Text; followup.Department = gridView1.GetRowCellValue(i, "DeptId").ToString(); aFollowups.Add(followup); } } return(aFollowups); }
public int UpdateFollowUp(Followup followup) { int count = 0; foreach (DataRow value in followup.ListOfDrug.Rows) { Query = "UPDATE TABLE tbl_PatientFollowup SET Drug=@Drug,DoctorID=@DoctorID,Dous=@Dous,FollowupId=@FollowupId," + "BP=@BP,ExtraNote=@ExtraNote,ExtraNoteSpecial=@ExtraNoteSpecial,Date=@Date WHERE OPID='" + followup.OPID + "'"; Command = new SqlCommand(Query, Connection); Command.CommandType = CommandType.Text; Command.Parameters.AddWithValue(@"Drug", value["DrugId"]); Command.Parameters.AddWithValue(@"DoctorID", followup.DocId); Command.Parameters.AddWithValue(@"Dous", value["Dous"]); Command.Parameters.AddWithValue(@"FollowupId", ""); Command.Parameters.AddWithValue(@"BP", followup.Bp); Command.Parameters.AddWithValue(@"ExtraNote", value["ExtraNote"]); Command.Parameters.AddWithValue(@"ExtraNoteSpecial", value["ExtraNoteSpecial"]); Command.Parameters.AddWithValue(@"Date", followup.Date); count += Command.ExecuteNonQuery(); } return(count); }
private void searchLookTreatmentInfo_EditValueChanged(object sender, EventArgs e) { Followup followup = new Followup(); followup.OPID = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("OPID").ToString(); //txtName.Text = pidSearchLookUpEdit.Properties.View.GetFocusedRowCellValue("PatientName").ToString(); cmbPid.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("OPID").ToString(); txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("SerialFollowUp").ToString(); //txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("Drug").ToString(); txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("DoctorID").ToString(); txtName.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("PatientName").ToString(); txtGender.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("Gender").ToString(); //txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("Dous").ToString(); txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("FollowupId").ToString(); txtFollowupSlNo.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("BP").ToString(); txtExtraNotes.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("ExtraNote").ToString(); txtSuggetion.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("ExtraNoteSpecial").ToString(); FolluwUpDate.Text = searchLookTreatmentInfo.Properties.View.GetFocusedRowCellValue("Date").ToString(); aMedicalManager = new MedicalManager(); //dgvServices.DataSource = null; //drugTable.Rows.Clear(); DataTable dataTable = new DataTable(); dataTable = new MedicalManager().GetPatientFollowupByOpid(followup); for (int i = 0; i < dataTable.Rows.Count; i++) { DataRow rows = drugTable.NewRow(); rows["DrugId"] = dataTable.Rows[i]["DrugId"]; rows["Drug"] = dataTable.Rows[i]["Drug"]; rows["Dous"] = dataTable.Rows[i]["Dous"]; rows["ExtraNote"] = dataTable.Rows[i]["ExtraNote"]; rows["ExtraNoteSpecial"] = dataTable.Rows[i]["ExtraNoteSpecial"]; } dgvServices.DataSource = drugTable; }
public async Task <ImportedCards> FetchCards() { // Fetch spreadsheet from Google Sheet API V4 Debug.Log("[GoogleSheetsImporter] Fetching cards from Google Sheet " + _spreadsheetId + " ..."); HttpWebResponse response; try { HttpWebRequest request = WebRequest.CreateHttp( "https://sheets.googleapis.com/v4/spreadsheets/" + _spreadsheetId + "?includeGridData=true&key=" + _apiKey); response = (HttpWebResponse)await request.GetResponseAsync(); } catch (WebException e) { Debug.LogError("[GoogleSheetsImporter] Request failed: " + e.Message); return(new ImportedCards()); } Debug.Log("[GoogleSheetsImporter] " + (int)response.StatusCode + " " + response.StatusDescription); if (!response.ContentType.Contains("application/json")) { Debug.LogError("[GoogleSheetsImporter] Google Sheets API returned unrecognised data format"); return(new ImportedCards()); } Stream responseStream; if ((responseStream = response.GetResponseStream()) == null) { Debug.LogError("[GoogleSheetsImporter] Google Sheets API returned empty response"); return(new ImportedCards()); } Spreadsheet spreadsheet = JsonUtility.FromJson <Spreadsheet>( new StreamReader(responseStream).ReadToEnd()); // Parse Metadata sheet RowData[] metaRowData = spreadsheet.sheets[0].data[0].rowData; Dictionary <string, CellData> metadata = new Dictionary <string, CellData>(); foreach (RowData row in metaRowData) { if (row.values[0].StringValue != null) { if (metadata.ContainsKey(row.values[0].StringValue)) { Debug.LogWarning("[GoogleSheetsImporter] Duplicate key found in Metadata sheet"); } else { metadata.Add(row.values[0].StringValue, row.values[1]); } } } // Check sheet format version if (!RequireMetadata("majorFormatVersion", metadata)) { return(new ImportedCards()); } if (!RequireMetadata("minorFormatVersion", metadata)) { return(new ImportedCards()); } int sheetMajorVersion = metadata["majorFormatVersion"].IntValue; if (sheetMajorVersion != _majorFormatVersion) { Debug.LogError("[GoogleSheetsImporter] Incompatible sheet format major version (required: " + _majorFormatVersion + ", found: " + sheetMajorVersion + ")"); return(new ImportedCards()); } int sheetMinorVersion = metadata["minorFormatVersion"].IntValue; if (sheetMinorVersion < _minorFormatVersion) { Debug.LogError("[GoogleSheetsImporter] Incompatible sheet format minor version (required min: " + _minorFormatVersion + ", found: " + sheetMinorVersion + ")"); return(new ImportedCards()); } // Get sheet indices from metadata if (!RequireMetadata("cardSheetIndex", metadata)) { return(new ImportedCards()); } if (!RequireMetadata("specialCardSheetIndex", metadata)) { return(new ImportedCards()); } if (!RequireMetadata("characterSheetIndex", metadata)) { return(new ImportedCards()); } if (!RequireMetadata("imageSheetIndex", metadata)) { return(new ImportedCards()); } int cardSheetIndex = metadata["cardSheetIndex"].IntValue; int specialCardSheetIndex = metadata["specialCardSheetIndex"].IntValue; int characterSheetIndex = metadata["characterSheetIndex"].IntValue; int imageSheetIndex = metadata["imageSheetIndex"].IntValue; // Sanity-check sheet formats Sheet cardSheet = spreadsheet.sheets[cardSheetIndex]; if (!CheckCardSheetFormat(cardSheet)) { return(new ImportedCards()); } Sheet specialCardSheet = spreadsheet.sheets[specialCardSheetIndex]; if (!CheckCardSheetFormat(specialCardSheet)) { return(new ImportedCards()); } Sheet characterSheet = spreadsheet.sheets[characterSheetIndex]; if (!CheckCharacterSheetFormat(characterSheet)) { return(new ImportedCards()); } Sheet imageSheet = spreadsheet.sheets[imageSheetIndex]; if (!CheckImageSheetFormat(imageSheet)) { return(new ImportedCards()); } // Parse Images sheet Dictionary <int, Sprite> sprites = new Dictionary <int, Sprite>(); RowData[] imageRowData = imageSheet.data[0].rowData; for (int i = 1; i < imageRowData.Length; i++) { int id = imageRowData[i].values[0].IntValue; string imageUrl = imageRowData[i].values[1].hyperlink; if (sprites.ContainsKey(id)) { Debug.LogWarning("[GoogleSheetsImporter] Duplicate id found in Images sheet"); } else if (imageUrl == null) { Debug.LogWarning("[GoogleSheetsImporter] Image (id: " + id + ") has a null URL"); } else { Debug.Log("[GoogleSheetsImporter] Fetching image from " + imageUrl + " ..."); HttpWebRequest imageRequest = WebRequest.CreateHttp(imageUrl); HttpWebResponse imageResponse = (HttpWebResponse)await imageRequest.GetResponseAsync(); Debug.Log("[GoogleSheetsImporter] " + (int)imageResponse.StatusCode + " " + imageResponse.StatusDescription); Stream imageStream; if ((imageStream = imageResponse.GetResponseStream()) == null) { Debug.LogWarning("[GoogleSheetsImporter] Remote host returned no image in response"); } else { byte[] imageData = Util.BytesFromStream(imageStream); Texture2D texture = new Texture2D(1, 1); if (!texture.LoadImage(imageData)) { Debug.LogWarning("[GoogleSheetsImporter] Could not create sprite texture from image"); } else { Sprite sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f)); sprites.Add(id, sprite); } } } } // Parse Characters sheet Dictionary <int, Character> characters = new Dictionary <int, Character>(); RowData[] characterRowData = characterSheet.data[0].rowData; for (int i = 1; i < characterRowData.Length; i++) { int id = characterRowData[i].values[0].IntValue; if (characters.ContainsKey(id)) { Debug.LogWarning("[GoogleSheetsImporter] Duplicate id found in Images sheet"); } else { Character character = new Character(characterRowData[i].values[1].GetStringValue(""), defaultSprite); sprites.TryGetValue(characterRowData[i].values[2].IntValue, out character.sprite); characters.Add(id, character); } } // Parse Cards sheet Dictionary <int, Card> cards = new Dictionary <int, Card>(); RowData[] cardRowData = cardSheet.data[0].rowData; for (int i = 1; i < cardRowData.Length; i++) { int id = cardRowData[i].values[0].IntValue; if (cards.ContainsKey(id)) { Debug.LogWarning("[GoogleSheetsImporter] Duplicate id found in Cards sheet"); } else { JsonArray <CardPrerequisite> cardPrerequisites = JsonUtility.FromJson <JsonArray <CardPrerequisite> >(cardRowData[i].values[13].StringValue); JsonArray <SpecialCardPrerequisite> specialCardPrerequisites = JsonUtility.FromJson <JsonArray <SpecialCardPrerequisite> >(cardRowData[i].values[14].StringValue); List <ICardPrerequisite> prerequisites = new List <ICardPrerequisite>(); if (cardPrerequisites?.array != null) { prerequisites.AddRange(cardPrerequisites.array); } if (specialCardPrerequisites?.array != null) { prerequisites.AddRange(specialCardPrerequisites.array); } IFollowup leftActionFollowup = null; IFollowup rightActionFollowup = null; if (cardRowData[i].values[16].IntValue > 0) { if (cardRowData[i].values[15].StringValue == null) { leftActionFollowup = new Followup( cardRowData[i].values[15].IntValue, cardRowData[i].values[16].IntValue); } else { leftActionFollowup = new SpecialFollowup( cardRowData[i].values[15].StringValue, cardRowData[i].values[16].IntValue); } } if (cardRowData[i].values[18].IntValue > 0) { if (cardRowData[i].values[17].StringValue == null) { rightActionFollowup = new Followup( cardRowData[i].values[17].IntValue, cardRowData[i].values[18].IntValue); } else { rightActionFollowup = new SpecialFollowup( cardRowData[i].values[17].StringValue, cardRowData[i].values[18].IntValue); } } Card card = new Card( cardRowData[i].values[2].GetStringValue(""), cardRowData[i].values[3].GetStringValue(""), cardRowData[i].values[8].GetStringValue(""), null, new ActionOutcome( cardRowData[i].values[4].IntValue, cardRowData[i].values[5].IntValue, cardRowData[i].values[6].IntValue, cardRowData[i].values[7].IntValue, leftActionFollowup), new ActionOutcome( cardRowData[i].values[9].IntValue, cardRowData[i].values[10].IntValue, cardRowData[i].values[11].IntValue, cardRowData[i].values[12].IntValue, rightActionFollowup), prerequisites); characters.TryGetValue(cardRowData[i].values[1].IntValue, out card.character); cards.Add(id, card); } } // Parse SpecialCards sheet Dictionary <string, Card> specialCards = new Dictionary <string, Card>(); RowData[] specialCardRowData = specialCardSheet.data[0].rowData; for (int i = 1; i < specialCardRowData.Length; i++) { string id = specialCardRowData[i].values[0].StringValue; if (id == null) { Debug.LogWarning("[GoogleSheetsImporter] Null id found in SpecialCards sheet"); } else if (specialCards.ContainsKey(id)) { Debug.LogWarning("[GoogleSheetsImporter] Duplicate id found in SpecialCards sheet"); } else { Card card = new Card( specialCardRowData[i].values[2].GetStringValue(""), specialCardRowData[i].values[3].GetStringValue(""), specialCardRowData[i].values[8].GetStringValue(""), null, new GameOverOutcome(), new GameOverOutcome(), null); characters.TryGetValue(specialCardRowData[i].values[1].IntValue, out card.character); specialCards.Add(id, card); } } Debug.Log("[GoogleSheetsImporter] Cards imported successfully"); return(new ImportedCards(cards, specialCards)); }
private void loadJsonFromFile(string path) { rootConversation = JsonConvert.DeserializeObject <Followup>(File.ReadAllText(path)); this.locationOpened = path; UpdateTreeView(); }