Ejemplo n.º 1
0
 public DataAnggotaDto InserOrUpdate(DataAnggotaDto Dto)
 {
     if (Dto.Id == 0)
     {
         Dto = Insert(Dto);
     }
     else
     {
         Dto = Update(Dto);
     }
     return(Dto);
 }
        private void BtnSimpan_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(IdAnggota.Text) || IdAnggota.Text == "0")
                {
                    System.Windows.MessageBox.Show("Id Anggota tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                if (string.IsNullOrEmpty(NamaAnggota.Text))
                {
                    System.Windows.MessageBox.Show("Nama Anggota tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                if (string.IsNullOrEmpty(TanggalGabung.Text))
                {
                    System.Windows.MessageBox.Show("Tanggal Gabung tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                DataAnggotaDto Dto = new DataAnggotaDto();
                Dto.Id = Convert.ToInt64(Id.Text);
                var ExistID = _dataAnggotaServices.GetByIdAnggota(IdAnggota.Text);
                if (ExistID != null)
                {
                    System.Windows.MessageBox.Show("Id Anggota sudah ada", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                Dto.CreatedBy    = CreatedBy.Text;
                Dto.CreatedDate  = Convert.ToDateTime(CreatedDate.Text);
                Dto.ModifiedBy   = ModifiedBy.Text;
                Dto.ModifiedDate = Convert.ToDateTime(ModifiedDate.Text);

                Dto.IdAnggota     = Convert.ToString(IdAnggota.Text);
                Dto.NamaAnggota   = NamaAnggota.Text;
                Dto.TanggalGabung = Convert.ToDateTime(TanggalGabung.Text);
                Dto.Status        = Status.IsChecked.HasValue ? Status.IsChecked.Value : false;

                Dto = _dataAnggotaServices.InserOrUpdate(Dto);
                System.Windows.MessageBox.Show("Data sudah tersimpan", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                CloseWin();
            }
            catch (Exception ex)
            {
                LogError.WriteError(ex);
                System.Windows.MessageBox.Show("Error!! \n telah terjadi kesalahan, Hubungi administrator", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 private DataAnggotaDto CheckAnggotaExist(string IdAnggota)
 {
     try
     {
         DataAnggotaDto result       = null;
         var            CheckAnggota = _dataAnggotaServices.GetByIdAnggota(IdAnggota);
         if (CheckAnggota != null)
         {
             return(CheckAnggota);
         }
         return(result);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 4
0
        public List <DataAnggotaDto> GetAllActive()
        {
            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn = DBConnection.connect();
                List <DataAnggotaDto> ListDto = new List <DataAnggotaDto>();
                using (OleDbCommand _command = new OleDbCommand())
                {
                    _command.CommandType = CommandType.Text;
                    _command.Connection  = conn;
                    _command.CommandText = "Select * from DATA_ANGGOTA WHERE STATUS = TRUE ";

                    using (OleDbDataReader _dr = _command.ExecuteReader())
                    {
                        DataTable _dt = new DataTable();
                        _dt.Load(_dr);

                        foreach (DataRow row in _dt.AsEnumerable())
                        {
                            var Dto = new DataAnggotaDto();
                            Dto.Id            = Convert.ToInt64(row["id"]);
                            Dto.IdAnggota     = Convert.ToString(row["id_anggota"]);
                            Dto.NamaAnggota   = Convert.ToString(row["nama_anggota"]);
                            Dto.TanggalGabung = Convert.ToDateTime(row["tanggal_gabung"]);
                            Dto.Status        = Convert.ToBoolean(row["status"]);
                            Dto.ModifiedBy    = Convert.ToString(row["modified_by"]);
                            Dto.ModifiedDate  = Convert.ToDateTime(row["modified_date"]);
                            Dto.CreatedBy     = Convert.ToString(row["created_by"]);
                            Dto.CreatedDate   = Convert.ToDateTime(row["created_date"]);

                            ListDto.Add(Dto);
                        }
                    }
                }
                return(ListDto);
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        public DataAnggotaDto Insert(DataAnggotaDto Dto)
        {
            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn = DBConnection.connect();
                using (OleDbCommand _command = new OleDbCommand())
                {
                    _command.CommandType = CommandType.Text;
                    _command.Connection  = conn;
                    _command.CommandText = "INSERT INTO DATA_ANGGOTA " +
                                           "(id_anggota, nama_anggota, tanggal_gabung, status, created_date, created_by, modified_date, modified_by) " +
                                           "VALUES (@IdAnggota, @NamaAnggota, @TanggalGabung, @Status, @created_date, @created_by, @modified_date, @modified_by);";
                    _command.Parameters.AddWithValue("@IdAnggota", Dto.IdAnggota);
                    _command.Parameters.AddWithValue("@NamaAnggota", Dto.NamaAnggota);
                    _command.Parameters.AddWithValue("@TanggalGabung", Dto.TanggalGabung);
                    _command.Parameters.AddWithValue("@Status", Dto.Status);
                    _command.Parameters.AddWithValue("@created_date", DateTime.Today);
                    _command.Parameters.AddWithValue("@created_by", "Admin");
                    _command.Parameters.AddWithValue("@modified_date", DateTime.Today);
                    _command.Parameters.AddWithValue("@modified_by", "Admin");

                    _command.ExecuteNonQuery();

                    string query2 = "Select @@Identity";
                    _command.CommandText = query2;
                    int ID = (int)_command.ExecuteScalar();

                    Dto.CreatedBy    = "Admin";
                    Dto.CreatedDate  = DateTime.Today;
                    Dto.ModifiedBy   = "Admin";
                    Dto.ModifiedDate = DateTime.Today;
                    Dto.Id           = ID;
                    return(Dto);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        public DataAnggotaDto GetByIdAnggota(string IdAnggota)
        {
            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn = DBConnection.connect();
                DataAnggotaDto Dto = null;
                using (OleDbCommand _command = new OleDbCommand())
                {
                    _command.CommandType = CommandType.Text;
                    _command.Connection  = conn;
                    _command.CommandText = "Select * from DATA_ANGGOTA WHERE id_anggota =  @IdAnggota";
                    _command.Parameters.AddWithValue("@IdAnggota", IdAnggota);

                    using (OleDbDataReader _dr = _command.ExecuteReader())
                    {
                        DataTable _dt = new DataTable();
                        _dt.Load(_dr);

                        foreach (DataRow row in _dt.AsEnumerable())
                        {
                            Dto               = new DataAnggotaDto();
                            Dto.Id            = Convert.ToInt64(row["id"]);
                            Dto.IdAnggota     = Convert.ToString(row["id_anggota"]);
                            Dto.NamaAnggota   = Convert.ToString(row["nama_anggota"]);
                            Dto.TanggalGabung = Convert.ToDateTime(row["tanggal_gabung"]);
                            Dto.Status        = Convert.ToBoolean(row["status"]);
                            Dto.CreatedBy     = Convert.ToString(row["created_by"]);
                            Dto.CreatedDate   = Convert.ToDateTime(row["created_date"]);
                            Dto.ModifiedDate  = Convert.ToDateTime(row["modified_date"]);
                            Dto.ModifiedBy    = Convert.ToString(row["modified_by"]);
                        }
                    }
                }
                return(Dto);
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void BtnSimpan_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(IdAnggota.Text) || IdAnggota.Text == "0")
                {
                    System.Windows.MessageBox.Show("Id Anggota tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                if (string.IsNullOrEmpty(NamaAnggota.Text))
                {
                    System.Windows.MessageBox.Show("Nama Anggota tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                if (string.IsNullOrEmpty(TanggalGabung.Text))
                {
                    System.Windows.MessageBox.Show("Tanggal Gabung tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                DataAnggotaDto Dto = new DataAnggotaDto();
                Dto.Id            = 0;
                Dto.IdAnggota     = Convert.ToString(IdAnggota.Text);
                Dto.NamaAnggota   = NamaAnggota.Text;
                Dto.TanggalGabung = Convert.ToDateTime(TanggalGabung.Text);
                Dto.Status        = Status.IsChecked.HasValue? Status.IsChecked.Value:false;

                var CheckAnggota = CheckAnggotaExist(Dto.IdAnggota);
                if (CheckAnggota != null)
                {
                    System.Windows.MessageBox.Show("ID tersebut sudah terdaftar", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                Dto = _dataAnggotaServices.Insert(Dto);
                System.Windows.MessageBox.Show("Data sudah tersimpan", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                CloseWin();
            }
            catch (Exception ex)
            {
                LogError.WriteError(ex);
                System.Windows.MessageBox.Show("Error!! \n telah terjadi kesalahan, Hubungi administrator", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 8
0
        public DataAnggotaDto Update(DataAnggotaDto Dto)
        {
            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
                conn = DBConnection.connect();
                var GetData = GetById(Dto.Id);

                using (OleDbCommand _command = new OleDbCommand())
                {
                    _command.CommandType = CommandType.Text;
                    _command.Connection  = conn;
                    _command.CommandText = "Update DATA_ANGGOTA " +
                                           "SET id_anggota = @IdAnggota, nama_anggota =@NamaAnggota, tanggal_gabung=@TanggalGabung, status = @status, modified_date=@modified_date, modified_by=@modified_by WHERE id = @Id;";

                    _command.Parameters.AddWithValue("@IdAnggota", Dto.IdAnggota);
                    _command.Parameters.AddWithValue("@NamaAnggota", Dto.NamaAnggota);
                    _command.Parameters.AddWithValue("@TanggalGabung", Dto.TanggalGabung);
                    _command.Parameters.AddWithValue("@status", Dto.Status);
                    _command.Parameters.AddWithValue("@modified_date", DateTime.Today);
                    _command.Parameters.AddWithValue("@modified_by", "Admin");
                    _command.Parameters.AddWithValue("@Id", Dto.Id);

                    _command.ExecuteNonQuery();

                    Dto.ModifiedDate = DateTime.Today;
                    Dto.ModifiedBy   = "Admin";

                    return(Dto);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }