Example #1
0
        public static void Update(string DIN, string bloodGroup, string note)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation e = DonationBLL.Get(db, DIN);

            if (e == null)
            {
                throw new Exception(DonationErrEnum.NonExist.Message);
            }

            if (!CanUpdateTestResult(e))
            {
                throw new Exception(DonationErrEnum.TRLocked.Message);
            }

            if (bloodGroup.Trim() != e.BloodGroup)
            {
                e.BloodGroup = bloodGroup;
                DonationTestLogBLL.Insert(db, e, PropertyName.For <Donation>(r => r.BloodGroup), note);
            }

            //Have to save before updaye TestResult Status
            db.SubmitChanges();

            UpdateTestResultStatus(e);
            db.SubmitChanges();
        }
Example #2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Donation d = DonationBLL.Get(db, DIN);

        if (d == null)
        {
            Clear();
        }
        else
        {
            //TODO: Check to see too late to update
            // Code check will be here

            d.Collector = txtCollector.Text.Trim();

            if (d.Pack != null)
            {
                d.Pack.Volume = txtVolume.Text.ToInt();
                d.Pack.Note   = txtNote.Text.Trim();
            }

            d.Note = txtNote.Text.Trim();

            db.SubmitChanges();

            this.Alert("Lưu thành công.");
        }
    }
Example #3
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);
        }
        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();
        }
Example #5
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();
        }
        public static void Add(int orderID, string DIN, string productCode)
        {
            //using (TransactionScope scope = new TransactionScope())
            //{
            //    scope.Complete();
            //}

            RedBloodDataContext db = new RedBloodDataContext();

            Order r = OrderBLL.Get4Add(orderID);
            Pack p = PackBLL.Get4Order(DIN, productCode);

            var check_po = db.PackOrders.FirstOrDefault(r1 => r1.PackID == p.ID
                                                            && r1.OrderID == r.ID && r1.ReturnID == null);
            if (check_po == null)
            {
                PackOrder po = new PackOrder();
                po.OrderID = r.ID;
                po.PackID = p.ID;

                db.PackOrders.InsertOnSubmit(po);
                db.SubmitChanges();

                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;

                PackBLL.ChangeStatus(p.ID, Pack.StatusX.Delivered, transType, "PackOrderID = " + po.ID.ToString());
            }
            else {
                throw new Exception("Túi máu đã có trong đợt cấp phát này.");
            }
        }
Example #7
0
    public string Delete(int ID)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        TestDef c = (from i in db.TestDefs
                     where i.ID == ID
                     select i).First();

        if (c == null)
        {
            return("");
        }

        Delete_Route(c, db);

        try
        {
            db.SubmitChanges();
            return("");
        }
        catch (Exception)
        {
            return("Dữ liệu đã được sử dụng. Không thể xóa.");
        }
    }
Example #8
0
        public static DonationErr Assign(string DIN, Guid peopleID, int campaignID, DateTime?collectedDate, string actor)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation d = (from c in db.Donations
                          where c.DIN == DIN && c.PeopleID == null && c.CampaignID == null
                          select c).FirstOrDefault();

            if (d == null)
            {
                return(DonationErrEnum.NonExist);
            }

            try
            {
                d.PeopleID      = peopleID;
                d.CollectedDate = collectedDate;
                d.CampaignID    = campaignID;
                d.Actor         = actor;

                UpdateStatus(db, d, Donation.StatusX.Assigned, "Assign peopleID=" + peopleID.ToString() + "&CampaignID=" + campaignID.ToString());

                db.SubmitChanges();

                CampaignBLL.SetStatus(campaignID);
            }
            catch (Exception ex)
            {
                return(new DonationErr(ex.Message));
            }

            return(DonationErrEnum.Non);
        }
Example #9
0
        //Only pack has status 0 can be remove, to re-assign to another people.
        public static Pack RemovePeople(int autonum)
        {
            if (autonum == 0)
            {
                return(null);
            }

            RedBloodDataContext db = new RedBloodDataContext();

            //Pack p = Get(db, autonum, Pack.StatusX.Collected);
            Pack p = new Pack();

            //if (p == null && p.PeopleID != null) return p;
            //if (p.TestResultStatus != Pack.TestResultStatusX.Non) return p;

            ////remove people
            //p.PeopleID = null;
            //p.CollectedDate = null;
            //p.CampaignID = null;

            //PackStatusHistory h = ChangeStatus(db, p, Pack.StatusX.Init, "Remove peopleID=" + p.PeopleID.ToString() + "&CampaignID=" + p.CampaignID.ToString());
            //db.PackStatusHistories.InsertOnSubmit(h);

            db.SubmitChanges();

            return(p);
        }
Example #10
0
        public static DonationErr Assign(string DIN, Guid peopleID, int campaignID, DateTime? collectedDate, string actor)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation d = (from c in db.Donations
                          where c.DIN == DIN && c.PeopleID == null && c.CampaignID == null
                          select c).FirstOrDefault();

            if (d == null)
            {
                return DonationErrEnum.NonExist;
            }

            try
            {
                d.PeopleID = peopleID;
                d.CollectedDate = collectedDate;
                d.CampaignID = campaignID;
                d.Actor = actor;

                UpdateStatus(db, d, Donation.StatusX.Assigned, "Assign peopleID=" + peopleID.ToString() + "&CampaignID=" + campaignID.ToString());

                db.SubmitChanges();

                CampaignBLL.SetStatus(campaignID);
            }
            catch (Exception ex)
            {
                return new DonationErr(ex.Message);
            }

            return DonationErrEnum.Non;
        }
    public void NewProfile(string username, string fullname, string phone)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        var users = from u in db.aspnet_Users
                    where u.UserName == username
                    select u;

        if (users.Count() != 1)
        {
            return;
        }

        aspnet_User user = users.First();

        aspnet_UserProfile user_profile = new aspnet_UserProfile();

        user_profile.UserID   = user.UserId;
        user_profile.Fullname = fullname;
        user_profile.Phone    = phone;

        if (user.aspnet_UserProfile == null)
        {
            db.aspnet_UserProfiles.InsertOnSubmit(user_profile);
            db.SubmitChanges();
        }
    }
Example #12
0
        static public void Delete(int ID)
        {
            RedBloodDataContext db = new RedBloodDataContext();
            Campaign            e  = Get(ID, db);

            db.Campaigns.DeleteOnSubmit(e);
            db.SubmitChanges();
        }
Example #13
0
    public static void Delete(int ID)
    {
        RedBloodDataContext db = new RedBloodDataContext();
        Campaign e = Get(ID, db);

        db.Campaigns.DeleteOnSubmit(e);
        db.SubmitChanges();
    }
Example #14
0
    private static Guid?ImportPeople(RedBloodDataContext db, People outerP)
    {
        //Importing people
        if (outerP == null || db == null)
        {
            return(null);
        }

        People innerP = PeopleBLL.GetByID(outerP.ID);

        if (innerP == null)
        {
            People newP = new People();

            newP.Name    = outerP.Name;
            newP.DOB     = outerP.DOB;
            newP.DOBYear = outerP.DOBYear;
            newP.CMND    = outerP.CMND;
            newP.SexID   = outerP.SexID;

            GeoBLL.Insert(
                outerP.ResidentGeo1 != null ? outerP.ResidentGeo1.Name : ""
                , outerP.ResidentGeo2 != null ? outerP.ResidentGeo2.Name : ""
                , outerP.ResidentGeo3 != null ? outerP.ResidentGeo3.Name : "");

            newP.ResidentAddress = outerP.ResidentAddress;
            newP.SetResidentGeo3(outerP.FullResidentalGeo);

            if (outerP.EnableMailingAddress.HasValue &&
                outerP.EnableMailingAddress.Value)
            {
                GeoBLL.Insert(
                    outerP.MailingGeo1 != null ? outerP.MailingGeo1.Name : ""
                    , outerP.MailingGeo2 != null ? outerP.MailingGeo2.Name : ""
                    , outerP.MailingGeo3 != null ? outerP.MailingGeo3.Name : "");

                newP.MailingAddress = outerP.MailingAddress;
                newP.SetMailingGeo3(outerP.FullMaillingGeo);

                newP.EnableMailingAddress = outerP.EnableMailingAddress;
            }

            newP.Job   = outerP.Job;
            newP.Email = outerP.Email;
            newP.Phone = outerP.Phone;
            newP.Note  = outerP.Note;

            db.Peoples.InsertOnSubmit(newP);
            db.SubmitChanges();

            return(newP.ID);
        }
        else
        {
            return(innerP.ID);
        }
    }
