PageRenderTime 18ms CodeModel.GetById 1ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 1ms

/dotnet/DatabaseForm.cs

http://sigma-h.googlecode.com/
C# | 105 lines | 82 code | 23 blank | 0 comment | 3 complexity | c5fa5ae3140232ce4eb2812fc54b7298 MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Data.SQLite;
  6using System.Drawing;
  7using System.Linq;
  8using System.Text;
  9using System.Windows.Forms;
 10
 11using ActivityInfo.Api;
 12using ActivityInfo.Sync;
 13using System.Net;
 14
 15namespace ActivityInfo
 16{
 17    public partial class DatabaseForm : Form, SyncLogger
 18    {
 19        private ActivityInfoService service;
 20        private LocalDb localDb;
 21
 22        public DatabaseForm()
 23        {
 24            InitializeComponent();
 25        }
 26
 27        private void label1_Click(object sender, EventArgs e)
 28        {
 29
 30        }
 31
 32        private void DatabaseForm_Load(object sender, EventArgs e)
 33        {
 34            LoginForm loginForm = new LoginForm();
 35            loginForm.ShowDialog(this);
 36
 37            if (loginForm.Service == null)
 38            {
 39                return;
 40            }
 41
 42            this.service = loginForm.Service;
 43            this.localDb = new LocalDb(service);
 44
 45        }
 46        private void synchronizeToolStripMenuItem_Click(object sender, EventArgs eventArgs)
 47        {
 48            try
 49            {
 50                this.localDb.NextSyncStep(this);
 51
 52                refreshTables();
 53            }
 54            catch (WebException e)
 55            {
 56                MessageBox.Show("Connection problem, SC = " + e.Message);
 57            }
 58               
 59        }
 60
 61        private void refreshTables()
 62        {
 63            SQLiteCommand cmd = new SQLiteCommand(localDb.Connection);
 64            cmd.CommandText = "select name from sqlite_master";
 65            SQLiteDataReader reader = cmd.ExecuteReader();
 66
 67            tableListView.Clear();
 68
 69            while (reader.Read())
 70            {
 71                tableListView.Items.Add(reader.GetString(0));
 72            }
 73        }
 74
 75        private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
 76        {
 77            refreshTables();
 78        }
 79
 80        private void tableListView_SelectedIndexChanged(object sender, EventArgs e)
 81        {
 82            string table = tableListView.FocusedItem.Text;
 83            SQLiteDataAdapter adapter = new SQLiteDataAdapter("select * from " + table, localDb.Connection);
 84            DataSet ds = new DataSet();
 85            adapter.Fill(ds);
 86
 87            dataGridView.DataSource = ds.Tables[0];
 88        }
 89
 90        private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
 91        {
 92
 93        }
 94
 95        #region SyncLogger Members
 96
 97        public void log(int level, string text)
 98        {
 99            loggingTextBox.Text += text + "\r\n";
100        }
101
102        #endregion
103
104    }
105}