コード例 #1
0
        private void buttonTambahPegawai_Click(object sender, EventArgs e)
        {
            if (textBoxPegawaiNama.Text == "" || textBoxUsernamePegawai.Text == "" || textBoxNoTelpPegawai.Text == "" || textBoxAlamatPegawai.Text == "" || comboBoxJabatanPegawai.Text == "" || comboBoxJenisKelaminPegawai.Text == "")
            {
                MessageBox.Show("Harap isi semua informasi terlebih dahulu");
            }
            else if (textBoxUsernamePegawai.Text.Length < 6)
            {
                MessageBox.Show("Username harus sama/lebih dari 6 karakter");
            }
            else
            {
                Jabatan jabatan = new Jabatan();
                jabatan.IdJabatan = Convert.ToInt32(comboBoxJabatanPegawai.Text.Split('-')[0]);
                jabatan.Nama      = comboBoxJabatanPegawai.Text.Split('-')[1];

                User user = new User();
                user.Nama         = textBoxPegawaiNama.Text.Trim();
                user.JenisKelamin = comboBoxJenisKelaminPegawai.Text.Trim();
                user.TanggalLahir = DateTime.Parse(dateTimePickerTanggalLahirPegawai.Value.ToString());
                user.NoTelp       = textBoxNoTelpPegawai.Text.Trim();
                user.Username     = textBoxUsernamePegawai.Text.Trim();
                user.Alamat       = textBoxAlamatPegawai.Text.Trim();
                user.Jabatan      = jabatan;

                if (pathFoto != "")
                {
                    user.Foto = Path.GetExtension(pathFoto);
                    string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\images\\users";
                    string folderName  = Path.Combine(projectPath, textBoxUsernamePegawai.Text.Trim());
                    Directory.CreateDirectory(folderName);
                    Array.ForEach(Directory.GetFiles(@folderName + "\\"), File.Delete);
                    File.Copy(pathFoto, folderName + "\\" + "foto" + user.Foto);
                }

                List <User> listUser = new List <User>();

                User.BacaPegawai("cari username", textBoxUsernamePegawai.Text, listUser);

                if (listUser.Count == 0)
                {
                    string hasilTambah = User.TambahPegawai(user);

                    if (hasilTambah == "1")
                    {
                        MessageBox.Show("Proses tambah berhasil");

                        this.mainForm.textBoxSearchPegawai.Clear();
                        this.mainForm.PopulatePegawaiTable("", "");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show(hasilTambah);
                    }
                }
            }
        }
コード例 #2
0
        private void FormTambahPegawai_Load(object sender, EventArgs e)
        {
            string hasilBaca = Jabatan.BacaData(listJabatan);

            if (hasilBaca == "1")
            {
                foreach (var item in listJabatan)
                {
                    comboBoxJabatanPegawai.Items.Add(item.IdJabatan + " - " + item.Nama);
                }
            }

            comboBoxJenisKelaminPegawai.Items.Add("Laki-laki");
            comboBoxJenisKelaminPegawai.Items.Add("Perempuan");
        }
コード例 #3
0
        private void FormUbahPegawai_Load(object sender, EventArgs e)
        {
            labelNama.Text            = FormMaster.listSelectedPegawai[0].Nama;
            textBoxNoTelpPegawai.Text = FormMaster.listSelectedPegawai[0].NoTelp;
            labelUsername.Text        = FormMaster.listSelectedPegawai[0].Username;
            textBoxAlamatPegawai.Text = FormMaster.listSelectedPegawai[0].Alamat;
            labelTanggalLahir.Text    = FormMaster.listSelectedPegawai[0].TanggalLahir.ToString("dd MMMM yyyy");

            if (FormMaster.listSelectedPegawai[0].Foto != "")
            {
                string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\images\\users";
                string folderName  = Path.Combine(projectPath, FormMaster.listSelectedPegawai[0].Username);
                pictureBoxUbahFotoUser.ImageLocation = folderName + "\\" + "foto" + FormMaster.listSelectedPegawai[0].Foto.ToString();
            }
            else
            {
                pictureBoxUbahFotoUser.Image = Resources.profile_picture;
            }

            labelJenisKelamin.Text = FormMaster.listSelectedPegawai[0].JenisKelamin;

            comboBoxStatusPegawai.Items.Add("Aktif");
            comboBoxStatusPegawai.Items.Add("Blokir");
            comboBoxStatusPegawai.SelectedItem = FormMaster.listSelectedPegawai[0].Status;

            string hasilBacaJabatan = Jabatan.BacaData(listJabatan);

            if (hasilBacaJabatan == "1")
            {
                foreach (var item in listJabatan)
                {
                    comboBoxJabatanPegawai.Items.Add(item.IdJabatan + " - " + item.Nama);
                }
                comboBoxJabatanPegawai.SelectedItem = FormMaster.listSelectedPegawai[0].Jabatan.IdJabatan + " - " + FormMaster.listSelectedPegawai[0].Jabatan.Nama;
            }

            textBoxNoTelpPegawai.SelectionStart  = textBoxNoTelpPegawai.Text.Length;
            textBoxNoTelpPegawai.SelectionLength = 0;
        }
コード例 #4
0
        private void buttonUbahPegawai_Click(object sender, EventArgs e)
        {
            if (textBoxNoTelpPegawai.Text == "" || textBoxAlamatPegawai.Text == "")
            {
                MessageBox.Show("Data harus diisi semua terlebih dahulu");
            }
            else
            {
                Jabatan jabatan = new Jabatan();
                jabatan.IdJabatan = int.Parse(comboBoxJabatanPegawai.Text.Split('-')[0]);
                jabatan.Nama      = comboBoxJabatanPegawai.Text.Split('-')[1];

                User user = new User();
                user.IdUser = FormMaster.listSelectedPegawai[0].IdUser;
                user.NoTelp = textBoxNoTelpPegawai.Text.Trim();

                if (pathFoto != "")
                {
                    user.Foto = Path.GetExtension(pathFoto);
                }

                if (statusUser == "Belum Aktif")
                {
                    user.Status = labelStatus.Text;
                }
                else
                {
                    user.Status = comboBoxStatusPegawai.Text;
                }

                user.Alamat  = textBoxAlamatPegawai.Text.Trim();
                user.Jabatan = jabatan;

                string hasilUbah = "";

                if (pictureBoxUbahFotoUser.Tag == "Default")
                {
                    hasilUbah = User.UbahPegawai(user, "Hapus");
                }
                else if (pictureBoxUbahFotoUser.Tag == "Unggahan")
                {
                    string projectPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + "\\images\\users";
                    string folderName  = Path.Combine(projectPath, FormMaster.listSelectedPegawai[0].Username);
                    Directory.CreateDirectory(folderName);
                    Array.ForEach(Directory.GetFiles(@folderName + "\\"), File.Delete);
                    File.Copy(pathFoto, folderName + "\\" + "foto" + user.Foto);
                    hasilUbah = User.UbahPegawai(user, "Ada");
                }
                else if (pictureBoxUbahFotoUser.Tag == null)
                {
                    hasilUbah = User.UbahPegawai(user, "Tidak Ada");
                }

                if (hasilUbah == "1")
                {
                    MessageBox.Show("Data berhasil disimpan");

                    this.mainForm.textBoxSearchPegawai.Clear();
                    this.mainForm.PopulatePegawaiTable("", "");
                    this.Close();
                }
            }
        }