Exemple #1
0
 private void BT_write_Click(object sender, EventArgs e)
 {
     try
     {
         //constraints according the student class structure
         if (TB_StudID.Text.ToString().Length > 4 || TB_StudID.Text.ToString().Length < 1)
         {
             throw new Exception("ID length must be  1-4 letters/digits");
         }
         if (TB_RegNR.Text.ToString().Length > 2 || TB_RegNR.Text.ToString().Length < 1)
         {
             throw new Exception("Registration Number length must be one or two letters/digits");
         }
         //chooses the right struct- int key or string key
         if (isint(TB_StudID.Text) == true)
         {
             StudCourseI SC = new StudCourseI();
             SC.StudID     = int.Parse(TB_StudID.Text);
             SC.RegNr      = int.Parse(TB_RegNR.Text);
             SC.Key        = SC.StudID * (int)(Math.Pow(10.0, SC.DigitCount(SC.RegNr))) + SC.RegNr;
             SC.FirstName  = TB_FN.Text;
             SC.FamilyName = TB_LN.Text;
             SC.CourseName = TB_C.Text;
             SC.Grade      = (TB_G.Text);
             HashFileStat.HFStatic.Write(SC.Key, SC);
             MessageBox.Show("Record was written succefully!", "Message");
             Close();
         }
         else
         {
             StudCourseC SC = new StudCourseC();
             SC.StudID     = int.Parse(TB_StudID.Text);
             SC.RegNr      = int.Parse(TB_RegNR.Text);
             SC.Key        = TB_StudID.Text + TB_RegNR.Text;
             SC.FirstName  = TB_FN.Text;
             SC.FamilyName = TB_LN.Text;
             SC.CourseName = TB_C.Text;
             SC.Grade      = (TB_G.Text);
             HashFileStat.HFStatic.Write(SC.Key, SC);
             MessageBox.Show("Record was written succefully!", "Message");
             Close();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #2
0
 private void BT_key_Click(object sender, EventArgs e)
 {
     if (ReedToUpdate.Checked == true)
     {
         if (did == false)
         {
             this.Height += 200;
             did          = true;
         }
         try
         {
             TB_c.Enabled   = false; TB_gr.Enabled = false; TB_rnr.Enabled = false;
             TB_sid.Enabled = false; TB_stun.Enabled = false;
             //chooses the right struct- int key or string key
             if (isint(TB_key.Text) == true)
             {
                 if (isint(TB_key.Text))
                 {
                     StudupdateI SC = new StudupdateI();
                     HashFileStat.HFStatic.Read(int.Parse(TB_key.Text), SC, 0);
                     SC.StudID     = int.Parse(TB_sid.Text);
                     SC.RegNr      = int.Parse(TB_rnr.Text);
                     SC.Key        = SC.StudID * (int)(Math.Pow(10.0, SC.DigitCount(SC.RegNr))) + SC.RegNr;
                     SC.Name       = TB_stun.Text;
                     SC.CourseName = TB_c.Text;
                     SC.Grade      = TB_gr.Text;
                     HashFileStat.HFStatic.Update(SC);
                     MessageBox.Show("The record updated successfully! ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Close();
                 }
                 else
                 {
                     StudupdateC SC = new StudupdateC();
                     HashFileStat.HFStatic.Read(int.Parse(TB_key.Text), SC, 0);
                     SC.StudID     = int.Parse(TB_sid.Text);
                     SC.RegNr      = int.Parse(TB_rnr.Text);
                     SC.Key        = TB_sid.Text + TB_rnr.Text;
                     SC.Name       = TB_stun.Text;
                     SC.CourseName = TB_c.Text;
                     SC.Grade      = TB_gr.Text;
                     HashFileStat.HFStatic.Update(SC);
                     MessageBox.Show("The record updated successfully! ", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     Close();
                 }
             }
         }
         catch (System.Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     else
     {
         if (did == false)
         {
             this.Height += 200;
             did          = true;
         }
         try
         {
             if (TB_key.Text == "")
             {
                 throw new Exception("הכנס מפתח!");
             }
             TB_c.Enabled   = false; TB_gr.Enabled = false; TB_rnr.Enabled = false;
             TB_sid.Enabled = false;  TB_stun.Enabled = false;
             //chooses the right struct- int key or string key
             if (isint(TB_key.Text))
             {
                 StudCourseI SC = new StudCourseI();
                 HashFileStat.HFStatic.Read(int.Parse(TB_key.Text), SC, 0);
                 TB_sid.Text  = SC.StudID.ToString();
                 TB_rnr.Text  = SC.RegNr.ToString();
                 TB_stun.Text = SC.FirstName + " " + SC.FamilyName;
                 TB_c.Text    = SC.CourseName;
                 TB_gr.Text   = SC.Grade.ToString();
             }
             else
             {
                 StudCourseC SC = new StudCourseC();
                 HashFileStat.HFStatic.Read(int.Parse(TB_key.Text), SC, 0);
                 TB_sid.Text  = SC.StudID.ToString();
                 TB_rnr.Text  = SC.RegNr.ToString();
                 TB_stun.Text = SC.FirstName + " " + SC.FamilyName;
                 TB_c.Text    = SC.CourseName;
                 TB_gr.Text   = SC.Grade.ToString();
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }