calpuff-server-GeoFile.cs
来源:互联网 发布:mac分区失败 发生错误 编辑:程序博客网 时间:2024/05/22 21:37
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace ServerV1._1{ public partial class GeoFile : Form { public static string terrelFileDir = @"C:\calpuff\terrel_file"; public static string ctgprocFileDir = @"C:\calpuff\ctgproc_file"; public static string[] ctgprocFiles; public static string[] terrelFiles; public GeoFile() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); folderBrowser.ShowDialog(); if (folderBrowser.SelectedPath != "") { terrelFileDir = folderBrowser.SelectedPath; label5.Text = terrelFileDir; } } private void button4_Click(object sender, EventArgs e) { FolderBrowserDialog folderBrowser = new FolderBrowserDialog(); folderBrowser.ShowDialog(); if (folderBrowser.SelectedPath != "") { ctgprocFileDir = folderBrowser.SelectedPath; label6.Text = ctgprocFileDir; } } //Refresh 刷新文件夹下所有的 并且存入数据库 private void button1_Click(object sender, EventArgs e) { //OpenFileDialog dialog = new OpenFileDialog(); //if(dialog.ShowDialog()==DialogResult.OK) //{ // terrel_file = dialog.FileName; //} textBox1.Text = ""; terrelFiles = Directory.GetFiles(terrelFileDir); for(int i=0;i<terrelFiles.Length;i++) { textBox1.AppendText(terrelFiles[i] + "\r\n"); } } // 第二个刷新操作 private void button3_Click(object sender, EventArgs e) { textBox2.Text = ""; ctgprocFiles = Directory.GetFiles(ctgprocFileDir); for (int i = 0; i < ctgprocFiles.Length; i++) { textBox2.AppendText(ctgprocFiles[i] + "\r\n"); } } // 更新数据库 private void button5_Click(object sender, EventArgs e) { //1 数据库连接 //细节 两个目录不能相同 if(terrelFileDir==ctgprocFileDir) { MessageBox.Show("The Two Directories Should Be Different"); return; } MySql.Data.MySqlClient.MySqlConnection conn = new MySql.Data.MySqlClient.MySqlConnection(); string connStr = "server=" + Form1.dbIp + ";user id=" + Form1.dbUser + ";password=" + Form1.dbPasswd + ";database=" + Form1.dbName + ";pooling=false;charset=utf8"; conn.ConnectionString = connStr; try { conn.Open(); } catch { MessageBox.Show("Database Connection Error"); return; } if(terrelFiles==null) { MessageBox.Show("Please Refresh Terrel Files First"); return; } if(ctgprocFiles==null) { MessageBox.Show("Please Refresh Ctgproc Files First"); return; } // 开始更新--推到重来 原来的数据要清除 MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "truncate t_geo_file"; cmd.ExecuteNonQuery(); cmd.Dispose();//此处可以不用调用, conn.Close();// 离开 using 块, connection 会自行关闭 // 更新terrel_file 的db for (int i = 0; i < terrelFiles.Length; i++) { // 关联新的cmd conn需要重启 conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = connStr; conn.Open(); cmd = new MySql.Data.MySqlClient.MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "insert into t_geo_file(path,type) values(@0,@1)"; cmd.Parameters.Add("@0", MySql.Data.MySqlClient.MySqlDbType.VarChar); cmd.Parameters.Add("@1", MySql.Data.MySqlClient.MySqlDbType.VarChar); cmd.Parameters[0].Value = terrelFiles[i]; cmd.Parameters[1].Value = "terrel"; cmd.ExecuteNonQuery(); cmd.Dispose();//此处可以不用调用, conn.Close();// 离开 using 块, connection 会自行关闭 } // 更新ctgproc 的DB for (int i = 0; i < ctgprocFiles.Length; i++) { conn = new MySql.Data.MySqlClient.MySqlConnection(); conn.ConnectionString = connStr; conn.Open(); cmd = new MySql.Data.MySqlClient.MySqlCommand(); cmd.Connection = conn; cmd.CommandText = "insert into t_geo_file(path,type) values(@0,@1)"; cmd.Parameters.Add("@0", MySql.Data.MySqlClient.MySqlDbType.VarChar); cmd.Parameters.Add("@1", MySql.Data.MySqlClient.MySqlDbType.VarChar); cmd.Parameters[0].Value = ctgprocFiles[i]; cmd.Parameters[1].Value = "ctgproc"; // 已经确认过可以连接了 cmd.ExecuteNonQuery(); cmd.Dispose();//此处可以不用调用, conn.Close();// 离开 using 块, connection 会自行关闭 } MessageBox.Show("Database Updated Successfully"); } }}
0 0
- Calpuff-Server-GeoFile.cs
- calpuff-server-GeoFile.cs
- calpuff-server-ServerConf.cs
- calpuff-server-Form1.cs
- calpuff-client-ServerConf.cs
- calpuff-client-Form1.cs
- cs 1.6 server
- Calpuff-Webclient-index.php
- Calpuff-WebClient-webclient.php
- 实体类cs中调用server.MapPath()
- CS..........................
- cs
- cs
- cs
- Cs
- cs
- cs
- cs
- Decode Ways
- 如何解析SDP中包含的H.264的SPS和PPS串
- css滑动门技术
- hadoop 不使用hostname,使用ip遇到的问题(Datanode denied communication with namenode because hostname cann)及解决方案
- Calpuff-Server-GeoFile.cs
- calpuff-server-GeoFile.cs
- calpuff-server-ServerConf.cs
- calpuff-server-Form1.cs
- 如何将jar包加入到Maven本地仓库
- jetty 内存溢出
- calpuff-client-ServerConf.cs
- calpuff-client-Form1.cs
- 真实的美国,是的
- 博登湖空难的令人痛心的管理者责任