Exemple #1
0
        public bool GetSerialBookByBookNumber(SerialBook objSerialBook, DateTime dtFrom, DateTime dtTo, ref string strResponse)
        {
            bool result = false;
            strResponse = string.Empty;
            if (objSerialBook == null)
            {

            }
            else
            {
                TimeSpan ts = objSerialBook.MaturityDate - objSerialBook.ValueDate;
                int nPeriod = (int)(ts.TotalDays / 30);
                int nRemain = (int)(ts.TotalDays % 30);
                if (nRemain >= 28) nPeriod++;
                objSerialBook.Period = nPeriod;

                if (objSerialBook.Period > 0)
                {
                    //month
                    CalculateSerialByMonth(objSerialBook);
                }
                else
                {
                    //week
                    CalculateSerialByWeek(objSerialBook, nRemain);
                }
                //initiate serial number 
                string[] strSerials = GenerateSerialNumber();
                ArrayList arrMasoduthuongs = new ArrayList();
                SerialMax objSerialMax = new SerialMax();
                using (Promotion.DataModel.SerialMax_BO objSerialMax_BO = new SerialMax_BO())
                {
                    objSerialMax = objSerialMax_BO.GetTop(1, dtFrom, dtTo).FirstOrDefault();
                }
                long lIndex = 0;
                if (objSerialMax != null)
                {
                    lIndex += objSerialMax.MaxSerial;
                }

                if ((lIndex + objSerialBook.Soluong) < Constant.MAX_SERIAL_COUNT)
                {
                    long nIdx = lIndex + objSerialBook.Soluong;
                    using (Promotion.DataModel.SerialMax_BO objSerialMax_BO = new SerialMax_BO())
                    {
                        objSerialMax = objSerialMax_BO.GetTop(1, dtFrom, dtTo).FirstOrDefault();
                        long lSerial = long.Parse(strSerials[nIdx]);
                        if (objSerialMax != null)
                        {
                            objSerialMax.MaxSerial = lSerial;
                            objSerialMax.input_time = DateTime.Now;
                            objSerialMax_BO.UpdateSerialMax(objSerialMax);
                        }
                        else
                        {
                            objSerialMax = new SerialMax();
                            objSerialMax.MaxSerial = lSerial;
                            objSerialMax.input_time = DateTime.Now;
                            objSerialMax_BO.CreateSerialMax(objSerialMax);
                        }
                    }
                    for (long nIndex = (lIndex + 1); nIndex <= (lIndex + objSerialBook.Soluong); nIndex++)
                    {
                        arrMasoduthuongs.Add(strSerials[nIndex]);
                    }
                }
                else if ((lIndex + objSerialBook.Soluong) >= Constant.MAX_SERIAL_COUNT)
                {
                    List<DelSerial> arrDel = new List<DelSerial>();
                    using (Promotion.DataModel.DelSerial_BO objDelSerial_BO = new DelSerial_BO())
                    {
                        arrDel = objDelSerial_BO.GetByDatTime(dtFrom, dtTo).ToList();
                    }

                    if ((lIndex + objSerialBook.Soluong) > (Constant.MAX_SERIAL_COUNT + arrDel.Count))
                    {
                        long nRemainSerial = (Constant.MAX_SERIAL_COUNT - lIndex) + arrDel.Count;
                        strResponse = string.Format("Không đủ mã dự thưởng để cấp.Số lượng mã dự thưởng còn lại {0}, số lượng phải cấp {1}.", nRemainSerial, (objSerialBook.Soluong));
                        log.Info(strResponse);
                    }
                    using (Promotion.DataModel.SerialMax_BO objSerialMax_BO = new SerialMax_BO())
                    {

                        objSerialMax = objSerialMax_BO.GetTop(1, dtFrom, dtTo).FirstOrDefault();
                        long lSerial = long.Parse(strSerials[Constant.MAX_SERIAL_COUNT]);

                        if (objSerialMax != null)
                        {
                            objSerialMax.MaxSerial = lSerial;
                            objSerialMax.input_time = DateTime.Now;
                            objSerialMax_BO.UpdateSerialMax(objSerialMax);
                        }
                        else
                        {
                            objSerialMax = new SerialMax();
                            objSerialMax.MaxSerial = lSerial;
                            objSerialMax.input_time = DateTime.Now;
                            objSerialMax_BO.CreateSerialMax(objSerialMax);
                        }
                    }
                    int nSerialCount = 0;
                    for (long i = lIndex + 1; i <= Constant.MAX_SERIAL_COUNT; i++)
                    {
                        nSerialCount++;
                        arrMasoduthuongs.Add(strSerials[i]);
                    }
                    if (nSerialCount < objSerialBook.Soluong)
                    {
                        using (Promotion.DataModel.DelSerial_BO objDelSerial_BO = new DelSerial_BO())
                        {
                            foreach (DelSerial oSerial in arrDel)
                            {
                                if (nSerialCount >= objSerialBook.Soluong)
                                {
                                    break;
                                }
                                arrMasoduthuongs.Add(oSerial.Serial);
                                objDelSerial_BO.DeleteDelSerial(oSerial.Id);
                                nSerialCount++;
                            }
                        }
                    }
                }
                objSerialBook.Masoduthuongs = (string[])arrMasoduthuongs.ToArray(typeof(string));
                result = true;
            }
            return result;
        }
Exemple #2
0
 public bool DeleteSerialBookByBookNumber(string strBook_Number, string strSavedBy, DateTime dtFrom, DateTime dtTo, ref string strResponse)
 {
     bool result = false;
     strResponse = string.Empty;
     using (Promotion.DataModel.SerialResult_BO objSerialResult_BO = new SerialResult_BO())
     {
         DataModel.SerialResult objSerialResult = objSerialResult_BO.GetByBook_numberAndInput_time(strBook_Number, dtFrom, dtTo);
         if (objSerialResult != null)
         {
             string strSerials = objSerialResult.Serials;
             string[] Serials = null;
             if (strSerials.Length > 0)
             {
                 strSerials = strSerials.Substring(0, strSerials.Length - 1);
                 Serials = strSerials.Split("|".ToCharArray());
             }
             else
             {
                 ArrayList arrTmp = new ArrayList();
                 Serials = (string[])arrTmp.ToArray(typeof(string));
             }
             log.Info(strSerials);
             using (Promotion.DataModel.DelSerial_BO objDelSerial_BO = new DelSerial_BO())
             {
                 for (int nIndex = 0; nIndex < Serials.Length; nIndex++)
                 {
                     DelSerial objDelSerial = new DelSerial();
                     objDelSerial.book_number = objSerialResult.book_number;
                     objDelSerial.Serial = Serials[nIndex];
                     objDelSerial.input_time = DateTime.Now;
                     objDelSerial.SavedBy = strSavedBy;
                     objDelSerial_BO.CreateDelSerial(objDelSerial);
                     log.Info(strBook_Number + ": Xóa " + Serials[nIndex]);
                 }
             }
             objSerialResult.DeletedBy = strSavedBy;
             objSerialResult.DeletedDate = DateTime.Now;
             objSerialResult_BO.DeleteSerialResult(objSerialResult);
             result = true;
         }
         else
         {
             strResponse = string.Format("Số sổ {0} không tồn tại.", strBook_Number);
             log.Info(strResponse);
         }
     }
     return result;
 }