Example #1
0
        public TPromotion ApplyRule(TPromotion promObj, string ruleName = "")
        {
			RuleSet newRule = null;

			TPromotion promOutputObj = new TPromotion();
			promObj.OutputObj = new OutputObject();

			string path = Assembly.GetExecutingAssembly().Location.Replace(Assembly.GetExecutingAssembly().ManifestModule.Name, String.Empty);

			if(String.IsNullOrEmpty(ruleName))
			{
				ruleName = promObj.InputObj.OfferCode;

				newRule = RulesEvaluator<TPromotion>.LaunchNewRulesDialog(ruleName, path);

				promOutputObj = RulesEvaluator<TPromotion>.ProcessRule(promObj, newRule);
			}
			else
			{
				newRule = RulesEvaluator<TPromotion>.LoadRule(path, ruleName);

				promOutputObj = RulesEvaluator<TPromotion>.ProcessRule(promObj, newRule);
			}
			
			return promOutputObj;
       }
Example #2
0
		private void button2_Click(object sender, EventArgs e)
		{
			TPromotion promObj = new TPromotion();
			promObj.InputObj = new InputObject();

			if (!String.IsNullOrEmpty(textBox1.Text))
			{
				promObj.InputObj.OfferCode = textBox1.Text;
			}
			else
			{
				label2.Text = "Please enter the offer code";
				label2.ForeColor = System.Drawing.Color.Red;
				return;
			}


			if (!String.IsNullOrEmpty(textBox2.Text) && Convert.ToDecimal(textBox2.Text) > 0)
			{
				promObj.InputObj.OrderValue = Convert.ToDecimal(textBox2.Text);
			}
			else
			{
				label2.Text = "Please enter vaild amount";
				label2.ForeColor = System.Drawing.Color.Red;
				return;
			}

			if(!String.IsNullOrEmpty(textBox13.Text))
			{
				promObj.InputObj.DOJ = DateTime.Parse(textBox13.Text);
				promObj.InputObj.DayOfWeek = promObj.InputObj.DOJ.DayOfWeek.ToString();
			}

			if(!String.IsNullOrEmpty(textBox16.Text))
			{
				promObj.InputObj.RouteId = textBox16.Text;
			}

			if (!String.IsNullOrEmpty(textBox10.Text))
			{
				promObj.InputObj.NumOfSeatsForBooking = Convert.ToInt32(textBox10.Text);
			}

			if (!String.IsNullOrEmpty(textBox20.Text))
			{
				promObj.InputObj.NumOfAdvanceBookingDays = Convert.ToInt32(textBox20.Text);
			}

			if (!String.IsNullOrEmpty(textBox21.Text))
			{
				promObj.InputObj.MinuteCountBeforeDept = Convert.ToInt32(textBox21.Text);
			}

			RuleController ruleCtrlObj = new RuleController();

			TPromotion promOutputObj = null;
			if (!String.IsNullOrEmpty(textBox3.Text))
			{
				promOutputObj = ruleCtrlObj.ApplyRule(promObj, textBox3.Text);
			}
			else
			{
				promOutputObj = ruleCtrlObj.ApplyRule(promObj);
			}

			if (promOutputObj != null && promOutputObj.OutputObj != null && promObj.OutputObj.Discount != 0)
			{
				decimal finalFare = (decimal)(promObj.InputObj.OrderValue - promOutputObj.OutputObj.Discount);
				label2.Text = "Congratulations!!! You have got an offer of Rs. " + promOutputObj.OutputObj.Discount.ToString()
								+ "\r\n Final Fare : Rs. " + finalFare;
				label2.ForeColor = System.Drawing.Color.Green;
			}
			else
			{
				label2.Text = "Oops!!! You are not eligible for this offer.";
				label2.ForeColor = System.Drawing.Color.Red;
			} 
		}