Beispiel #1
0
        /// <summary>
        /// Creates OgamaDataSet and fills it with data from SQL Databasefile
        /// given bei <see cref="Properties.ExperimentSettings.DatabaseConnectionString"/>.
        /// </summary>
        /// <param name="splash">The loading document splash screens background worker,
        /// needed for interrupting splash when SQL connection fails.</param>
        /// <returns><strong>True</strong>,if successful, otherwise
        /// <strong>false</strong>.</returns>
        public bool LoadSQLData(BackgroundWorker splash)
        {
            // Creates new DataSet
            this.dataSet = new SQLiteOgamaDataSet();

            // Data Source=C:\Users\Adrian\Documents\OgamaExperiments\SlideshowDemo\Database\SlideshowDemo.sdf;Max Database Size=4091
            //bool automaticCorrectMachineNameTried = false;
            //bool automaticResetConnectionTried = false;
            //bool logRebuild = false;

            if (!File.Exists(this.experimentSettings.DatabaseSQLiteFile))
            {
                var result = InformationDialog.Show(
                    "Upgrade Database",
                    "We need to convert the SQL Database to SQLite. Otherwise Ogama will not be able to open the data. Please confirm the conversion process",
                    true,
                    MessageBoxIcon.Question);
                switch (result)
                {
                case DialogResult.Cancel:
                    return(false);

                case DialogResult.Yes:
                    // Show loading splash screen if it is not running
                    var bgwConvert = new BackgroundWorker();
                    bgwConvert.DoWork += this.bgwConvert_DoWork;
                    bgwConvert.WorkerSupportsCancellation = true;
                    bgwConvert.RunWorkerAsync();

                    // Remove the log, cause it may disable the conversion process
                    // if it comes from another storage location
                    if (File.Exists(this.experimentSettings.DatabaseLDFFile))
                    {
                        File.Delete(this.experimentSettings.DatabaseLDFFile);
                    }

                    this.ConvertToSQLiteDatabase();

                    bgwConvert.CancelAsync();

                    InformationDialog.Show(
                        "Conversion done.",
                        "The database was converted to sqlite format. The original source was not removed.",
                        false,
                        MessageBoxIcon.Information);
                    break;

                case DialogResult.No:
                    break;
                }
            }

            // Check for existing database
            if (!File.Exists(this.experimentSettings.DatabaseSQLiteFile))
            {
                string message = "The experiments database: " + Environment.NewLine +
                                 this.experimentSettings.DatabaseSQLiteFile + Environment.NewLine +
                                 "does not exist. This error could not be automically resolved." +
                                 Environment.NewLine + "Please move the database to the above location, " +
                                 "or create a new experiment.";
                ExceptionMethods.ProcessErrorMessage(message);
                return(false);
            }


            // Show loading splash screen if it is not running
            if (splash != null && !splash.IsBusy)
            {
                splash.RunWorkerAsync();
            }

            //  SqlConnection connectionString = new SqlConnection(Document.ActiveDocument.ExperimentSettings.ServerConnectionString);
            //  ServerConnection connection = new ServerConnection(connectionString);
            //  Server sqlServer = new Server(connection);
            //Attach:
            //  try
            //  {
            //    StringCollection sc = new StringCollection();
            //    sc.Add(Document.ActiveDocument.ExperimentSettings.DatabaseMDFFile);
            //    if (logRebuild)
            //    {
            //      if (File.Exists(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile))
            //      {
            //        File.Delete(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile);
            //      }
            //    }
            //    else
            //    {
            //      sc.Add(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile);
            //    }

            //    // Attach database file
            //    if (!sqlServer.Databases.Contains(Document.ActiveDocument.ExperimentSettings.Name))
            //    {
            //      sqlServer.AttachDatabase(
            //        Document.ActiveDocument.ExperimentSettings.Name,
            //        sc,
            //        logRebuild ? AttachOptions.RebuildLog : AttachOptions.None);
            //    }

            //    sqlServer.ConnectionContext.Disconnect();
            //    logRebuild = false;
            //  }
            //  catch (Exception ex)
            //  {
            //    // Check for the SQLError 9004, which indicates a failure
            //    // in the log file, which can be fixed by rebuilding the log.
            //    if (ex.InnerException != null)
            //    {
            //      if (ex.InnerException.InnerException != null)
            //      {
            //        if (ex.InnerException.InnerException is SqlException)
            //        {
            //          if (((SqlException)ex.InnerException.InnerException).Number == 9004)
            //          {
            //            logRebuild = true;
            //          }
            //        }
            //      }
            //    }

            //    if (!logRebuild)
            //    {
            //      string message = @"The following error occured: " + ex.Message + Environment.NewLine + Environment.NewLine +
            //        @"If it is the following: 'Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.'" +
            //        @"Please delete the folder 'Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\" + Document.ActiveDocument.ExperimentSettings.SqlInstanceName +
            //        "' in WinXP or " +
            //        @"'AppData\Local\Microsoft\Microsoft SQL Server Data\" + Document.ActiveDocument.ExperimentSettings.SqlInstanceName + "' on Vista and Windows 7 and try again.";
            //      ExceptionMethods.ProcessMessage("SQL Server connection failed.", message);
            //      ExceptionMethods.ProcessUnhandledException(ex);
            //      if (splash != null && splash.IsBusy)
            //      {
            //        splash.CancelAsync();
            //      }

            //      return false;
            //    }
            //  }

            //  // Go back and rebuild the log file.
            //  if (logRebuild)
            //  {
            //    goto Attach;
            //  }

            // Test connection
            using (var conn = new SQLiteConnection(Document.ActiveDocument.ExperimentSettings.DatabaseConnectionString))
            {
                try
                {
                    conn.Open();
                }
                catch (Exception ex)
                {
                    //if (splash != null && splash.IsBusy)
                    //{
                    //  splash.CancelAsync();
                    //}

                    //if (!automaticResetConnectionTried)
                    //{
                    //  this.experimentSettings.CustomConnectionString = string.Empty;
                    //  this.isModified = true;
                    //  automaticResetConnectionTried = true;
                    //  goto Test;
                    //}

                    //if (!automaticCorrectMachineNameTried)
                    //{
                    //  string currentConnectionString = this.experimentSettings.DatabaseConnectionString;
                    //  int firstEqualSign = currentConnectionString.IndexOf('=', 0);
                    //  int firstBackslash = currentConnectionString.IndexOf('\\', 0);
                    //  string machineName = currentConnectionString.Substring(firstEqualSign + 1, firstBackslash - firstEqualSign - 1);
                    //  string currentMachineName = Environment.MachineName;
                    //  currentConnectionString = currentConnectionString.Replace(machineName + "\\", currentMachineName + "\\");
                    //  this.experimentSettings.CustomConnectionString = currentConnectionString;
                    //  automaticCorrectMachineNameTried = true;
                    //  this.isModified = true;
                    //  goto Test;
                    //}

                    string message = "Connection to SQLite database failed." + Environment.NewLine +
                                     "Take a careful look at the database file to attach and its path. " +
                                     "The .db file should be named the same as the experiment .oga file and located in the "
                                     + "Database subfolder of the experiment." + Environment.NewLine + "The error message is: "
                                     + Environment.NewLine + ex.Message + Environment.NewLine;
                    ExceptionMethods.ProcessErrorMessage(message);

                    //SQLConnectionDialog connectionDialog = new SQLConnectionDialog();
                    //connectionDialog.ConnectionString = this.experimentSettings.DatabaseConnectionString;
                    //if (connectionDialog.ShowDialog() == DialogResult.OK)
                    //{
                    //  this.experimentSettings.CustomConnectionString = connectionDialog.ConnectionString;
                    //  this.isModified = true;
                    //}
                    //else
                    //{
                    //  return false;
                    //}

                    //goto Test;
                }
                finally
                {
                    try
                    {
                        conn.Close();
                    }
                    catch (Exception)
                    {
                    }
                }
            }

            if (splash != null && !splash.IsBusy)
            {
                splash.RunWorkerAsync();
            }

            Application.DoEvents();

            // Loads tables and Data from SQL file into DataSet
            if (this.dataSet.LoadData(splash))
            {
                return(true);
            }

            return(false);
        }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the DataToTable structure.
 /// </summary>
 /// <param name="newRawData">A <see cref="List{RawData}"/> with the new data.</param>
 /// <param name="newRawDataTable">A <see cref="SQLiteOgamaDataSet.RawdataDataTable"/> of the current subject
 /// where to write the data to.</param>
 public DataToTable(List<RawData> newRawData, SQLiteOgamaDataSet.RawdataDataTable newRawDataTable)
 {
   this.RawDataList = newRawData.ToArray();
   this.RawDataTable = newRawDataTable;
 }
