Ejemplo n.º 1
0
 public void CreateSerialMax(SerialMax objSerialMax)
 {
     if (objSerialMax != null)
     {
         try
         {
             db.SerialMaxes.Add(objSerialMax);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             log.Fatal(ex);
         }
     }
 }
Ejemplo n.º 2
0
 public void CreateSerialMax(SerialMax objSerialMax)
 {
     if (objSerialMax != null)
     {
         try
         {
             db.SerialMaxes.Add(objSerialMax);
             db.SaveChanges();
         }
         catch (Exception ex)
         {
             log.Fatal(ex);
         }
     }
 }
Ejemplo n.º 3
0
 public void UpdateSerialMax(SerialMax objSerialMax)
 {
     if (objSerialMax != null)
     {
         try
         {
             SerialMax objTemp = db.SerialMaxes.FirstOrDefault(o => o.Id == objSerialMax.Id);
             if (objTemp != null)
             {
                 objTemp.input_time = objSerialMax.input_time;
                 objTemp.MaxSerial = objSerialMax.MaxSerial;
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             log.Fatal(ex);
         }
     }
 }
Ejemplo n.º 4
0
 public void UpdateSerialMax(SerialMax objSerialMax)
 {
     if (objSerialMax != null)
     {
         try
         {
             SerialMax objTemp = db.SerialMaxes.FirstOrDefault(o => o.Id == objSerialMax.Id);
             if (objTemp != null)
             {
                 objTemp.input_time = objSerialMax.input_time;
                 objTemp.MaxSerial  = objSerialMax.MaxSerial;
                 db.SaveChanges();
             }
         }
         catch (Exception ex)
         {
             log.Fatal(ex);
         }
     }
 }
Ejemplo n.º 5
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;
        }