Esempio n. 1
0
 public frmBroker()
 {
     InitializeComponent();
     broker            = new clsBroker();
     instrumentMapping = new BrokerInstrumentMapping();
     result            = new clsBroker();
 }
Esempio n. 2
0
        private void dataGridBrokers_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex < 0 || e.RowIndex < 0)
            {
                return;                                      // header clicked
            }
            if (e.ColumnIndex == dataGridBrokers.Columns["buttonColumn"].Index)
            {
                // Your logic here. You can gain access to any cell value via DataGridViewCellEventArgs
                int Id = Convert.ToInt32(dataGridBrokers["Id", e.RowIndex].Value);
                instrumentMapping.DeleteBroker(Id);
                var dataSource = instrumentMapping.GetBrokers();
                dataGridBrokers.DataSource = dataSource;
                MessageBox.Show(this, "Broker deleted successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (e.ColumnIndex == dataGridBrokers.Columns["buttonColumnEdit"].Index)
            {
                // Your logic here. You can gain access to any cell value via DataGridViewCellEventArgs
                int Id = Convert.ToInt32(dataGridBrokers["Id", e.RowIndex].Value);
                tabControl1.TabPages.Insert(2, updateTab);
                tabControl1.SelectedTab = updateTab;

                result = instrumentMapping.GetBroker(Id);

                txtUpdateBroker.Text      = result.BrokerCode;
                txtUpdateDescription.Text = result.BrokerDescription;
            }
        }
Esempio n. 3
0
        public List <clsBroker> GetBrokers()
        {
            var listBroker = new List <clsBroker>();
            // We use these three SQLite objects:
            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;
            SQLiteDataReader sqlite_datareader;

            // create a new database connection:

            sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
            // open the connection:
            sqlite_conn.Open();
            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();

            // First lets build a SQL-Query again:
            sqlite_cmd.CommandText = $"SELECT * FROM tblBroker";
            // Now the SQLiteCommand object can give us a DataReader-Object:
            sqlite_datareader = sqlite_cmd.ExecuteReader();
            // The SQLiteDataReader allows us to run through the result lines:
            while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
            {
                var broker = new clsBroker();
                broker.BrokerCode        = Convert.ToString(sqlite_datareader["BrokerCode"]);
                broker.BrokerDescription = Convert.ToString(sqlite_datareader["BrokerDescription"]);
                broker.Id = Convert.ToInt32(sqlite_datareader["Id"]);
                listBroker.Add(broker);
            }

            // We are ready, now lets cleanup and close our connection:
            DisposeConnection(sqlite_conn, sqlite_cmd, sqlite_datareader);

            return(listBroker);
        }
Esempio n. 4
0
        public clsBroker DeleteMapping(int id)
        {
            var broker = new clsBroker();
            // We use these three SQLite objects:
            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;

            sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
            // open the connection:
            sqlite_conn.Open();
            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();

            // First lets build a SQL-Query again:
            sqlite_cmd.CommandText = $"Delete from tblBrokerInstrumentMapping where Id={id}";
            // Now the SQLiteCommand object can give us a DataReader-Object:
            var result = sqlite_cmd.ExecuteScalar();

            // We are ready, now lets cleanup and close our connection:
            sqlite_conn.Close();
            sqlite_conn.Dispose();
            sqlite_cmd.Dispose();

            return(broker);
        }
Esempio n. 5
0
        public bool CheckDuplicateBroker(clsBroker model)
        {
            // We use these three SQLite objects:
            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;
            SQLiteDataReader sqlite_datareader;

            // create a new database connection:

            sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
            // open the connection:
            sqlite_conn.Open();
            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();

            // First lets build a SQL-Query again:
            sqlite_cmd.CommandText = $"SELECT Id FROM tblBroker where BrokerCode='{model.BrokerCode}' COLLATE NOCASE";
            // Now the SQLiteCommand object can give us a DataReader-Object:
            sqlite_datareader = sqlite_cmd.ExecuteReader();
            // The SQLiteDataReader allows us to run through the result lines:
            while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
            {
                DisposeConnection(sqlite_conn, sqlite_cmd, sqlite_datareader);
                return(false);
            }

            // We are ready, now lets cleanup and close our connection:

            DisposeConnection(sqlite_conn, sqlite_cmd, sqlite_datareader);

            return(true);
        }
Esempio n. 6
0
        public void UpdateBroker(clsBroker model)
        {
            // We use these three SQLite objects:

            SQLiteConnection sqlite_conn;
            SQLiteCommand    sqlite_cmd;

            // create a new database connection:

            sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=True;Compress=True;");
            // open the connection:
            sqlite_conn.Open();
            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();

            // Lets insert something into our new table:
            sqlite_cmd.CommandText = $"Update tblBroker set BrokerCode='{model.BrokerCode}',BrokerDescription='{model.BrokerDescription}' where Id={model.Id};";
            // And execute this again ;D
            sqlite_cmd.ExecuteNonQuery();
            // We are ready, now lets cleanup and close our connection:
            sqlite_conn.Close();
            sqlite_conn.Dispose();
            sqlite_cmd.Dispose();
        }