Example #1
0
        public JenisBayarModel Save(JenisBayarModel jenisBayar)
        {
            if (jenisBayar == null)
            {
                throw new ArgumentNullException(nameof(jenisBayar));
            }
            if (jenisBayar.JenisBayarID == "")
            {
                throw new ArgumentException("JenisBayarID empty");
            }

            if (jenisBayar.JenisBayarName == "")
            {
                throw new ArgumentException("JenisBayarName invalid");
            }

            var dummy = _jenisBayarDal.GetData(jenisBayar.JenisBayarID);

            if (dummy == null)
            {
                _jenisBayarDal.Insert(jenisBayar);
            }
            else
            {
                _jenisBayarDal.Update(jenisBayar);
            }

            return(jenisBayar);
        }
Example #2
0
        public IEnumerable <JenisBayarModel> ListData()
        {
            List <JenisBayarModel> result = null;
            var sSql = @"
                SELECT
                    aa.JenisBayarID, 
                    aa.JenisBayarName, aa.JenisKasID, aa.NoUrut,
                    ISNULL(bb.JenisKasName, '') JenisKasName,
                    ISNULL(bb.TipeKas, '') TipeKas
                FROM
                    JenisBayar aa 
                    LEFT JOIN JenisKas bb ON aa.JenisKasID = bb.JenisKasID ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            result = new List <JenisBayarModel>();
                            while (dr.Read())
                            {
                                var item = new JenisBayarModel
                                {
                                    JenisBayarID   = dr["JenisBayarID"].ToString(),
                                    JenisBayarName = dr["JenisBayarName"].ToString(),
                                    JenisKasID     = dr["JenisKasID"].ToString(),
                                    JenisKasName   = dr["JenisKasName"].ToString(),
                                    NoUrut         = Convert.ToInt16(dr["NoUrut"]),
                                    TipeKas        = dr["TipeKas"].ToString(),
                                };
                                result.Add(item);
                            }
                        }
                    }
                }
            return(result);
        }
Example #3
0
        public void Insert(JenisBayarModel jenisBayar)
        {
            var sSql = @"
                INSERT INTO
                    JenisBayar (
                        JenisBayarID, JenisBayarName, JenisKasID,
                        NoUrut)
                VALUES (
                        @JenisBayarID, @JenisBayarName, @JenisKasID,
                        @NoUrut) ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@JenisBayarID", jenisBayar.JenisBayarID);
                    cmd.AddParam("@JenisBayarName", jenisBayar.JenisBayarName);
                    cmd.AddParam("@JenisKasID", jenisBayar.JenisKasID);
                    cmd.AddParam("@NoUrut", jenisBayar.NoUrut);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Example #4
0
        public JenisBayarModel GetData(string id)
        {
            JenisBayarModel result = null;
            var             sSql   = @"
                SELECT
                    aa.JenisBayarName, aa.JenisKasID, aa.NoUrut,
                    ISNULL(bb.JenisKasName, '') JenisKasName,
                    ISNULL(bb.TipeKas, '') TipeKas
                FROM
                    JenisBayar aa
                    LEFT JOIN JenisKas bb ON aa.JenisKasID = bb.JenisKasID
                WHERE
                    aa.JenisBayarID = @JenisBayarID ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@JenisBayarID", id);
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (dr.HasRows)
                        {
                            dr.Read();
                            result = new JenisBayarModel
                            {
                                JenisBayarID   = id,
                                JenisBayarName = dr["JenisBayarName"].ToString(),
                                JenisKasID     = dr["JenisKasID"].ToString(),
                                JenisKasName   = dr["JenisKasName"].ToString(),
                                NoUrut         = Convert.ToInt16(dr["NoUrut"]),
                                TipeKas        = dr["TipeKas"].ToString(),
                            };
                        }
                    }
                }
            return(result);
        }
Example #5
0
        public void Update(JenisBayarModel jenisBayar)
        {
            var sSql = @"
                UPDATE
                    JenisBayar 
                SET
                    JenisBayarName = @JenisBayarName,
                    JenisKasID = @JenisKasID,
                    NoUrut = @NoUrut
                WHERE
                    JenisBayarID = @JenisBayarID ";

            using (var conn = new SqlConnection(_connString))
                using (var cmd = new SqlCommand(sSql, conn))
                {
                    cmd.AddParam("@JenisBayarID", jenisBayar.JenisBayarID);
                    cmd.AddParam("@JenisBayarName", jenisBayar.JenisBayarName);
                    cmd.AddParam("@JenisKasID", jenisBayar.JenisKasID);
                    cmd.AddParam("@NoUrut", jenisBayar.NoUrut);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }