Example #1
0
        private void btnKeysAdd_Click(object sender, EventArgs e)
        {
            NewTableController controller = new NewTableController();

            try
            {
                controller.CheckThoseDamnAtributesToPrimaryKeys(cmbColumnAtribut.SelectedItem.ToString(), dirPath1);
                for (int i = 0; i < dgvStupci.RowCount - 1; i++)
                {
                    if (dgvStupci.Rows[i].Cells[0].Value.ToString() == cmbColumnAtribut.SelectedItem.ToString())
                    {
                        dgvStupci.Rows[i].Cells[4].Value = true;
                        dgvStupci.Rows[i].Cells[3].Value = true;
                        dgvStupci.Refresh();
                        dgvKeys.Rows.Add(1);
                        dgvKeys.Rows[rowIndex].Cells[0].Value = cmbColumnAtribut.SelectedItem.ToString();
                        dgvKeys.Rows[rowIndex].Cells[1].Value = dgvStupci.Rows[i].Cells[1].Value;
                        dgvKeys.Rows[rowIndex].Cells[2].Value = chcboxKeysPrimary.Checked;
                        rowIndex++;
                    }
                }
                cmbColumnAtribut.DataSource = controller.ListOfTableAtributesForPrimaryKey(dirPath1);
            }
            catch { }
        }
