/// <summary> /// 根据员工编号导出身份证 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { if (richTextBox2.Lines.Length > 0) { richTextBox2.Text = ""; } wznr_Servise wznr = new wznr_Servise(); string line; //获取路径,循环每次都需要读取文本文件里设置的关键词 string path = Directory.GetCurrentDirectory(); string txtpath = path + @"\App_Data\yuangongNo.txt"; //读取文本内容逐行 StreamReader file = new StreamReader(txtpath); DataTable dt = wznr.GetDataTable("select CardNo,Dept_Id,Name,Phone,IdentityCard from HrManagementDB..UserInfo where Dept_Id in(select Id from HrManagementDB..DepartmentInfo where FAld='31DC10A8-B578-4AE0-B7F2-5FB2D4BBF083')"); int i = 0; while ((line = file.ReadLine()) != null) { DataRow[] rows = dt.Select("CardNo='" + line + "'"); if (rows.Count() > 0) { i++; richTextBox2.AppendText(string.Format("序号:{0},员工姓名:{1},员工编号:{2},对应身份证为:{3} \n", i, rows[0][2], rows[0][0], rows[0][4])); richTextBox2.ForeColor = Color.Green; richTextBox2.Focus(); } else { i++; richTextBox2.AppendText(string.Format("序号:{0},员工姓名:无,员工编号:{1}无此记录,对应身份证为:无 \n", i, line)); richTextBox2.ForeColor = Color.Red; richTextBox2.Focus(); } } }
//导出数据总数 public int GetTotalN(GetTotalNum gettotalnum) { int total = 0; wznr_Servise wznr = new wznr_Servise(); DataTable dt = wznr.GetDataTable("select * from test5Table"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { total++; gettotalnum(total); } } return(total); }
//创建索引 private void button3_Click(object sender, EventArgs e) { bool isPangu = true; wznr_Servise wznr = new wznr_Servise(); Analyzer analyzer = new PanGuAnalyzer();//盘古Analyzer DirectoryInfo dirInfo = Directory.CreateDirectory(Config.INDEX_STORE_PATH); LuceneIO.Directory directory = LuceneIO.FSDirectory.Open(dirInfo); IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED); DataTable dt = wznr.GetDataTable("SELECT Title, p FROM test4Table"); for (int i = 0; i < dt.Rows.Count; i++) { string title = Convert.ToString(dt.Rows[i][0]); string content = Convert.ToString(dt.Rows[i][1]); CreateIndex(writer, title, content); } writer.Optimize(); writer.Close(); this.richTextBox1.Text = string.Format("{0}索引创建成功", isPangu ? "盘古分词" : string.Empty); }
/// <summary> /// 创建数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btndatabase_Click(object sender, EventArgs e) { string path = Directory.GetCurrentDirectory() + @"\App.config"; if (!Directory.Exists(path)) { //MessageBox.Show("cunzai"); } else { CreateXml(comboBox1.Text.Trim(), textdatabase.Text.Trim()); } string sql = string.Format("select * from master.dbo.sysdatabases where name = '{0}'", textdatabase.Text.Trim()); wznr_Servise wznrservise = new wznr_Servise(); DataTable dt = wznrservise.GetDataTable(sql); if (dt.Rows.Count > 0) { MessageBox.Show("数据库已存在!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { try { string sql1 = " Create table test2Table( ID int IDENTITY PRIMARY KEY, Title varchar(255), Content ntext, keys varchar(255) )"; string sql2 = " CREATE TYPE test2Udt AS TABLE ( Title varchar(255), Content ntext, keys varchar(255) )"; wznrservise.ExecuteSql(sql1); wznrservise.ExecuteSql(sql2); } catch (SqlException ex) { MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } } //wznrservise.Exists(strsql.ToString()); //MessageBox.Show("创建成功!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); }
/// <summary> /// 根据合同编号导出身份证 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { if (richTextBox1.Lines.Length > 0) { richTextBox1.Text = ""; } wznr_Servise wznr = new wznr_Servise(); string line; //获取路径,循环每次都需要读取文本文件里设置的关键词 string path = Directory.GetCurrentDirectory(); string txtpath = path + @"\App_Data\hetongNo.txt"; //读取文本内容逐行 StreamReader file = new StreamReader(txtpath); DataTable dt = wznr.GetDataTable("select Name,IDNo,ContractCode from Financial f inner join InvestmentInfo i on f.FinancialId=i.FinancialId"); int i = 0; while ((line = file.ReadLine()) != null) { DataRow[] rows = dt.Select("ContractCode='" + line + "'"); if (rows.Count() > 0) { i++; richTextBox1.AppendText(string.Format("序号:{0},客户姓名:{3},该合同编号:{1},对应身份证为:{2} \n", i, line, rows[0][1], rows[0][0])); richTextBox1.ForeColor = Color.Green; richTextBox1.Focus(); } else { i++; richTextBox1.AppendText(string.Format("序号:{0},客户姓名:无,该合同编号:{1}无此记录,对应身份证为:无 \n", i, line)); richTextBox1.ForeColor = Color.Red; richTextBox1.Focus(); } } file.Close(); }
//导出数据db3 public void OutPut(GetTotalDelegateOutPut gettotaldelegateoutput, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { wznr_Servise wznr = new wznr_Servise(); int totalRecords = 0; string dbn = "SpiderResult.db3";//数据库文件名称 // 创建数据库文件 File.Delete(dbn); SQLiteConnection.CreateFile(dbn); DbProviderFactory factory = SQLiteFactory.Instance; using (DbConnection conn = factory.CreateConnection()) { // 连接数据库 conn.ConnectionString = "Data Source=" + dbn + ""; conn.Open(); // 创建数据表 string sql = "CREATE TABLE Content([ID] integer primary key autoincrement,[已采] tinyint(1) default 0,[已发] tinyint(1) default 0,[标题] Text,[内容] Text,[PageUrl] Text)"; DbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); sw.Start(); DbTransaction trans = conn.BeginTransaction(); // <------------------- try { // 查询出数据导出 通过数据库查询出 DataTable dt = wznr.GetDataTable("SELECT Title, p FROM test5Table"); for (int i = 0; i < dt.Rows.Count; i++) { totalRecords++; gettotaldelegateoutput(totalRecords); cmd.CommandText = "insert into [Content] ([已采],[已发],[标题],[内容],[PageUrl]) values (?,?,?,?,?)"; SQLiteParameter[] parameter = { new SQLiteParameter("@[已采]", DbType.Byte, 1), new SQLiteParameter("@[已发]", DbType.Byte, 1), new SQLiteParameter("@[标题]", DbType.Object), new SQLiteParameter("@[内容]", DbType.Object), new SQLiteParameter("@[PageUrl]", DbType.Object) }; //foreach (SQLiteParameter p in parameter) //{ // cmd.Parameters.Add(p); //} cmd.Parameters[0].Value = 1; cmd.Parameters[1].Value = 0; cmd.Parameters[2].Value = dt.Rows[i][0].ToString(); cmd.Parameters[3].Value = dt.Rows[i][1].ToString(); cmd.Parameters[4].Value = "http://www.9111766.com"; //rich.Text += cmd.Parameters[2].Value.ToString()+"-----导出成功\n"; //StreamWriter sr = File.CreateText(dt.Rows[i][0].ToString().Trim()+".txt"); //sr.WriteLine(dt.Rows[i][0].ToString()+"\n"+dt.Rows[i][1].ToString()); //sr.Close(); rich.AppendText(cmd.Parameters[2].Value.ToString() + "-----导出成功\n"); rich.ForeColor = System.Drawing.Color.Green;//ConsoleColor.Green; rich.Focus(); cmd.ExecuteNonQuery(); } trans.Commit(); // <------------------- } catch { trans.Rollback(); // <------------------- throw; // <------------------- } // 停止计时 sw.Stop(); } }
//导出access数据库 public void access_OutPut(GetTotalDelegateOutPut gettotaldelegateoutput, System.Diagnostics.Stopwatch sw, System.Windows.Forms.RichTextBox rich) { wznr_Servise wznr = new wznr_Servise(); int totalRecords = 0; string dbn = System.AppDomain.CurrentDomain.BaseDirectory + "Access_Data\\" + "SpiderResult.mdb";//数据库文件名称 // 创建数据库文件 File.Delete(dbn); ADOX.Catalog catalog = new Catalog(); catalog.Create("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbn + ";Jet OLEDB:Engine Type=5"); OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbn); conn.Open(); // 创建数据表 string sql = "CREATE TABLE Content([ID] Counter primary key,[已采] Bit,[已发] Bit,[标题] Memo,[内容] Memo,[PageUrl] Memo)"; OleDbCommand cmd = conn.CreateCommand(); cmd.Connection = conn; cmd.CommandText = sql; cmd.ExecuteNonQuery(); sw.Start(); //DbTransaction trans = conn.BeginTransaction(); // <------------------- try { // 查询出数据导出 通过数据库查询出 DataTable dt = wznr.GetDataTable("SELECT Title, p FROM test5Table order by NEWID()"); for (int i = 0; i < dt.Rows.Count; i++) { totalRecords++; gettotaldelegateoutput(totalRecords); //cmd.CommandText = "insert into [Content] ([已采],[已发],[标题],[内容],[PageUrl]) values (?,?,?,?,?)"; string strSql = "insert into [Content]([已采],[已发],[标题],[内容],[PageUrl]) values(?,?,?,?,?)"; OleDbParameter[] parameter = { new OleDbParameter("@[已采]", OleDbType.Boolean, 1), new OleDbParameter("@[已发]", OleDbType.Boolean, 1), new OleDbParameter("@[标题]", OleDbType.VarChar, 0), new OleDbParameter("@[内容]", OleDbType.VarChar, 0), new OleDbParameter("@[PageUrl]", OleDbType.VarChar, 0) }; parameter[0].Value = 1; parameter[1].Value = 0; parameter[2].Value = dt.Rows[i][0].ToString(); parameter[3].Value = dt.Rows[i][1].ToString(); parameter[4].Value = "http://www.xxx.com.cn"; rich.AppendText(parameter[2].Value.ToString() + "-----导出成功\n"); rich.ForeColor = System.Drawing.Color.Green;//ConsoleColor.Green; rich.Focus(); DbHelperOleDb.GetSingle(strSql.ToString(), parameter); //cmd.ExecuteNonQuery(); } //trans.Commit(); // <------------------- } catch { // trans.Rollback(); // <------------------- throw; // <------------------- // } // 停止计时 } sw.Stop(); }