Exemplo n.º 1
0
        public ParamNoModel GetById(string id)
        {
            //  ambil dari parameter database
            TransactionOptions tranOption = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            ParamNoModel retVal = null;

            using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, tranOption))
            {
                retVal = _paramNoDal.GetById(id);

                //  jika belum ada param tsb
                if (retVal == null)
                {
                    retVal = new ParamNoModel
                    {
                        Prefix = id,
                        Value  = 1
                    };
                    _paramNoDal.Insert(retVal);
                }
                retVal.Value++;
                _paramNoDal.Update(retVal);
                tran.Complete();
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public ParamNoModel GetById(string id)
        {
            ParamNoModel retVal = null;

            string sSql = @"
                SELECT      fs_prefix, fn_value
                FROM        tz_param_no
                WHERE       fs_prefix = @Prefix ";

            using (SqlConnection conn = new SqlConnection(_connString))
                using (SqlCommand cmd = new SqlCommand(sSql, conn))
                {
                    cmd.Parameters.AddWithValue("@Prefix", id);
                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows)
                    {
                        dr.Read();
                        retVal        = new ParamNoModel();
                        retVal.Prefix = dr["fs_prefix"].ToString();
                        retVal.Value  = Convert.ToInt64(dr["fn_value"].ToString());
                    }
                }
            return(retVal);
        }
Exemplo n.º 3
0
        private string GenNewID(IParamNoKey key)
        {
            /*  Cek apakah paramkey sudah ada di database
             *  Jika sudah ada, ambil nilai-nya, setu retVal,
             *  dan tambahkan satu (hexa-desimal mode)
             */
            var param = _paramNoDal.GetData(key);

            if (param == null)
            {
                param = new ParamNoModel
                {
                    ParamID    = key.ParamID,
                    ParamValue = "0"
                }
            }
            ;
            var retVal = param.ParamValue;

            param.ParamValue = AddHexa(param.ParamValue, "1");
            _paramNoDal.Delete(key);
            _paramNoDal.Insert(param);

            return(retVal);
        }
Exemplo n.º 4
0
        public IParamNoModel GetData(IParamNoKey key)
        {
            ParamNoModel result = null;
            var          sql    = @"
                SELECT
                    ParamValue
                FROM
                    OFTA_ParamNo
                WHERE
                    ParamID = @ParamID ";

            using (var conn = new SqlConnection(ConnStringHelper.Get()))
                using (var cmd = new SqlCommand(sql, conn))
                {
                    cmd.AddParam("@ParamID", key.ParamID, SqlDbType.VarChar);
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (!dr.HasRows)
                        {
                            return(null);
                        }
                        dr.Read();
                        result = new ParamNoModel()
                        {
                            ParamID    = key.ParamID,
                            ParamValue = dr["ParamValue"].ToString()
                        };
                    }
                }
            return(result);
        }
Exemplo n.º 5
0
        public IEnumerable <IParamNoModel> ListData()
        {
            List <ParamNoModel> result = null;
            var sql = @"
                SELECT
                    ParamID, ParamValue
                FROM
                    OFTA_ParamNo ";

            using (var conn = new SqlConnection(ConnStringHelper.Get()))
                using (var cmd = new SqlCommand(sql, conn))
                {
                    conn.Open();
                    using (var dr = cmd.ExecuteReader())
                    {
                        if (!dr.HasRows)
                        {
                            return(null);
                        }
                        result = new List <ParamNoModel>();
                        while (dr.Read())
                        {
                            var itemResult = new ParamNoModel()
                            {
                                ParamID    = dr["ParamID"].ToString(),
                                ParamValue = dr["ParamValue"].ToString()
                            };
                            result.Add(itemResult);
                        }
                    }
                }
            return(result);
        }
Exemplo n.º 6
0
        public void ParamNoDal_Update_Test()
        {
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 1
            };

            paramNoDal.Update(paramNo);
        }
Exemplo n.º 7
0
        public void ParamNoDal_Insert_Test()
        {
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 1
            };

            paramNoDal.Insert(paramNo);
        }
