public void selectUserTransitionUtteranceOption(int transitionId, string userNote) { //--Data Base Access Variables-- MySql.Data.MySqlClient.MySqlCommand dbCommand = new MySql.Data.MySqlClient.MySqlCommand(); MySql.Data.MySqlClient.MySqlConnection dbConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); dbCommand.Connection = dbConnection; //----------------------------- int queryResult = -1; try { dbConnection.Open(); TTransitionUtterance tTransitionUtterance = getTransitionUtterance(transitionId); THistory tHistory = new THistory(tTransitionUtterance.simulation_id, tTransitionUtterance.id, userNote, -1, "", DateTime.Now); addHistory(tHistory); do { dbCommand.CommandText = "DELETE FROM TB_TRANSITION_UTTERANCES WHERE simulation_id = " + tTransitionUtterance.simulation_id + " AND history_id = -1"; queryResult = dbCommand.ExecuteNonQuery(); //Futuramente deletar os que não possuem correspondência. } while (queryResult < 0); } catch { System.Threading.Thread.Sleep(20000); } dbConnection.Close(); }
public THistory getLastHistory(int simulationId) { //--Data Base Access Variables-- MySql.Data.MySqlClient.MySqlCommand dbCommand = new MySql.Data.MySqlClient.MySqlCommand(); MySql.Data.MySqlClient.MySqlConnection dbConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); MySql.Data.MySqlClient.MySqlDataReader dbDataReader; dbCommand.Connection = dbConnection; //------------------------------ dbCommand.CommandText = "SELECT * FROM TB_HISTORYS WHERE (simulation_id = " + simulationId.ToString() + ") ORDER BY dialogDateTime DESC"; try { dbConnection.Open(); THistory tHistory; dbDataReader = dbCommand.ExecuteReader(); dbDataReader.Read(); tHistory = new THistory(Convert.ToInt32(dbDataReader["simulation_id"]), Convert.ToInt32(dbDataReader["user_tu_id"]), dbDataReader["user_note"].ToString(), Convert.ToInt32(dbDataReader["designer_tu_id"]), dbDataReader["designer_note"].ToString(), Convert.ToDateTime(dbDataReader["dialogDateTime"])); tHistory.id = Convert.ToInt32(dbDataReader["id"].ToString()); dbDataReader.Close(); dbConnection.Close(); return(tHistory); } catch { dbConnection.Close(); System.Threading.Thread.Sleep(20000); return(null); } }
public void addHistory(THistory tHistory) { //--Data Base Access Variables-- MySql.Data.MySqlClient.MySqlCommand dbCommand = new MySql.Data.MySqlClient.MySqlCommand(); MySql.Data.MySqlClient.MySqlConnection dbConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); MySql.Data.MySqlClient.MySqlDataReader dbDataReader; dbCommand.Connection = dbConnection; //----------------------------- int historyId = -1; try { dbConnection.Open(); dbCommand.CommandText = "INSERT INTO TB_HISTORYS (simulation_id, user_tu_id, user_note, designer_tu_id, designer_note, dialogDateTime) VALUES(" + tHistory.simulation_id.ToString() + ", " + tHistory.user_tu_id.ToString() + ", '" + tHistory.user_note + "', " + tHistory.designer_tu_id.ToString() + ", '" + tHistory.designer_note + "', '" + tHistory.dialogDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "')"; dbCommand.ExecuteNonQuery(); dbCommand.CommandText = "SELECT * FROM TB_HISTORYS WHERE (simulation_id = " + tHistory.simulation_id.ToString() + ") AND (dialogDateTime = '" + tHistory.dialogDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "')"; dbDataReader = dbCommand.ExecuteReader(); if (!dbDataReader.HasRows) { IFormatProvider culture = new CultureInfo("en-US"); dbDataReader.Close(); dbCommand.CommandText = "SELECT * FROM TB_HISTORYS WHERE (simulation_id = " + tHistory.simulation_id.ToString() + ") AND (dialogDateTime = '" + tHistory.dialogDateTime.GetDateTimeFormats(culture)[74].ToString() + "')"; dbDataReader = dbCommand.ExecuteReader(); } dbDataReader.Read(); historyId = Convert.ToInt32(dbDataReader["id"]); dbDataReader.Close(); if (tHistory.user_tu_id > 0) { dbCommand.CommandText = "UPDATE TB_TRANSITION_UTTERANCES SET history_id = '" + historyId + "' WHERE id = " + tHistory.user_tu_id; } else { dbCommand.CommandText = "UPDATE TB_TRANSITION_UTTERANCES SET history_id = '" + historyId + "' WHERE id = " + tHistory.designer_tu_id; } dbCommand.ExecuteNonQuery(); dbConnection.Close(); } catch (Exception ex) { System.Threading.Thread.Sleep(20000); } }
private void proceedConversation() { if (listBoxOptions.Items.Count <= 0) { //##### USER TURN ##### THistory tHistory = DbControl.getInstance().getLastHistory(simulationId); tHistory.designer_note = txtDesignerNote.Text; DbControl.getInstance().setHistory(tHistory); dataGridHistory.Rows[dataGridHistory.Rows.Count - 2].Cells[5].Value = tHistory.designer_note; //Wait For User Response callNextSpeakerAndWait(); txtDesignerNote.Text = ""; continueNavigation(); //##################### } else { //##### DESIGNER TURN ##### if (listBoxOptions.SelectedIndex < 0) { return; } TTransitionUtterance tTransitionUtterance = (TTransitionUtterance)listBoxOptions.SelectedItem; int transitionId = DbControl.getInstance().addTransitionUtterance(tTransitionUtterance, null); THistory tHistory = new THistory(tTransitionUtterance.simulation_id, -1, "", transitionId, txtDesignerNote.Text, DateTime.Now); DbControl.getInstance().addHistory(tHistory); txtDesignerNote.Text = ""; //Continue... continueNavigation(); //Clear "listBoxOptions" with the Designer's selected Option listBoxOptions.Items.Clear(); //Wait For User Response callNextSpeakerAndWait(); //Continue... continueNavigation(); //######################### } }
public void setHistory(THistory tHistory) { //--Data Base Access Variables-- MySql.Data.MySqlClient.MySqlCommand dbCommand = new MySql.Data.MySqlClient.MySqlCommand(); MySql.Data.MySqlClient.MySqlConnection dbConnection = new MySql.Data.MySqlClient.MySqlConnection(connectionString); dbCommand.Connection = dbConnection; //----------------------------- try { dbConnection.Open(); dbCommand.CommandText = "UPDATE TB_HISTORYS SET simulation_id = " + tHistory.simulation_id.ToString() + ", user_tu_id = " + tHistory.user_tu_id.ToString() + ", user_note = '" + tHistory.user_note + "', designer_tu_id = " + tHistory.designer_tu_id.ToString() + ", designer_note = '" + tHistory.designer_note + "', dialogDateTime = '" + tHistory.dialogDateTime.ToString("yyyy-MM-dd HH:mm:ss") + "' WHERE id = " + tHistory.id; dbCommand.ExecuteNonQuery(); } catch (Exception ex) { System.Threading.Thread.Sleep(20000); } dbConnection.Close(); }
private void listBoxOptions_DoubleClick(object sender, EventArgs e) { if (listBoxOptions.SelectedIndex < 0) { return; } int transactionId = ((TTransitionUtterance)listBoxOptions.SelectedItem).id; doDialog(transactionId, txtUserNote.Text); txtUserNote.Text = ""; THistory tLastHistory = DbControl.getInstance().getLastHistory(simulationId); refreshHistory(tLastHistory); callNextSpeakerAndWait(); tLastHistory = DbControl.getInstance().getLastHistory(simulationId); refreshHistory(tLastHistory); showDialogOptions(); }
private void continueNavigation() { THistory tHistory = DbControl.getInstance().getLastHistory(simulationId); TTransitionUtterance tTransitionUtterance; refresHistory(tHistory); //Get Last Transition Utterance if (tHistory.user_tu_id >= 0) { tTransitionUtterance = DbControl.getInstance().getTransitionUtterance(tHistory.user_tu_id); } else { tTransitionUtterance = DbControl.getInstance().getTransitionUtterance(tHistory.designer_tu_id); } //Get TARGET options from LAST TARGET List <TTransitionUtterance> transitionUtterances = getXmlTransitionUtterances(tTransitionUtterance.target); //Check EMITTER if (transitionUtterances.Count <= 0) { listBoxOptions.Items.Clear(); listBoxOptions.Enabled = false; gbInteractionPosition.Visible = false; splitContainer1.SplitterDistance = 0; MessageBox.Show("The user reached a closing point. The interaction has been completed."); callNextSpeaker(); return; } if (transitionUtterances[0].emitter == "user") { int queryResult = 0; //###### Add Dialog Options To User ###### for (int countTu = 0; countTu < transitionUtterances.Count; countTu++) { transitionUtterances[countTu].simulation_id = simulationId; List <TDialog> tDialogs = null; if (transitionUtterances[countTu].legend == 1) { tDialogs = getDialogsFromXml(transitionUtterances[countTu].source); } queryResult = DbControl.getInstance().addUserTransitionUtteranceOption(transitionUtterances[countTu], tDialogs); } //######################################## //###### Add Ubiquitous Access Options To User ###### XmlNodeList ubiquitousAccessNodes = xmlDocument.GetElementsByTagName("ubiquitousAccess"); //List Of Opening Points for (int countOp = 0; countOp < ubiquitousAccessNodes.Count; countOp++) { List <TTransitionUtterance> listTransitionUtterances = getXmlTransitionUtterances(ubiquitousAccessNodes[countOp].Attributes["id"].Value); for (int countTu = 0; countTu < listTransitionUtterances.Count; countTu++) { listTransitionUtterances[countTu].simulation_id = simulationId; //####### Verify PRECOND ####### string precond = getAttributeFromXml("transitionUtterance", listTransitionUtterances[countTu].xml_id, "precond"); if (precond != "") { if (tTransitionUtterance.target == precond) { continue; //User is in the precond scene } } //############################## DbControl.getInstance().addUserTransitionUtteranceOption(listTransitionUtterances[countTu], null); } } //################################################### if (!tTransitionUtterance.isBreakdown) { showOnlyNoteOnNextStep(true); } } else { //Designer choose listBoxOptions.Items.Clear(); //###### Add Transaction Utterance Options ###### //List Of Opening Points for (int count = 0; count < transitionUtterances.Count; count++) { listBoxOptions.Items.Add(transitionUtterances[count]); } if (transitionUtterances.Count > 0) { listBoxOptions.SelectedIndex = 0; listBoxOptions.Focus(); } //################################ showOnlyNoteOnNextStep(false); } }
private void refresHistory(THistory tHistory) { /*dataGridHistory.DataSource = null; * dataGridHistory.Refresh(); * this.tB_HISTORYSTableAdapter.Connection = new System.Data.OleDb.OleDbConnection(DbControl.getInstance().getDataBaseConnectionString()); * this.tB_HISTORYSTableAdapter.Fill(this.dbMoLIC_WOz_TB_HISTORY.TB_HISTORYS, simulationId); * dataGridHistory.DataSource = dbMoLIC_WOz_TB_HISTORY.TB_HISTORYS; * dataGridHistory.Refresh();*/ TTransitionUtterance tTransactionUtterance; if (tHistory.user_tu_id >= 0) { tTransactionUtterance = DbControl.getInstance().getTransitionUtterance(tHistory.user_tu_id); //------ Set Last Transition ------ lbSpeaker.Text = "The user said:"; lbLastTransition.Text = tTransactionUtterance.description; lbTopic.Text = tTransactionUtterance.source_topic; if (tHistory.user_note != "") { txtUserNote.Text = tHistory.user_note; txtUserNote.Visible = true; } else { txtUserNote.Visible = false; } Image imgLegend = null; if (tTransactionUtterance.source.Contains("scene")) { imgLegend = imgListLegends.Images[1]; } if (tTransactionUtterance.source.Contains("system")) { imgLegend = imgListLegends.Images[5]; } if (tTransactionUtterance.source.Contains("op")) { imgLegend = imgListLegends.Images[3]; } /*pbLocation.Image = imgLegend; * pbAnswer.Image = imgListLegends.Images[5];*/ //--------------------------------- //------ Add Dialogs & Signs ------ listBoxDialogsAndSigns.Items.Clear(); if (tTransactionUtterance.legend == 1) { List <TDialog> tDialogs = DbControl.getInstance().getUserTransitionUtteranceDialogs(tTransactionUtterance.id); if (tDialogs != null) { showDialogsAndSigns(true); for (int countDialogs = 0; countDialogs < tDialogs.Count; countDialogs++) { listBoxDialogsAndSigns.Items.Add(tDialogs[countDialogs].dialog); if (tDialogs[countDialogs].signs != null) { for (int countSigns = 0; countSigns < tDialogs[countDialogs].signs.Count; countSigns++) { listBoxDialogsAndSigns.Items.Add(" - " + tDialogs[countDialogs].signs[countSigns].sign); } } } } else { showDialogsAndSigns(false); } } else { showDialogsAndSigns(false); } //--------------------------------- dataGridHistory.Rows.Add(imgListLegends.Images[tTransactionUtterance.legend], tTransactionUtterance.source_topic, tHistory.user_note, imgListLegends.Images[0], "", tHistory.designer_note, tHistory.dialogDateTime.ToString()); if (tTransactionUtterance.isBreakdown) { dataGridHistory.Rows.Add(imgListLegends.Images[8], tTransactionUtterance.description, "", imgListLegends.Images[0], "", "", tHistory.dialogDateTime.ToString()); } else { dataGridHistory.Rows.Add(imgListLegends.Images[7], tTransactionUtterance.description, "", imgListLegends.Images[0], "", "", tHistory.dialogDateTime.ToString()); } if (tTransactionUtterance.target.Contains("cp")) { dataGridHistory.Rows.Add(imgListLegends.Images[4], tTransactionUtterance.target, "", imgListLegends.Images[0], "", "", tHistory.dialogDateTime.ToString()); } } else { tTransactionUtterance = DbControl.getInstance().getTransitionUtterance(tHistory.designer_tu_id); //------ Set Last Transition ------ lbSpeaker.Text = "You said:"; lbLastTransition.Text = tTransactionUtterance.description; if (tHistory.user_note != "") { txtUserNote.Text = tHistory.user_note; txtUserNote.Visible = true; } else { txtUserNote.Visible = false; } Image imgLegend = null; if (tTransactionUtterance.source.Contains("scene")) { imgLegend = imgListLegends.Images[1]; } if (tTransactionUtterance.source.Contains("system")) { imgLegend = imgListLegends.Images[5]; } if (tTransactionUtterance.source.Contains("op")) { imgLegend = imgListLegends.Images[3]; } /*pbLocation.Image = imgLegend; * pbAnswer.Image = imgListLegends.Images[5];*/ //--------------------------------- dataGridHistory.Rows.Add(imgListLegends.Images[0], "", tHistory.user_note, imgListLegends.Images[tTransactionUtterance.legend], tTransactionUtterance.source_topic, tHistory.designer_note, tHistory.dialogDateTime.ToString()); if (tTransactionUtterance.isBreakdown) { dataGridHistory.Rows.Add(imgListLegends.Images[0], "", "", imgListLegends.Images[8], tTransactionUtterance.description, "", tHistory.dialogDateTime.ToString()); } else { dataGridHistory.Rows.Add(imgListLegends.Images[0], "", "", imgListLegends.Images[7], tTransactionUtterance.description, "", tHistory.dialogDateTime.ToString()); } if (tTransactionUtterance.target.Contains("cp")) { dataGridHistory.Rows.Add(imgListLegends.Images[4], tTransactionUtterance.target, "", imgListLegends.Images[0], "", "", tHistory.dialogDateTime.ToString()); } } }