Exemple #1
0
        private void DataBaseImport(object sender, EventArgs e)
        {
            //SaveFileDialog openDlg = new SaveFileDialog();
            SaveMenu saveMenu = new SaveMenu();

            saveMenu.indexSave = 1;
            saveMenu.ShowDialog();
            //saveMenu.ShowDialog();
            if (saveMenu.fileName != null)
            {
                if (studyPairs.Count == 0)
                {
                    MessageBox.Show("Пустой файл", "DataBaseImport", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    //Ассоциативная память не работает. Чинить бессмысленно, так как этим занимается другая группа
                    ChangeNetSettings();
                    File.WriteAllText("temp.txt", net.StudyPairsToString(studyPairs.Count));

                    byte[] fileData;
                    using (FileStream fs = new FileStream("temp.txt", FileMode.Open))
                    {
                        fileData = new byte[fs.Length];
                        fs.Read(fileData, 0, fileData.Length);
                    }

                    string query = "select max(id) from SaveGraphs";
                    databaseSQLite.OpenConnection();
                    SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                    int           maxID;
                    if (myCommand.ExecuteScalar() == DBNull.Value)
                    {
                        maxID = 0;
                    }
                    else
                    {
                        maxID = Convert.ToInt32(myCommand.ExecuteScalar()) + 1;
                    }

                    query     = "INSERT INTO SaveGraphs (id,Name,Graph) values (@id, @Name, @Graph)";
                    myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                    myCommand.Parameters.AddWithValue("@id", maxID);
                    myCommand.Parameters.AddWithValue("@Name", saveMenu.fileName);
                    myCommand.Parameters.AddWithValue("@Graph", fileData);
                    myCommand.ExecuteNonQuery();
                    databaseSQLite.CloseConnection();

                    //neuronGraphics.RecognizeImages(this, EventArgs.Empty);
                    //this.Close();
                }
            }
        }
Exemple #2
0
        private void импортВБазуДанныхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BinaryFormatter bf = new BinaryFormatter();
            //SaveFileDialog openDlg = new SaveFileDialog();
            SaveMenu saveMenu = new SaveMenu();

            saveMenu.indexSave = 2;
            saveMenu.ShowDialog();
            if (saveMenu.fileName != null)
            {
                Database databaseSQLite = new Database();
                currentClass.listBrushes.Clear();
                foreach (ObjectClass brushes in classes)
                {
                    currentClass.listBrushes.Add(brushes);
                }
                FileStream fd = new FileStream("temp.dat", FileMode.Create, FileAccess.Write);
                //net.AccessChangeNet = false;
                bf.Serialize(fd, currentClass);
                fd.Close();

                byte[] fileData;
                using (FileStream fs = new FileStream("temp.dat", FileMode.Open))
                {
                    fileData = new byte[fs.Length];
                    fs.Read(fileData, 0, fileData.Length);
                }

                string query = "select max(id) from SaveFilesClassification";
                databaseSQLite.OpenConnection();
                SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                int           maxID;
                if (myCommand.ExecuteScalar() == DBNull.Value)
                {
                    maxID = 0;
                }
                else
                {
                    maxID = Convert.ToInt32(myCommand.ExecuteScalar()) + 1;
                }

                query     = "INSERT INTO SaveFilesClassification (id,Name,File) values (@id, @Name, @File)";
                myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                myCommand.Parameters.AddWithValue("@id", maxID);
                myCommand.Parameters.AddWithValue("@Name", saveMenu.fileName);
                myCommand.Parameters.AddWithValue("@File", fileData);
                myCommand.ExecuteNonQuery();
                databaseSQLite.CloseConnection();
            }
        }
Exemple #3
0
        //Сохранение
        private void SerializeNet(object sender, EventArgs e)
        {
            BinaryFormatter bf = new BinaryFormatter();
            //SaveFileDialog openDlg = new SaveFileDialog();
            SaveMenu saveMenu = new SaveMenu();

            saveMenu.indexSave = 0;
            saveMenu.ShowDialog();
            if (saveMenu.fileName != null)
            {
                FileStream fd = new FileStream("temp.dat", FileMode.Create, FileAccess.Write);
                net.AccessChangeNet = false;
                bf.Serialize(fd, (NeuronNet)net);
                fd.Close();

                byte[] fileData;
                using (FileStream fs = new FileStream("temp.dat", FileMode.Open))
                {
                    fileData = new byte[fs.Length];
                    fs.Read(fileData, 0, fileData.Length);
                }

                string query = "select max(id) from SaveFiles";
                databaseSQLite.OpenConnection();
                SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                int           maxID;
                if (myCommand.ExecuteScalar() == DBNull.Value)
                {
                    maxID = 0;
                }
                else
                {
                    maxID = Convert.ToInt32(myCommand.ExecuteScalar()) + 1;
                }

                query     = "INSERT INTO SaveFiles (id,Name,File) values (@id, @Name, @File)";
                myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                myCommand.Parameters.AddWithValue("@id", maxID);
                myCommand.Parameters.AddWithValue("@Name", saveMenu.fileName);
                myCommand.Parameters.AddWithValue("@File", fileData);
                myCommand.ExecuteNonQuery();
                databaseSQLite.CloseConnection();
            }
        }
Exemple #4
0
        private void импортВБазуДанныхToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Database databaseSQLite = new Database();
            SaveMenu saveMenu       = new SaveMenu();

            saveMenu.indexSave = 3;
            saveMenu.ShowDialog();

            //SaveFileDialog openFileDialog = new SaveFileDialog();
            //openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            //openFileDialog.FilterIndex = 2;
            //openFileDialog.RestoreDirectory = true;
            if (saveMenu.fileName != null)
            {
                //if (openFileDialog.ShowDialog() != DialogResult.OK) return;
                StreamWriter SW = new StreamWriter("temp.txt");
                SW.WriteLine(EqvNum.ToString());
                SW.WriteLine(VarNum.ToString());

                String data;
                int    i = 0, j = 0;
                for (i = 0; i < DataGridMain.ColumnCount; i++)
                {
                    for (j = 0; j < DataGridMain.RowCount - 1; j++)
                    {
                        data = DataGridMain[i, j].Value.ToString();
                        SW.WriteLine(data);
                    }
                }
                SW.Flush();
                SW.Close();

                byte[] fileData;
                using (FileStream fs = new FileStream("temp.txt", FileMode.Open))
                {
                    fileData = new byte[fs.Length];
                    fs.Read(fileData, 0, fileData.Length);
                }

                //SaveLinearSystemTask
                string query = "select max(id) from SaveLinearSystemTask";
                databaseSQLite.OpenConnection();
                SQLiteCommand myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                int           maxID;
                if (myCommand.ExecuteScalar() == DBNull.Value)
                {
                    maxID = 0;
                }
                else
                {
                    maxID = Convert.ToInt32(myCommand.ExecuteScalar()) + 1;
                }

                query     = "INSERT INTO SaveLinearSystemTask (id,Name,File) values (@id, @Name, @File)";
                myCommand = new SQLiteCommand(query, databaseSQLite.myConnection);
                myCommand.Parameters.AddWithValue("@id", maxID);
                myCommand.Parameters.AddWithValue("@Name", saveMenu.fileName);
                myCommand.Parameters.AddWithValue("@File", fileData);
                myCommand.ExecuteNonQuery();
                databaseSQLite.CloseConnection();
            }
        }