程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 學校的英語作業實在不想寫啊,於是。。。,英語作業

學校的英語作業實在不想寫啊,於是。。。,英語作業

編輯:C#入門知識

學校的英語作業實在不想寫啊,於是。。。,英語作業


寫了個自動刷題的軟件按一下就完成一項,一學期省了我好幾天的時間,做到了1.2版本了,自認為代碼比1.0漂亮的多得多得多了,求各路大神指點啊

 

後端代碼:

  1 class BottomProcess
  2     {
  3         public bool Confirm { private set; get; }
  4         public void ConfirmIt()
  5         {
  6             Confirm = false;
  7             string[] name=new string[]{"寢室人的名字,才不讓人亂用吶~~~"};
  8             foreach (string item in name)
  9             {
 10                 Regex tempregex = new Regex(item);
 11                 Match tempmatch = tempregex.Match(WebSource);
 12                 if (tempmatch.Success)
 13                 {
 14                     Confirm = true;
 15                 }
 16             }
 17         }
 18         //level, unit, lessonnumber, lessonname, extranumber, unitID, lessonID
 19         private static string[] Attributes = { "Level0", "UNIT", "class=c jQuery", "None", "None", "unitID=", "sectionID=" };
 20         private static string[] AllLessonName = { "Warm Up", "Listening Task", "Real World Listening", "Reading Task", "RWV Listening Task", "RWV Speaking Task", "RWV Role Play" };
 21         public BottomProcess(string webSource)
 22         {
 23             WebSource = webSource;
 24             ConfirmIt();
 25             Informations = new string[7];
 26             ExtractToInformation();
 27             FinishAddressBuild();
 28         }
 29         private Regex regex { get; set; }
 30         private Match match { get; set; }
 31         private string WebSource { get; set; }
 32         public string FinishAddress { get; private set; }
 33         private delegate string Extractions();
 34         public string[] Informations { get; set; }
 35         //level, unit, lessonnumber, lessonname, extranumber, unitID, lessonID
 36         private void ExtractToInformation()
 37         {
 38             Extractions[] extractions =
 39             {
 40                 GetLevel,
 41                 GetUnit,
 42                 GetLessonNumber,
 43                 GetLessonName,
 44                 GetExtraNumber,
 45                 GetUnitID,
 46                 GetLessonID
 47             };
 48             for (int index = 0; index < 7; index++)
 49             {
 50                 Informations[index] = ExtractFromWebSource(index, extractions[index]);
 51             }
 52         }
 53         private string ExtractFromWebSource(int index, Extractions extract)
 54         {
 55             if (Attributes[index] != "None")
 56             {
 57                 regex = new Regex(Attributes[index]);
 58                 match = regex.Match(WebSource);
 59             }
 60             return extract();
 61         }
 62         private string GetLevel()//0
 63         {
 64             return WebSource.Substring(match.Index + Attributes[0].Length, 1);
 65         }
 66         private string GetUnit()//1
 67         {
 68             return GetOnlyNumber(WebSource.Substring(match.Index + Attributes[1].Length, 2));
 69         }
 70         private string GetLessonNumber()//2
 71         {
 72             return GetOnlyNumber(WebSource.Substring(match.Index - 4, 7));
 73         }
 74         private string GetLessonName()//3
 75         {
 76             foreach (string lessonName in AllLessonName)
 77             {
 78                 regex = new Regex(lessonName);
 79                 match = regex.Match(WebSource);
 80                 if (match.Success)
 81                 {
 82                     return lessonName;
 83                 }
 84             }
 85             return "NoUseReturn";
 86         }
 87         private string GetExtraNumber()//4
 88         {
 89             return GetOnlyNumber(WebSource.Substring(match.Index + Informations[3].Length, 2));
 90         }
 91         private string GetUnitID()//5
 92         {
 93             return GetOnlyNumber(WebSource.Substring(match.Index + Attributes[5].Length, 5));
 94         }
 95         private string GetLessonID()//6
 96         {
 97             return GetOnlyNumber(WebSource.Substring(match.Index + Attributes[6].Length, 5));
 98         }
 99         private string GetOnlyNumber(string unprocessed)
100         {
101             string result = "";
102             foreach (char item in unprocessed)
103             {
104                 if (Char.IsNumber(item))
105                 {
106                     result += item;
107                 }
108             }
109             return result;
110         }
111         private void FinishAddressBuild()
112         {
113             string[] Address = new string[16];
114             Address[0] = "http://222.28.61.102/HepStudent/Ajax/ScoreAjax.ashx?Math=0.8867987910421455&levelSequence=";
115             Address[1] = Convert.ToString(Convert.ToDouble(Informations[0]) + 1);
116             Address[2] = "&unitSequence=";
117             Address[3] = Convert.ToString(Convert.ToDouble(Informations[1]) - 1);
118             Address[4] = "&sectionSequence=";
119             Address[5] = Informations[2];
120             Address[6] = "&sectionName=";
121             Address[7] = Informations[3];
122             if (Informations[4] == "")
123             {
124                 Address[8] = "";
125             }
126             else
127             {
128                 Address[8] = "+" + Informations[4];
129             }
130             Address[9] = "&topictype=6&score=80&rolea=0&roleb=0&sectionID=";
131             Address[10] = Informations[6];
132             Address[11] = "&unitid=";
133             Address[12] = Informations[5];
134             Address[13] = "&passScore=20&timeLimited=00%3A10%3A00&levelID=";
135             Address[14] = Convert.ToString(Convert.ToDouble(Informations[0]) + 1);
136             Address[15] = "&duration=00%3A00%3A05&highWords=&lowWords=&pScore=%E8%89%AF&rScore=%E5%B7%AE&fScore=%E8%89%AF&sScore=%E5%B7%AE&tScore=%E8%89%AF";
137             StringBuilder WebAddress = new StringBuilder();
138             foreach (var item in Address)
139             {
140                 WebAddress.Append(item);
141             }
142             FinishAddress = WebAddress.ToString();
143         }
144     }

 

前端代碼:

 1 <Window x:Class="Redemption.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         Title="救贖---------By AuroraDysis" Height="500" Width="800" Background="LightBlue">
 5     <Grid>
 6         <Grid.RowDefinitions>
 7             <RowDefinition Height="Auto"></RowDefinition>
 8             <RowDefinition Height="Auto"></RowDefinition>
 9             <RowDefinition></RowDefinition>
10         </Grid.RowDefinitions>
11         <Grid Grid.Row="0">
12             <Grid.ColumnDefinitions>
13                 <ColumnDefinition Width="*"></ColumnDefinition>
14                 <ColumnDefinition Width="Auto"></ColumnDefinition>
15                 <ColumnDefinition Width="Auto"></ColumnDefinition>
16                 <ColumnDefinition Width="Auto"></ColumnDefinition>
17             </Grid.ColumnDefinitions>
18             <TextBox x:Name="url_text" Grid.Row="0" Grid.Column="0" Background="LightGray" Margin="3" FontSize="24"></TextBox>
19             <Button Grid.Column="1" Margin="3">Close</Button>
20             <Button Grid.Column="2" Margin="3" Click="Button_Click">Home</Button>
21             <Button Background="Firebrick" Grid.Column="3" Margin="3" FontSize="22" Click="Button_Click_1">Finish</Button>
22         </Grid>
23         <Grid Grid.Row="1">
24             <Grid.ColumnDefinitions>
25                 <ColumnDefinition></ColumnDefinition>
26                 <ColumnDefinition></ColumnDefinition>
27                 <ColumnDefinition></ColumnDefinition>
28                 <ColumnDefinition></ColumnDefinition>
29                 <ColumnDefinition></ColumnDefinition>
30                 <ColumnDefinition></ColumnDefinition>
31                 <ColumnDefinition></ColumnDefinition>
32                 <ColumnDefinition Width="2*"></ColumnDefinition>
33                 <ColumnDefinition></ColumnDefinition>
34                 <ColumnDefinition></ColumnDefinition>
35                 <ColumnDefinition></ColumnDefinition>
36                 <ColumnDefinition></ColumnDefinition>
37                 <ColumnDefinition></ColumnDefinition>
38                 <ColumnDefinition></ColumnDefinition>
39             </Grid.ColumnDefinitions>
40             <TextBlock Grid.Column="0" Width="Auto">Level:</TextBlock>
41             <TextBlock x:Name="tb_Level" Grid.Column="1"></TextBlock>
42             <TextBlock Grid.Column="2" Width="Auto">Unit:</TextBlock>
43             <TextBlock x:Name="tb_Unit" Grid.Column="3"></TextBlock>
44             <TextBlock Grid.Column="4" Width="Auto">LessonNumber:</TextBlock>
45             <TextBlock x:Name="tb_LessonNumber" Grid.Column="5"></TextBlock>
46             <TextBlock Grid.Column="6" Width="Auto">LessonName:</TextBlock>
47             <TextBlock x:Name="tb_LessonName" Grid.Column="7"></TextBlock>
48             <TextBlock Grid.Column="8" Width="Auto">ExtraName</TextBlock>
49             <TextBlock x:Name="tb_ExtraName" Grid.Column="9"></TextBlock>
50             <TextBlock Grid.Column="10" Width="Auto">UnitID</TextBlock>
51             <TextBlock x:Name="tb_UnitID" Grid.Column="11"></TextBlock>
52             <TextBlock Grid.Column="12" Width="Auto">SectionID</TextBlock>
53             <TextBlock x:Name="tb_SectionID" Grid.Column="13"></TextBlock>
54         </Grid>
55         <WebBrowser x:Name="webbrowser" Grid.Row="2" LoadCompleted="webbrowser_LoadCompleted"></WebBrowser>
56     </Grid>
57 </Window>
 1     public partial class MainWindow : Window
 2     {
 3         bool flag = false;
 4         public MainWindow()
 5         {
 6             InitializeComponent();
 7             Home();
 8         }
 9         private void Home()
10         {
11             Uri homeUri = new Uri("http://222.28.61.102/HepStudent/Login.aspx");
12             webbrowser.Navigate(homeUri);
13             url_text.Text = "http://222.28.61.102/HepStudent/Login.aspx";
14         }
15 
16         private void Button_Click(object sender, RoutedEventArgs e)
17         {
18             Home();
19         }
20         private string GetWebSource()
21         {
22             mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)webbrowser.Document;
23             return doc.body.innerHTML;
24         }
25         //level, unit, lessonnumber, lessonname, extranumber, unitID, SectionID
26 
27         private void InToOut(string[] informations)
28         {
29             List<TextBlock> Show = new List<TextBlock>() { tb_Level, tb_Unit, tb_LessonNumber, tb_LessonName, tb_ExtraName, tb_UnitID, tb_SectionID };
30             for (int index = 0; index < informations.Length; index++)
31             {
32                 Show[index].Text = informations[index];
33             }
34         }
35         private void Button_Click_1(object sender, RoutedEventArgs e)
36         {
37             BottomProcess inbox = new BottomProcess(GetWebSource());
38             if (!inbox.Confirm)
39             {
40                 this.Close();
41             }
42             InToOut(inbox.Informations);
43             webbrowser.Navigate(inbox.FinishAddress);
44             flag = true;
45         }
46         private void webbrowser_LoadCompleted(object sender, NavigationEventArgs e)
47         {
48             url_text.Text = webbrowser.Source.ToString();
49             if (flag)
50             {
51                 webbrowser.GoBack();
52                 flag = false;
53             }
54         }
55     }

