コード例 #1
0
        public static PackTransaction Add(Guid packID, Pack.StatusX fromStatus, Pack.StatusX toStatus, PackTransaction.TypeX type, string note)
        {
            //Always run SOD before new transaction
            RedBloodSystemBLL.SOD();

            RedBloodDataContext db = new RedBloodDataContext();

            if (fromStatus == toStatus)
            {
                throw new Exception("Can not add pack transaction if not change pack status.");
            }

            PackTransaction e = new PackTransaction();

            e.FromStatus = fromStatus;
            e.ToStatus   = toStatus;
            e.PackID     = packID;
            e.Type       = type;
            e.Actor      = RedBloodSystem.CurrentActor;
            e.Note       = note.Trim();

            db.PackTransactions.InsertOnSubmit(e);

            db.SubmitChanges();

            return(e);
        }
コード例 #2
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);
        }