Classes for Echo

Simple Caculator

using System;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Convert;

namespace SolutionsByProgrammingTask
{
    internal static class Program
    {
        private static string Oper2(string input, char key, Func<decimal, decimal, decimal> f)
        {
            if (input[0] == '-')
            {
                input = '0' + input;
            }

            decimal a = 0;
            decimal b = 0;
            for (var i = 0; i < input.Length; i++)
            {
                if (input[i] != key) continue;
                int j = i - 1, ai = -1, bi = -1;
                for (; j >= 0; j--)
                {
                    if (!Regex.IsMatch(input[j].ToString(), @"[+\-*\/]")) continue;
                    ai = j + 1;
                    a = ToDecimal(input.Substring(ai, i - ai));
                    break;
                }

                if (ai == -1)
                {
                    ai = 0;
                    a = ToDecimal(input.Substring(ai, i));
                }

                for (j = i + 1; j < input.Length; j++)
                {
                    if (!Regex.IsMatch(input[j].ToString(), @"[+\-*\/]")) continue;
                    bi = j - 1;
                    b = ToDecimal(input.Substring(i + 1, bi - i));
                    break;
                }

                if (bi == -1)
                {
                    bi = input.Length - 1;
                    b = ToDecimal(input.Substring(i + 1, bi - i));
                }

                input = input.Replace(input.Substring(ai, bi - ai + 1), f(a, b).ToString());
                i = 0;
            }

            return input;
        }

        private static string Oper1(string input, string key, Func<decimal, decimal> f)
        {
            decimal a = 0;
            decimal b = 0;
            for (var i = 0; i < input.Length - (key.Length + 2); i++)
            {
                if (input.Substring(i, key.Length) != key) continue;
                int j = i - 1, bi = -1;

                int count = 0;
                for (j = i + key.Length + 1; j < input.Length; j++)
                {
                    if (input[j] == '(')
                        ++count;
                    else if (input[j] == ')' && count == 0)
                    {
                        bi = j;
                        break;
                    }
                    else if (input[j] == ')') --count;
                }

                input = input.Replace(input.Substring(i, bi - i + 1),
                    f(ToDecimal(FA(input.Substring(i + key.Length + 1, bi - (i + key.Length + 1))))).ToString());
                i = 0;
            }

            return input;
        }

        public static string FF(string input) =>
            Oper1(
                Oper1(Oper1(input, "tan", x => (decimal) System.Math.Tan(ToDouble(x))), "cos",
                    x => (decimal) System.Math.Cos(ToDouble(x))), "sin", x => (decimal) System.Math.Sin(ToDouble(x)));

        public static string F4(string input) =>
            Oper2(Oper2(Oper2(Oper2(input, '*', (a, b) => a * b), '/', (a, b) => a / b), '+', (a, b) => a + b), '-',
                (a, b) => a - b);

        public static string FA(string input) => F4(FF(input));

        public static void Main(string[] args)
        {
            var input = ReadLine();
            WriteLine(FA(input));
            ReadLine();
        }
    }
}

Tic Tac Toe

MainWindow.xaml

<Window x:Class="WpfApp1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        Title="Tic Tac Toe" Height="280" Width="280" ResizeMode="NoResize">
    <Grid>
        <ItemsControl>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate >
                    <UniformGrid Rows="3" Columns="3"/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <Button x:Name="Button11" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button11_Click"/>
            <Button x:Name="Button21" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button21_Click"/>
            <Button x:Name="Button31" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button31_Click"/>
            <Button x:Name="Button12" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button12_Click"/>
            <Button x:Name="Button22" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button22_Click"/>
            <Button x:Name="Button32" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button32_Click"/>
            <Button x:Name="Button13" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button13_Click"/>
            <Button x:Name="Button23" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button23_Click"/>
            <Button x:Name="Button33" Content="" HorizontalAlignment="Left" Height="83" VerticalAlignment="Top" Width="91" FontSize="72" FontFamily="FangSong" Click="Button33_Click"/>
        </ItemsControl>
    </Grid>
</Window>

MainWindow.xaml.cs

using System.Windows;

