public static bool GetMSSQLRecords(string[] dbparemeters, string workingFolder, string projectXMLFile, string projectSqLiteFile) { string table; var fqProjectFilePath = Path.Combine(workingFolder, projectXMLFile); var fqProjectDBFilePath = Path.Combine(workingFolder, projectSqLiteFile); if (File.Exists(fqProjectFilePath)) { table = ReadXML.ReadProjectDBTableName(fqProjectFilePath); } else { throw new FileNotFoundException("Project file not found!"); } SqlConnectionStringBuilder dbConString = new SqlConnectionStringBuilder { DataSource = dbparemeters[0], InitialCatalog = dbparemeters[1], UserID = dbparemeters[2], Password = dbparemeters[3] }; using (SqlConnection connection = new SqlConnection(dbConString.ConnectionString)) { try { connection.Open(); string command = "SELECT * from " + table + ";"; using (SqlCommand cmd = new SqlCommand(command, connection)) { SqlDataReader drItem = cmd.ExecuteReader(); //make a List to send to the SQL Lite add method List <string> list = new List <string>(); //populate the List while (drItem.Read()) { //populate the List string xPos = drItem["xPos"].ToString(); string yPos = drItem["yPos"].ToString(); string zPos = drItem["zPos"].ToString(); string length = drItem["length"].ToString(); string width = drItem["width"].ToString(); string height = drItem["height"].ToString(); string weight = drItem["weight"].ToString(); string name = drItem["name"].ToString(); list.Add(xPos); list.Add(yPos); list.Add(zPos); list.Add(length); list.Add(width); list.Add(height); list.Add(weight); list.Add(name); if (File.Exists(fqProjectDBFilePath)) { //finally add the new list to the project database WriteSQLite.AddSQLiteData(FilePathDefaults.ScratchFolder, projectSqLiteFile, list); } else { throw new FileNotFoundException("Project database to write new SQL data into not found!"); } } //end of while return(true); } //end of using SqlCommand } //end of try catch (SqlException) { return(false); } } }
/// <summary> /// Sets up a default project XML file with the given project name. /// </summary> /// <param name="projectName"></param> public static void NewProjectDetailOperations(string tempFileDirectory, string newProjectXMLFile, string newProjectDBFile) { WriteXML.WriteBlankXML(tempFileDirectory, newProjectXMLFile); //write a new project file out with the given path and file name WriteSQLite.CreateProjectDatabase(tempFileDirectory, newProjectDBFile); //write a new project database out with the given path and file name //TODO write project name, savepath, and time accessed to settings XML file, or move to top and update time if already there }