Пример #1
0
        private void Initialize(string identityNumber)
        {
            if (identityNumber.IsNullOrEmptyTrimmed())
            {
                return;
            }

            const string numericPattern = @"^\d{13}$";

            IdentityNumber = identityNumber.Trim();
            if (IdentityNumber.Length != 13)
            {
                return;
            }
            var isMatch = Regex.IsMatch(IdentityNumber, numericPattern);

            if (!isMatch)
            {
                return;
            }

            var month = int.Parse(identityNumber.Substring(2, 2));

            if (month < 1 || month > 12)
            {
                return;
            }

            var day = int.Parse(identityNumber.Substring(4, 2));

            if (day < 1 || day > 31)
            {
                return;
            }

            var digits = new int[13];

            for (var i = 0; i < 13; i++)
            {
                digits[i] = int.Parse(IdentityNumber.Substring(i, 1));
            }
            var control1 = digits.Where((v, i) => i % 2 == 0 && i < 12).Sum();
            var second   = string.Empty;

            digits.Where((v, i) => i % 2 != 0 && i < 12).ToList().ForEach(v => second += v.ToString(CultureInfo.InvariantCulture));
            var string2  = (int.Parse(second) * 2).ToString(CultureInfo.InvariantCulture);
            var control2 = string2.Select((t, i) => int.Parse(string2.Substring(i, 1))).Sum();
            var control  = (10 - (control1 + control2) % 10) % 10;

            if (digits[12] != control)
            {
                return;
            }

            IsFemale       = digits[6] < 5;
            IsMale         = !IsFemale;
            IsSouthAfrican = digits[10] == 0;
            IsValid        = true;
        }
 public void Sample_test()
 {
     IdentityNumber.IsValid("8905151430088");
     IdentityNumber.IsValid("8905151430088");
     IdentityNumber.IsValid("7002222412087");
     IdentityNumber.IsValid("7808035176089");
     IdentityNumber.IsValid("7503035682087");
 }
Пример #3
0
 /// <summary>
 /// Releases an ID and removes its object from the Database.
 /// </summary>
 /// <param name="id">The ID to release.</param>
 /// <returns><code>True</code> if the ID was released successfully,
 /// <code>False</code> otherwise.
 /// </returns>
 /// <exception cref="UnregisteredPackageException">If the package specified
 /// by the ID is not registered.
 /// </exception>
 public static bool Release(IdentityNumber id)
 {
     WriteLine("release id " + id.ToString());
     if (!_registered[id.Package])
     {
         throw new UnregisteredPackageException(id.Package);
     }
     return(map.Release(id));
 }
Пример #4
0
 /// <summary>
 /// Returns the object associated with an ID.
 /// </summary>
 /// <param name="id">The ID number.</param>
 /// <returns>The object at that ID.</returns>
 /// <exception cref="UnregisteredObjectException">If no object is found
 /// at the given ID.
 /// </exception>
 /// <exception cref="UnregisteredPackageException">If the package specified
 /// by the ID is not registered.
 /// </exception>
 public static Identifiable Get(IdentityNumber id)
 {
     WriteLine("get id " + id.ToString());
     if (!map.Has(id))
     {
         throw GetNumError(id);
     }
     return(map[id]);
 }
Пример #5
0
 public static void Set(Identifiable obj, IdentityNumber id)
 {
     if (id == 0 && !(obj is Object.Player))
     {
         throw new IdentityOverrideException(id);
     }
     Release(id);
     obj.SetID(id);
     map[id] = obj;
 }
Пример #6
0
 /// <summary>
 /// Determines the cause of error for an unregistered ID.
 /// </summary>
 /// <param name="id">An ID</param>
 /// <returns>An <code>UnregisteredPackageException</code> if the package
 /// is not registered, or an <code>UnregisteredObjectException</code> otherwise.
 /// </returns>
 private static Exception GetNumError(IdentityNumber id)
 {
     if (!_registered[id.Package])
     {
         return(new UnregisteredPackageException(id.Package));
     }
     else
     {
         return(new UnregisteredObjectException(id));
     }
 }
