Пример #1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Open file system to select file(s)
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Multiselect = true;


            Nullable <bool> result = dlg.ShowDialog();  // Display OpenFileDialog by calling ShowDialog method

            byte[] rawData;
            List <Tuple <string, byte[]> > dataList = new List <Tuple <string, byte[]> >();
            string ext      = "";
            string filename = "";

            // Add all files selected into the the db. If multiple files added, project destination is the same.
            foreach (String file in dlg.FileNames)
            {
                // Get the selected file name and display in a TextBox
                if (result.HasValue == true && result.Value == true)
                {
                    rawData = File.ReadAllBytes(file);
                    dataList.Add(Tuple.Create(file, rawData));
                    ext      = Path.GetExtension(file);
                    filename = file;
                }
            }

            AnalysisMsgPrompt a = new AnalysisMsgPrompt(new DataGridLoader(), null);



            if (a.ShowDialog() == true)
            {
                dgl.loadSpeakers(a.PID);
                rowS = dgl.getCollection("S");
                foreach (var elem in rowS.ToList())
                {
                    ((dynamic)rowS).Add((Speaker)elem);
                }


                foreach (var dataItem in dataList)
                {
                    var comm = new MySqlCommand();
                    filename = Path.GetFileName(dataItem.Item1);

                    using (DBConnection db = new DBConnection())
                    {
                        comm.CommandText = "INSERT INTO Analysis (AID, Description, FileData, FileType) VALUES(@AID, @Desc, @FileAsBlob, @FileType)";
                        comm.Parameters.AddWithValue("@AID", filename);
                        if (a.Desc.Equals(""))
                        {
                            comm.Parameters.AddWithValue("@Desc", "No description");
                        }
                        else
                        {
                            //Add to analysis table
                            comm.CommandText = "create table if not exists analysis (AID varchar(150) primary key, File mediumblob, Description varchar(500))";
                            comm.ExecuteNonQuery();

                            comm.CommandText = "INSERT INTO analysis (AID, File, Description) VALUES(@AID, @FileAsBlob, @Desc)";
                            comm.Parameters.AddWithValue("@AID", dataItem.Item1);
                            comm.Parameters.AddWithValue("@FileAsBlob", dataItem.Item2);
                            if (a.Desc.Equals(""))
                            {
                                comm.Parameters.AddWithValue("@Desc", "No description");
                            }
                            else
                            {
                                comm.Parameters.AddWithValue("@Desc", a.Desc);
                            }
                            comm.ExecuteNonQuery();

                            //Add to the mapping table(to link with speaker)
                            List <Row> startsWithAge = rowS.Where(s => ((Speaker)s).SpeakerName.StartsWith(a.Age)).ToList();

                            MessageBox.Show(a.Age);
                            foreach (var row in rowS)
                            {
                                //comm.CommandText = "create table if not exists files2analysis (AID varchar(150) primary key, ID varchar(150) primary key)";
                                //comm.ExecuteNonQuery();
                                if (((Speaker)row).SpeakerName.StartsWith(a.Age))
                                {
                                    db.insertIntoDB(comm);
                                }


                                comm.CommandText = "INSERT IGNORE INTO files2analysis (ID, AID) VALUES (@ID2, @AID2)";
                                comm.Parameters.Clear();
                                comm.Parameters.AddWithValue("@ID2", ((Speaker)row).ID);
                                comm.Parameters.AddWithValue("@AID2", dataItem.Item1);
                                comm.ExecuteNonQuery();
                            }


                            HashSet <Tuple <String, String> > uniqueAnalysis = new HashSet <Tuple <String, String> >();
                            HashSet <Tuple <String, String> > uniqueRowName  = new HashSet <Tuple <String, String> >();
                            string previous = "";
                            foreach (var row in rowS)
                            {
                                if (!((Speaker)row).Name.Equals(previous))
                                {
                                    previous = ((Speaker)row).Name;
                                    uniqueAnalysis.Add(Tuple.Create(((Speaker)row).Name, ((Speaker)row).ID));
                                }
                            }
                            foreach (var uRow in uniqueAnalysis)
                            {
                                if ((uRow.Item1.StartsWith(a.Age)))
                                {
                                    comm.CommandText = "INSERT IGNORE INTO File2Analysis (File_FID, Analysis_AID) VALUES (@FileID, @AID)";
                                    comm.Parameters.Clear();
                                    comm.Parameters.AddWithValue("@FileID", uRow.Item2);
                                    comm.Parameters.AddWithValue("@AID", filename);
                                    db.insertIntoDB(comm);
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            // Open file system to select file(s)
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.Multiselect = true;

            Nullable<bool> result = dlg.ShowDialog();  // Display OpenFileDialog by calling ShowDialog method
            byte[] rawData;
            List<Tuple<string, byte[]>> dataList = new List<Tuple<string, byte[]>>();
            string ext = "";
            string filename = "";

            // Add all files selected into the the db. If multiple files added, project destination is the same.
            foreach (String file in dlg.FileNames)
            {
                // Get the selected file name and display in a TextBox
                if (result.HasValue == true && result.Value == true)
                {
                    rawData = File.ReadAllBytes(file);
                    dataList.Add(Tuple.Create(file, rawData));
                    ext = Path.GetExtension(file);
                    filename = file;
                }
            }

            AnalysisMsgPrompt a = new AnalysisMsgPrompt(new DataGridLoader(), null);

            if (a.ShowDialog() == true)
            {
                dgl.loadSpeakers(a.PID);
                rowS = dgl.getCollection("S");
                foreach (var elem in rowS.ToList())
                {

                    ((dynamic)rowS).Add((Speaker)elem);
                }

                foreach (var dataItem in dataList)
                {
                    var comm = new MySqlCommand();
                    filename = Path.GetFileName(dataItem.Item1);

                    using (DBConnection db = new DBConnection())
                    {

                        comm.CommandText = "INSERT INTO Analysis (AID, Description, FileData, FileType) VALUES(@AID, @Desc, @FileAsBlob, @FileType)";
                        comm.Parameters.AddWithValue("@AID", filename);
                        if (a.Desc.Equals(""))
                        {
                            comm.Parameters.AddWithValue("@Desc", "No description");
                        }
                        else
                        {

                            //Add to analysis table
                            comm.CommandText = "create table if not exists analysis (AID varchar(150) primary key, File mediumblob, Description varchar(500))";
                            comm.ExecuteNonQuery();

                            comm.CommandText = "INSERT INTO analysis (AID, File, Description) VALUES(@AID, @FileAsBlob, @Desc)";
                            comm.Parameters.AddWithValue("@AID", dataItem.Item1);
                            comm.Parameters.AddWithValue("@FileAsBlob", dataItem.Item2);
                            if (a.Desc.Equals(""))
                            {
                                comm.Parameters.AddWithValue("@Desc", "No description");
                            }
                            else
                            {

                                comm.Parameters.AddWithValue("@Desc", a.Desc);
                            }
                            comm.ExecuteNonQuery();

                            //Add to the mapping table(to link with speaker)
                            List<Row> startsWithAge = rowS.Where(s => ((Speaker)s).SpeakerName.StartsWith(a.Age)).ToList();

                            MessageBox.Show(a.Age);
                            foreach (var row in rowS)
                            {

                                //comm.CommandText = "create table if not exists files2analysis (AID varchar(150) primary key, ID varchar(150) primary key)";
                                //comm.ExecuteNonQuery();
                                if (((Speaker)row).SpeakerName.StartsWith(a.Age))
                                {

                                    db.insertIntoDB(comm);
                                }

                                comm.CommandText = "INSERT IGNORE INTO files2analysis (ID, AID) VALUES (@ID2, @AID2)";
                                comm.Parameters.Clear();
                                comm.Parameters.AddWithValue("@ID2", ((Speaker)row).ID);
                                comm.Parameters.AddWithValue("@AID2", dataItem.Item1);
                                comm.ExecuteNonQuery();
                            }

                            HashSet<Tuple<String, String>> uniqueAnalysis = new HashSet<Tuple<String, String>>();
                            HashSet<Tuple<String, String>> uniqueRowName = new HashSet<Tuple<String, String>>();
                            string previous = "";
                            foreach (var row in rowS)
                            {
                                if (!((Speaker)row).Name.Equals(previous))
                                {
                                    previous = ((Speaker)row).Name;
                                    uniqueAnalysis.Add(Tuple.Create(((Speaker)row).Name, ((Speaker)row).ID));
                                }
                            }
                            foreach (var uRow in uniqueAnalysis)
                            {
                                if ((uRow.Item1.StartsWith(a.Age)))
                                {
                                    comm.CommandText = "INSERT IGNORE INTO File2Analysis (File_FID, Analysis_AID) VALUES (@FileID, @AID)";
                                    comm.Parameters.Clear();
                                    comm.Parameters.AddWithValue("@FileID", uRow.Item2);
                                    comm.Parameters.AddWithValue("@AID", filename);
                                    db.insertIntoDB(comm);
                                }
                            }
                        }
                    }
                }
            }
        }