界面

 1 <Window x:Class="Redemption.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         Title="救贖---------By AuroraDysis" Height="500" Width="800" Background="LightBlue">
 5     <Grid>
 6         <Grid.RowDefinitions>
 7             <RowDefinition Height="Auto"></RowDefinition>
 8             <RowDefinition Height="Auto"></RowDefinition>
 9             <RowDefinition></RowDefinition>
10         </Grid.RowDefinitions>
11         <Grid Grid.Row="0">
12             <Grid.ColumnDefinitions>
13                 <ColumnDefinition Width="*"></ColumnDefinition>
14                 <ColumnDefinition Width="Auto"></ColumnDefinition>
15                 <ColumnDefinition Width="Auto"></ColumnDefinition>
16                 <ColumnDefinition Width="Auto"></ColumnDefinition>
17             </Grid.ColumnDefinitions>
18             <TextBox x:Name="url_text" Grid.Row="0" Grid.Column="0" Background="LightGray" Margin="3" FontSize="24"></TextBox>
19             <Button Grid.Column="1" Margin="3">Close</Button>
20             <Button Grid.Column="2" Margin="3" Click="Button_Click">Home</Button>
21             <Button Background="Firebrick" Grid.Column="3" Margin="3" FontSize="22" Click="Button_Click_1">Finish</Button>
22         </Grid>
23         <Grid Grid.Row="1">
24             <Grid.ColumnDefinitions>
25                 <ColumnDefinition></ColumnDefinition>
26                 <ColumnDefinition></ColumnDefinition>
27                 <ColumnDefinition></ColumnDefinition>
28                 <ColumnDefinition></ColumnDefinition>
29                 <ColumnDefinition></ColumnDefinition>
30                 <ColumnDefinition></ColumnDefinition>
31                 <ColumnDefinition></ColumnDefinition>
32                 <ColumnDefinition Width="2*"></ColumnDefinition>
33                 <ColumnDefinition></ColumnDefinition>
34                 <ColumnDefinition></ColumnDefinition>
35                 <ColumnDefinition></ColumnDefinition>
36                 <ColumnDefinition></ColumnDefinition>
37                 <ColumnDefinition></ColumnDefinition>
38                 <ColumnDefinition></ColumnDefinition>
39             </Grid.ColumnDefinitions>
40             <TextBlock Grid.Column="0" Width="Auto">Level:</TextBlock>
41             <TextBlock x:Name="tb_Level" Grid.Column="1"></TextBlock>
42             <TextBlock Grid.Column="2" Width="Auto">Unit:</TextBlock>
43             <TextBlock x:Name="tb_Unit" Grid.Column="3"></TextBlock>
44             <TextBlock Grid.Column="4" Width="Auto">LessonNumber:</TextBlock>
45             <TextBlock x:Name="tb_LessonNumber" Grid.Column="5"></TextBlock>
46             <TextBlock Grid.Column="6" Width="Auto">LessonName:</TextBlock>
47             <TextBlock x:Name="tb_LessonName" Grid.Column="7"></TextBlock>
48             <TextBlock Grid.Column="8" Width="Auto">ExtraName</TextBlock>
49             <TextBlock x:Name="tb_ExtraName" Grid.Column="9"></TextBlock>
50             <TextBlock Grid.Column="10" Width="Auto">UnitID</TextBlock>
51             <TextBlock x:Name="tb_UnitID" Grid.Column="11"></TextBlock>
52             <TextBlock Grid.Column="12" Width="Auto">SectionID</TextBlock>
53             <TextBlock x:Name="tb_SectionID" Grid.Column="13"></TextBlock>
54         </Grid>
55         <WebBrowser x:Name="webbrowser" Grid.Row="2" LoadCompleted="webbrowser_LoadCompleted"></WebBrowser>
56     </Grid>
57 </Window>

 

求各路大神指點

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved