예제 #1
0
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            string   user = textBoxUsername.Text;
            string   pass = textBoxPassword.Text;
            string   CV   = "QuanLy";
            Random   rd   = new Random();
            int      id   = rd.Next(200, 300);
            Nhanvien nv   = new Nhanvien();

            if (nv.insertQL(id))
            {
                if (nv.insertLogin(user, pass, CV, id))
                {
                    MessageBox.Show("Thêm Quản Lý thành Công", "Register Quản Lý", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Thất Bại xem lại thông tin", "Register Quản Lý", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("Thất Bại xem lại thông tin", "Regiter Quản Lý", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 private void ButtonAdd_Click(object sender, EventArgs e)
 {
     if ((TextboxID.Text.Trim() == ""))
     {
         MessageBox.Show("Enter ID To ADD", " Thêm Lao CÔng", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         My_DB    db       = new My_DB();
         Nhanvien nhanvien = new Nhanvien();
         int      ca       = (int)ComboBoxCaDK.SelectedValue;
         string   CV       = "LaoCong";
         int      id       = Convert.ToInt32(TextboxID.Text);
         string   fname    = TextboxFirstName.Text;
         string   lname    = TextboxLastName.Text;
         DateTime bdate    = dateTimePickerLetan.Value;
         string   phone    = TextboxPhone.Text;
         string   adrs     = TextboxAddress.Text;
         string   UserName = TextBoxUSERNAME.Text;
         string   Password = TextBoxPASSWORD.Text;
         string   LBGT     = "Male";
         if (RadioButtonFemale.Checked)
         {
             LBGT = "Female";
         }
         MemoryStream   pic       = new MemoryStream();
         int            born_year = dateTimePickerLetan.Value.Year;
         int            this_year = DateTime.Now.Year;
         SqlDataAdapter adapter   = new SqlDataAdapter();
         DataTable      table     = new DataTable();
         SqlCommand     command   = new SqlCommand("Select * From TTNV WHERE @ID= IdNhanVien", db.GetConnection);
         command.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextboxID.Text;
         adapter.SelectCommand = command;
         adapter.Fill(table);
         if ((table.Rows.Count) > 0)
         {
             MessageBox.Show("trung id", " nhap lai", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         else if (((this_year - born_year) < 18) || ((this_year - born_year) > 50))
         {
             MessageBox.Show("Tuổi lao công từ 18 -> 50", " Birth Date error", MessageBoxButtons.OK, MessageBoxIcon.Error);;
         }
         else if (verif1())
         {
             pictureBox1.Image.Save(pic, pictureBox1.Image.RawFormat);
             if (nhanvien.insertNhanVien(id, fname, lname, bdate, LBGT, phone, adrs, pic, ca))
             {
                 if (nhanvien.insertLogin(UserName, Password, CV, id))
                 {
                     MessageBox.Show("Thành Công", " Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MessageBox.Show("Thất bại", "Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
         else
         {
             MessageBox.Show("Thiếu thông tin", " Thêm nhân viên", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
 }