private void button1_Click_1(object sender, EventArgs e) { //分析文件 DataGridViewCheckBoxCell check = new DataGridViewCheckBoxCell(); List <string> pathlist = new List <string>(); foreach (DataGridViewRow row in GridViewFileShow.Rows) { check = (DataGridViewCheckBoxCell)row.Cells[0]; if ((bool)check.EditedFormattedValue || (bool)check.FormattedValue) { pathlist.Add(row.Cells[1].Value.ToString()); } } progressBar1.Maximum = pathlist.Count; progressBar1.Step = 1; System.Configuration.AppSettingsReader AppSettings = new System.Configuration.AppSettingsReader(); string sqlconn = string.Empty; try { sqlconn = AppSettings.GetValue("SQLiteConnection", typeof(String)).ToString(); } catch (InvalidOperationException ex) { //配置文件不正确 } string sqlstr = @"create table if not exists filepath( id integer primary key autoincrement, path text, grouplabel text );"; SQLiteCommand SQLiteCmd = new SQLiteCommand(); SQLiteCmd.CommandText = sqlstr; SQLiteCmd.CommandType = CommandType.Text; if (SQLiteCommand.Execute(sqlstr, SQLiteExecuteType.Default, sqlconn) != null) { sqlstr = ""; List <string> linkes = new List <string>(); string lable = hidgroup.Text = DateTime.Now.ToString("yyyyMMddhhmmss"); foreach (string path in pathlist) { sqlstr += "insert into filepath(path,grouplabel) values('" + path + "','" + lable + "');"; linkes.AddRange(GetFileCssJSLink(path, "")); progressBar1.PerformStep(); } int count = (int)SQLiteCommand.Execute(sqlstr, SQLiteExecuteType.NonQuery, sqlconn); List <filemodel> myfile = new List <filemodel>(); filemodel myfilemodel = new filemodel(); linkes = linkes.Distinct().ToList(); foreach (string model in linkes) { myfilemodel = new filemodel(); myfilemodel.path = model; myfile.Add(myfilemodel); } GridViewFileShow.DataSource = myfile; } }
private void BindData(string searchtype) { if (!string.IsNullOrEmpty(textBox1.Text.Trim())) { IEnumerable <string> files = Directory.EnumerateFiles(textBox1.Text, searchtype, SearchOption.TopDirectoryOnly); List <filemodel> myfile = new List <filemodel>(); filemodel myfilemodel = new filemodel(); foreach (string model in files) { myfilemodel = new filemodel(); myfilemodel.path = model; myfile.Add(myfilemodel); } GridViewFileShow.DataSource = myfile; } }