public virtual void CalculateCruiseExpense(IList costTypes, IDictionary <CostType, double> serviceTotal, int adultHaiPhong, int childHaiPhong, CruiseExpenseTable cruiseTable) { CostType cruise = null; foreach (CostType type in costTypes) { if (type.Id == SailsModule.HAIPHONG) { cruise = type; break; } } if (cruise != null) { double haiphong = adultHaiPhong + childHaiPhong / 2; if (haiphong > 0) { int index = -1; for (int ii = 0; ii < cruiseTable.Expenses.Count; ii++) { CruiseExpense cExpense = (CruiseExpense)cruiseTable.Expenses[ii]; if (cExpense.CustomerFrom <= haiphong && cExpense.CustomerTo >= haiphong) { index = ii; break; } } if (index < 0) { throw new Exception("Hai phong cruise price is not valid, can not find price for " + haiphong + " persons"); } serviceTotal[cruise] += ((CruiseExpense)cruiseTable.Expenses[index]).Price; } } }
public virtual void CalculateCruiseExpense(IList costTypes, IDictionary <CostType, double> serviceTotal, int adultHaiPhong, int childHaiPhong, CruiseExpenseTable cruiseTable) { CostType cruise = null; foreach (CostType type in costTypes) { if (type.Id == SailsModule.HAIPHONG) { cruise = type; break; } } // Nếu tồn tại loại chi phí có ID giống như cấu hình cứng tại SailsModule.HAIPHONG if (cruise != null) { // Tính số khách dùng để tính giá double haiphong = adultHaiPhong + childHaiPhong / 2; if (haiphong > 0) { #region Dò tìm dòng giá tàu Hải Phong phù hợp với số khách int index = -1; for (int ii = 0; ii < cruiseTable.Expenses.Count; ii++) { CruiseExpense cExpense = (CruiseExpense)cruiseTable.Expenses[ii]; if (cExpense.CustomerFrom <= haiphong && cExpense.CustomerTo >= haiphong) { index = ii; break; } } if (index < 0) { throw new Exception("Hai phong cruise price is not valid, can not find price for " + haiphong + " persons"); } #endregion #region Dựa vào dòng giá, tính chi phí serviceTotal[cruise] += ((CruiseExpense)cruiseTable.Expenses[index]).Price; // Nếu đúng bằng, lấy luôn giá này //if (((CruiseExpense)cruiseTable.Expenses[index]).CustomerFrom == haiphong) //{ // serviceTotal[cruise] += ((CruiseExpense)cruiseTable.Expenses[index]).Price; //} //else //{ // if (index < 1) // { // throw new Exception("Hai phong cruise price is not valid, can not calculate for " + // haiphong + // " persons"); // } // CruiseExpense upperExpense = (CruiseExpense)cruiseTable.Expenses[index]; // CruiseExpense lowerExpense = (CruiseExpense)cruiseTable.Expenses[index - 1]; // if (lowerExpense.CustomerTo != upperExpense.CustomerFrom - 1) // { // throw new Exception("Hai phong cruise price is not valid, price table must be continity"); // } // // Nếu nhỏ hơn thì có 2 trường hợp: nhỏ hơn và nằm trong khoảng nhỏ // if (lowerExpense.CustomerTo > haiphong) // { // // Công thức sai toét, nhưng tạm thời bỏ qua // serviceTotal[cruise] += lowerExpense.Price * haiphong / // (lowerExpense.CustomerTo - lowerExpense.CustomerFrom + 1); // } // else // { // serviceTotal[cruise] += lowerExpense.Price + // (upperExpense.Price - lowerExpense.Price) * // (haiphong - lowerExpense.CustomerTo); // } //} #endregion } } }