Exemplo n.º 1
0
        public bool CSQL_AddDevice(CDevice device)
        {
            string sql = "INSERT INTO devices VALUES ('" +
                               device.DeviceID + "', '" +
                               device.DeviceDescription + "', '" +
                                 device.DeviceLocation + "', '" +
                         		device.DeviceServer + "', '" +
                         		device.DeviceServerSubDir + "');";

            SqliteCommand dbhCmd;
            int num_recs = 0;

            if (CSQL_Connected ()) {

                dbhCmd = new SqliteCommand (sql, dbh);
                num_recs = dbhCmd.ExecuteNonQuery ();

                if (num_recs > 0) {
                    CSQL_AddDeviceLogFileDescription (device, dbhCmd.Connection);
                }

            }

            return false;
        }
Exemplo n.º 2
0
        public bool CSQL_AddDevice(CDevice device)
        {
            string sql = "INSERT INTO devices VALUES ('" +
                         device.DeviceID + "', '" +
                         device.DeviceDescription + "', '" +
                         device.DeviceLocation + "', '" +
                         device.DeviceServer + "', '" +
                         device.DeviceServerSubDir + "');";


            SqliteCommand dbhCmd;
            int           num_recs = 0;

            if (CSQL_Connected())
            {
                dbhCmd   = new SqliteCommand(sql, dbh);
                num_recs = dbhCmd.ExecuteNonQuery();

                if (num_recs > 0)
                {
                    CSQL_AddDeviceLogFileDescription(device, dbhCmd.Connection);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        private bool CSQL_AddDeviceLogFileDescription(CDevice device, SqliteConnection hconn)
        {
            string        sql      = null;
            SqliteCommand dbhCmd   = null;
            int           num_recs = 0;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++)
            {
                CDeviceFileDescription descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                sql = "INSERT INTO device_logfile_descr VALUES ('" +
                      descr.DeviceCodeType + "', '" +
                      descr.DeviceCodeDescription + "', '" +
                      descr.DeviceCode + "', " +
                      i + ", '" +
                      device.DeviceID + "');";

                dbhCmd   = new SqliteCommand(sql, hconn);
                num_recs = dbhCmd.ExecuteNonQuery();

                if (num_recs == 0)
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 4
0
        public int CLogFile_Get_Y_Axis_Code_Index(CDevice device)
        {
            CDeviceFileDescription _descr = null;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++)
            {
                // Find the log time and return the index.
                _descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                if (_descr.DeviceCode == "CURTEMP")
                {
                    _logTimeIndex = i;
                    return(i);
                }
            }

            return(-1);
        }
Exemplo n.º 5
0
        public bool CSQL_UpdateDevice(CDevice device)
        {
            string sql_update_device = "UPDATE devices " +
                                       "SET device_id = '" + device.DeviceID + "', " +
                                       "device_descr = '" + device.DeviceDescription + "', " +
                                       "device_location = '" + device.DeviceLocation + "', " +
                                       "device_server = '" + device.DeviceServer + "', " +
                                       "device_server_subdir = '" + device.DeviceServerSubDir + "' " +
                                       "WHERE device_id like '" + device.OldDeviceID + "';";

            string sql_remove_logfile_descr = "DELETE FROM device_logfile_descr " +
                                              "WHERE device_id like '" + device.OldDeviceID + "';";

            SqliteCommand     dbhCmd = null;
            SqliteTransaction Tr     = null;

            Console.WriteLine("SQL -> " + sql_update_device);

            if (CSQL_Connected())
            {
                /*
                 * UPDATE DEVICE SETTINGS
                 */

                dbhCmd = new SqliteCommand(sql_update_device, dbh);
                Tr     = dbh.BeginTransaction();

                dbhCmd.ExecuteNonQuery();

                /*
                 * UPDATE logfile description by first removing all and
                 * then replacing them with the new description.
                 */

                dbhCmd = new SqliteCommand(sql_remove_logfile_descr, dbh);
                dbhCmd.ExecuteNonQuery();

                CSQL_AddDeviceLogFileDescription(device, Tr.Connection);

                Tr.Commit();
            }

            return(true);
        }
Exemplo n.º 6
0
        public CDevice CSQL_GetDevice(string device_id)
        {
            //TODO: Finish CSQL_GetDevice implementation.

            string sql_device = "SELECT * FROM devices " +
                                "WHERE devices.device_id = '" + device_id + "';";

            string sql_device_descr = "SELECT * FROM device_logfile_descr " +
                                      "WHERE device_logfile_descr.device_id = '" + device_id + "' " +
                                      "ORDER BY device_logfile_descr.device_logfile_order;";

            CDevice   _device = null;
            ArrayList _ar_device_logfile_descr;
            CDeviceFileDescription _device_file_descr = null;
            SqliteCommand          dbhCmd             = null;
            SqliteDataReader       dbhReader          = null;

            if (CSQL_Connected())
            {
                dbhCmd    = new SqliteCommand(sql_device, dbh);
                dbhReader = dbhCmd.ExecuteReader();

                if (dbhReader.HasRows)
                {
                    dbhReader.Read();

                    _device = new CDevice(dbhReader.GetString((int)tbl_devices.DEVICE_ID),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_DESCR),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_LOCATION),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_SERVER),
                                          dbhReader.GetString((int)tbl_devices.DEVICE_SERVER_SUBDIR));


                    //Get device log file description.
                    dbhCmd    = new SqliteCommand(sql_device_descr, dbh);
                    dbhReader = dbhCmd.ExecuteReader();

                    if (dbhReader.HasRows)
                    {
                        _ar_device_logfile_descr = new ArrayList();

                        while (dbhReader.Read())
                        {
                            _device_file_descr = new CDeviceFileDescription
                                                 (
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_CODE),
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_DESCR),
                                dbhReader.GetString((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_TYPES)
                                                 );

                            _ar_device_logfile_descr.Add(_device_file_descr);
                        }

                        _device.DeviceFileDescription = _ar_device_logfile_descr;
                    }
                    else
                    {
                        cleanup();
                        return(_device);
                    }
                }
                else
                {
                    cleanup();
                    return(null);
                }
            }
            else
            {
                cleanup();
                return(null);
            }

            return(_device);
        }
