Ejemplo n.º 1
0
        public void Execute(PriceCalculationContext context)
        {
            var matcher    = new PromotionMatcher(_ruleEngine);
            var promotions = _promotionService.Query().WhereAvailableNow().ToList();

            var matches = matcher.MatchApplicablePromotions(context, promotions);

            foreach (var match in matches)
            {
                var policy = _policyFactory.FindByName(match.Promotion.PromotionPolicyName);
                if (policy == null)
                {
                    throw new InvalidOperationException("Cannot load promotion policy with name '" + match.Promotion.PromotionPolicyName + "'. Ensure corresponding add-in has been installed.");
                }

                object config = null;
                if (policy.ConfigType != null)
                {
                    config = match.Promotion.LoadPolicyConfig(policy.ConfigType);
                }

                policy.Execute(new PromotionContext(match.Promotion, config, match.ConditionMatchedItems, context));
                context.AppliedPromotions.Add(match.Promotion);
            }
        }
Ejemplo n.º 2
0
        protected void ProcessWizListSelectedCourse(string enableAction, bool recalculatePromotion)
        {
            bool enableAct;

            Boolean.TryParse(enableAction, out enableAct);

            outBuf.Append("<br>");
            // get data from session
            RegisTransaction reg = (RegisTransaction)Session[SessionVar.CURRENT_REGIS];

            if (reg == null)
            {
                return;
            }
            if (reg._courses.Count == 0)
            {
                outBuf.Append("&nbsp&nbspยังไม่ได้เลือกคอร์ส");
            }

            if (recalculatePromotion)
            {
                // copy to temp list
                Course[] courses = new Course[reg._courses.Count];
                reg._courses.CopyTo(courses, 0);
                LinkedList <Course> copyCourses = new LinkedList <Course>(courses);

                // find matching promotions
                DBManager db = new MySQLDBManager(Config.DB_SERVER, Config.DB_NAME, Config.DB_USER, Config.DB_PASSWORD, Config.DB_CHAR_ENC);

                PromotionMatcher matcher = Promotion.LoadFromDBByMatchingCourses(db, reg._courses);
                db.Close();

                // store back to reg
                reg._modCourses    = (matcher._matchedCourses != null) ? matcher._matchedCourses : new LinkedList <Course>();
                reg._modPromotions = (matcher._matchedPromotions != null) ? matcher._matchedPromotions : new LinkedList <Promotion>();
                Session[SessionVar.CURRENT_REGIS] = reg;
            }

            // print
            Promotion[] proArray = new Promotion[reg._modPromotions.Count];
            reg._modPromotions.CopyTo(proArray, 0);

            int sumCost     = 0;
            int sumFullCost = 0;

            outBuf.Append("<table>");
            for (int i = 0; i < proArray.Length; i++)
            {
                sumCost += proArray[i]._discountedCost;
                outBuf.Append("<tr valign=middle><td>&nbsp&nbsp&nbsp</td><td>" + Promotion.GetPromotionID(proArray[i]._promotionID) + " " + proArray[i]._promotionName);
                string costTxt = StringUtil.Int2StrComma(proArray[i]._discountedCost);
                if (!enableAct)
                {
                    costTxt = " <a href=\"javascript:modifyPCost(" + proArray[i]._promotionID + "," + proArray[i]._discountedCost + ")\" >" + StringUtil.Int2StrComma(proArray[i]._discountedCost) + "</a>";
                }
                if (proArray[i]._cost != proArray[i]._discountedCost)
                {
                    costTxt = " <strike>" + StringUtil.Int2StrComma(proArray[i]._cost) + "</strike> &nbsp ลดพิเศษเหลือ " + costTxt;
                }

                outBuf.Append(" ( <strike>" + StringUtil.Int2StrComma(proArray[i].GetFullCost()) + "</strike> &nbsp" + costTxt + " )</td></tr>");
                for (int j = 0; j < proArray[i]._courses.Length; j++)
                {
                    Course c = proArray[i]._courses[j];
                    sumFullCost += c._cost;
                    string jsShowDiv  = " onmouseover=\"queryCourseDetail(" + c._courseID + ");showDivAt('divdetail')\" onmouseout=\"hideDiv('divdetail')\" ";
                    string icon       = "<img style=\"cursor:pointer\" border=0 src=\"" + Config.URL_PIC_SYS + "/info.gif\" " + jsShowDiv + ">";
                    string courseLine = c._btsCourseID + "&nbsp" + c._courseName;
                    string costLine   = " ( <strike>" + StringUtil.Int2StrComma(c._cost) + "</strike> )";

                    if (enableAct)
                    {
                        courseLine = "<a href=\"javascript:removeCourse('" + c._courseID + "')\">" + courseLine + "</a>";
                    }
                    outBuf.Append("<tr valign=middle><td>&nbsp&nbsp" + icon + "</td><td>&nbsp&nbsp&nbsp" + courseLine + costLine + "</td></tr>");
                    // remove from copied list
                    //copyCourses.Remove(c);
                }
            }

            // print no promotion
            foreach (Course c in reg._modCourses)
            {
                sumCost     += c._discountedCost;
                sumFullCost += c._cost;
                string jsShowDiv  = " onmouseover=\"queryCourseDetail(" + c._courseID + ");showDivAt('divdetail')\" onmouseout=\"hideDiv('divdetail')\" ";
                string icon       = "<img style=\"cursor:pointer\" border=0 src=\"" + Config.URL_PIC_SYS + "/info.gif\" " + jsShowDiv + ">";
                string courseLine = c._btsCourseID + "&nbsp" + c._courseName;
                if (enableAct)
                {
                    courseLine = "<a href=\"javascript:removeCourse('" + c._courseID + "')\">" + courseLine + "</a>";
                }

                string costTxt = " ( ";
                if (c._cost != c._discountedCost)
                {
                    costTxt = costTxt + " <strike>" + StringUtil.Int2StrComma(c._cost) + "</strike> &nbsp ลดพิเศษเหลือ ";
                }
                if (!enableAct)
                {
                    costTxt = costTxt + "<a href=\"javascript:modifyCCost(" + c._courseID + "," + c._discountedCost + ")\" >" + StringUtil.Int2StrComma(c._discountedCost) + "</a> )";
                }
                else
                {
                    costTxt = costTxt + StringUtil.Int2StrComma(c._discountedCost) + " )";
                }

                outBuf.Append("<tr valign=middle><td>&nbsp&nbsp" + icon + "</td><td>" + courseLine + costTxt + "</td></tr>");
            }
            outBuf.Append("</table><br><br>");
            outBuf.Append("&nbsp&nbsp<b>รวมค่าใช้จ่ายทั้งหมด <strike>" + StringUtil.Int2StrComma(sumFullCost) + "</strike>&nbsp<font size=2 color=red>" + StringUtil.Int2StrComma(sumCost) + "</font> บาท</b>");
        }