Beispiel #3
0
    /// <summary>
    /// Creates OgamaDataSet and fills it with data from SQL Databasefile 
    /// given bei <see cref="Properties.ExperimentSettings.DatabaseConnectionString"/>.
    /// </summary>
    /// <param name="splash">The loading document splash screens background worker,
    /// needed for interrupting splash when SQL connection fails.</param>
    /// <returns><strong>True</strong>,if successful, otherwise
    /// <strong>false</strong>.</returns>
    public bool LoadSQLData(BackgroundWorker splash)
    {
      // Creates new DataSet
      this.dataSet = new SQLiteOgamaDataSet();

      // Data Source=C:\Users\Adrian\Documents\OgamaExperiments\SlideshowDemo\Database\SlideshowDemo.sdf;Max Database Size=4091
      //bool automaticCorrectMachineNameTried = false;
      //bool automaticResetConnectionTried = false;
      //bool logRebuild = false;

      if (!File.Exists(this.experimentSettings.DatabaseSQLiteFile))
      {
        var result = InformationDialog.Show(
          "Upgrade Database",
          "We need to convert the SQL Database to SQLite. Otherwise Ogama will not be able to open the data. Please confirm the conversion process",
          true,
          MessageBoxIcon.Question);
        switch (result)
        {
          case DialogResult.Cancel:
            return false;
          case DialogResult.Yes:
            // Show loading splash screen if it is not running
            var bgwConvert = new BackgroundWorker();
            bgwConvert.DoWork += this.bgwConvert_DoWork;
            bgwConvert.WorkerSupportsCancellation = true;
            bgwConvert.RunWorkerAsync();

            // Remove the log, cause it may disable the conversion process
            // if it comes from another storage location
            if (File.Exists(this.experimentSettings.DatabaseLDFFile))
            {
              File.Delete(this.experimentSettings.DatabaseLDFFile);
            }

            this.ConvertToSQLiteDatabase();

            bgwConvert.CancelAsync();

            InformationDialog.Show(
              "Conversion done.",
              "The database was converted to sqlite format. The original source was not removed.",
              false,
              MessageBoxIcon.Information);
            break;
          case DialogResult.No:
            break;
        }
      }

      // Check for existing database
      if (!File.Exists(this.experimentSettings.DatabaseSQLiteFile))
      {
        string message = "The experiments database: " + Environment.NewLine +
          this.experimentSettings.DatabaseSQLiteFile + Environment.NewLine +
          "does not exist. This error could not be automically resolved." +
          Environment.NewLine + "Please move the database to the above location, " +
          "or create a new experiment.";
        ExceptionMethods.ProcessErrorMessage(message);
        return false;
      }


      // Show loading splash screen if it is not running
      if (splash != null && !splash.IsBusy)
      {
        splash.RunWorkerAsync();
      }

      //  SqlConnection connectionString = new SqlConnection(Document.ActiveDocument.ExperimentSettings.ServerConnectionString);
      //  ServerConnection connection = new ServerConnection(connectionString);
      //  Server sqlServer = new Server(connection);
      //Attach:
      //  try
      //  {
      //    StringCollection sc = new StringCollection();
      //    sc.Add(Document.ActiveDocument.ExperimentSettings.DatabaseMDFFile);
      //    if (logRebuild)
      //    {
      //      if (File.Exists(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile))
      //      {
      //        File.Delete(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile);
      //      }
      //    }
      //    else
      //    {
      //      sc.Add(Document.ActiveDocument.ExperimentSettings.DatabaseLDFFile);
      //    }

      //    // Attach database file
      //    if (!sqlServer.Databases.Contains(Document.ActiveDocument.ExperimentSettings.Name))
      //    {
      //      sqlServer.AttachDatabase(
      //        Document.ActiveDocument.ExperimentSettings.Name,
      //        sc,
      //        logRebuild ? AttachOptions.RebuildLog : AttachOptions.None);
      //    }

      //    sqlServer.ConnectionContext.Disconnect();
      //    logRebuild = false;
      //  }
      //  catch (Exception ex)
      //  {
      //    // Check for the SQLError 9004, which indicates a failure 
      //    // in the log file, which can be fixed by rebuilding the log.
      //    if (ex.InnerException != null)
      //    {
      //      if (ex.InnerException.InnerException != null)
      //      {
      //        if (ex.InnerException.InnerException is SqlException)
      //        {
      //          if (((SqlException)ex.InnerException.InnerException).Number == 9004)
      //          {
      //            logRebuild = true;
      //          }
      //        }
      //      }
      //    }

      //    if (!logRebuild)
      //    {
      //      string message = @"The following error occured: " + ex.Message + Environment.NewLine + Environment.NewLine +
      //        @"If it is the following: 'Failed to generate a user instance of SQL Server due to a failure in starting the process for the user instance. The connection will be closed.'" +
      //        @"Please delete the folder 'Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\" + Document.ActiveDocument.ExperimentSettings.SqlInstanceName +
      //        "' in WinXP or " +
      //        @"'AppData\Local\Microsoft\Microsoft SQL Server Data\" + Document.ActiveDocument.ExperimentSettings.SqlInstanceName + "' on Vista and Windows 7 and try again.";
      //      ExceptionMethods.ProcessMessage("SQL Server connection failed.", message);
      //      ExceptionMethods.ProcessUnhandledException(ex);
      //      if (splash != null && splash.IsBusy)
      //      {
      //        splash.CancelAsync();
      //      }

      //      return false;
      //    }
      //  }

      //  // Go back and rebuild the log file.
      //  if (logRebuild)
      //  {
      //    goto Attach;
      //  }

      // Test connection
      using (var conn = new SQLiteConnection(Document.ActiveDocument.ExperimentSettings.DatabaseConnectionString))
      {
        try
        {
          conn.Open();
        }
        catch (Exception ex)
        {
          //if (splash != null && splash.IsBusy)
          //{
          //  splash.CancelAsync();
          //}

          //if (!automaticResetConnectionTried)
          //{
          //  this.experimentSettings.CustomConnectionString = string.Empty;
          //  this.isModified = true;
          //  automaticResetConnectionTried = true;
          //  goto Test;
          //}

          //if (!automaticCorrectMachineNameTried)
          //{
          //  string currentConnectionString = this.experimentSettings.DatabaseConnectionString;
          //  int firstEqualSign = currentConnectionString.IndexOf('=', 0);
          //  int firstBackslash = currentConnectionString.IndexOf('\\', 0);
          //  string machineName = currentConnectionString.Substring(firstEqualSign + 1, firstBackslash - firstEqualSign - 1);
          //  string currentMachineName = Environment.MachineName;
          //  currentConnectionString = currentConnectionString.Replace(machineName + "\\", currentMachineName + "\\");
          //  this.experimentSettings.CustomConnectionString = currentConnectionString;
          //  automaticCorrectMachineNameTried = true;
          //  this.isModified = true;
          //  goto Test;
          //}

          string message = "Connection to SQLite database failed." + Environment.NewLine +
            "Take a careful look at the database file to attach and its path. " +
            "The .db file should be named the same as the experiment .oga file and located in the "
            + "Database subfolder of the experiment." + Environment.NewLine + "The error message is: "
            + Environment.NewLine + ex.Message + Environment.NewLine;
          ExceptionMethods.ProcessErrorMessage(message);

          //SQLConnectionDialog connectionDialog = new SQLConnectionDialog();
          //connectionDialog.ConnectionString = this.experimentSettings.DatabaseConnectionString;
          //if (connectionDialog.ShowDialog() == DialogResult.OK)
          //{
          //  this.experimentSettings.CustomConnectionString = connectionDialog.ConnectionString;
          //  this.isModified = true;
          //}
          //else
          //{
          //  return false;
          //}

          //goto Test;
        }
        finally
        {
          try
          {
            conn.Close();
          }
          catch (Exception)
          {
          }
        }
      }

      if (splash != null && !splash.IsBusy)
      {
        splash.RunWorkerAsync();
      }

      Application.DoEvents();

      // Loads tables and Data from SQL file into DataSet
      if (this.dataSet.LoadData(splash))
      {
        return true;
      }

      return false;
    }
 /// <summary>
 /// Updates the specified data table.
 /// </summary>
 /// <param name="dataTable">
 /// The data table.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet.ShapeGroupsDataTable dataTable)
 {
   return this.Adapter.Update(dataTable);
 }
 /// <summary>
 /// Updates the specified data set.
 /// </summary>
 /// <param name="dataSet">
 /// The data set.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet dataSet)
 {
   return this.Adapter.Update(dataSet, "ShapeGroups");
 }
 /// <summary>
 /// Updates the specified data set.
 /// </summary>
 /// <param name="dataSet">
 /// The data set.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet dataSet)
 {
   return this.Adapter.Update(dataSet, "Rawdata");
 }
    public virtual int Fill(SQLiteOgamaDataSet.ShapeGroupsDataTable dataTable)
    {
      this.Adapter.SelectCommand = this.CommandCollection[0];
      if (this.ClearBeforeFill)
      {
        dataTable.Clear();
      }

      int returnValue = this.Adapter.Fill(dataTable);
      return returnValue;
    }
 /// <summary>
 /// Updates the specified data set.
 /// </summary>
 /// <param name="dataSet">
 /// The data set.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet dataSet)
 {
   return this.Adapter.Update(dataSet, "TrialEvents");
 }
 /// <summary>
 /// Updates the specified data table.
 /// </summary>
 /// <param name="dataTable">
 /// The data table.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet.RawdataDataTable dataTable)
 {
   return this.Adapter.Update(dataTable);
 }
 /// <summary>
 /// Updates the specified data set.
 /// </summary>
 /// <param name="dataSet">
 /// The data set.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet dataSet)
 {
   return this.Adapter.Update(dataSet, "SubjectParameters");
 }
 /// <summary>
 /// Updates the specified data table.
 /// </summary>
 /// <param name="dataTable">
 /// The data table.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet.TrialEventsDataTable dataTable)
 {
   return this.Adapter.Update(dataTable);
 }
 /// <summary>
 /// Updates the specified data table.
 /// </summary>
 /// <param name="dataTable">
 /// The data table.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet.SubjectParametersDataTable dataTable)
 {
   return this.Adapter.Update(dataTable);
 }
 /// <summary>
 /// Updates the specified data set.
 /// </summary>
 /// <param name="dataSet">
 /// The data set.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet dataSet)
 {
   return this.Adapter.Update(dataSet, "MouseFixations");
 }
 /// <summary>
 /// Updates the specified data table.
 /// </summary>
 /// <param name="dataTable">
 /// The data table.
 /// </param>
 /// <returns>
 /// System.Int32.
 /// </returns>
 public virtual int Update(SQLiteOgamaDataSet.MouseFixationsDataTable dataTable)
 {
   return this.Adapter.Update(dataTable);
 }