Exemplo n.º 8
0
        public string FormatKode(ParamNoModel paramNo, int length, string suffix)
        {
            string strValue      = Convert.ToString(paramNo.Value).Trim();
            int    appliedLength = length - paramNo.Prefix.Length - suffix.Length;

            if (appliedLength > 0)
            {
                return(paramNo.Prefix + strValue.PadLeft(appliedLength, '0') + suffix);
            }
            else
            {
                return(paramNo.Prefix + strValue + suffix);
            }
        }
Exemplo n.º 9
0
        public void ParamNoDal_GetById_Test()
        {
            //  arrange
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 1
            };

            paramNoDal.Insert(paramNo);

            //  act
            var dummy = paramNoDal.GetById("AA");
        }
Exemplo n.º 10
0
        public void ParamNoDal_Delete_Test()
        {
            //  arrange
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 1
            };

            paramNoDal.Insert(paramNo);

            //  act
            paramNoDal.Delete("AA");
        }
Exemplo n.º 11
0
        /// <summary>
        ///     FormatKode();
        ///     Length di parameter lebih kecil dari Prefix + Suffic
        ///     => Expect Succeed
        /// </summary>        [TestMethod()]
        public void ParamNoBL_FormatKode2_Test()
        {
            //  arrange
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 112
            };

            //  act
            var dummy = _paramNoBL.FormatKode(paramNo, 5, "A");

            //  assert
            Assert.IsTrue(dummy == "AA112A");
        }
Exemplo n.º 12
0
        public void Update(ParamNoModel paramNo)
        {
            string sSql = @"
                UPDATE      tz_param_no
                SET         fn_value = @Value
                WHERE       fs_prefix = @Prefix ";

            using (SqlConnection conn = new SqlConnection(_connString))
                using (SqlCommand cmd = new SqlCommand(sSql, conn))
                {
                    cmd.Parameters.AddWithValue("@Prefix", paramNo.Prefix);
                    cmd.Parameters.AddWithValue("@Value", paramNo.Value);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Exemplo n.º 13
0
        public void Insert(ParamNoModel paramNo)
        {
            string sSql = @"
                INSERT INTO tz_param_no
                            (fs_prefix, fn_value)
                VALUES      (@Prefix, @Value) ";

            using (SqlConnection conn = new SqlConnection(_connString))
                using (SqlCommand cmd = new SqlCommand(sSql, conn))
                {
                    cmd.Parameters.AddWithValue("@Prefix", paramNo.Prefix);
                    cmd.Parameters.AddWithValue("@Value", paramNo.Value);
                    conn.Open();
                    cmd.ExecuteNonQuery();
                }
        }
Exemplo n.º 14
0
        public void ParamNoBL_GetById_Test()
        {
            //  arrange
            ParamNoModel paramNo = new ParamNoModel
            {
                Prefix = "AA",
                Value  = 2
            };

            _paramNoDal.Stub(x => x.GetById("AA")).Return(paramNo);

            //  act
            var value = _paramNoBL.GetById("AA");

            //  assert
            _paramNoDal.AssertWasCalled(x => x.Update(Arg <ParamNoModel>
                                                      .Matches(y => y.Prefix == "AA" && y.Value == 3)));
        }
Exemplo n.º 15
0
        public string GenNewID(string prefix, ParamNoLengthEnum length)
        {
            /*  CI-206-0000-00A = Code_15
             *  US-206-00-00A   = Code_13
             *  BE-206-00A      = Code_10
             *  PG001           = Code_5
             */

            var periode = DateTime.Now.ToString("yy");

            switch (DateTime.Now.Month)
            {
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
            case 9:
                periode += DateTime.Now.Month.ToString();
                break;

            case 10:
                periode += "A";
                break;

            case 11:
                periode += "B";
                break;

            case 12:
                periode += "C";
                break;
            }

            var param = new ParamNoModel
            {
                ParamID = $"{prefix}-{periode}"
            };

            if (length == ParamNoLengthEnum.Code_5)
            {
                param.ParamID = prefix;
            }

            var    noUrutHex  = GenNewID(param);
            var    random     = new Random();
            var    checkDigit = random.Next(0, 9);
            string noUrutBlok = "";

            switch (length)
            {
            case ParamNoLengthEnum.Code_10:
                noUrutBlok = $"{noUrutHex.PadLeft(2, '0')}{checkDigit}";
                break;

            case ParamNoLengthEnum.Code_13:
                noUrutBlok = $"{noUrutHex.PadLeft(4, '0')}";
                noUrutBlok = $"{noUrutBlok.Substring(0, 2)}-{noUrutBlok.Substring(2, 2)}";
                noUrutBlok = $"{noUrutBlok}{checkDigit}";

                break;

            case ParamNoLengthEnum.Code_15:
                noUrutBlok = $"{noUrutHex.PadLeft(6, '0')}";
                noUrutBlok = $"{noUrutBlok.Substring(0, 4)}-{noUrutBlok.Substring(4, 2)}";
                noUrutBlok = $"{noUrutBlok}{checkDigit}";
                break;

            case ParamNoLengthEnum.Code_5:
                noUrutBlok = $"{noUrutHex.PadLeft(3, '0')}";
                break;

            default:
                break;
            }

            var result = $"{prefix}-{periode}-{noUrutBlok}";

            if (length == ParamNoLengthEnum.Code_5)
            {
                result = $"{prefix}{noUrutBlok}";
            }
            return(result);
        }
Exemplo n.º 16
0
        public void Save(JadwalHariModel jadwal)
        {
            //--validasi
            //  dokter
            if (_dokterBL.GetById(jadwal.KodeDokter).Nama.Trim() == "")
            {
                throw new ArgumentException("Invalid DOKTER");
            }

            //  layanan
            if (_layananBL.GetById(jadwal.KodeLayanan).Nama.Trim() == "")
            {
                throw new ArgumentException("Invalid LAYANAN");
            }

            //  hari
            if (jadwal.Hari < 1 || jadwal.Hari > 7)
            {
                throw new ArgumentException("Invalid HARI");
            }

            //  jam mulai
            TimeSpan jamMulai;

            if (!TimeSpan.TryParse(jadwal.JamMulai, out jamMulai))
            {
                throw new ArgumentException("Invalid JAM MULAI");
            }

            //  jam selesai
            TimeSpan jamSelesai;

            if (!TimeSpan.TryParse(jadwal.JamSelesai, out jamSelesai))
            {
                throw new ArgumentException("Invalid JAM SELESAI");
            }

            //  urutan jam mulai-jam selesai
            if (TimeSpan.Compare(jamMulai, jamSelesai) == 1)
            {
                throw new ArgumentException("Invalid JAM MULAI-SELESAI");
            }

            //--validasi detil per jam
            foreach (JadwalHariPerJamModel item in jadwal.JadwalPerJams)
            {
                //  format jam
                TimeSpan jamDetil;
                if (!TimeSpan.TryParse(item.Jam, out jamDetil))
                {
                    throw new ArgumentException("Invalid Format Detil JAM");
                }

                //  jam detil harus berada di range jam di header
                if (TimeSpan.Compare(jamMulai, jamDetil) == 1)
                {
                    throw new ArgumentException("Invalid Range Detil JAM");
                }
                if (TimeSpan.Compare(jamDetil, jamSelesai) == 1)
                {
                    throw new ArgumentException("Invalid Range Detil JAM");
                }

                //  booked tidak boleh melebihi max
                if (item.Booked > item.Max)
                {
                    throw new ArgumentException("Invalid BOOKED QTY");
                }
            }

            //  cek duplikasi dokter-hari-jam (case beda jadwal sama (ini)))
            //      ambil data header
            var result =
                from jadwalJam in jadwal.JadwalPerJams
                group jadwalJam by jadwalJam.Jam into jamGroup
                select new { Jam = jamGroup.Key, Count = jamGroup.Count() };

            if (result.ToList().Exists(x => x.Count > 1))
            {
                throw new ArgumentException("Duplicated JAM PRAKTEK");
            }


            TransactionOptions tranOption = new TransactionOptions
            {
                IsolationLevel = IsolationLevel.ReadCommitted
            };

            using (TransactionScope tran = new TransactionScope(TransactionScopeOption.Required, tranOption))
            {
                //  generate kode jadwal jika kosong
                if (jadwal.Kode.Trim() == "")
                {
                    ParamNoModel paramNo = _paramNoBL.GetById("JD");
                    jadwal.Kode = _paramNoBL.FormatKode(paramNo, 5, "");
                    _jadwalHariDal.Insert(jadwal);
                }
                else
                {
                    _jadwalHariDal.Update(jadwal);
                }
                tran.Complete();
            }
        }