Пример #7
0
        /// <summary>
        /// Adds an identifiable object to the active "scene." Please note that the object's
        /// identity may change based on which identities are available, and these new IDs are
        /// randomly generated.
        /// </summary>
        /// <param name="o">The object to add.</param>
        /// <returns>The IdentityNumber that the added object was registered with.</returns>
        public static IdentityNumber Add(Identifiable o)
        {
            IdentityNumber id = o.GetID();

            if (map.Has(id))
            {
                o.SetID(map.Random((Package)id.Package));
                id = o.GetID();
            }
            WriteLine("assigning to id " + id);
            map[id] = o;
            return(id);
        }
Пример #8
0
 public void NumbersThatAreCorrectIdentityNumbers()
 {
     string[] numbers = new string[] { "8907159027", "8003224758" };
     foreach (string number in numbers)
     {
         try
         {
             IdentityNumber num = new IdentityNumber(number);
         }
         catch (Exception ex)
         {
             Assert.Fail("Failed due to exception: " + ex.Message);
         }
     }
 }
Пример #9
0
 public void NumbersThatShouldBeIncorrectIdentityNumbers()
 {
     string[] numbers = new string[] { "890715902752", "803fhf3348" };
     foreach (string number in numbers)
     {
         try
         {
             IdentityNumber num = new IdentityNumber(number);
             Assert.Fail("No exception thrown");
         }
         catch (Exception)
         {
             // Test successful.
         }
     }
 }
Пример #10
0
        private void Initialize(string identityNumber)
        {
            IdentityNumber = (identityNumber ?? string.Empty).Replace(" ", "");
            if (IdentityNumber.Length == 13)
            {
                int[] digits = new int[13];
                for (int i = 0; i < 13; i++)
                {
                    digits[i] = int.Parse(IdentityNumber.Substring(i, 1));
                }
                int    control1 = digits.Where((v, i) => i % 2 == 0 && i < 12).Sum();
                string second   = string.Empty;
                digits.Where((v, i) => i % 2 != 0 && i < 12).ToList().ForEach(v =>
                                                                              second += v.ToString());
                string string2  = (int.Parse(second) * 2).ToString();
                int    control2 = 0;
                for (int i = 0; i < string2.Length; i++)
                {
                    control2 += int.Parse(string2.Substring(i, 1));
                }
                int control = (10 - ((control1 + control2) % 10)) % 10;
                if (digits[12] == control)
                {
                    BirthDate = DateTime.ParseExact(IdentityNumber
                                                    .Substring(0, 6), "yyMMdd", null);
                    Gender         = digits[6] < 5 ? "Female" : "Male";
                    IsSouthAfrican = digits[10] == 0;
                    if (BirthDate > DateTime.Now)
                    {
                        IsValid = false;
                        return;
                    }

                    Age             = CalculateAge(BirthDate);
                    AgeToLongString = CalculateAgeToLongString(BirthDate);
                    IsValid         = true;
                }
            }
            validateRSAidnumber(identityNumber);
        }
Пример #11
0
 public void SetID(IdentityNumber newIdentity)
 {
     Identity = newIdentity;
 }
Пример #12
0
 public Entity(IdentityNumber id)
 {
     Identity = id;
 }
