private void экспортИзБазыДанныхToolStripMenuItem_Click(object sender, EventArgs e) { BinaryFormatter bf = new BinaryFormatter(); //OpenFileDialog openDlg = new OpenFileDialog(); LoadMenu loadMenu = new LoadMenu(); loadMenu.indexSave = 2; loadMenu.ShowDialog(); Database databaseSQLite = new Database(); if (loadMenu.fileName != null) { string query = "select File from SaveFilesClassification where Name=" + "\"" + loadMenu.fileName + "\""; databaseSQLite.OpenConnection(); SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection); List <SaveFiles> list = new List <SaveFiles>(); using (SQLiteDataReader reader = myCommand.ExecuteReader()) { if (reader.HasRows) // если есть данные { while (reader.Read()) // построчно считываем данные { byte[] data = (byte[])reader.GetValue(0); SaveFiles saveFile1 = new SaveFiles(data); list.Add(saveFile1); } } } databaseSQLite.CloseConnection(); using (FileStream fd = new FileStream("temp.dat", FileMode.OpenOrCreate)) { fd.Write(list[0].File, 0, list[0].File.Length); } FileStream fs = new FileStream("temp.dat", FileMode.Open, FileAccess.Read); currentClass = (ObjectClass)bf.Deserialize(fs); classes = currentClass.listBrushes; foreach (ObjectClass brushes in classes) { brushes.brush = ObjectClass.brushes[brushes.id]; } currentClass.brush = ObjectClass.brushes[currentClass.id]; ObjectClass.singleValueID = classes.Last().ids.Last() + 1; //net.AccessChangeNet = true; fs.Close(); DrawGraphics(); DrawObjects(); Refresh(); } }
private void экспортИзБазыДанныхToolStripMenuItem_Click(object sender, EventArgs e) { Database databaseSQLite = new Database(); LoadMenu loadMenu = new LoadMenu(); loadMenu.indexSave = 3; loadMenu.ShowDialog(); //OpenFileDialog openFileDialog = new OpenFileDialog(); //openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; //openFileDialog.FilterIndex = 2; //openFileDialog.RestoreDirectory = true; //if (openFileDialog.ShowDialog() != DialogResult.OK) return; if (loadMenu.fileName != null) { string query = "select File from SaveLinearSystemTask where Name=" + "\"" + loadMenu.fileName + "\""; databaseSQLite.OpenConnection(); SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection); using (SQLiteDataReader reader = myCommand.ExecuteReader()) { if (reader.HasRows) // если есть данные { while (reader.Read()) // построчно считываем данные { string data = (string)reader.GetValue(0); File.WriteAllText("temp.txt", data); } } } databaseSQLite.CloseConnection(); StreamReader SR = new StreamReader("temp.txt"); textBoxEqvNum.Text = SR.ReadLine();; textBoxVarNum.Text = SR.ReadLine(); int i = 0, j = 0; for (i = 0; i < DataGridMain.ColumnCount; i++) { for (j = 0; j < DataGridMain.RowCount - 1; j++) { DataGridMain[i, j].Value = SR.ReadLine(); } } DataGridMain.Refresh(); SR.Close(); } }
//Загрузка private void DeserializeNet(object sender, EventArgs e) { BinaryFormatter bf = new BinaryFormatter(); //OpenFileDialog openDlg = new OpenFileDialog(); LoadMenu loadMenu = new LoadMenu(); loadMenu.indexSave = 0; loadMenu.ShowDialog(); if (loadMenu.fileName != null) { string query = "select File from SaveFiles where Name=" + "\"" + loadMenu.fileName + "\""; databaseSQLite.OpenConnection(); SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection); List <SaveFiles> list = new List <SaveFiles>(); using (SQLiteDataReader reader = myCommand.ExecuteReader()) { if (reader.HasRows) // если есть данные { while (reader.Read()) // построчно считываем данные { byte[] data = (byte[])reader.GetValue(0); SaveFiles saveFile1 = new SaveFiles(data); list.Add(saveFile1); } } } databaseSQLite.CloseConnection(); using (FileStream fd = new FileStream("temp.dat", FileMode.OpenOrCreate)) { fd.Write(list[0].File, 0, list[0].File.Length); } FileStream fs = new FileStream("temp.dat", FileMode.Open, FileAccess.Read); Net = (NeuronNet)bf.Deserialize(fs); net.AccessChangeNet = true; fs.Close(); } }
private void DataBaseExport(object sender, EventArgs e) { LoadMenu loadMenu = new LoadMenu(); loadMenu.indexSave = 1; loadMenu.ShowDialog(); string[] file; if (loadMenu.fileName != null) { string query = "select Graph from SaveGraphs where Name=" + "\"" + loadMenu.fileName + "\""; databaseSQLite.OpenConnection(); SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection); using (SQLiteDataReader reader = myCommand.ExecuteReader()) { if (reader.HasRows) // если есть данные { while (reader.Read()) // построчно считываем данные { string data = (string)reader.GetValue(0); File.WriteAllText("temp.txt", data); } } } databaseSQLite.CloseConnection(); studyPairs.Clear(); FileStream fs = new FileStream("temp.txt", FileMode.Open, FileAccess.Read); file = File.ReadAllLines("temp.txt", Encoding.Default); for (int i = 0; i < file.Length; i++) { studyPairs.Add(StudyPair.FromString(file[i])); } colorGrid.SetData(studyPairs[currentStudyPair].inputs); ChangeNetSettings(); CreatePreview(); fs.Close(); } }