Files
kami_itunes_june/AppleBatch_June/FindAppListOptions.cs
2024-07-22 00:43:14 +08:00

314 lines
11 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
namespace AppleBatch_June
{
public class FindAppListOptions : Form
{
private Dictionary<string, string> countriesList = new Dictionary<string, string>();
private IContainer components;
private Button button2;
private ListView listView1;
private ColumnHeader columnHeader1;
private ColumnHeader columnHeader3;
private LinkLabel linkLabel1;
private TextBox txtFilePach;
private Label label4;
private ColumnHeader columnHeader2;
private ColumnHeader columnHeader4;
private Label label1;
private ContextMenuStrip contextMenuStrip1;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem ToolStripMenuItem;
private ToolStripMenuItem ToolStripMenuItem;
public string filePatch { get; set; }
public FindAppListOptions()
{
InitializeComponent();
}
private void FindAppListOptions_Load(object sender, EventArgs e)
{
txtFilePach.Text = filePatch;
foreach (DataRow row in AppleUtlis.dataTable_0.Rows)
{
string text = row["area"].ToString();
string value = row["name"].ToString();
if (!countriesList.ContainsKey(text))
{
countriesList.Add(text.ToLower(), value);
}
}
LoadFile();
}
private void LoadFile()
{
List<string> list = AppleUtlis.restTxt(filePatch);
listView1.Items.Clear();
int num = 0;
Dictionary<string, int> dictionary = new Dictionary<string, int>();
foreach (string item in list)
{
if (!string.IsNullOrEmpty(item))
{
num++;
string[] array = item.Split('\t');
string input = array[0].Split(' ')[0];
string text = "";
if (array.Length > 1)
{
text = array[1];
}
if (array[0].Split(' ').Length > 1)
{
text = array[0].Split(' ')[1];
}
string key = new Regex("com/([\\s\\S]*?)/").Match(input).Groups[1].Value.ToLower();
ListViewItem listViewItem = new ListViewItem(num.ToString());
listViewItem.SubItems.Add(input);
if (countriesList.ContainsKey(key))
{
key = countriesList[key];
}
if (dictionary.ContainsKey(key))
{
dictionary[key]++;
}
else
{
dictionary.Add(key, 1);
}
listViewItem.SubItems.Add(key);
listViewItem.SubItems.Add(text);
listView1.Items.Add(listViewItem);
}
}
label1.Text = "当前应用文件共有应用 " + num + " 个";
if (num <= 0)
{
return;
}
label1.Text += ",其中 ";
foreach (KeyValuePair<string, int> item2 in dictionary)
{
label1.Text = label1.Text + item2.Key + "有 " + item2.Value + " 个,";
}
label1.Text = label1.Text.TrimEnd(',');
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "文本txt|*.txt";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
string text = (txtFilePach.Text = openFileDialog.FileName);
filePatch = text;
LoadFile();
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (ListViewItem selectedItem in listView1.SelectedItems)
{
Process.Start(selectedItem.SubItems[1].Text);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
string text = "";
foreach (ListViewItem selectedItem in listView1.SelectedItems)
{
string text2 = selectedItem.SubItems[1].Text;
text = text + text2 + "\n";
}
if (text.Length > 0)
{
Clipboard.SetText(text);
MessageBox.Show("复制成功");
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
deleOption();
}
private void deleOption()
{
string text = Tools.readFile(filePatch, Encoding.UTF8);
int count = listView1.SelectedItems.Count;
if (count <= 0 || MessageBox.Show("删除选中的" + count + "个应用地址", "提示", MessageBoxButtons.YesNo) != DialogResult.Yes)
{
return;
}
foreach (ListViewItem selectedItem in listView1.SelectedItems)
{
string value = selectedItem.SubItems[1].Text;
string[] array = text.Split('\n');
foreach (string text2 in array)
{
if (text2.StartsWith(value))
{
text = text.Replace(text2 + "\n", "");
text = text.Replace(text2, "");
}
}
}
File.WriteAllText(filePatch, text, Encoding.UTF8);
LoadFile();
}
private void button2_Click(object sender, EventArgs e)
{
deleOption();
}
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
components.Dispose();
}
base.Dispose(disposing);
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.button2 = new System.Windows.Forms.Button();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.txtFilePach = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.columnHeader4 = new System.Windows.Forms.ColumnHeader();
this.label1 = new System.Windows.Forms.Label();
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.contextMenuStrip1.SuspendLayout();
base.SuspendLayout();
this.button2.Font = new System.Drawing.Font("微软雅黑", 10.5f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
this.button2.ForeColor = System.Drawing.Color.Brown;
this.button2.Location = new System.Drawing.Point(567, 10);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(109, 34);
this.button2.TabIndex = 6;
this.button2.Text = "删除选中应用";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(button2_Click);
this.listView1.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right;
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[4] { this.columnHeader1, this.columnHeader3, this.columnHeader4, this.columnHeader2 });
this.listView1.ContextMenuStrip = this.contextMenuStrip1;
this.listView1.FullRowSelect = true;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(21, 73);
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(767, 365);
this.listView1.TabIndex = 7;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.columnHeader1.Text = "序号";
this.columnHeader1.Width = 40;
this.columnHeader3.Text = "URL地址";
this.columnHeader3.Width = 350;
this.columnHeader2.Text = "应用名称";
this.columnHeader2.Width = 250;
this.linkLabel1.AutoSize = true;
this.linkLabel1.Location = new System.Drawing.Point(491, 15);
this.linkLabel1.Name = "linkLabel1";
this.linkLabel1.Size = new System.Drawing.Size(53, 12);
this.linkLabel1.TabIndex = 13;
this.linkLabel1.TabStop = true;
this.linkLabel1.Text = "选择文件";
this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(linkLabel1_LinkClicked);
this.txtFilePach.Location = new System.Drawing.Point(102, 12);
this.txtFilePach.Name = "txtFilePach";
this.txtFilePach.ReadOnly = true;
this.txtFilePach.Size = new System.Drawing.Size(383, 21);
this.txtFilePach.TabIndex = 12;
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(37, 15);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(53, 12);
this.label4.TabIndex = 11;
this.label4.Text = "文本地址";
this.columnHeader4.Text = "应用国家";
this.columnHeader4.Width = 100;
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("微软雅黑", 9f, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, 134);
this.label1.ForeColor = System.Drawing.Color.Chocolate;
this.label1.Location = new System.Drawing.Point(36, 44);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(372, 17);
this.label1.TabIndex = 14;
this.label1.Text = "当前应用文件共有应用120个其中 中国大陆有100个美国有 20个";
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[3] { this.ToolStripMenuItem, this.ToolStripMenuItem, this.ToolStripMenuItem });
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(125, 70);
this.ToolStripMenuItem.Name = "打开链接ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(184, 22);
this.ToolStripMenuItem.Text = "打开链接";
this.ToolStripMenuItem.Click += new System.EventHandler(ToolStripMenuItem_Click);
this.ToolStripMenuItem.Name = "复制链接ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ToolStripMenuItem.Text = "复制链接";
this.ToolStripMenuItem.Click += new System.EventHandler(ToolStripMenuItem_Click);
this.ToolStripMenuItem.Name = "删除链接ToolStripMenuItem";
this.ToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.ToolStripMenuItem.Text = "删除链接";
this.ToolStripMenuItem.Click += new System.EventHandler(ToolStripMenuItem_Click);
base.AutoScaleDimensions = new System.Drawing.SizeF(6f, 12f);
base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
base.ClientSize = new System.Drawing.Size(800, 450);
base.Controls.Add(this.label1);
base.Controls.Add(this.linkLabel1);
base.Controls.Add(this.txtFilePach);
base.Controls.Add(this.label4);
base.Controls.Add(this.listView1);
base.Controls.Add(this.button2);
base.MaximizeBox = false;
base.Name = "FindAppListOptions";
base.ShowIcon = false;
base.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "编辑文件应用列表";
base.Load += new System.EventHandler(FindAppListOptions_Load);
this.contextMenuStrip1.ResumeLayout(false);
base.ResumeLayout(false);
base.PerformLayout();
}
}
}