Пример #1
0
        private void guna2Button3_Click(object sender, EventArgs e)
        {
            DBconnection ui   = new DBconnection();
            string       type = empType.Text;



            if (name.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Name Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (nic.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty NIC Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (dob.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty DOB Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (email.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Email Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else if (empType.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Enter Designation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //!type.Equals("MLT") || !type.Equals("Cashier") || !type.Equals("Admin") || !type.Equals("Other")
            else if (empType.Text.Trim() != string.Empty)
            {
                if (type.Equals("MLT"))
                {
                }
                else if (type.Equals("Casheir"))
                {
                }
                else if (type.Equals("Admin"))
                {
                }
                else if (type.Equals("Other"))
                {
                    if (other.Text.Trim() == string.Empty)
                    {
                        MessageBox.Show("Empty Other Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Enter valid Designation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else if (phone.Text.Trim() == string.Empty)
            {
                MessageBox.Show("Empty Phone Number Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            else
            {
                return;
            }

            if (user.Checked)
            {
                if (userName.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Empty UserName Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (password.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Empty Password Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (cPassword.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("Empty Confirm Password Field!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (password.Text != cPassword.Text)
                {
                    MessageBox.Show("Password does not match!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else if (ui.checkUserName(userName.Text))
                {
                    MessageBox.Show("Username Already Taken!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DialogResult answer;

            answer = MessageBox.Show("Are you sure want to add Employee?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question);


            //*************database**********************
            if (answer == DialogResult.Yes || answer == DialogResult.OK)
            {
                try
                {
                    MemoryStream ms  = new MemoryStream();
                    byte[]       img = ms.ToArray();
                    if (pictureBox1.Image == null)
                    {
                        MessageBox.Show("Empty Image!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
                    }


                    string   Enic      = "E" + nic.Text;
                    string   Ename     = name.Text;
                    string   date      = dob.Value.ToShortDateString();
                    string   Eemail    = email.Text;
                    int      Ephone    = Convert.ToInt32(phone.Text);
                    string   eType     = empType.Text;
                    string   Eusername = userName.Text;
                    string   Epassword = password.Text;
                    byte[]   Photo     = img;
                    employee ox        = new employee(Enic, Ename, date, Eemail, Ephone, eType, Eusername, Epassword, Photo);

                    ui.addEmployees(ox);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("erro: \n" + ex);
                    Console.WriteLine("erro: \n" + ex);
                }


                clearFileds();
            }
        }
Пример #2
0
        //*************Employees Registration************//


        public void addEmployees(employee obj)
        {
            String sqlQuery = "INSERT INTO dbo.Employee(EmployeeNic,Name,Dob,Email,Phone,EmployeeType,UserName,Password,Photo) " +
                              << << << < HEAD
                              "VALUES ('" + obj.ENic + "','" + obj.Name + "','" + obj.Dob + "','" + obj.Email + "','" + obj.Phone + "','" + obj.EmployeeType + "','" + obj.UserName + "','" + obj.Password + "',CONVERT(VARBINARY(25), '" + obj.Picture + "', 1))";