Exemplo n.º 7
0
        public int CLogFile_Get_Y_Axis_Code_Index( CDevice device )
        {
            CDeviceFileDescription _descr = null;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++) {

                // Find the log time and return the index.
                _descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                if (_descr.DeviceCode == "CURTEMP") {
                    _logTimeIndex = i;
                    return i;
                }

            }

            return -1;
        }
Exemplo n.º 8
0
    private void populate_device_settings( CDevice device )
    {
        //TODO: Fix broken bits for device settings population <- cboServers.

        entDeviceID.Text = device.DeviceID;
        entDeviceDescription.Text = device.DeviceDescription;
        entDeviceLocation.Text = device.DeviceLocation;
        entDeviceServerSubDir.Text = device.DeviceServerSubDir;

        // Do cboDeviceSever
        populate_server_combo ();

            TreeIter iter;
            cboDeviceServer.Model.GetIterFirst (out iter);
            string server = null;

            while ( (server = (string)cboDeviceServer.Model.GetValue (iter, 0)) != null) {

            string[] server_split = server.Split ('\t');

                if ( server_split[0] == device.DeviceServer || server_split[1] == device.DeviceServer )
                    break;

                cboDeviceServer.Model.IterNext (ref iter);
            }

            cboDeviceServer.SetActiveIter (iter);
    }
Exemplo n.º 9
0
 private void populate_device_file_descr( CDevice device )
 {
     ar_file_description = device.DeviceFileDescription;
         populate_log_file_columns ();
 }
Exemplo n.º 10
0
        public bool CSQL_UpdateDevice( CDevice device )
        {
            string sql_update_device = "UPDATE devices " +
                                       "SET device_id = '" + device.DeviceID + "', " +
                                       "device_descr = '" + device.DeviceDescription + "', " +
                                       "device_location = '" + device.DeviceLocation + "', " +
                                       "device_server = '" + device.DeviceServer + "', " +
                                       "device_server_subdir = '" + device.DeviceServerSubDir + "' " +
                                       "WHERE device_id like '" + device.OldDeviceID + "';";

            string sql_remove_logfile_descr = "DELETE FROM device_logfile_descr " +
                                              "WHERE device_id like '" + device.OldDeviceID + "';";

            SqliteCommand dbhCmd = null;
            SqliteTransaction Tr = null;

            Console.WriteLine ("SQL -> " + sql_update_device);

            if (CSQL_Connected ()) {

                /*
                 * UPDATE DEVICE SETTINGS
                 */

                dbhCmd = new SqliteCommand (sql_update_device, dbh);
                Tr = dbh.BeginTransaction ();

                dbhCmd.ExecuteNonQuery ();

                /*
                 * UPDATE logfile description by first removing all and
                 * then replacing them with the new description.
                 */

                dbhCmd = new SqliteCommand (sql_remove_logfile_descr, dbh);
                dbhCmd.ExecuteNonQuery ();

                CSQL_AddDeviceLogFileDescription (device, Tr.Connection);

                Tr.Commit ();
            }

            return true;
        }
Exemplo n.º 11
0
    private void build_popups()
    {
        /** ====================
         * DO SERVER MENU
         * ====================
         */

        mnu_add_server.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {

            clear_server_settings();
            c_current_server = new CServer();
            c_current_server.Update = false;
            nbFrames.CurrentPage = (int)nb_Notebook_Pages.SERVER_SETTINGS;

        };

        mnu_del_server.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {

            mnu_server.Popdown();

            MessageDialog dlg = new MessageDialog(this,DialogFlags.DestroyWithParent, MessageType.Question, ButtonsType.YesNo,
                "Are you sure you want to delete the Server \n" +
                "and all it's data?", 0);
            ResponseType res = (ResponseType)dlg.Run();
            dlg.Destroy();

            if (res == ResponseType.Yes) {
                ListStore store = (ListStore) ivServerBrowser.Model;
                TreePath[] path = ivServerBrowser.SelectedItems;
                TreeIter iter;

                store.GetIter (out iter, path[0]);

                if (curTreePathItem.value != null) {
                    csql.CSQL_DeleteServer (curTreePathItem.value);
                    store.Remove(ref iter);
                }
            }

        };

        mnu_edit_server.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {
            populate_server_settings();
        };

        mnu_server.Add (mnu_server_menu_title);
        mnu_server.Add (new SeparatorMenuItem());
        mnu_server.Add (mnu_add_server);
        mnu_server.Add (mnu_del_server);
        mnu_server.Add (mnu_edit_server);

        mnu_server.ShowAll ();

        mnu_del_server.Visible = false;
        mnu_edit_server.Visible = false;

        /*
         * ==============
         * DO DEVICE MENU
         * ==============
         */

        mnu_add_device.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {
            clear_device_settings();
            populate_server_combo();
            populate_log_file_columns();
            c_current_device = new CDevice();
            c_current_device.Update = false;

            nbFrames.CurrentPage = (int)nb_Notebook_Pages.DEVICE_SETTINGS;
        };

        mnu_del_device.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {

            mnu_device.Popdown();

            MessageDialog dlg = new MessageDialog (this, DialogFlags.DestroyWithParent, MessageType.Question,
                ButtonsType.YesNo, "Are you woud like to delete the device and all it's records?", 0);

            ResponseType res = (ResponseType)dlg.Run();

            if (res == ResponseType.Yes) {
                ListStore store = (ListStore)ivDeviceBrowser.Model;
                TreePath[] path = ivDeviceBrowser.SelectedItems;
                TreeIter iter;

                store.GetIter (out iter, path[0]);

                if (curTreePathItem.value != null) {
                    if (csql.CSQL_DeleteDevice (curTreePathItem.value))
                        store.Remove (ref iter);
                }
            }

            dlg.Destroy();
        };

        mnu_edit_device.ButtonReleaseEvent += delegate(object o, ButtonReleaseEventArgs args) {
            edit_device();
        };

        mnu_device_menu_title.CanDefault = false;
        mnu_device_menu_title.CanFocus = false;
        mnu_device.Add (mnu_device_menu_title);
        mnu_device.Add (new SeparatorMenuItem ());
        mnu_device.Add (mnu_add_device);
        mnu_device.Add (mnu_del_device);
        mnu_device.Add (mnu_edit_device);

        mnu_device.ShowAll ();
        mnu_del_device.Visible = false;
        mnu_edit_device.Visible = false;

        /*
         * ====================
         * DO LOGFILE MENU
         * ==================
         */
    }
Exemplo n.º 12
0
    protected void OnIvDeviceBrowserItemActivated(object o, ItemActivatedArgs args)
    {
        //TODO: Implement device browser item activated for Ftp.

        /**
         * - Get item activated from browser model
         * - Get item activated from sqlite
         * - Get Server for selected Device
         * - Get File list
         * - Build file list model for ftp browser.
         */

        // Get device details from model and sqlite.
        TreePath[] path = ivDeviceBrowser.SelectedItems;
        TreeIter iter;
        string _device_key = null;
        ArrayList ftp_file_list = new ArrayList();

            ivDeviceBrowser.Model.GetIter (out iter, path [0]);
            _device_key = (string)ivDeviceBrowser.Model.GetValue (iter, 0);

            c_current_device = csql.CSQL_GetDevice (_device_key);
            c_current_server = csql.CSQL_GetServer (c_current_device.DeviceServer);
            c_current_ftp_session = new CFTP (c_current_server, c_current_device);

        if (c_current_server.ServerProtocol == "file://") {

            string __dir_to_list = c_current_device.DeviceServerSubDir;

            foreach (string s_file in Directory.EnumerateFiles (__dir_to_list)) {

                string c_file = s_file;

                if (c_current_platform == PlatformID.Win32NT)
                    c_file = s_file.Substring (2);

                string[] file_name = c_file.Split (System.IO.Path.DirectorySeparatorChar);
                ftp_file_list.Add (file_name[(file_name.Length - 1)]);

            }

        } else {

            try {

                ftp_file_list = c_current_ftp_session.CFTP_GetFileList ();

            } catch (WebException e) {

                if (e.Status == WebExceptionStatus.ProtocolError) {

                    string msg = "Please check you Server and Device directory settings.";

                    new Gtk.MessageDialog (null, Gtk.DialogFlags.Modal, Gtk.MessageType.Error,
                        Gtk.ButtonsType.Ok, e.Message + "\n" + msg, 0).Run ();

                } else {

                    Console.WriteLine (e.Status + "\n" + e.Message + "\n" + e.Source);
                }

                return;
            }
        }

        if (ftp_file_list != null) {
            populate_FtpFileBrowser (ftp_file_list);
        }
    }
Exemplo n.º 13
0
 public CFTP( CServer server, CDevice device )
 {
     _server = server;
     _device = device;
 }
Exemplo n.º 14
0
        private bool CSQL_AddDeviceLogFileDescription(CDevice device, SqliteConnection hconn)
        {
            string sql = null;
            SqliteCommand dbhCmd = null;
            int num_recs = 0;

            for (int i = 0; i < device.DeviceFileDescription.Count; i++) {
                CDeviceFileDescription descr = (CDeviceFileDescription)device.DeviceFileDescription [i];

                sql = "INSERT INTO device_logfile_descr VALUES ('" +
                              descr.DeviceCodeType + "', '" +
                              descr.DeviceCodeDescription + "', '" +
                              descr.DeviceCode + "', " +
                              i + ", '" +
                              device.DeviceID + "');";

                dbhCmd = new SqliteCommand (sql, hconn);
                num_recs = dbhCmd.ExecuteNonQuery ();

                if (num_recs == 0)
                    return false;

            }

            return true;
        }
Exemplo n.º 15
0
    private void edit_device()
    {
        // Get device details and populate device settings.
        TreePath[] path = ivDeviceBrowser.SelectedItems;
        TreeIter iter;
        string _device_key = null;

        mnu_device.Popdown ();

        ivDeviceBrowser.Model.GetIter (out iter, path[0]);
        _device_key = (string)ivDeviceBrowser.Model.GetValue (iter, 0);

        c_current_device = csql.CSQL_GetDevice (_device_key);

        populate_device_settings (c_current_device);

        populate_device_file_descr (c_current_device);

        c_current_device.Update = true;
        nbFrames.CurrentPage = (int)nb_Notebook_Pages.DEVICE_SETTINGS;
    }
Exemplo n.º 16
0
 public CFTP(CServer server, CDevice device)
 {
     _server = server;
     _device = device;
 }
Exemplo n.º 17
0
        public CDevice CSQL_GetDevice( string device_id )
        {
            //TODO: Finish CSQL_GetDevice implementation.

            string sql_device = "SELECT * FROM devices " +
                                "WHERE devices.device_id = '" + device_id + "';";

            string sql_device_descr = "SELECT * FROM device_logfile_descr " +
                                      "WHERE device_logfile_descr.device_id = '" + device_id + "' " +
                                      "ORDER BY device_logfile_descr.device_logfile_order;";

            CDevice _device = null;
            ArrayList _ar_device_logfile_descr;
            CDeviceFileDescription _device_file_descr = null;
            SqliteCommand dbhCmd = null;
            SqliteDataReader dbhReader = null;

            if (CSQL_Connected ()) {

                dbhCmd = new SqliteCommand (sql_device, dbh);
                dbhReader = dbhCmd.ExecuteReader ();

                if (dbhReader.HasRows) {

                    dbhReader.Read ();

                    _device = new CDevice (dbhReader.GetString ((int)tbl_devices.DEVICE_ID),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_DESCR),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_LOCATION),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_SERVER),
                        dbhReader.GetString ((int)tbl_devices.DEVICE_SERVER_SUBDIR));

                    //Get device log file description.
                    dbhCmd = new SqliteCommand (sql_device_descr, dbh);
                    dbhReader = dbhCmd.ExecuteReader ();

                    if (dbhReader.HasRows) {

                        _ar_device_logfile_descr = new ArrayList ();

                        while (dbhReader.Read()) {

                            _device_file_descr = new CDeviceFileDescription
                            (
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_CODE),
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_DESCR),
                                 dbhReader.GetString ((int)tbl_device_logfile_descr.DEVICE_SENSOR_VALUE_TYPES)
                            );

                            _ar_device_logfile_descr.Add (_device_file_descr);

                        }

                        _device.DeviceFileDescription = _ar_device_logfile_descr;

                    } else {
                        cleanup ();
                        return _device;
                    }

                } else {
                    cleanup ();
                    return null;
                }

            } else {
                cleanup ();
                return null;
            }

            return _device;
        }