Beispiel #15
0
    /// <summary>
    /// Updates row in raw data table from given subject and ID
    /// with data given in parameter row.
    /// Uses given subjects raw data table.
    /// </summary>
    /// <param name="table">A <see cref="SQLiteOgamaDataSet.RawdataDataTable"/> with the new values</param>
    /// <param name="subject">A <see cref="string"/> with the subject name to which the data belongs.</param>
    /// <returns>A <see cref="int"/> with the number of updated rows.</returns>
    /// <exception cref="ArgumentNullException">Thrown, when row or subject is null or empty.</exception>
    public static int UpdateRawDataBySubject(SQLiteOgamaDataSet.RawdataDataTable table, string subject)
    {
      if (table == null)
      {
        throw new ArgumentNullException();
      }

      if (subject == string.Empty)
      {
        throw new ArgumentNullException();
      }

      SQLiteDataAdapter adapter = Document.ActiveDocument.DocDataSet.RawDataAdapterDict[subject];

      adapter.UpdateCommand = new SQLiteCommand();
      adapter.UpdateCommand.Connection = Document.ActiveDocument.DocDataSet.DatabaseConnection;
      adapter.UpdateCommand.CommandText = @"UPDATE [" + subject + @"Rawdata] SET [SubjectName] = @SubjectName, [TrialSequence] = @TrialSequence, [Time] = @Time, [PupilDiaX] = @PupilDiaX, [PupilDiaY] = @PupilDiaY, [GazePosX] = @GazePosX, [GazePosY] = @GazePosY, [MousePosX] = @MousePosX, [MousePosY] = @MousePosY, [EventID] = @EventID WHERE (([ID] = @Original_ID) AND ([SubjectName] = @Original_SubjectName) AND ([TrialSequence] = @Original_TrialSequence) AND ([Time] = @Original_Time) AND ((@IsNull_PupilDiaX = 1 AND [PupilDiaX] IS NULL) OR ([PupilDiaX] = @Original_PupilDiaX)) AND ((@IsNull_PupilDiaY = 1 AND [PupilDiaY] IS NULL) OR ([PupilDiaY] = @Original_PupilDiaY)) AND ((@IsNull_GazePosX = 1 AND [GazePosX] IS NULL) OR ([GazePosX] = @Original_GazePosX)) AND ((@IsNull_GazePosY = 1 AND [GazePosY] IS NULL) OR ([GazePosY] = @Original_GazePosY)) AND ((@IsNull_MousePosX = 1 AND [MousePosX] IS NULL) OR ([MousePosX] = @Original_MousePosX)) AND ((@IsNull_MousePosY = 1 AND [MousePosY] IS NULL) OR ([MousePosY] = @Original_MousePosY)) AND ((@IsNull_EventID = 1 AND [EventID] IS NULL) OR ([EventID] = @Original_EventID)));
SELECT ID, SubjectName, TrialSequence, Time, PupilDiaX, PupilDiaY, GazePosX, GazePosY, MousePosX, MousePosY, EventID FROM " + subject + "Rawdata WHERE (ID = @ID)";
      adapter.UpdateCommand.CommandType = CommandType.Text;
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@SubjectName", DbType.String, 0, ParameterDirection.Input, 0, 0, "SubjectName", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@TrialSequence", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "TrialSequence", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Time", DbType.Int64, 0, ParameterDirection.Input, 0, 0, "Time", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@PupilDiaX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "PupilDiaX", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@PupilDiaY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "PupilDiaY", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@GazePosX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "GazePosX", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@GazePosY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "GazePosY", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@MousePosX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "MousePosX", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@MousePosY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "MousePosY", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@EventID", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "EventID", DataRowVersion.Current, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_ID", DbType.Int64, 0, ParameterDirection.Input, 0, 0, "ID", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_SubjectName", DbType.String, 0, ParameterDirection.Input, 0, 0, "SubjectName", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_TrialSequence", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "TrialSequence", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_Time", DbType.Int64, 0, ParameterDirection.Input, 0, 0, "Time", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_PupilDiaX", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "PupilDiaX", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_PupilDiaX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "PupilDiaX", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_PupilDiaY", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "PupilDiaY", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_PupilDiaY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "PupilDiaY", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_GazePosX", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "GazePosX", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_GazePosX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "GazePosX", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_GazePosY", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "GazePosY", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_GazePosY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "GazePosY", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_MousePosX", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "MousePosX", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_MousePosX", DbType.Single, 0, ParameterDirection.Input, 0, 0, "MousePosX", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_MousePosY", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "MousePosY", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_MousePosY", DbType.Single, 0, ParameterDirection.Input, 0, 0, "MousePosY", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@IsNull_EventID", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "EventID", DataRowVersion.Original, true, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@Original_EventID", DbType.Int32, 0, ParameterDirection.Input, 0, 0, "EventID", DataRowVersion.Original, false, null));
      adapter.UpdateCommand.Parameters.Add(new SQLiteParameter("@ID", DbType.Int64, 8, ParameterDirection.Input, 0, 0, "ID", DataRowVersion.Current, false, null));

      // Update row
      int numUpdatedRows = adapter.Update(table);

      return numUpdatedRows;
    }
