public partial class Form1 : Form
{
struct Job
{
public int Id { get; set; } // شماره
public int ExecutionTime { get; set; } // زمان اجرا
public int Gain { get; set; } // سود
public override string ToString()
{
return string.Format("JobId : {0} \t ExecutionTime : {1} \t Gain : {2}", this.Id, this.ExecutionTime, this.Gain);
}
}
List<Job> jobs;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
jobs = new List<Job>();
if (textBox1.Text != "")
{
AddJob(1, textBox1.Text, textBox11.Text);
}
if (textBox2.Text != "")
{
AddJob(2, textBox2.Text, textBox12.Text);
}
if (textBox1.Text != "")
{
AddJob(3, textBox3.Text, textBox13.Text);
}
if (textBox4.Text != "")
{
AddJob(4, textBox4.Text, textBox14.Text);
}
if (textBox5.Text != "")
{
AddJob(5, textBox5.Text, textBox15.Text);
}
if (textBox1.Text != "")
{
AddJob(6, textBox6.Text, textBox16.Text);
}
if (textBox7.Text != "")
{
AddJob(7, textBox7.Text, textBox17.Text);
}
if (textBox8.Text != "")
{
AddJob(8, textBox8.Text, textBox18.Text);
}
if (textBox9.Text != "")
{
AddJob(9, textBox9.Text, textBox19.Text);
}
if (textBox10.Text != "")
{
AddJob(10, textBox10.Text, textBox20.Text);
}
Job temp1;
for (int i = jobs.Count - 1; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (jobs[j].Gain < jobs[j + 1].Gain)
{
temp1 = jobs[j];
jobs[j] = jobs[j + 1];
jobs[j + 1] = temp1;
}
}
}
/*
//moratab sazi job
Job temp2;
for (int i = 8; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
if (jobs[j].ExecutionTime > jobs[j + 1].ExecutionTime)
{
temp2 = jobs[j];
jobs[j] = jobs[j + 1];
jobs[j + 1] = temp2;
}
}
}
*/
for (int i = 0; i < 9; i++)
{
if (jobs[i].ExecutionTime != 0 && jobs[i].Gain != 0)
{
listBox1.Items.Add(jobs[i].ToString());
}
}
}
private void AddJob(int _id, string _execTime, string _gain)
{
Job j = new Job()
{
Id = _id,
ExecutionTime = Convert.ToInt32(_execTime),
Gain = Convert.ToInt32(_gain)
};
jobs.Add(j);
}
}