コード例 #1
0
        private void AddColumn_Click(object sender, RoutedEventArgs e)
        {
            EnterNameWindow enterNameWindow = new EnterNameWindow();

            if (enterNameWindow.ShowDialog() == true)
            {
                string        columnName = Transliteration.Front(enterNameWindow.result);
                SQLiteCommand command    = new SQLiteCommand("ALTER TABLE clients ADD COLUMN [" + columnName + "] TEXT", conn);
                try
                {
                    command.ExecuteNonQuery();

                    doConnection();

                    table_clients.Clear();
                    adapter.Fill(table_clients);

                    DataGridColumn column = new DataGridTextColumn
                    {
                        Header      = table_clients.Columns.Count.ToString() + ". " + enterNameWindow.result,
                        Binding     = new Binding(string.Format("[{0}]", columnName)),
                        CanUserSort = false
                    };
                    dgDataClient.Columns.Add(column);
                    dgClients.Items.Refresh();
                    dgDataClient.Items.Refresh();
                }
                catch (SQLiteException ex) {
                    MessageBox.Show("Ошибка - " + ex.Message, "Ошибка");
                }
            }
        }
コード例 #2
0
        private void ClientsList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dgClients.SelectedIndex == -1)
            {
                return;
            }

            if (conn == null)
            {
                doConnection();
            }

            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            // id  выделенного клиента
            long CLIENT_ID = (long)(dgClients.SelectedItem as DataRowView).Row[0];

            SQLiteCommand SelectCommand = new SQLiteCommand("SELECT * FROM clients WHERE id="
                                                            + CLIENT_ID.ToString(), conn);

            using (SQLiteDataReader reader = SelectCommand.ExecuteReader())
            {
                table = new DataTable();
                table.Load(reader);

                if ((long)table.Rows[0][8] == 1)
                {
                    is_closed.IsChecked = true;
                }
                else
                {
                    is_closed.IsChecked = false;
                }

                is_closed.Visibility = Visibility.Visible;

                DataTable pivotTable = new DataTable("pivotDataClient");
                pivotTable.Columns.Add(new DataColumn("Header", System.Type.GetType("System.String")));
                pivotTable.Columns.Add(new DataColumn("Value", System.Type.GetType("System.String")));
                for (int i = 1; i < table.Columns.Count; ++i)
                {
                    DataRow row = pivotTable.NewRow();

                    switch (i)
                    {
                    case 1: row["Header"] = i.ToString() + ". Клиент"; break;

                    case 2: row["Header"] = i.ToString() + ". Контакты"; break;

                    case 3: row["Header"] = i.ToString() + ". Статус"; break;

                    case 4: row["Header"] = i.ToString() + ". Суд"; break;

                    case 5: row["Header"] = i.ToString() + ". Номер"; break;

                    case 6: row["Header"] = i.ToString() + ". Адвокат"; break;

                    case 7: row["Header"] = i.ToString() + ". Результат"; break;

                    case 8: continue;

                    default: row["Header"] = (i - 1).ToString() + ". " + Transliteration.Back(table.Columns[i].ColumnName); break;
                    }

                    row["Value"] = table.Rows[0][i];
                    pivotTable.Rows.Add(row);
                }
                dgDataClient.ItemsSource = pivotTable.DefaultView;
            }

            lblInfo.Text = "Данные о клиенте - " + (dgClients.SelectedItem as DataRowView).Row[1].ToString();
            // выбираем все даты заседаний этого клиента
            adapter_dates.SelectCommand.Parameters["@c"].Value = CLIENT_ID;
            // обработчик изменений в этой таблице для сохранения
            table_dates.RowChanged -= new DataRowChangeEventHandler(onNewDates);
            table_dates.Clear();
            adapter_dates.Fill(table_dates);
            table_dates.RowChanged += new DataRowChangeEventHandler(onNewDates);

            dgDates.ItemsSource = table_dates.DefaultView;
            // аналогично с файлами
            adapter_files.SelectCommand.Parameters["@c"].Value = CLIENT_ID;

            table_files.Clear();
            adapter_files.Fill(table_files);

            dgFiles.ItemsSource = table_files.DefaultView;
        }