Example #1
0
 private void GenerateCustomerCode()
 {
     if (CustomerNameTextBox.Text.Length > 3)
     {
         Random random       = new Random();
         string CustomerCode = "";
         string hexa         = "abcdefghjkmnpqruvwxyz";
         int    a            = 1;
         int    b            = 20;
         int    c            = 9;
         int    d            = 99;
         int    e            = 999;
         CustomerCode += hexa.Substring(random.Next(0, b), 1).ToUpper();
         CustomerCode += (random.Next(a, d)).ToString("0");
         CustomerCode += hexa.Substring(random.Next(0, b), 1).ToUpper();
         CustomerCode += (random.Next(a, e)).ToString("0");
         if (context.Customers.SingleOrDefault(p => p.CustomerCode == CustomerCode) != null)
         {
             CustomerCode += (random.Next(a, c)).ToString("0");
         }
         CustomerCodeTextBox.Text = CustomerCode;
     }
     else
     {
         CustomerNameTextBox.Select();
     }
 }
Example #2
0
 private void AddCustomer()
 {
     if (CustomerNameTextBox.Text.Length > 3 && CustomerCodeTextBox.Text.Length > 3)
     {
         Customer cust = new Customer()
         {
             CustomerCode = CustomerCodeTextBox.Text,
             Name         = CustomerNameTextBox.Text,
             EntryDate    = DateTime.Now
         };
         if (context.Customers.SingleOrDefault(c => c.CustomerCode == cust.CustomerCode) != null)
         {
             MessageBox.Show("Cannot create duplicate");
         }
         else
         {
             context.Customers.Add(cust);
             context.SaveChanges();
         }
     }
     else
     {
         CustomerNameTextBox.Select();
     }
 }
Example #3
0
        public void ClearCustomerTextBoxes()
        {
            // RB sets all text boxes value to empty string
            CustomerIDTextBox.Text       = "";
            CustomerNameTextBox.Text     = "";
            CustomerLastNameTextBox.Text = "";
            CustomerAddressTextBox.Text  = "";

            // RB Set focus to Customer Name Field
            CustomerNameTextBox.Select();
        }