Example #1
0
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            List <string> namesList = new List <string>();

            for (int i = 0; i < dataGridViewAll.ColumnCount; i++)
            {
                namesList.Add(dataGridViewAll.Columns[i].HeaderText);
            }

            DinamycAddModForm f = new DinamycAddModForm(namesList.ToArray(), false, connectionString,
                                                        tablesName[comboBoxTables.SelectedIndex]);

            f.ShowDialog();
            try
            {
                SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(connectionString);
                string         sqlExpr  = @"select * from " + tablesName[comboBoxTables.SelectedIndex];
                SqlConnection  userConn = new SqlConnection(sqlBuilder.ToString());
                SqlCommand     comm     = new SqlCommand(sqlExpr, userConn);
                SqlDataAdapter adapter  = new SqlDataAdapter(comm);

                DataTable dt = new DataTable();
                adapter.Fill(dt);
                tablesDict[comboBoxTables.SelectedText.ToString()] = dt;
                dataGridViewAll.DataSource = dt;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
Example #2
0
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            var           row        = dataGridViewAll.SelectedRows;
            List <string> valuesList = new List <string>();

            for (int i = 0; i < dataGridViewAll.ColumnCount; i++)
            {
                var zap = row[0].Cells[i].Value.ToString();
                if (zap.Contains("0:00:00"))
                {
                    zap = zap.Replace("0:00:00", "");
                }
                valuesList.Add(zap.Replace(" ", ""));
            }
            List <string> namesList = new List <string>();

            for (int i = 0; i < dataGridViewAll.ColumnCount; i++)
            {
                namesList.Add(dataGridViewAll.Columns[i].HeaderText);
            }
            DinamycAddModForm f = new DinamycAddModForm(namesList.ToArray(), true, connectionString, tablesName[comboBoxTables.SelectedIndex], valuesList);

            f.ShowDialog();
            try
            {
                SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(connectionString);
                string         sqlExpr  = @"select * from " + tablesName[comboBoxTables.SelectedIndex];
                SqlConnection  userConn = new SqlConnection(sqlBuilder.ToString());
                SqlCommand     comm     = new SqlCommand(sqlExpr, userConn);
                SqlDataAdapter adapter  = new SqlDataAdapter(comm);

                DataTable dt = new DataTable();
                adapter.Fill(dt);
                tablesDict[comboBoxTables.SelectedText.ToString()] = dt;
                dataGridViewAll.DataSource = dt;
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }