示例#1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="connections"></param>
 public FormConnection(Connection connection)
     : this()
 {
     _connection = connection;
     txtName.Text = connection.Name;
     txtConnectionString.Text = connection.ConnectionString;
     txtCollectionName.Text = connection.CollectionName;
     txtNetwitnessIp.Text = connection.ConcentratorIp;
 }
示例#2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="connection"></param>
        public void SetConnection(Connection connection)
        {
            _connection = connection;
            UpdateSensors();

            using (NPoco.Database db = new NPoco.Database(Db.GetOpenMySqlConnection()))
            {
                _acknowledgmentClasses = db.Fetch<AcknowledgmentClass>();
                _acknowledgmentClasses = (from a in _acknowledgmentClasses orderby a.Desc select a).ToList();
            }
        }
示例#3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOk_Click(object sender, EventArgs e)
        {
            if (txtName.Text.Trim().Length == 0)
            {
                UserInterface.DisplayMessageBox(this, "The name must be entered", MessageBoxIcon.Exclamation);
                txtName.Select();
                return;
            }

            if (txtConnectionString.Text.Trim().Length == 0)
            {
                UserInterface.DisplayMessageBox(this, "The connection string must be entered", MessageBoxIcon.Exclamation);
                txtConnectionString.Select();
                return;
            }

            if (_connection == null)
            {
                var connections = from c in _connections.Data where c.Name == txtName.Text select c;
                if (connections.Count() > 0)
                {
                    UserInterface.DisplayMessageBox(this, "A connection with the same name already exists", MessageBoxIcon.Exclamation);
                    return;
                }

                connections = from c in _connections.Data where c.ConnectionString == txtConnectionString.Text select c;
                if (connections.Count() > 0)
                {
                    UserInterface.DisplayMessageBox(this, "A connection with the same connection string already exists", MessageBoxIcon.Exclamation);
                    return;
                }
            }

            if (_connection == null)
            {
                Connection connection = new Connection();
                connection.Name = txtName.Text;
                connection.ConnectionString = txtConnectionString.Text;
                connection.ConcentratorIp = txtNetwitnessIp.Text;
                connection.CollectionName = txtCollectionName.Text;
                _connections.Data.Add(connection);
            }
            else
            {
                var temp = (from c in _connections.Data where c.Name == _connection.Name & c.ConnectionString == _connection.ConnectionString select c).SingleOrDefault();
                if (temp == null)
                {
                    UserInterface.DisplayErrorMessageBox(this, "Unable to locate connection");
                    return;
                }

                temp.Name = txtName.Text;
                temp.ConnectionString = txtConnectionString.Text;
                temp.ConcentratorIp = txtNetwitnessIp.Text;
                temp.CollectionName = txtCollectionName.Text;
            }

            string ret = _connections.Save();
            if (ret.Length > 0)
            {
                UserInterface.DisplayErrorMessageBox(this, "An error occurred whilst saving the connections: " + ret);
                return;
            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
        }