namespace WpfApp1
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        private int curPlayerCount;

        private string GetCurPlayer() => curPlayerCount++ % 2 == 0 ? "○" : "×";

        public MainWindow()
        {
            InitializeComponent();
            Reset();
        }

        private void Reset()
        {
            curPlayerCount = 1;
            Button11.Content = "";
            Button21.Content = "";
            Button31.Content = "";
            Button12.Content = "";
            Button22.Content = "";
            Button32.Content = "";
            Button13.Content = "";
            Button23.Content = "";
            Button33.Content = "";
        }

        private string SubJudge()
        {
            if ((string) Button11.Content != "" &&
                Button11.Content == Button21.Content &&
                Button21.Content == Button31.Content)
                return (string) Button11.Content;

            if ((string) Button12.Content != "" &&
                Button12.Content == Button22.Content &&
                Button22.Content == Button32.Content)
                return (string) Button12.Content;

            if ((string) Button13.Content != "" &&
                Button13.Content == Button23.Content &&
                Button23.Content == Button33.Content)
                return (string) Button13.Content;

            if ((string) Button11.Content != "" &&
                Button11.Content == Button12.Content &&
                Button12.Content == Button13.Content)
                return (string) Button11.Content;

            if ((string) Button21.Content != "" &&
                Button21.Content == Button22.Content &&
                Button22.Content == Button23.Content)
                return (string) Button21.Content;

            if ((string) Button31.Content != "" &&
                Button31.Content == Button32.Content &&
                Button32.Content == Button33.Content)
                return (string) Button31.Content;

            if ((string) Button11.Content != "" &&
                Button11.Content == Button22.Content &&
                Button22.Content == Button33.Content)
                return (string) Button11.Content;

            if ((string) Button13.Content != "" &&
                Button13.Content == Button22.Content &&
                Button22.Content == Button31.Content)
                return (string) Button13.Content;

            if ((string) Button11.Content != "" &&
                (string) Button21.Content != "" &&
                (string) Button31.Content != "" &&
                (string) Button12.Content != "" &&
                (string) Button22.Content != "" &&
                (string) Button32.Content != "" &&
                (string) Button13.Content != "" &&
                (string) Button23.Content != "" &&
                (string) Button33.Content != "")
                return "DogFall!";

            return "";
        }

        private void Judge()
        {
            var res = SubJudge();
            if (res == "") return;
            MessageBox.Show(res == "DogFall!" ? res : $"{res} Win!");
            if (MessageBox.Show("Reset?", "", MessageBoxButton.YesNo) == MessageBoxResult.No)
                Application.Current.Shutdown();
            Reset();
        }

        private void Button11_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button11.Content != "") return;
            Button11.Content = GetCurPlayer();
            Judge();
        }

        private void Button21_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button21.Content != "") return;
            Button21.Content = GetCurPlayer();
            Judge();
        }

        private void Button31_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button31.Content != "") return;
            Button31.Content = GetCurPlayer();
            Judge();
        }

        private void Button12_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button12.Content != "") return;
            Button12.Content = GetCurPlayer();
            Judge();
        }

        private void Button22_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button22.Content != "") return;
            Button22.Content = GetCurPlayer();
            Judge();
        }

        private void Button32_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button32.Content != "") return;
            Button32.Content = GetCurPlayer();
            Judge();
        }

        private void Button13_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button13.Content != "") return;
            Button13.Content = GetCurPlayer();
            Judge();
        }

        private void Button23_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button23.Content != "") return;
            Button23.Content = GetCurPlayer();
            Judge();
        }

        private void Button33_Click(object sender, RoutedEventArgs e)
        {
            if ((string) Button33.Content != "") return;
            Button33.Content = GetCurPlayer();
            Judge();
        }
    }
}

script0

using System.IO;
using System.Linq;

namespace MSV
{
    internal static class Program
    {
        private static void StuCopy(string s, string d, string kw)
        {
            var input = Directory.EnumerateFiles(s).Select(Path.GetFileName).First(x => x.StartsWith(kw));
            File.Copy(Path.Combine(s, input), Path.Combine(d, Path.GetFileName(s) + Path.GetExtension(input)));
        }

        private static void Main(string[] args)
        {
            const string passStr = "行程卡";
            const string hpStr = "健康码";
            var path = args[0];
            var all = Directory.GetDirectories(path);
            var pass = Directory.CreateDirectory(Path.Combine(path, passStr));
            var hp = Directory.CreateDirectory(Path.Combine(path, hpStr));
            foreach (var stu in all)
            {
                StuCopy(stu, pass.FullName, passStr);
                StuCopy(stu, hp.FullName, hpStr);
            }
        }
    }
}

WindowsFormsMySqlQuery

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 MySql.Data.MySqlClient;
using System.Threading;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        private static readonly object Lock = new object();

        public Form1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(InputBox.Text)) return;

            Button.Enabled = false;
            Button.Text = @"查询中";

            new Thread((() =>
            {
                lock (Lock)
                {
                    var conn = new MySqlConnection(
                        "data source=localhost;database=filemd5database;user id=root;password=toor;pooling=false;charset=utf8");
                    var cmd = new MySqlCommand("select * from fmd_200816 where path like @p limit 500", conn);
                    cmd.Parameters.Add(new MySqlParameter("@p", $"%{InputBox.Text}%"));

                    try
                    {
                        Output.Invoke(new Action((() => Output.Rows.Clear())));
                        conn.Open();
                        var reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            var dt = Enumerable.Range(0, 5).Select(x => reader.GetString(x)).ToArray();
                            Output.Invoke(new Action(() =>
                                Output.Rows.Add(dt[0], dt[1], dt[2], Convert.ToInt64(dt[3]), dt[4])));
                        }
                    }
                    catch (Exception exception)
                    {
                        MessageBox.Show(exception.Message, @"错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    finally
                    {
                        conn.Close();
                        Button.Invoke(new Action((() =>
                        {
                            Button.Enabled = true;
                            Button.Text = @"查询";
                        })));
                    }
                }
            })).Start();
        }
    }
}

 

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注