Example #2
0
        private void btnNewColumnRemove_Click(object sender, EventArgs e)
        {
            NewTableController controller = new NewTableController();

            try
            {
                int    lineToDelete = dgvStupci.CurrentCell.RowIndex;
                string atributName  = dgvStupci.Rows[lineToDelete].Cells[0].Value.ToString();
                dgvStupci.Rows.RemoveAt(lineToDelete);
                controller.DelteRowFromTable(lineToDelete, dirPath1);
                brojAtributa--;

                cmbColumnAtribut.DataSource         = controller.ListOfTableAtributesForPrimaryKey(dirPath1);
                cmbCurrentTableAtributes.DataSource = controller.ListOfAtributesInCurrentTable(dirPath1);

                try
                {
                    int rowIndex1   = -1;
                    int newRowIndex = -1;
                    foreach (DataGridViewRow row in dgvForeignKeys.Rows)
                    {
                        if (row.Cells[1].Value != null)
                        {
                            if (row.Cells[1].Value.ToString().Equals(atributName))
                            {
                                rowIndex1 = row.Index;
                                dgvForeignKeys.Rows.RemoveAt(rowIndex1);
                                rowIndexForFK--;
                                break;
                            }
                        }
                    }

                    foreach (DataGridViewRow row in dgvKeys.Rows)
                    {
                        if (row.Cells[0].Value != null)
                        {
                            if (row.Cells[0].Value.ToString().Equals(atributName))
                            {
                                newRowIndex = row.Index;
                                dgvKeys.Rows.RemoveAt(newRowIndex);
                                rowIndex--;
                                break;
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            catch (Exception f)
            {
                MessageBox.Show("Please select valid row");
            }
        }
Example #3
0
        private void btnUnosStupca_Click(object sender, EventArgs e)
        {
            NewTableController kontroler = new NewTableController();
            DataTypes          dataTypes = new DataTypes();

            if (kontroler.CheckForSameAtributes(dirPath1, txtName.Text))
            {
                if (kontroler.CheckTextInput(txtName.Text) && kontroler.CheckDataType(txtType.Text))
                {
                    if (chcBoxNotNull.Checked == false && chcoxPrimaryKey.Checked == true)
                    {
                        MessageBox.Show("Primary key can not be null!");
                    }
                    else if ((kontroler.CheckPrimaryKey(dirPath1) && chcoxPrimaryKey.Checked == true))
                    {
                        MessageBox.Show("Primary key already exists!");
                    }
                    else if (kontroler.CheckPrimaryKeyType(txtType.Text) && chcoxPrimaryKey.Checked == true)
                    {
                        MessageBox.Show("Primary key is wrong type!");
                    }
                    else
                    {
                        dgvStupci.Rows.Add(1);
                        dgvStupci.Rows[brojAtributa].Cells[0].Value = kontroler.ProvjeraImena(txtName.Text);
                        dgvStupci.Rows[brojAtributa].Cells[1].Value = txtType.Text;
                        dgvStupci.Rows[brojAtributa].Cells[2].Value = chcboxAutoInc.Checked;
                        dgvStupci.Rows[brojAtributa].Cells[3].Value = chcBoxNotNull.Checked;
                        dgvStupci.Rows[brojAtributa].Cells[4].Value = chcoxPrimaryKey.Checked;
                        brojAtributa++;
                        string foreingName = string.Empty;
                        foreingName += txtForeignName.Text;
                        kontroler.InsertDataIntoTextFile(dirPath1, dgvStupci.NewRowIndex, kontroler.ProvjeraImena(txtName.Text), txtType.Text, chcBoxNotNull.Checked, chcboxAutoInc.Checked, chcboxUnique.Checked, chcoxPrimaryKey.Checked, foreingName);
                        cmbColumnAtribut.DataSource         = kontroler.ListOfTableAtributesForPrimaryKey(dirPath1);
                        cmbCurrentTableAtributes.DataSource = kontroler.ListOfAtributesInCurrentTable(dirPath1);
                        if (chcoxPrimaryKey.Checked)
                        {
                            dgvKeys.Rows.Add(1);
                            dgvKeys.Rows[rowIndex].Cells[0].Value = kontroler.ProvjeraImena(txtName.Text);
                            dgvKeys.Rows[rowIndex].Cells[1].Value = txtType.Text;
                            dgvKeys.Rows[rowIndex].Cells[2].Value = true;
                            rowIndex++;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Wrong input");
                }
            }
            else
            {
                MessageBox.Show("Attribute already exists");
            }
            //Reset fields
            txtName.Clear();
            txtType.Clear();
            chcboxAutoInc.Checked   = false;
            chcoxPrimaryKey.Checked = false;
            chcBoxNotNull.Checked   = false;
            chcboxUnique.Checked    = false;
        }
Example #4
0
        private void formNovaTablica_Load(object sender, EventArgs e)
        {
            brojAtributa         = 0;
            rowIndex             = 0;
            rowIndexForFK        = 0;
            txtTableName.Text    = tableName1.Replace(" ", "_");
            txtKeyNameTable.Text = tableName1.Replace(" ", "_");
            NewTableController controller   = new NewTableController();
            LoadProjects       loadProjects = new LoadProjects();



            if (reload1)
            {
                foreach (var item in loadProjects.OpenSpecificTable(dirPath1))
                {
                    string[] parts = item.Split(',');
                    dgvStupci.Rows.Add(1);
                    dgvStupci.Rows[brojAtributa].Cells[0].Value = parts[0].ToString();
                    dgvStupci.Rows[brojAtributa].Cells[1].Value = parts[1].ToString();
                    if (parts[3].ToString() == "True")
                    {
                        dgvStupci.Rows[brojAtributa].Cells[2].Value = true;
                    }
                    else
                    {
                        dgvStupci.Rows[brojAtributa].Cells[2].Value = false;
                    }
                    if (parts[2].ToString() == "True")
                    {
                        dgvStupci.Rows[brojAtributa].Cells[3].Value = true;
                    }
                    else
                    {
                        dgvStupci.Rows[brojAtributa].Cells[3].Value = false;
                    }
                    if (parts[4].ToString() == "True")
                    {
                        dgvKeys.Rows.Add(1);
                        dgvStupci.Rows[brojAtributa].Cells[4].Value = true;
                        dgvKeys.Rows[rowIndex].Cells[0].Value       = parts[0].ToString();
                        dgvKeys.Rows[rowIndex].Cells[1].Value       = parts[1].ToString();
                        dgvKeys.Rows[rowIndex].Cells[2].Value       = true;
                        rowIndex++;
                    }
                    else
                    {
                        dgvStupci.Rows[brojAtributa].Cells[4].Value = false;
                    }

                    if (parts[5].ToString() != "")
                    {
                        string[] line = parts[5].Split(':');
                        dgvForeignKeys.Rows.Add(1);
                        dgvForeignKeys.Rows[rowIndexForFK].Cells[0].Value = line[0].Substring(line[0].IndexOf("[") + 1, line[0].Length - 1);
                        dgvForeignKeys.Rows[rowIndexForFK].Cells[1].Value = parts[0];
                        dgvForeignKeys.Rows[rowIndexForFK].Cells[2].Value = line[1].Substring(0, line[1].IndexOf("]"));
                        rowIndexForFK++;
                    }

                    brojAtributa++;
                }
            }
            cmbFKTableName.DataSource           = loadProjects.LoadTablesWithoutExtension(projectName1);
            cmbColumnAtribut.DataSource         = controller.ListOfTableAtributesForPrimaryKey(dirPath1);
            cmbCurrentTableAtributes.DataSource = controller.ListOfAtributesInCurrentTable(dirPath1);
        }