Пример #13
0
 new public void SetID(IdentityNumber newIdentity)
 {
     throw new ImmutableIdentityException(typeof(Player));
 }
        private void button2_Click(object sender, EventArgs e)
        {
            label22.Visible      = false;
            richTextBox1.Visible = false;
            if (cEmail.Text == "" || cAddress.Text == "" || cCell.Text == "" || cName.Text == "" || cSurname.Text == "" || cID.Text == "")
            {
                label22.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                ///////////////////////CHECKS//////////////////
                bool           isEmail = Regex.IsMatch(cEmail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                bool           isCell  = Regex.IsMatch(cCell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                bool           name    = Regex.IsMatch(cName.Text, @"^[a-zA-Z ]+$");
                bool           sName   = Regex.IsMatch(cSurname.Text, @"^[a-zA-Z ]+$");
                IdentityNumber id      = new IdentityNumber(cID.Text);
                bool           IDVALID = id.IsValid;
                int            exist;
                if (oldcID == cID.Text)
                {
                    exist = 0;
                }
                else
                {
                    exist = DAT.DataAccess.GetCustomer().Where(i => i.IDno == cID.Text).ToList().Count;
                }



                //////////////////////CHECKS//////////////////
                if (!isEmail || !isCell || !name || !sName || !IDVALID || exist != 0)
                {
                    label22.Visible      = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    int custID;

                    using (DataGridViewRow item = this.dataGridView1.SelectedRows[0])
                    {
                        int i = item.Index;

                        string ID = dataGridView1.Rows[i].Cells[2].Value.ToString();


                        custID = DAT.DataAccess.GetCustomer().Where(o => o.IDno == ID).FirstOrDefault().CustID;
                    }
                    try
                    {
                        LTS.Customer newCust = new LTS.Customer();
                        newCust.CustID      = custID;
                        newCust.Name        = cName.Text;
                        newCust.Surname     = cSurname.Text;
                        newCust.IDno        = cID.Text;
                        newCust.CustAddress = cAddress.Text;
                        newCust.CellNo      = cCell.Text;
                        newCust.Email       = cEmail.Text;
                        bool updated = DAT.DataAccess.UpdateCustomer(newCust);
                        if (updated)
                        {
                            if (DialogResult.OK == MessageBox.Show("Customer information edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllCustomer1>();
                            }
                        }
                        else
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the customer information was not edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <AllCustomer1>();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }
Пример #15
0
        private void button2_Click(object sender, EventArgs e)
        {
            error.Visible        = false;
            richTextBox1.Visible = false;
            label22.Visible      = false;
            IdentityNumber id = new IdentityNumber(txtID.Text);

            if (txtName.Text == "" || txtSur.Text == "" || txtID.Text == "" || txtCell.Text == "" || txtEmail.Text == "" || txtAddress.Text == "" || txtsalary.Text == "" || txtUsername.Text == "" || txtPassword.Text == "" || comboBoxActiv.SelectedItem.ToString() == "" || comboBoxAdmin.SelectedItem.ToString() == "" || !id.IsValid)
            {
                error.Visible        = true;
                richTextBox1.Visible = true;
            }
            else
            {
                ///////////////////////CHECKS//////////////////
                bool isEmail = Regex.IsMatch(txtEmail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                bool isCell  = Regex.IsMatch(txtCell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                bool name    = Regex.IsMatch(txtName.Text, @"^[a-zA-Z ]+$");
                bool sName   = Regex.IsMatch(txtSur.Text, @"^[a-zA-Z ]+$");

                int exist;
                if (oldeID == txtID.Text)
                {
                    exist = 0;
                }
                else
                {
                    exist = DAT.DataAccess.GetEmployee().Where(i => i.IDno == txtID.Text).ToList().Count;
                }


                //////////////////////CHECKS//////////////////
                if (!isEmail || !isCell || !name || !sName || exist != 0)
                {
                    if (exist != 0)
                    {
                        label22.Visible = true;
                    }
                    error.Visible        = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    try
                    {
                        LTS.Employee newEmp = new LTS.Employee();
                        newEmp.EmpID      = Convert.ToInt32(em.Text);
                        newEmp.Name       = txtName.Text;
                        newEmp.Surname    = txtSur.Text;
                        newEmp.IDno       = txtID.Text;
                        newEmp.CellNo     = txtCell.Text;
                        newEmp.Email      = txtEmail.Text;
                        newEmp.EmpAddress = txtAddress.Text;
                        newEmp.Salary     = Convert.ToDecimal(txtsalary.Text);
                        newEmp.IsAdmin    = Convert.ToBoolean(comboBoxAdmin.SelectedItem);
                        newEmp.Username   = txtUsername.Text;
                        newEmp.Pass       = txtPassword.Text;
                        newEmp.Activated  = Convert.ToBoolean(comboBoxActiv.SelectedItem);
                        bool updated = DAT.DataAccess.UpdateEmployee(newEmp);
                        if (updated)
                        {
                            if (DialogResult.OK == MessageBox.Show("Employee item edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <Employee>();
                            }
                        }
                        else
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Employee item was not edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <Employee>();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        error.Visible        = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }
 public void Invalid_length()
 {
     IdentityNumber.IsValid("780803517608933").ShouldBe(false);
 }
 public void Invalid_birth_date()
 {
     IdentityNumber.IsValid("7888835176089").ShouldBe(false);
 }
 public void Valid_identity_number()
 {
     IdentityNumber.IsValid("7808035176089").ShouldBe(true);
 }
Пример #19
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem == null || comboBox2.SelectedItem == null || (radioButton1.Checked == false && radioButton2.Checked == false))
            {
                label22.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                if (radioButton1.Checked && NewNameC.Text != "" && NewSurnameC.Text != "" && newIDC.Text != "" && newCellC.Text != "" && newEmailC.Text != "" && newAddressC.Text != "")
                {
                    IdentityNumber iN      = new IdentityNumber(newIDC.Text);
                    bool           validID = iN.IsValid;
                    if (validID)
                    {
                        label22.Visible = false;
                        LTS.Customer c = new LTS.Customer();
                        c.Name        = NewNameC.Text;
                        c.Surname     = NewSurnameC.Text;
                        c.IDno        = newIDC.Text;
                        c.Email       = newEmailC.Text;
                        c.CellNo      = newCellC.Text;
                        c.CustAddress = newAddressC.Text;

                        int custID = DAT.DataAccess.AddCustomer(c);

                        if (custID != -1)
                        {
                            LTS.Sale s = new LTS.Sale();
                            s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                            s.SaleDate = DateTime.Now.Date;
                            s.CustID   = custID;

                            if (comboBoxp.SelectedItem.ToString() == "Yes")
                            {
                                s.Paid = true;
                            }
                            else
                            {
                                s.Paid = false;
                            }
                            s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                            int saleID  = DAT.DataAccess.AddSale(s);

                            if (saleID == -1)
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                            else
                            {
                                LTS.Stock res = new LTS.Stock();

                                res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                                res.VehicleStatus = "Sold";
                                bool updated = DAT.DataAccess.UpdateStock(res);
                                if (updated)
                                {
                                    if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                    }
                                }
                                else
                                {
                                    if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                    {
                                        ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        label22.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
                else if (radioButton2.Checked && oldNameC.Text != "" && oldSurnameC.Text != "" && comboBoxOldNameC.SelectedItem != null && oldCellC.Text != "" && oldEmailC.Text != "" && oldAddressC.Text != "")
                {
                    label22.Visible      = false;
                    richTextBox1.Visible = false;
                    LTS.Customer c = DAT.DataAccess.GetCustomer().Where(p => p.IDno == comboBoxOldNameC.SelectedItem.ToString()).FirstOrDefault();
                    c.Name        = oldNameC.Text;
                    c.Surname     = oldSurnameC.Text;
                    c.Email       = oldEmailC.Text;
                    c.CellNo      = oldCellC.Text;
                    c.CustAddress = oldAddressC.Text;

                    bool custID = DAT.DataAccess.UpdateCustomer(c);

                    if (custID)
                    {
                        LTS.Sale s = new LTS.Sale();
                        s.EmpID    = DAT.DataAccess.GetEmployee().ToList()[comboBox2.SelectedIndex].EmpID;
                        s.SaleDate = DateTime.Now.Date;
                        s.CustID   = c.CustID;

                        if (comboBoxp.SelectedItem.ToString() == "Yes")
                        {
                            s.Paid = true;
                        }
                        else
                        {
                            s.Paid = false;
                        }
                        s.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                        int stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == comboBox1.SelectedItem.ToString()).FirstOrDefault().StockID;
                        int saleID  = DAT.DataAccess.AddSale(s);

                        if (saleID == -1)
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                            }
                        }
                        else
                        {
                            LTS.Stock res = new LTS.Stock();

                            res = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault();
                            res.VehicleStatus = "Sold";
                            bool updated = DAT.DataAccess.UpdateStock(res);
                            if (updated)
                            {
                                if (DialogResult.OK == MessageBox.Show("The Sale Item was added successfully!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                            else
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Sale Item was not Added!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Sale1>();
                                }
                            }
                        }
                    }
                }

                else

                {
                    label22.Visible      = true;
                    richTextBox1.Visible = true;
                }
            }
        }
Пример #20
0
 public abstract void SetID(IdentityNumber newIdentity);
Пример #21
0
 public override void SetID(IdentityNumber newIdentity)
 {
     throw new ImmutableIdentityException(typeof(LinearBehavior));
 }
Пример #22
0
 /// <summary>
 /// Basically the <code>HasKey</code> method.
 /// </summary>
 /// <param name="n">The <code>IdentityNumber</code> to query for.</param>
 /// <returns>
 /// <code>True</code> if the given <code>IdentityNumber</code> is
 /// already in this <code>IdentityMap</code>, <code>False</code>
 /// otherwise.
 /// </returns>
 internal bool Has(IdentityNumber n)
 {
     return(dict.ContainsKey(n));
 }
 public void Invalid_characters()
 {
     IdentityNumber.IsValid("78080351abcde").ShouldBe(false);
 }
        private void button2_Click(object sender, EventArgs e)
        {
            label18.Visible      = false;
            richTextBox1.Visible = false;
            if (Namep.Text == "" || surnameP.Text == "" || PID.Text == "" || cell.Text == "" || mail.Text == "")
            {
                label18.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                ///////////////////////CHECKS//////////////////
                bool           isEmail = Regex.IsMatch(mail.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                bool           isCell  = Regex.IsMatch(cell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                bool           name    = Regex.IsMatch(Namep.Text, @"^[a-zA-Z ]+$");
                bool           sName   = Regex.IsMatch(surnameP.Text, @"^[a-zA-Z ]+$");
                IdentityNumber id      = new IdentityNumber(PID.Text);
                bool           IDVALID = id.IsValid;

                //////////////////////CHECKS//////////////////
                if (!isEmail || !isCell || !name || !sName || !IDVALID)
                {
                    label18.Visible      = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    int stockID;
                    using (DataGridViewRow item = this.dataGridView1.SelectedRows[0])
                    {
                        int    i      = item.Index;
                        string oldVIN = dataGridView1.Rows[i].Cells[0].Value.ToString();
                        stockID = DAT.DataAccess.GetStock().Where(o => o.VIN == oldVIN).FirstOrDefault().StockID;
                    }
                    try
                    {
                        LTS.Reserve res = new LTS.Reserve();
                        res.ResID   = DAT.DataAccess.GetReserve().Where(o => o.StockID == stockID).FirstOrDefault().ResID;
                        res.StockID = stockID;
                        res.Name    = Namep.Text;
                        res.Surname = surnameP.Text;
                        res.IDno    = PID.Text;
                        res.CellNo  = cell.Text;
                        res.Email   = mail.Text;
                        res.ResDate = DAT.DataAccess.GetReserve().Where(o => o.StockID == stockID).FirstOrDefault().ResDate;
                        bool updated = DAT.DataAccess.UpdateReserve(res);
                        if (updated)
                        {
                            if (DialogResult.OK == MessageBox.Show("Reservation edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <ReserveA>();
                            }
                        }
                        else
                        {
                            if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Reservation was not edited successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <ReserveA>();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        label18.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }
        public void Valid_identity_number_date_of_birth()
        {
            var identityNumber = new IdentityNumber("7808035176089");

            identityNumber.DateOfBirth.ShouldBe(new DateOfBirth(1978, 08, 03));
        }
        public void Valid_identity_number_gender()
        {
            var identityNumber = new IdentityNumber("7808035176089");

            identityNumber.Gender.ShouldBe(Gender.Male);
        }
Пример #27
0
 public Identifiable this[IdentityNumber n] {
     get { return(dict[n]); }
     set { dict[n] = value; }
 }
 public void Valid_identity_number_5008150764080() //test case from identity number that is correct but failed validation
 {
     IdentityNumber.IsValid("5008150764080").ShouldBe(true);
 }
Пример #29
0
 /// <summary>
 /// Removes the given <code>IdentityNumber</code>
 /// from this <code>IdentityMap</code>, freeing
 /// the number to prevent leakage.
 /// </summary>
 /// <param name="n">The <code>IdentityNumber</code> to release.</param>
 /// <returns><code>True</code> if the <code>IdentityNumber</code> was successfully removed, <code>False</code> otherwise.</returns>
 internal bool Release(IdentityNumber n)
 {
     return(dict.Remove(n));
 }
Пример #30
0
        private void button2_Click(object sender, EventArgs e)
        {
            label17.Visible      = false;
            richTextBox1.Visible = false;
            if (VID.SelectedItem == null || email.Text == "" || cell.Text == "" || PID.Text == "" || Surname.Text == "" || Pname.Text == "")
            {
                label17.Visible      = true;
                richTextBox1.Visible = true;
            }
            else
            {
                ///////////////////////CHECKS//////////////////
                bool           isEmail = Regex.IsMatch(email.Text, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase);
                bool           isCell  = Regex.IsMatch(cell.Text, @"^(?:\+?1[-. ]?)?\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$");
                bool           name    = Regex.IsMatch(Pname.Text, @"^[a-zA-Z ]+$");
                bool           sName   = Regex.IsMatch(Surname.Text, @"^[a-zA-Z ]+$");
                IdentityNumber id      = new IdentityNumber(PID.Text);
                bool           IDVALID = id.IsValid;

                //////////////////////CHECKS//////////////////
                if (!isEmail || !isCell || !name || !sName || !IDVALID)
                {
                    label17.Visible      = true;
                    richTextBox1.Visible = true;
                }
                else
                {
                    LTS.Reserve r = new LTS.Reserve();
                    r.StockID = DAT.DataAccess.GetStock().Where(i => i.VIN == VID.SelectedItem.ToString()).FirstOrDefault().StockID;
                    r.Name    = Pname.Text;
                    r.Surname = Surname.Text;
                    r.IDno    = PID.Text;
                    r.CellNo  = cell.Text;
                    r.Email   = email.Text;
                    r.ResDate = DateTime.Now;

                    int RID = DAT.DataAccess.AddReserve(r);

                    int    stockID;
                    string status;

                    string oldVIN = VID.SelectedItem.ToString();


                    stockID = DAT.DataAccess.GetStock().Where(i => i.VIN == VID.SelectedItem.ToString()).FirstOrDefault().StockID;


                    try
                    {
                        LTS.Stock newStock = new LTS.Stock();
                        newStock.StockID       = stockID;
                        newStock.Make          = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Make;
                        newStock.Model         = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Model;
                        newStock.Price         = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().Price;
                        newStock.VehicleStatus = "Reserved";
                        newStock.VehicleYear   = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().VehicleYear;
                        newStock.VIN           = DAT.DataAccess.GetStock().Where(i => i.StockID == stockID).FirstOrDefault().VIN;
                        bool updated = DAT.DataAccess.UpdateStock(newStock);
                        if (RID > 0 && updated == true)
                        {
                            if (DialogResult.OK == MessageBox.Show("The Reservation was made successfully!"))
                            {
                                ((Form1)this.Parent.Parent).ChangeView <Reserve1>();
                            }
                            else
                            {
                                if (DialogResult.OK == MessageBox.Show("Sorry something went wrong, the Reservation was not made!"))
                                {
                                    ((Form1)this.Parent.Parent).ChangeView <Reserve1>();
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        label17.Visible      = true;
                        richTextBox1.Visible = true;
                    }
                }
            }
        }