Example #15
0
        public static List <Donation> New(int count)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            List <Donation> l = New(db, count);

            db.SubmitChanges();
            return(l);
        }
Example #16
0
    public static void Delete(Guid ID)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Receipt e = Get(ID, db);

        db.Receipts.DeleteOnSubmit(e);
        db.SubmitChanges();
    }
Example #17
0
        public static void Delete(Guid ID)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Receipt e = Get(ID, db);

            db.Receipts.DeleteOnSubmit(e);
            db.SubmitChanges();
        }
Example #18
0
        public static DonationErr Update(string DIN,
                                         string HIV, string HCV_Ab, string HBs_Ag, string Syphilis, string Malaria,
                                         string note, bool updateIfAllNon = false)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation e = DonationBLL.Get(db, DIN);

            if (e == null || !CanUpdateTestResult(e))
            {
                return(DonationErrEnum.TRLocked);
            }

            string old = e.InfectiousMarkers;

            if (!updateIfAllNon ||
                (updateIfAllNon && e.Markers.IsAllNon)
                )
            {
                // Warning: As CR user requirement, value for both test result are always the same.
                e.InfectiousMarkers = Infection.HIV_Ab.Encode(e.InfectiousMarkers, HIV);
                e.InfectiousMarkers = Infection.HIV_Ag.Encode(e.InfectiousMarkers, HIV);

                e.InfectiousMarkers = Infection.HCV_Ab.Encode(e.InfectiousMarkers, HCV_Ab);
                e.InfectiousMarkers = Infection.HBs_Ag.Encode(e.InfectiousMarkers, HBs_Ag);
                e.InfectiousMarkers = Infection.Syphilis.Encode(e.InfectiousMarkers, Syphilis);
                e.InfectiousMarkers = Infection.Malaria.Encode(e.InfectiousMarkers, Malaria);

                if (old != e.InfectiousMarkers)
                {
                    DonationTestLogBLL.Insert(db, e, PropertyName.For <Donation>(r => r.Markers), note);
                }

                //Have to save before update TestResult Status
                db.SubmitChanges();

                UpdateTestResultStatus(e);
                db.SubmitChanges();
            }

            return(DonationErrEnum.Non);
        }
        public Guid Insert(string name)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Sex e = new Sex();
            e.Name = name;

            db.Sexes.InsertOnSubmit(e);
            db.SubmitChanges();
            return e.ID;
        }
Example #20
0
    public Guid Insert(string name)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Sex e = new Sex();

        e.Name = name;

        db.Sexes.InsertOnSubmit(e);
        db.SubmitChanges();
        return(e.ID);
    }
        public ActionResult ChangeProduct(string DIN, string oldProductCode, string newProductCode)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var v = db.Packs.First(r => r.ProductCode == oldProductCode && r.DIN == DIN);

            v.ProductCode = newProductCode;

            db.SubmitChanges();

            return View("About");
        }
Example #22
0
        public static void Delete(int deleteID, Guid packID, string note)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Pack p = Get4Delete(db, packID);

            p.DeleteID = deleteID;

            db.SubmitChanges();

            PackBLL.ChangeStatus(p.ID, Pack.StatusX.Delete, PackTransaction.TypeX.Out_Delete, note);
        }
Example #23
0
        public static Donation SetOriginalPack(string DIN, Guid packID)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation d = Get4CreateOriginal(db, DIN);

            d.OrgPackID = packID;

            db.SubmitChanges();

            return(d);
        }
