Beispiel #1
0
 public void PopulateData(DataKoperasiDto data)
 {
     Id.Text             = data.Id.ToString();
     total_shu.Text      = data.TotalShu.ToString();
     total_simpanan.Text = data.TotalSimpanan.ToString();
     total_belanja.Text  = data.TotalPenjualan.ToString();
     total_pinjaman.Text = data.TotalPinjaman.ToString();
     CreatedBy.Text      = data.CreatedBy;
     CreatedDate.Text    = data.CreatedDate.ToString("yyyy-MM-dd HH:mm:ss");
     ModifiedBy.Text     = data.ModifiedBy;
     ModifiedDate.Text   = data.ModifiedDate.ToString("yyyy-MM-dd HH:mm:ss");
 }
 public DataKoperasiDto InserOrUpdate(DataKoperasiDto Dto)
 {
     if (Dto.Id == 0)
     {
         Dto = Insert(Dto);
     }
     else
     {
         Dto = Update(Dto);
     }
     return(Dto);
 }
        public DataKoperasiDto Insert(DataKoperasiDto 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_KOPERASI " +
                                           "(tahun, total_shu, total_simpanan, total_penjualan, total_pinjaman, created_date, created_by, modified_date, modified_by) " +
                                           "VALUES (@Tahun, @TotalShu, @TotalSimpanan, @TotalPenjualan, @TotalPinjaman, @created_date, @created_by, @modified_date, @modified_by);";
                    _command.Parameters.AddWithValue("@Tahun", Dto.Tahun);
                    _command.Parameters.AddWithValue("@TotalShu", Dto.TotalShu);
                    _command.Parameters.AddWithValue("@TotalSimpanan", Dto.TotalSimpanan);
                    _command.Parameters.AddWithValue("@TotalPenjualan", Dto.TotalPenjualan);
                    _command.Parameters.AddWithValue("@TotalPinjaman", Dto.TotalPinjaman);
                    _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;
            }
        }
        public DataKoperasiDto Update(DataKoperasiDto 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_KOPERASI " +
                                           "SET tahun =@Tahun, total_shu =@TotalShu, total_simpanan =@TotalSimpanan, total_penjualan=@TotalPenjualan, total_pinjaman=@TotalPinjaman, created_date=@created_date, created_by=@created_by, modified_date=@modified_date, modified_by=@modified_by WHERE id = @Id;";

                    _command.Parameters.AddWithValue("@Tahun", Dto.Tahun);
                    _command.Parameters.AddWithValue("@TotalShu", Dto.TotalShu);
                    _command.Parameters.AddWithValue("@TotalSimpanan", Dto.TotalSimpanan);
                    _command.Parameters.AddWithValue("@TotalPenjualan", Dto.TotalPenjualan);
                    _command.Parameters.AddWithValue("@TotalPinjaman", Dto.TotalPinjaman);
                    _command.Parameters.AddWithValue("@created_date", GetData.CreatedDate);
                    _command.Parameters.AddWithValue("@created_by", GetData.CreatedBy);
                    _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;
            }
        }
        public DataKoperasiDto GetById(long Id)
        {
            if (conn.State == ConnectionState.Open)
            {
                conn.Close();
            }
            conn = DBConnection.connect();
            DataKoperasiDto Dto = null;

            using (OleDbCommand _command = new OleDbCommand())
            {
                _command.CommandType = CommandType.Text;
                _command.Connection  = conn;
                _command.CommandText = "Select * from DATA_KOPERASI WHERE ID =  @Id";
                _command.Parameters.AddWithValue("@Id", Id);

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

                    foreach (DataRow row in _dt.AsEnumerable())
                    {
                        Dto                = new DataKoperasiDto();
                        Dto.Id             = Convert.ToInt64(row["id"]);
                        Dto.Tahun          = Convert.ToInt32(row["tahun"]);
                        Dto.TotalShu       = Convert.ToDouble(row["total_shu"]);
                        Dto.TotalSimpanan  = Convert.ToDouble(row["total_simpanan"]);
                        Dto.TotalPenjualan = Convert.ToDouble(row["total_penjualan"]);
                        Dto.TotalPinjaman  = Convert.ToDouble(row["total_pinjaman"]);
                        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);
        }
Beispiel #6
0
        private void BtnSimpan_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var Dto = new DataKoperasiDto();

                if (string.IsNullOrEmpty(total_shu.Text))
                {
                    System.Windows.MessageBox.Show("Total SHU tidak boleh kosong", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                if (string.IsNullOrEmpty(total_belanja.Text))
                {
                    total_belanja.Text = "0";
                }

                if (string.IsNullOrEmpty(total_simpanan.Text))
                {
                    total_simpanan.Text = "0";
                }

                if (string.IsNullOrEmpty(total_pokok.Text))
                {
                    total_pokok.Text = "0";
                }

                if (string.IsNullOrEmpty(total_wajib.Text))
                {
                    total_wajib.Text = "0";
                }

                if (string.IsNullOrEmpty(total_sukarela.Text))
                {
                    total_sukarela.Text = "0";
                }

                if (string.IsNullOrEmpty(total_pinjaman.Text))
                {
                    total_pinjaman.Text = "0";
                }



                if (!string.IsNullOrEmpty(Id.Text))
                {
                    Dto.Id = Convert.ToInt32(Id.Text);
                }

                Dto.Tahun          = Convert.ToInt32(Tahun.Text);
                Dto.TotalShu       = Convert.ToDouble(total_shu.Text);
                Dto.TotalPenjualan = Convert.ToDouble(total_belanja.Text);
                Dto.TotalPinjaman  = Convert.ToDouble(total_pinjaman.Text);
                Dto.TotalSimpanan  = Convert.ToDouble(total_simpanan.Text);

                _dataKoperasiServices.InserOrUpdate(Dto);
                PopulateData(Dto);
                System.Windows.MessageBox.Show("Data sudah tersimpan", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (Exception ex)
            {
                LogError.WriteError(ex);
                System.Windows.MessageBox.Show("Error!! \n telah terjadi kesalahan, Hubungi administrator", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }