public void btnSaveProjectName_Click(object sender, EventArgs e) { NewTableController controller = new NewTableController(); LoadProjects loadProjects = new LoadProjects(); bool exists = false; foreach (var project in loadProjects.ProjectList()) { if (project == projectName1 && rename1) { string folderName = loadProjects.CreateProjectDirectory(); string pathString = System.IO.Path.Combine(folderName, projectName1.Replace(" ", "_")); string pathString1 = System.IO.Path.Combine(folderName, txtProjectName.Text.Replace(" ", "_")); if (!loadProjects.ProjectList().Contains(txtProjectName.Text.Replace(" ", "_"))) { if (controller.CheckTextInput(txtProjectName.Text.Replace(" ", "_"))) { System.IO.Directory.Move(pathString, pathString1); f1.oldName = projectName1.Replace(" ", "_"); f1.newProject = txtProjectName.Text.Replace(" ", "_"); f1.projectIsRenamed = true; this.Hide(); } else { MessageBox.Show("Invalid input!"); } } } else if (project == txtProjectName.Text.Replace(" ", "_")) { exists = true; } } if (!exists) { if (controller.CheckTextInput(txtProjectName.Text)) { string folderName = loadProjects.CreateProjectDirectory(); string pathString = System.IO.Path.Combine(folderName, txtProjectName.Text.Replace(" ", "_")); System.IO.Directory.CreateDirectory(pathString); f1.newProject = txtProjectName.Text.Replace(" ", "_"); this.Hide(); } else if (!rename1) { txtProjectName.Text = ""; MessageBox.Show("Invalid input"); } } else { MessageBox.Show("Project already exists!"); } }
private void btnSaveTableName_Click(object sender, EventArgs e) { NewTableController controller = new NewTableController(); LoadProjects loadProjects = new LoadProjects(); bool exists = false; foreach (var table in loadProjects.LoadTables(projectName)) { if ((table) == (tableName1 + ".dat") && rename1) { string projectPath = loadProjects.CreateProjectDirectory() + "\\" + projectName + "\\" + tableName1.Replace(" ", "_") + ".dat"; string projectPath1 = loadProjects.CreateProjectDirectory() + "\\" + projectName + "\\" + txtTableName.Text.Replace(" ", "_") + ".dat"; string projectPathForChangeFK = loadProjects.CreateProjectDirectory() + "\\" + projectName; controller.ChangeFKNameInDatAfterRenaming(tableName1.Replace(" ", "_"), txtTableName.Text.Replace(" ", "_"), projectName, projectPathForChangeFK); if (!loadProjects.LoadTables(projectName).Contains(txtTableName.Text + ".dat")) { if (controller.CheckTextInput(txtTableName.Text.Replace(" ", "_"))) { System.IO.File.Move(projectPath, projectPath1); this.Close(); } else { MessageBox.Show("Invalid input"); } } } if (table == txtTableName.Text + ".dat") { MessageBox.Show("Table already exists!"); exists = true; } } if (controller.CheckTextInput(txtTableName.Text) && !rename1 && !exists) { string projectPath = loadProjects.CreateProjectDirectory() + "\\" + projectName + "\\" + txtTableName.Text.Replace(" ", "_") + ".dat"; FileStream fs = File.Create(projectPath); fs.Close(); formNovaTablica frmNewTable = new formNovaTablica(txtTableName.Text, projectPath, projectName); frmNewTable.Show(); this.Close(); } else if (!controller.CheckTextInput(txtTableName.Text) && !rename1) { MessageBox.Show("Invalid input!"); } }
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; }