private void button2_Click(object sender, EventArgs s)
        {
            MessageBoxButtons buttons = MessageBoxButtons.YesNo;
            DialogResult      result  = MessageBox.Show("Are you sure you want to delete this student?", "Confirm Delete", buttons);

            if (result == DialogResult.Yes)
            {
                try
                {
                    int delete   = listBox1.SelectedIndex;
                    var employee = stu[delete];
                    using (var db = new CodeFirstContext())
                    {
                        db.Students.Attach(employee);
                        db.Students.Remove(employee);
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Unable to Delete - Contact your administrator");
                }
            }
            listBox1.DataSource = Student.displayStudents();
        }
Exemple #2
0
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
     this.tabControl1 = new System.Windows.Forms.TabControl();
     this.tabPage2    = new System.Windows.Forms.TabPage();
     this.button1     = new System.Windows.Forms.Button();
     this.label6      = new System.Windows.Forms.Label();
     this.label1      = new System.Windows.Forms.Label();
     this.textBox4    = new System.Windows.Forms.TextBox();
     this.textBox3    = new System.Windows.Forms.TextBox();
     this.textBox2    = new System.Windows.Forms.TextBox();
     this.label4      = new System.Windows.Forms.Label();
     this.label3      = new System.Windows.Forms.Label();
     this.label2      = new System.Windows.Forms.Label();
     this.tabPage4    = new System.Windows.Forms.TabPage();
     this.button3     = new System.Windows.Forms.Button();
     this.button2     = new System.Windows.Forms.Button();
     this.listBox1    = new System.Windows.Forms.ListBox();
     this.tabPage1    = new System.Windows.Forms.TabPage();
     this.label12     = new System.Windows.Forms.Label();
     this.button4     = new System.Windows.Forms.Button();
     this.textBox1    = new System.Windows.Forms.TextBox();
     this.label11     = new System.Windows.Forms.Label();
     this.label10     = new System.Windows.Forms.Label();
     this.label9      = new System.Windows.Forms.Label();
     this.label8      = new System.Windows.Forms.Label();
     this.label7      = new System.Windows.Forms.Label();
     this.label5      = new System.Windows.Forms.Label();
     this.label13     = new System.Windows.Forms.Label();
     this.label14     = new System.Windows.Forms.Label();
     this.tabControl1.SuspendLayout();
     this.tabPage2.SuspendLayout();
     this.tabPage4.SuspendLayout();
     this.tabPage1.SuspendLayout();
     this.SuspendLayout();
     //
     // tabControl1
     //
     this.tabControl1.Controls.Add(this.tabPage2);
     this.tabControl1.Controls.Add(this.tabPage4);
     this.tabControl1.Controls.Add(this.tabPage1);
     this.tabControl1.Location      = new System.Drawing.Point(60, 12);
     this.tabControl1.Name          = "tabControl1";
     this.tabControl1.SelectedIndex = 0;
     this.tabControl1.Size          = new System.Drawing.Size(694, 336);
     this.tabControl1.TabIndex      = 2;
     //
     // tabPage2
     //
     this.tabPage2.Controls.Add(this.button1);
     this.tabPage2.Controls.Add(this.label6);
     this.tabPage2.Controls.Add(this.label1);
     this.tabPage2.Controls.Add(this.textBox4);
     this.tabPage2.Controls.Add(this.textBox3);
     this.tabPage2.Controls.Add(this.textBox2);
     this.tabPage2.Controls.Add(this.label4);
     this.tabPage2.Controls.Add(this.label3);
     this.tabPage2.Controls.Add(this.label2);
     this.tabPage2.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.tabPage2.Location = new System.Drawing.Point(4, 22);
     this.tabPage2.Name     = "tabPage2";
     this.tabPage2.Padding  = new System.Windows.Forms.Padding(3);
     this.tabPage2.Size     = new System.Drawing.Size(686, 310);
     this.tabPage2.TabIndex = 1;
     this.tabPage2.Text     = "Add";
     this.tabPage2.UseVisualStyleBackColor = true;
     this.tabPage2.Click += new System.EventHandler(this.tabPage2_Click);
     //
     // button1
     //
     this.button1.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.button1.Location = new System.Drawing.Point(457, 234);
     this.button1.Name     = "button1";
     this.button1.Size     = new System.Drawing.Size(103, 45);
     this.button1.TabIndex = 10;
     this.button1.Text     = "Add";
     this.button1.UseVisualStyleBackColor = true;
     this.button1.Click += new System.EventHandler(this.button1_Click_1);
     //
     // label6
     //
     this.label6.AutoSize = true;
     this.label6.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.label6.Location = new System.Drawing.Point(97, 121);
     this.label6.Name     = "label6";
     this.label6.Size     = new System.Drawing.Size(68, 25);
     this.label6.TabIndex = 9;
     this.label6.Text     = "Tuition";
     //
     // label1
     //
     this.label1.AutoSize = true;
     this.label1.Location = new System.Drawing.Point(81, 89);
     this.label1.Name     = "label1";
     this.label1.Size     = new System.Drawing.Size(0, 25);
     this.label1.TabIndex = 8;
     //
     // textBox4
     //
     this.textBox4.Font         = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.textBox4.Location     = new System.Drawing.Point(195, 157);
     this.textBox4.Name         = "textBox4";
     this.textBox4.Size         = new System.Drawing.Size(386, 30);
     this.textBox4.TabIndex     = 6;
     this.textBox4.TextChanged += new System.EventHandler(this.textBox4_TextChanged);
     //
     // textBox3
     //
     this.textBox3.Font         = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.textBox3.Location     = new System.Drawing.Point(195, 121);
     this.textBox3.Name         = "textBox3";
     this.textBox3.Size         = new System.Drawing.Size(386, 30);
     this.textBox3.TabIndex     = 5;
     this.textBox3.TextChanged += new System.EventHandler(this.textBox3_TextChanged);
     //
     // textBox2
     //
     this.textBox2.Font         = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.textBox2.Location     = new System.Drawing.Point(195, 85);
     this.textBox2.Name         = "textBox2";
     this.textBox2.Size         = new System.Drawing.Size(386, 30);
     this.textBox2.TabIndex     = 4;
     this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
     //
     // label4
     //
     this.label4.AutoSize = true;
     this.label4.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.label4.Location = new System.Drawing.Point(78, 157);
     this.label4.Name     = "label4";
     this.label4.Size     = new System.Drawing.Size(87, 25);
     this.label4.TabIndex = 2;
     this.label4.Text     = "Major";
     //
     // label3
     //
     this.label3.AutoSize = true;
     this.label3.Location = new System.Drawing.Point(78, 91);
     this.label3.Name     = "label3";
     this.label3.Size     = new System.Drawing.Size(0, 25);
     this.label3.TabIndex = 1;
     //
     // label2
     //
     this.label2.AutoSize = true;
     this.label2.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.label2.Location = new System.Drawing.Point(101, 85);
     this.label2.Name     = "label2";
     this.label2.Size     = new System.Drawing.Size(64, 25);
     this.label2.TabIndex = 0;
     this.label2.Text     = "Name";
     //
     // tabPage4
     //
     this.tabPage4.Controls.Add(this.button3);
     this.tabPage4.Controls.Add(this.button2);
     this.tabPage4.Controls.Add(this.listBox1);
     this.tabPage4.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.tabPage4.Location = new System.Drawing.Point(4, 22);
     this.tabPage4.Name     = "tabPage4";
     this.tabPage4.Size     = new System.Drawing.Size(686, 310);
     this.tabPage4.TabIndex = 3;
     this.tabPage4.Text     = "View / Delete";
     this.tabPage4.UseVisualStyleBackColor = true;
     //
     // button3
     //
     this.button3.Location = new System.Drawing.Point(319, 237);
     this.button3.Name     = "button3";
     this.button3.Size     = new System.Drawing.Size(101, 40);
     this.button3.TabIndex = 2;
     this.button3.Text     = "Refresh";
     this.button3.UseVisualStyleBackColor = true;
     this.button3.Click += new System.EventHandler(this.button3_Click);
     //
     // button2
     //
     this.button2.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.button2.Location = new System.Drawing.Point(466, 237);
     this.button2.Name     = "button2";
     this.button2.Size     = new System.Drawing.Size(105, 40);
     this.button2.TabIndex = 1;
     this.button2.Text     = "Delete";
     this.button2.UseVisualStyleBackColor = true;
     this.button2.Click += new System.EventHandler(this.button2_Click);
     //
     // listBox1
     //
     this.listBox1.DataSource            = Student.displayStudents();
     this.listBox1.Font                  = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.listBox1.FormattingEnabled     = true;
     this.listBox1.ItemHeight            = 25;
     this.listBox1.Location              = new System.Drawing.Point(60, 48);
     this.listBox1.Name                  = "listBox1";
     this.listBox1.Size                  = new System.Drawing.Size(564, 154);
     this.listBox1.TabIndex              = 0;
     this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
     //
     // tabPage1
     //
     this.tabPage1.Controls.Add(this.label14);
     this.tabPage1.Controls.Add(this.label13);
     this.tabPage1.Controls.Add(this.label12);
     this.tabPage1.Controls.Add(this.button4);
     this.tabPage1.Controls.Add(this.textBox1);
     this.tabPage1.Controls.Add(this.label11);
     this.tabPage1.Controls.Add(this.label10);
     this.tabPage1.Controls.Add(this.label9);
     this.tabPage1.Controls.Add(this.label8);
     this.tabPage1.Controls.Add(this.label7);
     this.tabPage1.Controls.Add(this.label5);
     this.tabPage1.Font     = new System.Drawing.Font("Microsoft Sans Serif", 15F);
     this.tabPage1.Location = new System.Drawing.Point(4, 22);
     this.tabPage1.Name     = "tabPage1";
     this.tabPage1.Size     = new System.Drawing.Size(686, 310);
     this.tabPage1.TabIndex = 4;
     this.tabPage1.Text     = "College";
     this.tabPage1.UseVisualStyleBackColor = true;
     //
     // label12
     //
     this.label12.AutoSize = true;
     this.label12.Location = new System.Drawing.Point(133, 212);
     this.label12.Name     = "label12";
     this.label12.Size     = new System.Drawing.Size(50, 25);
     this.label12.TabIndex = 8;
     this.label12.Text     = "$.00";
     this.label12.Click   += new System.EventHandler(this.label12_Click);
     //
     // button4
     //
     this.button4.Location = new System.Drawing.Point(398, 224);
     this.button4.Name     = "button4";
     this.button4.Size     = new System.Drawing.Size(154, 42);
     this.button4.TabIndex = 7;
     this.button4.Text     = "Calculate";
     this.button4.UseVisualStyleBackColor = true;
     this.button4.Click += new System.EventHandler(this.button4_Click);
     //
     // textBox1
     //
     this.textBox1.Location     = new System.Drawing.Point(178, 157);
     this.textBox1.Name         = "textBox1";
     this.textBox1.Size         = new System.Drawing.Size(209, 30);
     this.textBox1.TabIndex     = 6;
     this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
     //
     // label11
     //
     this.label11.AutoSize = true;
     this.label11.Location = new System.Drawing.Point(51, 162);
     this.label11.Name     = "label11";
     this.label11.Size     = new System.Drawing.Size(98, 25);
     this.label11.TabIndex = 5;
     this.label11.Text     = "Expenses: $";
     //
     // label10
     //
     this.label10.AutoSize = true;
     this.label10.Location = new System.Drawing.Point(51, 212);
     this.label10.Name     = "label10";
     this.label10.Size     = new System.Drawing.Size(62, 25);
     this.label10.TabIndex = 4;
     this.label10.Text     = "Total:";
     //
     // label9
     //
     this.label9.Location = new System.Drawing.Point(0, 0);
     this.label9.Name     = "label9";
     this.label9.Size     = new System.Drawing.Size(100, 23);
     this.label9.TabIndex = 9;
     //
     // label8
     //
     this.label8.Location = new System.Drawing.Point(0, 0);
     this.label8.Name     = "label8";
     this.label8.Size     = new System.Drawing.Size(100, 23);
     this.label8.TabIndex = 10;
     //
     // label7
     //
     this.label7.AutoSize = true;
     this.label7.Location = new System.Drawing.Point(51, 108);
     this.label7.Name     = "label7";
     this.label7.Size     = new System.Drawing.Size(138, 25);
     this.label7.TabIndex = 1;
     this.label7.Text     = "Total Tuition: $";
     //
     // label5
     //
     this.label5.AutoSize = true;
     this.label5.Location = new System.Drawing.Point(51, 53);
     this.label5.Name     = "label5";
     this.label5.Size     = new System.Drawing.Size(164, 25);
     this.label5.TabIndex = 0;
     this.label5.Text     = "Total Students:";
     //
     // label13
     //
     this.label13.AutoSize = true;
     this.label13.Location = new System.Drawing.Point(195, 108);
     this.label13.Name     = "label13";
     this.label13.Size     = new System.Drawing.Size(50, 25);
     this.label13.TabIndex = 11;
     this.label13.Text     = Student.totalTuition();
     //
     // label14
     //
     this.label14.AutoSize = true;
     this.label14.Location = new System.Drawing.Point(221, 53);
     this.label14.Name     = "label14";
     this.label14.Size     = new System.Drawing.Size(23, 25);
     this.label14.TabIndex = 12;
     this.label14.Text     = Student.total() + " ";
     //
     // Form1
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     this.ClientSize          = new System.Drawing.Size(800, 450);
     this.Controls.Add(this.tabControl1);
     this.Name  = "Form1";
     this.Text  = "Form1";
     this.Load += new System.EventHandler(this.Form1_Load);
     this.tabControl1.ResumeLayout(false);
     this.tabPage2.ResumeLayout(false);
     this.tabPage2.PerformLayout();
     this.tabPage4.ResumeLayout(false);
     this.tabPage1.ResumeLayout(false);
     this.tabPage1.PerformLayout();
     this.ResumeLayout(false);
 }
Exemple #3
0
 public static string total()
 {
     return(Student.displayStudents().Count.ToString());
 }
 private void button3_Click(object sender, EventArgs e)
 {
     listBox1.DataSource = Student.displayStudents();
     label13.Text        = "$" + Student.totalTuition() + ".00";
     label14.Text        = Student.total();
 }