Esempio n. 1
0
        public static void Backup(DateTime date)
        {
            Validate(date);

            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            RedBloodDataContext db = new RedBloodDataContext();

            if (db.PackRemainDailies.Where(r => r.Date.Value.Date == date.Date).Count() > 0)
            {
                LogBLL.LogsFailAndThrow(err + "Existing data.");
            }

            IQueryable <Pack> rows = db.Packs.Where(r => r.Status == Pack.StatusX.Product);

            //Insert
            foreach (Pack item in rows)
            {
                PackRemainDaily r = new PackRemainDaily();
                r.PackID = item.ID;
                r.Status = item.Status;
                r.Date   = date;
                r.Note   = "Process on: " + DateTime.Now.ToString();

                db.PackRemainDailies.InsertOnSubmit(r);
            }

            db.SubmitChanges();

            LogBLL.Logs();
        }
Esempio n. 2
0
        public static void SOD()
        {
            if (!LogBLL.IsLogged())
            {
                FinalizeStoreInPast();
                OrderBLL.CloseOrder();
                FacilityBLL.ResetCounting();

                LogBLL.Logs(RedBloodSystem.SODActor);
            }
        }
Esempio n. 3
0
        public static void Clear(DateTime date)
        {
            Validate(date);

            RedBloodDataContext db = new RedBloodDataContext();

            var v = db.PackRemainDailies.Where(r => r.Date == date.Date);

            db.PackRemainDailies.DeleteAllOnSubmit(v);
            db.SubmitChanges();

            LogBLL.Logs();
        }
Esempio n. 4
0
        public static void FinalizeStoreInPast()
        {
            GetAndValidateFinalizeData();

            DateTime yesterday = DateTime.Now.Date.AddDays(-1);
            DateTime startDate = lastFinalizeDate.HasValue ? lastFinalizeDate.Value.Date.AddDays(1) : yesterday;

            for (DateTime i = startDate; i < DateTime.Now.Date; i = i.Date.AddDays(1))
            {
                StoreFinalizeBLL.FinalizeStore(i, false);
            }

            LogBLL.Logs();
        }
Esempio n. 5
0
        //public static void Add(int ID, string DIN, string productCode)
        //{
        //    Order r = OrderBLL.Get(ID);

        //    if (r.Status == Order.StatusX.Done)
        //        throw new Exception("Đợt cấp phát này đã kết thúc.");

        //    Pack p = PackBLL.Get4Order(DIN, productCode);

        //    PackOrder po = new PackOrder();
        //    po.OrderID = r.ID;
        //    po.PackID = p.ID;
        //    po.Status = PackOrder.StatusX.Order;

        //    RedBloodDataContext db = new RedBloodDataContext();

        //    db.PackOrders.InsertOnSubmit(po);

        //    db.SubmitChanges();

        //    string fullNote = "Add to Order: " + po.OrderID.Value.ToString() + ".";

        //    PackBLL.Update(db, po.Pack, Pack.StatusX.Delivered, fullNote);

        //    PackTransaction.TypeX transType = r.Type == Order.TypeX.ForCR ? PackTransaction.TypeX.Out_Order4CR
        //        : r.Type == Order.TypeX.ForOrg ? PackTransaction.TypeX.Out_Order4Org
        //        : PackTransaction.TypeX.Out_OrderGen;

        //    PackTransactionBLL.Add(p.ID,
        //        transType,
        //        fullNote);
        //}

        //public static void Remove(int packOrderID, string note)
        //{
        //    RedBloodDataContext db = new RedBloodDataContext();

        //    PackOrder po = db.PackOrders.Where(r => r.ID == packOrderID).FirstOrDefault();

        //    if (po == null
        //        || po.Pack == null
        //        || po.Order == null) return;

        //    string fullNote = DateTime.Now.ToStringVNLong() + ". " + RedBloodSystem.CurrentActor + ". Remove from Order: " + po.OrderID.Value.ToString() + ". " + note;

        //    PackBLL.Update(db, po.Pack, Pack.StatusX.Product, fullNote);

        //    po.Status = PackOrder.StatusX.Return;
        //    po.Note = fullNote;

        //    db.SubmitChanges();

        //    PackTransactionBLL.Add(po.Pack.ID, PackTransaction.TypeX.In_Return, fullNote);

        //}

        public static void CloseOrder()
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var v = db.Orders.Where(r => r.Status == Order.StatusX.Init &&
                                    r.Date.Value.Date < DateTime.Now.Date).ToList();

            foreach (var item in v)
            {
                item.Status = Order.StatusX.Done;
            }

            db.SubmitChanges();

            LogBLL.Logs();
        }
Esempio n. 6
0
        public static int CountPackRemainByStoreFinalize(DateTime date)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var v = db.StoreFinalizes.Where(r => r.Date == date.Date &&
                                            r.Type == PackTransaction.TypeX.Remain)
                    .Select(r => r.Count);

            if (v.Count() > 1)
            {
                LogBLL.LogsFailAndThrow("Data Err.");
            }

            int?i = v.FirstOrDefault();

            return(i.HasValue ? i.Value : 0);
        }
Esempio n. 7
0
        private static bool Validate(DateTime date)
        {
            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            if (date.Date > DateTime.Now.Date)
            {
                LogBLL.LogsFailAndThrow(MyMethodBase.Current.Caller, err + "Date is in future.");
            }

            RedBloodDataContext db = new RedBloodDataContext();

            if (db.PackRemainDailies.Where(r => r.Date.Value.Date > date.Date).Count() > 0)
            {
                LogBLL.LogsFailAndThrow(MyMethodBase.Current.Caller, err + "Existing newer data.");
            }

            return(true);
        }
Esempio n. 8
0
        public static int Add(DateTime date, PackTransaction.TypeX type, int count)
        {
            if (Get(date, type) != null)
            {
                LogBLL.LogsFailAndThrow("Existing datat.");
            }

            RedBloodDataContext db = new RedBloodDataContext();

            StoreFinalize s = new StoreFinalize();

            s.Date  = date;
            s.Type  = type;
            s.Count = count;
            s.Note  = "Process on: " + DateTime.Now.ToString();

            db.StoreFinalizes.InsertOnSubmit(s);
            db.SubmitChanges();

            return(1);
        }
Esempio n. 9
0
        public static int CountPackRemainByPackStatus()
        {
            DateTime date = DateTime.Now.Date;

            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            RedBloodDataContext db = new RedBloodDataContext();

            if (db.PackTransactions.Where(r => r.Date.Value.Date > date).Count() > 0)
            {
                LogBLL.LogsFailAndThrow(err + "Data error. Having pack transaction in future.");
            }

            if (db.Packs.Where(r => r.Date.Value.Date > date).Count() > 0)
            {
                LogBLL.LogsFailAndThrow(err + "Data error. Having pack in future.");
            }

            int count = db.Packs.Where(r => r.Status == Pack.StatusX.Product).Count();

            return(count);
        }
Esempio n. 10
0
        public static int CountPackRemainByLastDayRemain(DateTime date)
        {
            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            if (date.Date > DateTime.Now.Date)
            {
                LogBLL.LogsFailAndThrow(err + "Date is in future.");
            }

            RedBloodDataContext db = new RedBloodDataContext();

            DateTime previousDate   = date.Date.AddDays(-1);
            int      previousRemain = CountPackRemainByStoreFinalize(previousDate);

            var v1 = CountPackTransaction(date);

            int?i = (previousRemain
                     + v1.Where(r => r.Type > 0).Sum(r => r.Count)
                     - v1.Where(r => r.Type < 0).Sum(r => r.Count)
                     );

            return(i.HasValue ? i.Value : 0);
        }
Esempio n. 11
0
        public static void Clear(DateTime date)
        {
            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            if (date.Date > DateTime.Now.Date)
            {
                LogBLL.LogsFailAndThrow(err + "Date is in future.");
            }

            RedBloodDataContext db = new RedBloodDataContext();

            if (db.StoreFinalizes.Where(r => r.Date.Value.Date > date.Date).Count() > 0)
            {
                LogBLL.LogsFailAndThrow(err + "Existing newer data.");
            }

            var v = db.StoreFinalizes.Where(r => r.Date == date.Date);

            db.StoreFinalizes.DeleteAllOnSubmit(v);
            db.SubmitChanges();

            LogBLL.Logs();
        }