Example #24
0
        static void Logs(Log.StatusX status, string method, string note)
        {
            Log e = new Log();
            e.Status = status;
            e.Method = method;
            e.Actor = RedBloodSystem.CurrentActor;
            e.Note = note;

            RedBloodDataContext db = new RedBloodDataContext();
            db.Logs.InsertOnSubmit(e);
            db.SubmitChanges();
        }
Example #25
0
    public static void Return(int returnID, int packOrderID, string note)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        PackOrder po = Get4Return(db, packOrderID);

        po.ReturnID = returnID;

        db.SubmitChanges();

        PackBLL.ChangeStatus(po.Pack.ID, Pack.StatusX.Product, PackTransaction.TypeX.In_Return, note);
    }
        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();
        }
Example #27
0
    public Guid InsertOrUpdate(Guid ID, Func <Receipt, Receipt> loadFromGUI)
    {
        RedBloodDataContext db = new RedBloodDataContext();
        Receipt             r;

        if (ID == Guid.Empty)
        {
            r = new Receipt();
            db.Receipts.InsertOnSubmit(r);
        }
        else
        {
            r = ReceiptBLL.Get(ID, db);
        }

        loadFromGUI(r);

        //Product In
        IEnumerable <ReceiptProduct> existingProductCodeInList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.In);

        db.ReceiptProducts.DeleteAllOnSubmit(
            existingProductCodeInList.Where(r1 => !ProductCodeInList.Contains(r1.ProductCode))
            );

        r.ReceiptProducts.AddRange(
            ProductCodeInList
            .Except(existingProductCodeInList.Select(r1 => r1.ProductCode))
            .Select(r1 => new ReceiptProduct()
        {
            ProductCode = r1, Type = ReceiptProduct.TypeX.In
        })
            );

        //Product Out
        IEnumerable <ReceiptProduct> existingProductCodeOutList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.Out);

        db.ReceiptProducts.DeleteAllOnSubmit(
            existingProductCodeOutList.Where(r1 => !ProductCodeOutList.Contains(r1.ProductCode))
            );

        r.ReceiptProducts.AddRange(
            ProductCodeOutList
            .Except(existingProductCodeOutList.Select(r1 => r1.ProductCode))
            .Select(r1 => new ReceiptProduct()
        {
            Product = ProductBLL.Get(db, r1), Type = ReceiptProduct.TypeX.Out
        })
            );

        db.SubmitChanges();
        return(r.ID);
    }
Example #28
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();
        }
Example #29
0
    public static void Add(string DIN, string productCode, int?volume, bool isOriginal)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Donation d = null;

        if (isOriginal)
        {
            d = DonationBLL.Get4CreateOriginal(db, DIN);
        }
        else
        {
            d = DonationBLL.Get(DIN);
        }

        Product product = ProductBLL.Get(productCode);

        if (IsExist(DIN, productCode))
        {
            throw new Exception(PackErrEnum.Existed.Message);
        }


        //TODO: Check to see valid product code in collection
        //Code will be here

        //TODO: Check to see if the pack is collector too late
        //Code check will be here.

        Pack pack = new Pack();

        pack.DIN         = DIN;
        pack.ProductCode = productCode;
        pack.Status      = Pack.StatusX.Product;
        pack.Actor       = RedBloodSystem.CurrentActor;
        //pack.Volume = product.OriginalVolume.HasValue ? product.OriginalVolume : defaultVolume;
        pack.Volume         = volume;
        pack.ExpirationDate = DateTime.Now.Add(product.Duration.Value - RedBloodSystem.RootTime);

        db.Packs.InsertOnSubmit(pack);
        db.SubmitChanges();


        PackTransactionBLL.Add(pack.ID, Pack.StatusX.Non, Pack.StatusX.Product,
                               isOriginal ? PackTransaction.TypeX.In_Collect : PackTransaction.TypeX.In_Product);

        if (isOriginal)
        {
            DonationBLL.SetOriginalPack(DIN, pack.ID);
        }
    }
