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!"); } }
public List <int> BiggestTableWidthAndHeight(string projectPath, string projectName) { int biggestHeight = 0; int biggestWidth = 0; List <int> listOfAtributes = new List <int>(); LoadProjects loadProjects = new LoadProjects(); foreach (var table in loadProjects.LoadTables(projectName)) { string tablePath = projectPath + "\\" + table; int height = (NumberOfLinesInFile(tablePath) * 15 + 17); int width = (LengthOfNameAndType(tablePath, table) * 8) + 46; if (height > biggestHeight) { biggestHeight = height; } if (width > biggestWidth) { biggestWidth = width; } } listOfAtributes.Add(biggestWidth); listOfAtributes.Add(biggestHeight); return(listOfAtributes); }
public void ChangeFKNameInDatAfterRenaming(string oldName, string newName, string projectName, string projectPath) { LoadProjects loadProjects = new LoadProjects(); List <String> listOfFileContent = new List <string>(); foreach (var table in loadProjects.LoadTables(projectName)) { listOfFileContent.Clear(); string tablePath = projectPath + "\\" + table; using (StreamReader sr = new StreamReader(tablePath)) { string line; while ((line = sr.ReadLine()) != null) { string[] parts = line.Split(','); if (parts[8].Contains(oldName)) { string newLine = null; for (int i = 0; i < parts.Length; i++) { if (i == 8) { string [] secondPart = parts[8].Split(':'); newLine += "[" + newName + ":" + secondPart[1]; } else if (parts[i] == "};") { newLine += "};"; break; } else { newLine += parts[i] + ","; } } listOfFileContent.Add(newLine); } else { listOfFileContent.Add(line); } } sr.Close(); } File.WriteAllLines(tablePath, listOfFileContent.ToArray()); } }
private void formERADijagram_Activated(object sender, EventArgs e) { treeProject.Nodes.Clear(); treeProject.Nodes.Add("Projects"); LoadProjects loadProjects = new LoadProjects(); // newProjectList = loadProjects.ProjectList(); if (newProject != "" && !projectIsRenamed) { newProjectList.Add(newProject); newProject = ""; } if (projectIsRenamed) { newProjectList.Remove(oldName); newProjectList.Add(newProject); System.Console.WriteLine("oldname" + oldName); System.Console.WriteLine("new name" + newProject); projectIsRenamed = false; newProject = ""; } foreach (var item in newProjectList) { TreeNode node; node = treeProject.Nodes[0].Nodes.Add(item.ToString()); foreach (var table in loadProjects.LoadTables(item.ToString())) { node.Nodes.Add(table.ToString()); } } filePanel.Height = 0; isFileMenuPanelOpen = false; treeProject.ExpandAll(); }
public int NumberOfTables(string projectName) { LoadProjects loadProjects = new LoadProjects(); return(loadProjects.LoadTables(projectName).Count()); }
private void lblGenerateERA_Click(object sender, EventArgs e) { Graphics gr = panelERADijagrama.CreateGraphics(); gr.Clear(Color.White); panelERADijagrama.Controls.Clear(); LoadProjects loadProjects = new LoadProjects(); GeneratingERA generatingERA = new GeneratingERA(); List <string> listOfTablePositionAndArea = new List <string>(); listOfEndTableTypePoints.Clear(); listOfEndPointsTable.Clear(); listOfDockingLinesPoints.Clear(); listOfStartTablePoints.Clear(); listOfStartTableTypePoints.Clear(); listOfRandomColor.Clear(); //Initilize drawing area int eraPanelWidth = panelERADijagrama.Width - (panel4.Width + panel1.Width); int eraPanelHeight = panelERADijagrama.Height - panel3.Height; int realEraPanelHeight = panelERADijagrama.Height; int realEraPanelWidth = panelERADijagrama.Width; //Initilaze starting position for drawing int eraStartingPositionX = panel4.Width + panel1.Width; int eraStartingPositionY = panel3.Height; Canvas canvas = new Canvas(eraPanelHeight, eraPanelWidth, eraStartingPositionX, eraStartingPositionY, realEraPanelHeight, realEraPanelWidth); //Making string path for selected project string projectName = treeProject.SelectedNode.Text; var dirPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var projectPath = $@"{dirPath}\Projects\" + projectName; // generatingERA.TableArea(projectPath,eraPanelWidth,eraPanelHeight); int numberOfTables = generatingERA.NumberOfTables(projectName); //Creating grid for drawing surface int biggestWidth = generatingERA.BiggestTableWidthAndHeight(projectPath, projectName).ElementAt(0); int biggestHeight = generatingERA.BiggestTableWidthAndHeight(projectPath, projectName).ElementAt(1); //Making empty canvas for tables canvas.SetMatrixToEmpty(); //Loading every table in project foreach (var table in loadProjects.LoadTables(projectName)) { string tablePath = projectPath + "\\" + table; int height = (generatingERA.NumberOfLinesInFile(tablePath) * 15 + 17); int width = (generatingERA.LengthOfNameAndType(tablePath, table) * 8) + 46; //Giving dimenisions for every table one by one and geting back coordinates int[,] point = canvas.StartingTablePoints(biggestWidth, biggestHeight, width, height, numberOfTables); int pointX = point.GetLength(0); int pointY = point.GetLength(1); //Creating panels for every table Panel tablePanel = new Panel(); tablePanel.Size = new System.Drawing.Size(width, height); tablePanel.Location = new Point(pointX, pointY); tablePanel.BorderStyle = BorderStyle.FixedSingle; tablePanel.BringToFront(); Color myCOlor = Color.FromArgb(169, 186, 171); tablePanel.BackColor = myCOlor; panelERADijagrama.Controls.Add(tablePanel); //Creating list for later drawings of connections string positionAndName = "[(" + pointX + "," + pointY + ");(" + width + "," + height + ");:" + table + "]"; listOfTablePositionAndArea.Add(positionAndName); //Creating label for table name Label lblTableName = new Label(); lblTableName.Text = table.Substring(0, table.IndexOf('.')); lblTableName.Font = new Font("Arial", 9, FontStyle.Bold); int tableNameWidth = table.Substring(0, table.IndexOf('.')).Length * 8; lblTableName.AutoSize = true; lblTableName.Location = new Point((width - tableNameWidth) / 2, 0); tablePanel.Controls.Add(lblTableName); //Drawing line to seperate table name from atributtes tablePanel.Paint += new PaintEventHandler(tablePanelPaint); tablePanel.Refresh(); int newY = 18; //Loop for placing labels which are PK foreach (var PK in generatingERA.ListOfPrimaryKeyInTable(tablePath)) { string[] parts = PK.Split(','); //Creating label for primary keys Label lbPK = new Label(); lbPK.Text = parts[0].ToString(); lbPK.Font = new Font("Arial", 8, FontStyle.Bold); lbPK.Location = new System.Drawing.Point(20, newY); lbPK.AutoSize = true; tablePanel.Controls.Add(lbPK); //Creating label for primary key type Label lbTypePK = new Label(); lbTypePK.Text = parts[1].ToString(); lbTypePK.Font = new Font("Arial", 8, FontStyle.Bold); lbTypePK.Location = new System.Drawing.Point(width - (width - (generatingERA.BiggestAttribute(tablePath)) * 8) + 26, newY); lbTypePK.AutoSize = true; tablePanel.Controls.Add(lbTypePK); //Creating Label for PK indicator Label lblPk1 = new Label(); lblPk1.Text = "PK"; lblPk1.Font = new Font("Arial", 8, FontStyle.Bold); lblPk1.Location = new System.Drawing.Point(0, newY); lblPk1.AutoSize = true; tablePanel.Controls.Add(lblPk1); newY += 15; lbTypePK.BringToFront(); } //Loop for placing labels that are normal atributes foreach (var attribute in generatingERA.AtributeNameAndTypeInFile(tablePath)) { string[] parts = attribute.Split(','); //Creating labels for every atribute Label lb = new Label(); lb.Text = parts[0].ToString(); lb.Font = new Font("Arial", 8, FontStyle.Regular); lb.Location = new System.Drawing.Point(20, newY); lb.AutoSize = true; tablePanel.Controls.Add(lb); //Creating label for type Label lbType = new Label(); lbType.Text = parts[1].ToString(); lbType.Font = new Font("Arial", 8, FontStyle.Regular); lbType.Location = new System.Drawing.Point(width - (width - (generatingERA.BiggestAttribute(tablePath)) * 8) + 26, newY); //lbType.Location = new System.Drawing.Point(width - lb.Width-10, newY); lbType.AutoSize = true; tablePanel.Controls.Add(lbType); newY += 15; lbType.BringToFront(); } //Adding foreing keys to table panel foreach (var PK in generatingERA.ListOfFKAtributeAndType(tablePath)) { string[] parts = PK.Split(','); //Creating laber from FK keys Label lbFK = new Label(); lbFK.Text = parts[0].ToString(); lbFK.Font = new Font("Arial", 8, FontStyle.Bold); lbFK.Location = new System.Drawing.Point(20, newY); lbFK.AutoSize = true; tablePanel.Controls.Add(lbFK); //Creating label for FK key type Label lbTypeFK = new Label(); lbTypeFK.Text = parts[1].ToString(); lbTypeFK.Font = new Font("Arial", 8, FontStyle.Bold); lbTypeFK.Location = new System.Drawing.Point(width - (width - (generatingERA.BiggestAttribute(tablePath)) * 8) + 26, newY); lbTypeFK.AutoSize = true; tablePanel.Controls.Add(lbTypeFK); //Creating Label for FK indicator Label lblFk1 = new Label(); lblFk1.Text = "FK"; lblFk1.Font = new Font("Arial", 8, FontStyle.Bold); lblFk1.Location = new System.Drawing.Point(0, newY); lblFk1.AutoSize = true; tablePanel.Controls.Add(lblFk1); newY += 15; lbTypeFK.BringToFront(); } } ; //Loop for drawing lines foreach (var item in listOfTablePositionAndArea) { string[] parts = item.Split(';'); string tableName = item.Substring(item.LastIndexOf(':') + 1, item.IndexOf(']') - item.IndexOf(':') - 1); int pointX = int.Parse(parts[0].Substring(item.IndexOf('(') + 1, item.IndexOf(',') - 2)); int pointY = int.Parse(parts[0].Substring(item.IndexOf(',') + 1, item.IndexOf(')') - item.IndexOf(',') - 1)); int width = int.Parse(parts[1].Substring(parts[1].IndexOf('(') + 1, parts[1].IndexOf(',') - 1)); int height = int.Parse(parts[1].Substring(parts[1].IndexOf(',') + 1, parts[1].IndexOf(')') - parts[1].IndexOf(',') - 1)); //Checks if table has a FK-that would be child table if (generatingERA.TableHasFK(projectPath + "\\" + tableName)) { //Checks list of FK for that table(how many of FK child table has ) foreach (var FK in generatingERA.ListOfTableFK(projectPath + "\\" + tableName)) { //Finding again coordinates for table that is the parent foreach (var tableFK in listOfTablePositionAndArea) { string[] newParts = tableFK.Split(';'); string parentTable = newParts[2].Substring(newParts[2].IndexOf(':') + 1, newParts[2].IndexOf('.') - newParts[2].IndexOf(':') - 1); //FK== item from list where child table has FK that FK is acctualy nake of primary table if (FK == parentTable) { //Primary table coordinates and dimension int newPointX = int.Parse(newParts[0].Substring(newParts[0].IndexOf('(') + 1, newParts[0].IndexOf(',') - 2)); int newPointY = int.Parse(newParts[0].Substring(newParts[0].IndexOf(',') + 1, newParts[0].IndexOf(')') - newParts[0].IndexOf(',') - 1)); int newWidth = int.Parse(newParts[1].Substring(newParts[1].IndexOf('(') + 1, newParts[1].IndexOf(',') - 1)); int newHeight = int.Parse(newParts[1].Substring(newParts[1].IndexOf(',') + 1, newParts[1].IndexOf(')') - newParts[1].IndexOf(',') - 1)); //Sada ovdje treba provijeriti na koji nacin su povezane te dvije tablice //Provijeriti tablica u kojoj se nalazi FK kojeg je tipa atribut //Onda na koordinate od child tablice staviti vezu //I na koordinate od parent tablice staviti takoker tip veze // tableName- ime tablice sa FK // parentTable- ime tablice sa PK Dictionary <string, string> typeOfConnection = generatingERA.TypeOfConnection(tableName, parentTable, projectPath); string childTableConnectionType = ""; string parentTableConnectionType = ""; try { foreach (var type in typeOfConnection) { childTableConnectionType = type.Key; parentTableConnectionType = type.Value; } } catch { } canvas.NewStartingCoordinates(newPointX, newPointY, pointX, pointY, newWidth, newHeight, width, height); Point[] pointsEndTable = canvas.MyDrawingPathEndTable(pointX, pointY, width, height); Point[] pointsStartTable = canvas.MyDrawingPathStartTable(newPointX, newPointY, newWidth, newHeight); Point[] startTabletypePoints = canvas.TableConnectionStartTable(parentTableConnectionType); Point[] endTableTypePoints = canvas.TableConnectionsEndTable(childTableConnectionType, parentTableConnectionType); Point[] dokcingPoints = canvas.AgainMyTry(); try { listOfEndPointsTable.Add(pointsEndTable); listOfStartTablePoints.Add(pointsStartTable); listOfStartTableTypePoints.Add(startTabletypePoints); listOfEndTableTypePoints.Add(endTableTypePoints); listOfDockingLinesPoints.Add(dokcingPoints); Random rnd = new Random(); Color randomColor = Color.FromArgb(rnd.Next(150), rnd.Next(150), rnd.Next(150)); try { while (listOfRandomColor.Contains(randomColor)) { randomColor = Color.FromArgb(rnd.Next(150), rnd.Next(150), rnd.Next(150)); } listOfRandomColor.Add(randomColor); } catch { listOfRandomColor.Add(randomColor); } } catch { System.Console.WriteLine("Not work"); } } } } } } //canvas.PrintMatrix(); panelERADijagrama.Invalidate(); projectOptionsPanel.Height = 0; isProjectMenuOpen = false; }