示例#1
0
        /// <summary>
        /// Submit Data based on parameter input form car Rental
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            int  id     = 0;
            int  days   = 0;
            int  carQty = 0;
            bool res    = false;

            string myStr = string.Empty;

            if (CbModel.SelectedValue != null)
            {
                myStr = CbModel.SelectedValue.ToString();
            }
            res = int.TryParse(myStr, out id);

            if (!string.IsNullOrEmpty(TbDaysQty.Text))
            {
                myStr = TbDaysQty.Text;
            }
            res = int.TryParse(myStr, out days);

            if (!string.IsNullOrEmpty(TbCarQty.Text))
            {
                myStr = TbCarQty.Text;
            }
            res = int.TryParse(myStr, out carQty);

            try
            {
                IEnumerable <CarsModel> query = hasilx.Where(s => s.Id == id).ToList();
                if (query != null && query.Count() > 0)
                {
                    obj.ModelYear  = Convert.ToInt32(query.Select(x => x.ModelYear).First().ToString());
                    obj.TotalDay   = days;
                    obj.Car        = query.Select(x => x.ModelName).First().ToString() + " | ";
                    obj.Car       += query.Select(x => x.SeriesName).First().ToString();
                    obj.QtyCar     = carQty;
                    obj.TotalPrice = Convert.ToDecimal(query.Select(x => x.RentCost).First().ToString());
                    obj.Discount   = processor.GetDiscountValue(obj.TotalDay, obj.QtyCar, obj.ModelYear);
                    obj.TotalPrice = obj.TotalPrice * obj.QtyCar * obj.TotalDay;
                    // Price after discount

                    obj.TotalPrice -= ((obj.TotalPrice * obj.Discount) / 100);
                    obj.CreateDate  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");

                    List <TransactionModel> _items = new List <TransactionModel>();
                    _items.Add(obj);
                    datagridTransactionData = new BindingList <TransactionModel>(_items.ToList());
                    DGResult.DataSource     = datagridTransactionData;
                    DGResult.Columns[5].DefaultCellStyle.Format = "c";
                }
            }
            catch (Exception err)
            {
                throw err;
            }
        }
        public void GetDiscountValueTest()
        {
            //Arrange
            var bm = new TransactionProcessor();

            obj.VarInput0  = 3;    // days length
            obj.VarInput01 = 2;    // car qty
            obj.VarInput02 = 2009; // year of car model
            obj.VarOutput  = 22;

            //Act
            obj.VarExpected = bm.GetDiscountValue(obj.VarInput0, obj.VarInput01, obj.VarInput02);

            //Assert
            Assert.AreEqual(obj.VarOutput, obj.VarExpected);
            bm.Dispose();
        }