Beispiel #16
0
    /// <summary>
    /// This method saves the given collection of <see cref="RawData"/> into the
    /// given <see cref="SQLiteOgamaDataSet.RawdataDataTable"/>
    /// </summary>
    /// <param name="lstRawData">A <see cref="RawData"/> with the new samples.</param>
    /// <param name="subjectRawDataTable">The <see cref="SQLiteOgamaDataSet.RawdataDataTable"/> to be filled.</param>
    /// <returns><strong>True</strong> if successful otherwise <strong>false</strong>.</returns>
    public static bool SaveDataToTable(RawData[] lstRawData, SQLiteOgamaDataSet.RawdataDataTable subjectRawDataTable)
    {
      try
      {
        // Notify the beginning of adding rows to subjectRawDataTable
        subjectRawDataTable.BeginLoadData();

        foreach (RawData data in lstRawData)
        {
          // Save data into datarow.
          SQLiteOgamaDataSet.RawdataRow workRowRawData =
            subjectRawDataTable.NewRawdataRow();

          workRowRawData.SubjectName = data.SubjectName;
          workRowRawData.TrialSequence = data.TrialSequence;
          workRowRawData.Time = data.Time;

          if (!data.PupilDiaX.HasValue)
          {
            workRowRawData.SetPupilDiaXNull();
          }
          else
          {
            workRowRawData.PupilDiaX = data.PupilDiaX.Value;
          }

          if (!data.PupilDiaY.HasValue)
          {
            workRowRawData.SetPupilDiaYNull();
          }
          else
          {
            workRowRawData.PupilDiaY = data.PupilDiaY.Value;
          }

          if (!data.GazePosX.HasValue)
          {
            workRowRawData.SetGazePosXNull();
          }
          else
          {
            workRowRawData.GazePosX = data.GazePosX.Value;
          }

          if (!data.GazePosY.HasValue)
          {
            workRowRawData.SetGazePosYNull();
          }
          else
          {
            workRowRawData.GazePosY = data.GazePosY.Value;
          }

          if (!data.MousePosX.HasValue)
          {
            workRowRawData.SetMousePosXNull();
          }
          else
          {
            workRowRawData.MousePosX = data.MousePosX.Value;
          }

          if (!data.MousePosY.HasValue)
          {
            workRowRawData.SetMousePosYNull();
          }
          else
          {
            workRowRawData.MousePosY = data.MousePosY.Value;
          }

          if (!data.EventID.HasValue)
          {
            workRowRawData.SetEventIDNull();
          }
          else
          {
            workRowRawData.EventID = data.EventID.Value;
          }

          subjectRawDataTable.AddRawdataRow(workRowRawData);
        }

        subjectRawDataTable.EndLoadData();
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);

        return false;
      }

      return true;
    }