Example #30
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        //Thread.Sleep(5000);
        if (PeopleID == Guid.Empty)
        {
            RedBloodDataContext db = new RedBloodDataContext();
            People p = new People();

            if (LoadFromGUI(p))
            {
                db.Peoples.InsertOnSubmit(p);
                db.SubmitChanges();
                PeopleID = p.ID;
            }
            else
            {
                return;
            }
        }
        else
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var p = (from c in db.Peoples
                     where c.ID == PeopleID
                     select c).First();

            if (p == null)
            {
                return;
            }

            if (LoadFromGUI(p))
            {
                db.SubmitChanges();
                PeopleID = p.ID;
            }
            else
            {
                return;
            }
        }
        //txtName.Focus();

        Page.Alert("Lưu thành công.");

        if (Page.Master is MasterPage)
        {
            ((MasterPage)Page.Master).TextBoxCode.Focus();
        }
    }
Example #31
0
        public static void ResetCounting()
        {
            RedBloodDataContext db = new RedBloodDataContext();
            Facility f = GetFirst(db);

            string YY = DateTime.Now.Year.ToString().Substring(2, 2);

            if (f.CountingYY != YY)
            {
                f.CountingYY = YY;
                f.CountingNumber = 0;
            }
            db.SubmitChanges();
        }
Example #32
0
    public static void UpdateFullname()
    {
        RedBloodDataContext db = new RedBloodDataContext();

        var r = from e in db.SideEffects
                select e;

        foreach (SideEffect e in r)
        {
            SetFullname(e);
        }

        db.SubmitChanges();
    }
Example #33
0
        public static void UpdateCollector(string DIN, string collector)
        {
            RedBloodDataContext db = new RedBloodDataContext();
            Donation            e  = Get(db, DIN);

            if (e != null &&
                string.IsNullOrEmpty(e.Collector) &&
                !string.IsNullOrEmpty(collector) &&
                !string.IsNullOrEmpty(collector.Trim()))
            {
                e.Collector = collector.Trim();
                db.SubmitChanges();
            }
        }
Example #34
0
    static void Logs(Log.StatusX status, string method, string note)
    {
        Log e = new Log();

        e.Status = status;
        e.Method = method;
        e.Actor  = RedBloodSystem.CurrentActor;
        e.Note   = note;

        RedBloodDataContext db = new RedBloodDataContext();

        db.Logs.InsertOnSubmit(e);
        db.SubmitChanges();
    }
Example #35
0
    public static void ResetCounting()
    {
        RedBloodDataContext db = new RedBloodDataContext();
        Facility            f  = GetFirst(db);

        string YY = DateTime.Now.Year.ToString().Substring(2, 2);

        if (f.CountingYY != YY)
        {
            f.CountingYY     = YY;
            f.CountingNumber = 0;
        }
        db.SubmitChanges();
    }
        public static DonationErr Assign(string DIN, Guid peopleID, int campaignID, DateTime? collectedDate, string actor)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            //Donation d = (from c in db.Donations
            //              where c.DIN == DIN && c.PeopleID == null && c.CampaignID == null
            //              select c).FirstOrDefault();

            var re = DonationErrEnum.Non;

            var existingPeople = db.Donations
                .FirstOrDefault(r => r.PeopleID == peopleID && r.CampaignID == campaignID);

            if (existingPeople == null)
            {
                var d = db.Donations
                    .FirstOrDefault(r => r.DIN == DIN && r.PeopleID == null && r.CampaignID == null);

                if (d == null)
                {
                    re = DonationErrEnum.NonExist;
                }
                else
                {
                    try
                    {
                        d.PeopleID = peopleID;
                        d.CollectedDate = collectedDate;
                        d.CampaignID = campaignID;
                        d.Actor = actor;

                        DonationDAL.UpdateStatus(db, d.DIN, Donation.StatusX.Assigned, "Assign peopleID=" + peopleID.ToString() + "&CampaignID=" + campaignID.ToString());

                        db.SubmitChanges();
                    }
                    catch (Exception ex)
                    {
                        re = new DonationErr(ex.Message);
                    }
                }
            }
            else
            {
                re = DonationErrEnum.PeopleCollected;
            }

            return re;
        }
