📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Data.SqlClient;
namespace WindowsApplication1
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// folderBrowserDialog1
//
this.folderBrowserDialog1.HelpRequest += new System.EventHandler(this.folderBrowserDialog1_HelpRequest);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem5,
this.menuItem9});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "文件";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "新建";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "打开";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "";
//
// menuItem5
//
this.menuItem5.Index = 1;
this.menuItem5.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem6,
this.menuItem7,
this.menuItem8});
this.menuItem5.Text = "编辑";
//
// menuItem6
//
this.menuItem6.Index = 0;
this.menuItem6.Text = "复制";
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.Text = "剪切";
//
// menuItem8
//
this.menuItem8.Index = 2;
this.menuItem8.Text = "粘贴";
//
// menuItem9
//
this.menuItem9.Index = 2;
this.menuItem9.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem10});
this.menuItem9.Text = "链接";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem10
//
this.menuItem10.Index = 0;
this.menuItem10.Text = "求入度";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// timer1
//
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.Location = new System.Drawing.Point(104, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(48, 16);
this.label1.TabIndex = 0;
this.label1.Text = "计时";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(152, 24);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(64, 21);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "hubness";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void folderBrowserDialog1_HelpRequest(object sender, System.EventArgs e)
{
}
private void button1_Click(object sender, System.EventArgs e)
{
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
}
private void menuItem10_Click(object sender, System.EventArgs e)
{
///
SqlConnection sqlConnection1 = new SqlConnection("Initial Catalog=Northwind;" + "Data Source=localhost;" + "Integrated Security=SSPI");
sqlConnection1.Open();
SqlCommand myCommand = new SqlCommand();
myCommand.Connection=sqlConnection1;
string myInsertQuery ="delete from linkinfo";//to linkinfo(fileid,linkIn,linkOut) Values('" + filename + "'," + linkin.ToString() +"," + linkout.ToString() +")";
myCommand.CommandText=myInsertQuery;
myCommand.ExecuteNonQuery();
///
DateTime oldDate=DateTime.Now;//得到当前时间
if(folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
int i,j,k,m;
int linkout,len,linkin;
string str,temp;
string filename,filename1;
string folder=folderBrowserDialog1.SelectedPath;
string[] file=null;
file=Directory.GetFiles(folder);//GetFileSystemEntries();
//获得文件名
for(i=0;i<file.Length;i++)
{
linkout=0;linkin=0;
filename1=null;filename=null;
k=0;
while(k<file[i].Length)
{
if(file[i].Substring(k,1)!="\\")
{
filename1=filename1+file[i].Substring(k,1);
k++;
}
else
{
filename1=null;
k++;
}
}
m=0;
while(m<filename1.Length)
{
if(filename1.Substring(m,1)!=".")
{
filename=filename+filename1.Substring(m,1);
m++;
}
else
break;
}
//得到文件的名字
//求出度,让出度表示为入度,如果入度大于50,取值50
StreamReader sReader=null;
sReader=new StreamReader(file[i],System.Text.Encoding.Default);
while((str=sReader.ReadLine())!=null)
{
len=str.Length;
for(j=0;j<len-4;j++)
{
temp=str.Substring(j,4);
if(temp=="href")
linkout=linkout+1;
}//for
}//while
if(linkout>80)
{
linkin=80;
linkout=0;
}
else
{
linkin=linkout;
linkout=0;
}
sReader.Close();
myInsertQuery ="INSERT INTO linkInfo (fileid,linkIn,linkOut) Values('" + filename + "'," + linkin.ToString() +"," + linkout.ToString() +")";
//SqlCommand myCommand = new SqlCommand(myInsertQuery,sqlConnection1);
myCommand.CommandText=myInsertQuery;
myCommand.ExecuteNonQuery();
//myCommand.ExecuteNonQuery();
}//for
}//if
DateTime newDate = DateTime.Now;//得到运行后的时间
TimeSpan ts = newDate - oldDate;//得到程序运行的时间
textBox1.Text=ts.ToString();
sqlConnection1.Close();
MessageBox.Show("success");
}
private void timer1_Tick(object sender, System.EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -