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(); }
public static void SOD() { if (!LogBLL.IsLogged()) { FinalizeStoreInPast(); OrderBLL.CloseOrder(); FacilityBLL.ResetCounting(); LogBLL.Logs(RedBloodSystem.SODActor); } }
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(); }
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(); }
//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(); }
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(); }
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); }