Example #37
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();
        }
Example #38
0
        public static void ChangeStatus(Guid ID, Pack.StatusX toStatus, PackTransaction.TypeX transType, string note)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Pack p = Get(db, ID);

            if (p.Status == toStatus)
            {
                throw new Exception("Can not change statuses which are the same.");
            }

            PackTransactionBLL.Add(ID, p.Status, toStatus, transType, note);

            p.Status = toStatus;
            db.SubmitChanges();
        }
Example #39
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();
        }
Example #40
0
    public void Update(int ID, string name)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        TestDef c = (from i in db.TestDefs
                     where i.ID == ID
                     select i).First();

        if (c == null)
        {
            return;
        }

        c.Name = name;
        db.SubmitChanges();
    }
Example #41
0
    public static void ChangeStatus(Guid ID, Pack.StatusX toStatus, PackTransaction.TypeX transType, string note)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Pack p = Get(db, ID);

        if (p.Status == toStatus)
        {
            throw new Exception("Can not change statuses which are the same.");
        }

        PackTransactionBLL.Add(ID, p.Status, toStatus, transType, note);

        p.Status = toStatus;
        db.SubmitChanges();
    }
Example #42
0
    public static void Add(string DIN, string productCode, int? volume, bool isOriginal)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        Donation d = null;

        if (isOriginal)
        {
            d = DonationBLL.Get4CreateOriginal(db, DIN);
        }
        else
        {
            d = DonationBLL.Get(DIN);
        }

        Product product = ProductBLL.Get(productCode);

        if (IsExist(DIN, productCode))
            throw new Exception(PackErrEnum.Existed.Message);

        //TODO: Check to see valid product code in collection
        //Code will be here

        //TODO: Check to see if the pack is collector too late
        //Code check will be here.

        Pack pack = new Pack();

        pack.DIN = DIN;
        pack.ProductCode = productCode;
        pack.Status = Pack.StatusX.Product;
        pack.Actor = RedBloodSystem.CurrentActor;
        //pack.Volume = product.OriginalVolume.HasValue ? product.OriginalVolume : defaultVolume;
        pack.Volume = volume;
        pack.ExpirationDate = DateTime.Now.Add(product.Duration.Value - RedBloodSystem.RootTime);

        db.Packs.InsertOnSubmit(pack);
        db.SubmitChanges();

        PackTransactionBLL.Add(pack.ID, Pack.StatusX.Non, Pack.StatusX.Product,
            isOriginal ? PackTransaction.TypeX.In_Collect : PackTransaction.TypeX.In_Product);

        if (isOriginal)
        {
            DonationBLL.SetOriginalPack(DIN, pack.ID);
        }
    }
Example #43
0
        //public object GetTSIn(bool isLongRun)
        //{
        //    RedBloodDataContext db = new RedBloodDataContext();

        //    if (isLongRun)
        //    {
        //        var rs = from r in db.Campaigns
        //                 let total = (r.Packs.Count(p => p.Status == Pack.StatusX.CommitReceived))
        //                 where total > 0 && r.Type == Campaign.TypeX.Long_run
        //                 select new { r.ID, r.Name, SourceName = r.Source.Name, r.Note, total };
        //        return rs;
        //    }
        //    else
        //    {
        //        var rs = from r in db.Campaigns
        //                 let total = (r.Packs.Count(p => p.Status == Pack.StatusX.CommitReceived))
        //                 where r.Type == Campaign.TypeX.Short_run && r.Status == Campaign.StatusX.Assign
        //                 select new { r.ID, r.Name, SourceName = r.Source.Name, r.Date, r.Note, total };
        //        return rs;
        //    }
        //}

        static public void New(Campaign e)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            if (e.Type == Campaign.TypeX.Long_run)
            {
                e.Status = Campaign.StatusX.Assign;
            }

            if (e.Type == Campaign.TypeX.Short_run)
            {
                e.Status = Campaign.StatusX.Init;
            }

            db.Campaigns.InsertOnSubmit(e);

            db.SubmitChanges();
        }
Example #44
0
        public static void RemoveOriginalPack(string DIN)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Donation d = Get(db, DIN);

            if (d.CanRemoveOriginalPack)
            {
                Pack p = d.Pack;
                d.Pack = null;

                db.PackTransactions.DeleteAllOnSubmit(p.PackTransactions);
                db.PackRemainDailies.DeleteAllOnSubmit(p.PackRemainDailies);
                db.Packs.DeleteOnSubmit(p);

                db.SubmitChanges();
            }
        }
Example #45
0
    public static int Add(List<int> packOrderIDList, string note)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        List<PackOrder> poL = PackOrderBLL.Get4Return(db, packOrderIDList);

        Return re = new Return();
        re.Note = note;

        db.Returns.InsertOnSubmit(re);
        db.SubmitChanges();

        foreach (var item in packOrderIDList)
        {
            PackOrderBLL.Return(re.ID, item, note);
        }

        return re.ID;
    }
Example #46
0
    public static int Add(List<Guid> packIDList, string note)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        List<Pack> poL = PackBLL.Get4Delete(db, packIDList);

        Delete re = new Delete();
        re.Note = note;

        db.Deletes.InsertOnSubmit(re);
        db.SubmitChanges();

        foreach (var item in packIDList)
        {
            PackBLL.Delete(re.ID, item, note);
        }

        return re.ID;
    }
Example #47
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;
        }
        public void UpdateProfile(string username, string fullname, string phone)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var users = from u in db.aspnet_Users
                        where u.UserName == username
                        select u;

            if (users.Count() != 1) return;

            aspnet_User user = users.First();

            if (user.aspnet_UserProfile != null)
            {
                user.aspnet_UserProfile.Fullname = fullname;
                user.aspnet_UserProfile.Phone = phone;

                db.SubmitChanges();
            }
        }
Example #49
0
        public static void Add(int orderID, string DIN, string productCode)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Order r = OrderBLL.Get4Add(orderID);
            Pack p = PackBLL.Get4Order(DIN, productCode);

            PackOrder po = new PackOrder();
            po.OrderID = r.ID;
            po.PackID = p.ID;

            db.PackOrders.InsertOnSubmit(po);
            db.SubmitChanges();

            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;

            PackBLL.ChangeStatus(p.ID, Pack.StatusX.Delivered, transType, "PackOrderID = " + po.ID.ToString());
        }
Example #50
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();
        }
Example #51
0
    public string Delete(int ID)
    {
        RedBloodDataContext db = new RedBloodDataContext();

        TestDef c = (from i in db.TestDefs
                 where i.ID == ID
                 select i).First();

        if (c == null) return "";

        Delete_Route(c, db);

        try
        {
            db.SubmitChanges();
            return "";
        }
        catch (Exception)
        {
            return "Dữ liệu đã được sử dụng. Không thể xóa.";
        }
    }
        public static int Add(List<Guid> packIDList, string note)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            List<Pack> poL = PackBLL.Get4Delete(db, packIDList);
            if (poL.Count == 0)
                throw new Exception("Không có túi máu để hủy.");

            Delete re = new Delete();
            re.Note = note;
            re.Actor = RedBloodSystem.CurrentActor;

            db.Deletes.InsertOnSubmit(re);
            db.SubmitChanges();

            foreach (var item in poL)
            {
                PackDeleteBLL.Add(re.ID, item.ID);
            }

            return re.ID;
        }
Example #53
0
        public static void Add(string DIN, string productCode, string fullSideEffects, string note)
        {
            Pack p = PackBLL.Get4ReportSideEffects(DIN, productCode);

            if (string.IsNullOrEmpty(fullSideEffects))
                throw new Exception("Phản ứng phụ trống.");

            PackSideEffect se = new PackSideEffect();

            se.PackID = p.ID;
            se.SetSideEffect(fullSideEffects);

            se.Actor = RedBloodSystem.CurrentActor;
            se.Date = DateTime.Now;
            se.Note = note;

            RedBloodDataContext db = new RedBloodDataContext();

            db.PackSideEffects.InsertOnSubmit(se);

            db.SubmitChanges();
        }
        public static string Insert(string name, int level, Guid? parentID)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            SideEffect geo = new SideEffect();
            geo.Name = name.Trim();
            geo.Level = level;
            geo.ParentID = parentID;

            db.SideEffects.InsertOnSubmit(geo);

            try
            {
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            return geo.ID.ToString();
        }
        static void LoadData(Type type)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            List<PrintSetting> list = db.PrintSettings.Where(r => r.Type == type.Name).ToList();

            var l = type
                .GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.GetProperty)
                .Where(r => r is PropertyInfo)
                .Select(r => r as PropertyInfo)
                .Where(r => r.PropertyType == typeof(PrintSetting));

            foreach (var item in l)
            {
                item.SetValue(type, list.Where(r => r.Name == item.Name).FirstOrDefault(), null);
            }

            bool needReload = false;
            foreach (var item in l)
            {
                var v = item.GetValue(type, null);
                if (v == null)
                {
                    PrintSetting e = new PrintSetting();
                    e.Type = type.Name;
                    e.Name = item.Name;
                    e.Note = item.Name;
                    db.PrintSettings.InsertOnSubmit(e);
                    db.SubmitChanges();
                    needReload = true;
                }
            }

            if (needReload)
            {
                LoadData(type);
            }
        }
Example #56
0
        public static string Insert(string name, int level, Guid? parentID)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            Department geo = new Department();
            geo.Name = name.Trim();
            geo.Level = level;
            geo.ParentID = parentID;
            geo.HospitalID = HospitalBLL.GetFirst().ID;

            db.Departments.InsertOnSubmit(geo);

            try
            {
                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

            return geo.ID.ToString();
        }
        public void NewProfile(string username, string fullname, string phone)
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var users = from u in db.aspnet_Users
                        where u.UserName == username
                        select u;

            if (users.Count() != 1) return;

            aspnet_User user = users.First();

            aspnet_UserProfile user_profile = new aspnet_UserProfile();
            user_profile.UserID = user.UserId;
            user_profile.Fullname = fullname;
            user_profile.Phone = phone;

            if (user.aspnet_UserProfile == null)
            {
                db.aspnet_UserProfiles.InsertOnSubmit(user_profile);
                db.SubmitChanges();
            }
        }
        public static void Add(int deleteID, Guid packID)
        {
            //using (TransactionScope scope = new TransactionScope())
            //{
            //    scope.Complete();
            //}

            RedBloodDataContext db = new RedBloodDataContext();

            Delete r = DeleteBLL.Get(deleteID);
            Pack p = PackBLL.Get4Delete(db, packID);

            PackDelete po = new PackDelete();
            po.DeleteID = r.ID;
            po.PackID = p.ID;
            po.Note = p.Donation.Description4Pos;

            db.PackDeletes.InsertOnSubmit(po);
            db.SubmitChanges();

            PackTransaction.TypeX transType = PackTransaction.TypeX.Out_Delete;

            PackBLL.ChangeStatus(p.ID, Pack.StatusX.Delete, transType, "PackDeleteID = " + po.ID.ToString());
        }
    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;
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        //Thread.Sleep(5000);
        if (PeopleID == Guid.Empty)
        {
            RedBloodDataContext db = new RedBloodDataContext();
            People p = new People();

            if (LoadFromGUI(p))
            {
                db.Peoples.InsertOnSubmit(p);
                db.SubmitChanges();
                PeopleID = p.ID;
            }
            else
                return;
        }
        else
        {
            RedBloodDataContext db = new RedBloodDataContext();

            var p = (from c in db.Peoples
                     where c.ID == PeopleID
                     select c).First();

            if (p == null) return;

            if (LoadFromGUI(p))
            {
                db.SubmitChanges();
                PeopleID = p.ID;
            }
            else return;
        }
        //txtName.Focus();

        Page.Alert("Lưu thành công.");

        if (Page.Master is MasterPage)
        {
            ((MasterPage)Page.Master).TextBoxCode.Focus();
        }
    }