コード例 #1
0
        public override void KaydetGuncelle()
        {
            if (!_guncelle)
            {
                if (vpDogrulama.Validate())
                {
                    try
                    {
                        _kullanici = new Kullanici();

                        string hashedSifre = BCrypt.HashPassword(txtSifre.Text.Trim(), BCrypt.GenerateSalt(12));
                        _kullanici.KullaniciAdi   = txtKullaniciAdi.Text.Trim();
                        _kullanici.AdSoyad        = txtAdSoyad.Text.Trim();
                        _kullanici.Sifre          = hashedSifre;
                        _kullanici.AdminKullanici = chbAdminKullanici.Checked;
                        _kullanici.Durum          = Convert.ToByte(chbDurum.Checked);
                        _kullanici.Ekleyen        = MevcutKullanici.KullaniciId;
                        _kullanici.Guncelleyen    = MevcutKullanici.KullaniciId;
                        _kullanici.KullaniciId    = Kullanici.InsertKullanici(_kullanici);

                        XtraMessageBox.Show("Veritabanına ekleme işlemi başarılı!", "Uyarı", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        FormuTemizle(false);
                        _sonKullaniciAdi = "";
                    }

                    catch (Exception ex)
                    {
                        CommonHelper.WriteLog("Kullanici Kartı Veri Ekleme.", ex.Message);
                        XtraMessageBox.Show("Ekleme işlemi sırasında hata meydana geldi! " + ex.Message, "Uyarı",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    XtraMessageBox.Show("Boş bırakılamaz! Alanları kontrol ediniz! ", "Uyarı", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                }
            }
            else
            {
                if (vpDogrulama.Validate())
                {
                    try
                    {
                        _kullanici = new Kullanici();
                        string hashedSifre = BCrypt.HashPassword(txtSifre.Text.Trim(), BCrypt.GenerateSalt(12));
                        _kullanici.KullaniciId    = _kullaniciId;
                        _kullanici.KullaniciAdi   = txtKullaniciAdi.Text.Trim();
                        _kullanici.AdSoyad        = txtAdSoyad.Text.Trim();
                        _kullanici.AdminKullanici = chbAdminKullanici.Checked;
                        _kullanici.Durum          = Convert.ToByte(chbDurum.Checked);
                        _kullanici.Guncelleyen    = MevcutKullanici.KullaniciId;
                        if (chbSifreDegistir.Checked)
                        {
                            _kullanici.Sifre = hashedSifre;
                            Kullanici.UpdateKullanici(_kullanici);
                        }
                        else
                        {
                            Kullanici.UpdateKullaniciSifresiz(_kullanici);
                        }
                        XtraMessageBox.Show("Güncelleme işlemi başarılı! ", "Uyarı", MessageBoxButtons.OK,
                                            MessageBoxIcon.Information);
                        FormuTemizle(false);
                        _sonKullaniciAdi = "";
                    }
                    catch (SqlException ex)
                    {
                        if (ex.Number == 2601)
                        {
                            CommonHelper.WriteLog("Veri değişimi", ex.Message);
                            XtraMessageBox.Show("Değişim yapılan veri zaten mevcut! " + ex.Message, "Uyarı",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            XtraMessageBox.Show("Veriler veritabanında güncellenemedi! Hata: " + ex.Message, "Uyarı",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    catch (Exception ex)
                    {
                        CommonHelper.WriteLog("Kullanıcı Kartı Güncelleme.", ex.Message);
                        XtraMessageBox.Show("Ekleme işlemi sırasında hata meydana geldi! " + ex.Message, "Uyarı",
                                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    XtraMessageBox.Show("Boş bırakılamaz! Alanları kontrol ediniz! ", "Uyarı", MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                }
            }
        }