Example #1
0
        public static bool IsUniqueEntry(TextBox textBox)
        {
            bool success = true;

            if ("Product Code".Equals(textBox.Tag))
            {
                Product[] products = ProductDB.GetProducts();
                if (products != null)
                {
                    for (int i = 0; i < ProductDB.count; i++)
                    {
                        if (products[i].Code.Equals(int.Parse(textBox.Text)))
                        {
                            MessageBox.Show(textBox.Tag + " already exists, please enter new unique value.", Title);
                            textBox.Clear();
                            textBox.Focus();
                            success = false;
                        }
                    }
                }
            }

            if ("Technician ID".Equals(textBox.Tag))
            {
                Technician[] technicians = TechnicianDB.GetTechnicians();
                if (technicians != null)
                {
                    for (int i = 0; i < TechnicianDB.count; i++)
                    {
                        if (technicians[i].ID.Equals(int.Parse(textBox.Text)))
                        {
                            MessageBox.Show(textBox.Tag + " already exists, please enter new unique value.", Title);
                            textBox.Clear();
                            textBox.Focus();
                            success = false;
                        }
                    }
                }
            }

            if ("Customer ID".Equals(textBox.Tag))
            {
                Customer[] customers = CustomerDB.GetCustomers();
                if (customers != null)
                {
                    for (int i = 0; i < CustomerDB.count; i++)
                    {
                        if (customers[i].ID.Equals(int.Parse(textBox.Text)))
                        {
                            MessageBox.Show(textBox.Tag + " already exists, please enter new unique value.", Title);
                            textBox.Clear();
                            textBox.Focus();
                            success = false;
                        }
                    }
                }
            }
            return(success);
        }
Example #2
0
 private void MaintainTechnician_Load(object sender, EventArgs e)
 {
     techs = TechnicianDB.GetTechnicians();
     if (techs != null)
     {
         FillTechnicianListBox();
     }
 }
Example #3
0
        private void btnTechnicianModify_Click(object sender, EventArgs e)
        {
            try
            {
                int            i        = lstTechnician.SelectedIndex;
                TechnicianForm techForm = new TechnicianForm();

                if (i != -1)
                {
                    Technician technician = techs[i];
                    techForm.SetTechFormFields(technician);
                    technician.ID    = 0;
                    technician.Name  = null;
                    technician.Email = null;
                    technician.Phone = null;
                    MessageBox.Show("Modify the record and click save !");
                    FillTechnicianListBox();
                    technician = techForm.GetNewTechnician();
                    if (technician != null)
                    {
                        if (TechnicianDB.AddTechnician(technician))
                        {
                            MessageBox.Show("Technician added successfully !");
                            FillTechnicianListBox();
                        }
                        else
                        {
                            MessageBox.Show("Failed to add Technician");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error");
            }
        }
Example #4
0
 private void btnTechnicianAdd_Click(object sender, EventArgs e)
 {
     try
     {
         TechnicianForm tech = new TechnicianForm();
         Technician     t    = tech.GetNewTechnician();
         if (t != null)
         {
             if (TechnicianDB.AddTechnician(t))
             {
                 MessageBox.Show("Technician added successfully !");
                 FillTechnicianListBox();
             }
             else
             {
                 MessageBox.Show("Failed to add Technician");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error");
     }
 }