public void btnAddState()
 {
     if (tbxCustName.Text.Length > 0 &&
         Support.isValidNIC(tbxNic.Text.Trim()) &&
         cmbType.Text != "" &&
         tbxQty.Text.Length > 0)
     {
         tbxTel.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals;
         if (tbxTel.Text == "")
         {
             btnAdd.Enabled = true;
         }
         else
         {
             if (Support.isValidTel(tbxTel.Text))
             {
                 btnAdd.Enabled = true;
             }
             else
             {
                 btnAdd.Enabled = false;
             }
         }
     }
     else
     {
         btnAdd.Enabled = false;
     }
 }
        private void btnAddWorker_Click(object sender, EventArgs e)
        {
            string empID     = tbxWorkerID.Text;
            string firstName = tbxFirstName.Text;
            string lastName  = tbxLastName.Text;
            string password  = tbxPassword.Text;
            string address   = tbxAddress.Text;
            string telNO     = tbxContactNumber.Text;
            string accNO     = tbxACNumber.Text;
            string nicNO     = tbxNIC.Text;
            string gender    = "";

            if (rbMale.Checked)
            {
                gender = "Male";
            }
            else if (rbFemale.Checked)
            {
                gender = "Female";
            }

            string dob = nudYear.Value.ToString() + "-" + dudMonth.Text + "-" + nudDate.Value.ToString();

            if (nudYear.Value + 15 >= DateTime.Now.Year)
            {
                MessageBox.Show("Enter worker's real date of birth.", "Something wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (Support.isValidNIC(nicNO) && isValidTelNO(telNO))
            {
                try
                {
                    conn.Open();

                    MySqlCommand comm = conn.CreateCommand();
                    MySqlCommand cmd  = conn.CreateCommand();
                    cmd.CommandText  = "update dtlogin set psw = @psw, empName = @empName where empID ='" + empID + "'";
                    comm.CommandText = "UPDATE worker_details SET first_name = @first_name,last_name=@last_name,password=@password,address=@address,acc_NO=@acc_NO,nic_NO=@nic_NO,gender=@gender,tel_NO=@tel_NO,dob=@dob WHERE empID = '" + empID + "' ";

                    cmd.Parameters.AddWithValue("@psw", password);
                    cmd.Parameters.AddWithValue("@empName", firstName + " " + lastName);
                    comm.Parameters.AddWithValue("@first_name", firstName);
                    comm.Parameters.AddWithValue("@last_name", lastName);

                    comm.Parameters.AddWithValue("@password", password);
                    comm.Parameters.AddWithValue("@address", address);
                    comm.Parameters.AddWithValue("@tel_NO", telNO);
                    comm.Parameters.AddWithValue("@acc_NO", accNO);
                    comm.Parameters.AddWithValue("@nic_NO", nicNO);
                    comm.Parameters.AddWithValue("@gender", gender);
                    comm.Parameters.AddWithValue("@dob", dob);
                    cmd.ExecuteNonQuery();
                    comm.ExecuteNonQuery();
                    conn.Close();

                    MessageBox.Show("Worker details changed successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                catch
                {
                    //MessageBox.Show("Error in adding mysql row. Error: ");
                    throw;
                }
            }
            else if (!Support.isValidNIC(nicNO))
            {
                MessageBox.Show("NIC Number is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxNIC.Focus();
            }
            else
            {
                MessageBox.Show("Contact Number is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxContactNumber.Focus();
            }
        }
Пример #3
0
        private void btnAddWorker_Click(object sender, EventArgs e)
        {
            string firstName  = tbxFirstName.Text;
            string lastName   = tbxLastName.Text;
            string workerType = cmbWorkerType.Text;
            string password   = tbxPassword.Text;
            string address    = tbxAddress.Text;
            string telNO      = tbxContactNumber.Text;


            string accNO = tbxACNumber.Text;
            string nicNO = tbxNIC.Text;
            string gender;
            string deleted = "No";

            if (nudYear.Value + 15 >= DateTime.Now.Year)
            {
                MessageBox.Show("Enter worker's real date of birth.", "Something wrong", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (Support.isValidNIC(nicNO) && isValidTelNO(telNO))
            {
                {
                    if (rbMale.Checked)
                    {
                        gender = "Male";
                    }
                    else
                    {
                        gender = "Female";
                    }
                    string dob = nudYear.Value.ToString() + "-" + dudMonth.Text + "-" + nudDate.Value.ToString();
                    try
                    {
                        conn.Open();

                        MySqlCommand comm = conn.CreateCommand();
                        MySqlCommand cmd  = new MySqlCommand("insert into dtlogin(empID,psw,empName) values (@empID,@psw,@empName)", conn);
                        comm.CommandText = "INSERT INTO worker_details(empID,first_name,last_name,worker_type,password,address,acc_NO,nic_NO,gender,tel_NO,dob,deleted) VALUES (@empID,@first_name,@last_name,@worker_type,@password,@address,@acc_NO,@nic_NO,@gender,@tel_NO,@dob,@deleted)";

                        cmd.Parameters.AddWithValue("@empID", empid);
                        cmd.Parameters.AddWithValue("@psw", password);
                        cmd.Parameters.AddWithValue("@empName", firstName + " " + lastName);
                        cmd.ExecuteNonQuery();
                        comm.Parameters.AddWithValue("@empID", empid);
                        comm.Parameters.AddWithValue("@first_name", firstName);
                        comm.Parameters.AddWithValue("@last_name", lastName);
                        comm.Parameters.AddWithValue("@worker_type", workerType);
                        comm.Parameters.AddWithValue("@password", password);
                        comm.Parameters.AddWithValue("@address", address);
                        comm.Parameters.AddWithValue("@tel_NO", telNO);
                        comm.Parameters.AddWithValue("@acc_NO", accNO);
                        comm.Parameters.AddWithValue("@nic_NO", nicNO);
                        comm.Parameters.AddWithValue("@gender", gender);
                        comm.Parameters.AddWithValue("@dob", dob);
                        comm.Parameters.AddWithValue("@deleted", deleted);
                        comm.ExecuteNonQuery();
                        conn.Close();

                        MessageBox.Show("New worker added successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();
                    }
                    catch
                    {
                        MessageBox.Show("Error in adding mysql row. Error: ");
                    }
                }
            }
            else if (!Support.isValidNIC(nicNO))
            {
                MessageBox.Show("NIC Number is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxNIC.Focus();
            }
            else
            {
                MessageBox.Show("Contact Number is not valid.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbxContactNumber.Focus();
            }
        }