/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
/ÖÐÎÄ/
ѧ·Ö¼ÆËãÆ÷ÊÇÒ»¿î¿ÉÒÔ°ïÖúÔÚУ´óѧÉú¼ÆËãѧ·ÖÓ뼨µãµÄ¼ÆË㹤¾ß£¬ËüÊÇÓÉÎá°®ÆƽâÂÛ̳ÍøÒ³·ÖÏíÌṩµÄ£¬Ñ§·Ö¼¨µãÊÇÒÔѧ·ÖÓ뼨µã×÷ΪºâÁ¿Ñ§ÉúѧϰµÄÁ¿ÓëÖʵļÆË㵥λ£¬Ê¹Óñ¾Èí¼þ¾ÍÄܹ»¸ù¾ÝÄãµÄ¿Î³Ìѧ·ÖºÍ³É¼¨¼ÆËã³öÄãµÄѧ·Ö¼¨µã¡£»¶ÓÏÂÔØʹÓá£
¹úÄڴ󲿷ָßУͨÓõļÆËã·½·¨ÊÇ£º¼¨µã=·ÖÊý/10-5£¬Ñ§·Ö¼¨µã=ѧ·Ö¡Á¼¨µã=ѧ·Ö¡Á(·ÖÊý/10-5)
ÿ¿ÆµÄ¿Î³Ìѧ·Ö¼¨µã=¿Î³Ìѧ·Ö¡Á¿Î³ÌȨÖØϵÊý¡Á¿Î³Ì¼¨µã
±ê×¼¼ÆËã·½·¨Êǽ«´óѧ³É¼¨µÄ¼ÓȨƽ¾ùÊý³ËÒÔ4£¬ÔÙ³ýÒÔ100¡£±È½Ï³£¼ûµÄ·½·¨»¹ÓаѸ÷¿Æ³É¼¨°´µÈ¼¶³ËÒÔѧ·ÖÇóºÍÔÙÒÔ×Üѧ·Ö³ýÖ®¡£
±¾³ÌÐò»ùÓÚ.NET 4.0ÖÆ×÷£¬¿ÉÒÔ¼ÆËã¿Î³Ìѧ·ÖÒÔ¼°´ï±êËùÐèѧ·Ö
¿Î³ÌÊý¾Ý´æÓÚtxtÎļþ
types.txtÓÃÓÚ´æ·Å¿Î³ÌÀà±ð£¬¿Î³ÌÀà±ð.txtÓÃÓÚ´æ·Å¸÷Àà±ðµÄ¿Î³ÌÊý¾Ý£¬¸ñʽ£º¿Î³ÌÃû£«¿Õ¸ñ+ѧ·Ö(ʵÑéѧ·Ö) tips£ºÊµÑéѧ·Ö¿É¿Õ
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace PointCalc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public struct Course
{
public string name;
public double point;
public double? point2;
public override string ToString()
{
return point2 == null ? name + " " + point : name + " " + point + "(" + point2 + ")";
}
}
double allPoint = 0;
double allPoint2 = 0;
List<Course> courses = new List<Course>();
FileStream fs;
StreamReader sr;
string content;
private void Form1_Load(object sender, EventArgs e)
{
fs = new FileStream("types.txt", FileMode.OpenOrCreate, FileAccess.Read);
sr = new StreamReader(fs, Encoding.Default);
content = sr.ReadLine();
while (content != null)
{
comboBox1.Items.Add(content);
content = sr.ReadLine();
}
sr.Close();
fs.Close();
if (comboBox1.Items.Count != 0)
comboBox1.SelectedIndex = 0;
toolStripStatusLabel1.Text = "";
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
content = (sender as CheckBox).Text;
int index = int.Parse(content.Substring(0, content.IndexOf('.'))) - 1;
if ((sender as CheckBox).Checked)
{
allPoint += courses[index].point;
if (courses[index].point2 != null)
allPoint2 += (double)courses[index].point2;
}
else
{
allPoint -= courses[index].point;
if (courses[index].point2 != null)
allPoint2 -= (double)courses[index].point2;
}
Updata();
}
private void Updata()
{
label1.Text = "µ±Ç°Ñ§·Ö£º" + allPoint.ToString("f1");
label2.Text = "µ±Ç°À¨ºÅѧ·Ö£º" + allPoint2.ToString("f1");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
label1.Text = "µ±Ç°Ñ§·Ö£º0";
label2.Text = "µ±Ç°À¨ºÅѧ·Ö£º0";
courses.Clear();
fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Open, FileAccess.Read);
sr = new StreamReader(fs, Encoding.Default);
content = sr.ReadLine();
while (content != null)
{
string[] infos = content.Split(' ');
Course course = new Course();
course.name = infos[0];
if (infos[1].Contains('('))
{
course.point = double.Parse(infos[1].Substring(0, infos[1].IndexOf('(')));
var temp = infos[1].Substring(infos[1].IndexOf('('));
course.point2 = double.Parse(temp.Substring(1, temp.Length - 2));
}
else
{
course.point = int.Parse(infos[1]);
}
courses.Add(course);
content = sr.ReadLine();
}
sr.Close();
fs.Close();
RefreshPanel();
toolStripStatusLabel1.Text = "";
}
private void RefreshPanel()
{
flowLayoutPanel1.Controls.Clear();
for (int i = 0; i < courses.Count; ++i)
{
AddCheckBox(courses[i], i);
}
}
private void AddCheckBox(Course course, int i)
{
CheckBox checkbox = new CheckBox();
checkbox.Text = i + 1 + "." + course.ToString();
checkbox.Size = new Size(210, 16);
checkbox.CheckedChanged += checkBox_CheckedChanged;
checkbox.CheckedChanged += Calc;
checkbox.ContextMenuStrip = contextMenuStrip1;
this.flowLayoutPanel1.Controls.Add(checkbox);
}
private void button1_Click(object sender, EventArgs e)
{
string newType;
Form2 form2 = new Form2();
if (form2.ShowDialog() != DialogResult.OK)
{
return;
}
newType = form2.result;
fs = new FileStream("types.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine(newType);
comboBox1.Items.Add(newType);
sw.Close();
fs.Close();
fs = new FileStream(newType + ".txt", FileMode.Create, FileAccess.Write);
fs.Close();
comboBox1.SelectedIndex = comboBox1.Items.Count - 1;
}
private void button3_Click(object sender, EventArgs e)
{
Course newCourse;
Form3 form3 = new Form3();
if (form3.ShowDialog() != DialogResult.OK)
{
return;
}
newCourse = form3.course;
fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
sw.WriteLine(newCourse.ToString());
sw.Close();
fs.Close();
AddCheckBox(newCourse, courses.Count);
courses.Add(newCourse);
}
private void button2_Click(object sender, EventArgs e)
{
DialogResult dialogResult = MessageBox.Show("È·¶¨É¾³ý£¿", "ɾ³ý", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
if (dialogResult != DialogResult.OK)
return;
File.Delete(comboBox1.SelectedItem.ToString() + ".txt");
int oldIndex = comboBox1.SelectedIndex;
comboBox1.Items.RemoveAt(comboBox1.SelectedIndex);
fs = new FileStream("types.txt", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
foreach (var item in comboBox1.Items)
{
sw.WriteLine(item.ToString());
}
sw.Close();
fs.Close();
comboBox1.SelectedIndex = oldIndex - 1;
}
private void ɾ³ýToolStripMenuItem_Click(object sender, EventArgs e)
{
content = (((sender as ToolStripMenuItem).GetCurrentParent() as ContextMenuStrip).SourceControl as CheckBox).Text;
courses.RemoveAt(int.Parse(content.Substring(0, content.IndexOf('.'))) - 1);
fs = new FileStream(comboBox1.SelectedItem.ToString() + ".txt", FileMode.Create, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs, Encoding.Default);
foreach (var item in courses)
{
sw.WriteLine(item.ToString());
}
sw.Close();
fs.Close();
RefreshPanel();
}
private void Calc(object sender, EventArgs e)
{
double needPoint = 0;
double needPoint2 = 0;
if (!string.IsNullOrEmpty(textBox1.Text))
{
double goalPoint = double.Parse(textBox1.Text);
if (goalPoint > allPoint)
needPoint = goalPoint - allPoint;
}
else
return;
if (!string.IsNullOrEmpty(textBox1.Text))
{
double goalPoint2 = double.Parse(textBox2.Text);
if (goalPoint2 > allPoint2)
needPoint2 = goalPoint2 - allPoint2;
}
if (needPoint == 0 && needPoint2 == 0)
{
toolStripStatusLabel1.Text = string.Format("ѧ·ÖÒÑ×ã¹»£¡");
toolStripStatusLabel1.ForeColor = Color.Green;
}
else
{
toolStripStatusLabel1.Text = string.Format("¾àÀëÄ¿±êѧ·Ö»¹²î£º{0:N1}({1:N1})", needPoint, needPoint2);
toolStripStatusLabel1.ForeColor = Color.Red;
}
}
}
}
¹ØÓÚÌÚÅ£ | ÁªÏµ·½Ê½ | ·¢Õ¹Àú³Ì | °æȨÉùÃ÷ | ÏÂÔØ°ïÖú(£¿) | ¹ã¸æÁªÏµ | ÍøÕ¾µØͼ | ÓÑÇéÁ´½Ó
Copyright 2005-2022 QQTN.com ¡¾ÌÚÅ£Íø¡¿ °æȨËùÓÐ ¶õICP±¸2022005668ºÅ-1 | ¶õ¹«Íø°²±¸ 42011102000260ºÅ
ÉùÃ÷£º±¾Õ¾·ÇÌÚѶQQ¹Ù·½ÍøÕ¾ ËùÓÐÈí¼þºÍÎÄÕÂÀ´×Ô»¥ÁªÍø ÈçÓÐÒìÒé ÇëÓë±¾Õ¾ÁªÏµ ±¾Õ¾Îª·ÇÓ®ÀûÐÔÍøÕ¾ ²»½ÓÊÜÈκÎÔÞÖúºÍ¹ã¸æ