Esempio n. 12
0
        static bool GetAndValidateFinalizeData()
        {
            GetLastFinalizeDate();

            if (
                !lastFinalizeDate.HasValue &&
                !lastPackTransactionDate.HasValue &&
                !lastBackupPackRemainDate.HasValue
                )
            {
                return(true);
            }

            if (
                lastFinalizeDate.HasValue && lastFinalizeDate.Value.Date > DateTime.Now.Date ||
                (lastPackTransactionDate.HasValue && lastPackTransactionDate.Value.Date > DateTime.Now.Date) ||
                (lastBackupPackRemainDate.HasValue && lastBackupPackRemainDate.Value.Date > DateTime.Now.Date)
                )
            {
                LogBLL.LogsFailAndThrow("Error. Data or Date in future.");
            }

            if (lastFinalizeDate < lastBackupPackRemainDate)
            {
                LogBLL.LogsFailAndThrow("Error. lastFinalizeDate != lastBackupPackRemainDate");
            }

            if (lastFinalizeDate.HasValue &&
                !lastPackTransactionDate.HasValue
                )
            {
                if (lastFinalizeDate == firstFinalizeDate)
                {
                }
                else
                {
                    LogBLL.LogsFailAndThrow("Error. lastFinalizeDate.HasValue && !lastPackTransactionDate.HasValue");
                }
            }

            if (lastPackTransactionDate.HasValue)
            {
                if (lastFinalizeDate.HasValue)
                {
                    int days = (lastPackTransactionDate.Value.Date - lastFinalizeDate.Value.Date).Days;

                    if (days == 0 || days == 1)
                    {
                    }
                    else
                    {
                        //LogBLL.LogsFailAndThrow("Error. days == 0 || days == 1 fail.");
                    }
                }
                else
                {
                    if (firstPackTransactionDate != lastPackTransactionDate)
                    {
                        LogBLL.LogsFailAndThrow("firstPackTransactionDate != lastPackTransactionDate");
                    }
                }
            }

            return(true);
        }
Esempio n. 13
0
        public static void FinalizeStore(DateTime date, bool overwrite)
        {
            string err = "Process for day: " + date.Date.ToShortDateString() + ". ";

            DateTime?firstFinalizeDate;
            DateTime?lastFinalizeDate;
            DateTime?lastPackTransactionDate;
            DateTime?firstPackTransactionDate;
            DateTime?lastBackupPackRemainDate;

            RedBloodSystemBLL.GetLastFinalizeDate(out firstFinalizeDate, out lastFinalizeDate, out lastPackTransactionDate, out firstPackTransactionDate, out lastBackupPackRemainDate);

            if (date.Date > DateTime.Now.Date ||
                lastFinalizeDate.HasValue && lastFinalizeDate.Value.Date > DateTime.Now.Date ||
                (lastPackTransactionDate.HasValue && lastPackTransactionDate.Value.Date > DateTime.Now.Date) ||
                (lastBackupPackRemainDate.HasValue && lastBackupPackRemainDate.Value.Date > DateTime.Now.Date)
                )
            {
                LogBLL.LogsFailAndThrow(err + "Error. Data or Date in future.");
            }

            //Data in DB is newer. Data error or system datetime error
            if (
                (lastFinalizeDate.HasValue && lastFinalizeDate.Value.Date > date.Date) ||
                (lastPackTransactionDate.HasValue && lastPackTransactionDate.Value.Date > date.Date) ||
                (lastBackupPackRemainDate.HasValue && lastBackupPackRemainDate.Value.Date > date.Date)
                )
            {
                LogBLL.LogsFailAndThrow(err + "Newer data in DB.");
            }

            if (lastFinalizeDate.HasValue)
            {
                int daysBefore = (date.Date - lastFinalizeDate.Value.Date).Days;

                if (daysBefore != 0 &&
                    daysBefore != 1)
                {
                    LogBLL.LogsFailAndThrow(err + "Data should be finalized with in or 1 day before.");
                }

                if (daysBefore == 0)
                {
                    if (overwrite)
                    {
                        //Clear StoreFinalizes
                        StoreFinalizeBLL.Clear(date);

                        //Clear PackRemainDailies
                        PackRemainDailyBLL.Clear(date);
                    }
                    else
                    {
                        LogBLL.LogsFailAndThrow(err + "Aldready finilized. Set overwrite=true to re-finilized.");
                    }
                }
            }

            StoreFinalizeBLL.CountPackTransaction(date).Select(r => StoreFinalizeBLL.Add(r.Date.Value, r.Type, r.Count.Value)).ToList();
            StoreFinalizeBLL.Add(date, PackTransaction.TypeX.Remain, StoreFinalizeBLL.CountPackRemainByPackStatus());
            PackRemainDailyBLL.Backup(date);

            LogBLL.Logs(err);
        }