Ejemplo n.º 1
0
        public override bool LoadFromDB(DBManager db, string sqlCriteria)
        {
            OdbcDataReader reader = db.Query("SELECT * FROM promotion WHERE " + sqlCriteria);

            if (!reader.Read())
            {
                return(false);
            }
            bool result = Promotion.CreateForm(reader, this);

            // Load course list

            result = Promotion.LoadCourseList(db, this);
            return(result);
        }
Ejemplo n.º 2
0
        // Extract to multiple Registration
        // TODO: Check duplicated student-course
        public override bool AddToDB(DBManager db)
        {
            if ((_modCourses == null) && (_modPromotions == null))
            {
                return(false);
            }

            LinkedList <Registration> regList = new LinkedList <Registration>();
            DateTime now = DateTime.Now;

            CreateTransactionCode(db, now);

            // Promotion
            if (_modPromotions != null)
            {
                foreach (Promotion p in _modPromotions)
                {
                    if (!Promotion.LoadCourseList(db, p))
                    {
                        continue;
                    }

                    int accumDiscountedCost = 0;
                    int accumFullCost       = 0;
                    for (int i = 0; i < p._courses.Length; i++)
                    {
                        Course c = p._courses[i];
                        int    fullCostByRatio       = (int)(((float)c._cost / (float)p._fullCost) * p._cost);
                        int    discountedCostByRatio = (int)(((float)c._cost / (float)p._fullCost) * p._discountedCost);
                        accumFullCost       += fullCostByRatio;
                        accumDiscountedCost += discountedCostByRatio;
                        // asjust to last course
                        if ((_isAdjustCost) && (i + 1 == p._courses.Length))
                        {
                            int fragmentFullCost       = p._cost - accumFullCost;
                            int fragmentDiscountedCost = p._discountedCost - accumDiscountedCost;
                            // adjust
                            fullCostByRatio       += fragmentFullCost;
                            discountedCostByRatio += fragmentDiscountedCost;
                        }

                        Registration reg = new Registration();
                        //reg._transactionID = this._transactionID;
                        // reg._regisID;  auto_increament
                        reg._regisdate      = now;
                        reg._studentID      = this._studentID;
                        reg._courseID       = c._courseID;
                        reg._promotionID    = p._promotionID;
                        reg._branchID       = this._branchID;
                        reg._fullCost       = fullCostByRatio;
                        reg._discountedCost = discountedCostByRatio;
                        reg._seatNo         = (string)_seatNoMap[reg._courseID.ToString()];
                        reg._note           = (string)_noteMap[reg._courseID.ToString()];
                        reg._username       = this._username;
                        reg._status         = 0;
                        reg._paidMethod     = this._paidMethod;
                        reg._paidRound      = 0;
                        reg._paiddate       = this._paiddate;
                        reg._isPaid         = false;

                        regList.AddLast(reg);
                    }
                }
            }
            // Course
            if (_modCourses != null)
            {
                foreach (Course c in _modCourses)
                {
                    Registration reg = new Registration();
                    //reg._transactionID = this._transactionID;
                    // reg._regisID;  auto_increament
                    reg._regisdate      = now;
                    reg._studentID      = this._studentID;
                    reg._courseID       = c._courseID;
                    reg._promotionID    = 0;
                    reg._branchID       = this._branchID;
                    reg._fullCost       = c._cost;
                    reg._discountedCost = c._discountedCost;
                    reg._seatNo         = (string)_seatNoMap[reg._courseID.ToString()];
                    reg._note           = (string)_noteMap[reg._courseID.ToString()];
                    reg._username       = this._username;
                    reg._status         = 0;
                    reg._paidMethod     = this._paidMethod;
                    reg._paidRound      = 0;
                    reg._paiddate       = this._paiddate;
                    reg._isPaid         = false;

                    regList.AddLast(reg);
                }
            }

            db.BeginTransaction(IsolationLevel.ReadCommitted);

            SynchronizedAddToDB(db, this, regList);

            db.Commit();

            return(true);
        }