Exemple #1
0
        private void btnSimpan_Click(object sender, EventArgs e)
        {
            StringBuilder sb     = new StringBuilder();
            bool          IsPass = true;

            if (string.IsNullOrEmpty(textBoxNamaPelanggan.Text))
            {
                IsPass = false;
                sb.Append("- Nama Pelanggan harus diisi \n");
            }

            if (string.IsNullOrEmpty(textBoxNomorKtp.Text))
            {
                IsPass = false;
                sb.Append("- Nomor KTP harus diisi \n");
            }

            if (string.IsNullOrEmpty(textBoxAlamat.Text))
            {
                IsPass = false;
                sb.Append("- Alamat harus diisi \n");
            }

            if (string.IsNullOrEmpty(textBoxNomorTelepon.Text))
            {
                IsPass = false;
                sb.Append("- Nomor Telepon harus diisi \n");
            }

            if (comboBoxMember.SelectedValue == null)
            {
                IsPass = false;
                sb.Append("- Member harus diisi \n");
            }

            if (!IsPass)
            {
                MessageBox.Show(sb.ToString(), "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            var member = memberService.Get(int.Parse(comboBoxMember.SelectedValue.ToString()));

            var pelanggan = pelangganService.Get(int.Parse(labelIdHidden.Text));

            pelanggan.NamaPelanggan = textBoxNamaPelanggan.Text;
            pelanggan.NomorKtp      = textBoxNomorKtp.Text;
            pelanggan.Alamat        = textBoxAlamat.Text;
            pelanggan.NoTelepon     = textBoxNomorTelepon.Text;
            pelanggan.MemberId      = member.Id;

            pelangganService.Put(pelanggan);

            this.ParentForm.dataGridViewPelanggan.DataSource = pelangganService.Get();
            this.Dispose();
        }