Example #1
0
        public string InsertRecommend(string recommendID, int itemID)
        {
            FPT_RECOMMEND currentRecommend = db.FPT_RECOMMEND.FirstOrDefault(s => s.RecommendID.ToLower() == recommendID.ToLower());
            ITEM          item             = db.ITEMs.FirstOrDefault(i => i.ID == itemID);

            if (currentRecommend != null && item != null)
            {
                currentRecommend.ITEMs.Add(item);
            }
            else if (currentRecommend == null && item != null)
            {
                currentRecommend = new FPT_RECOMMEND()
                {
                    RecommendID = recommendID
                };
                currentRecommend.ITEMs.Add(item);
                db.FPT_RECOMMEND.Add(currentRecommend);
            }
            db.SaveChanges();

            return("");
        }
Example #2
0
        public string InsertHolding(HOLDING holding, int numberOfCN, string recommendID, ref string composite)
        {
            if (String.IsNullOrEmpty(holding.CopyNumber))
            {
                return("Hãy tạo đăng ký cá biệt");
            }
            ITEM item = db.ITEMs.FirstOrDefault(i => i.ID == holding.ItemID);

            if (item == null)
            {
                return("Không tồn tại bản ghi");
            }

            List <HOLDING> holdings = new List <HOLDING>();

            //   ITEM item = db.ITEMs.Where(i => i.ID == holding.ItemID).FirstOrDefault();
            holding.Volume        = "";
            holding.UseCount      = 0;
            holding.InUsed        = false;
            holding.InCirculation = false;
            holding.ILLID         = 0;
            holding.DateLastUsed  = DateTime.Now;
            holding.CallNumber    = db.ITEMs.Where(i => i.ID == holding.ItemID).FirstOrDefault().CallNumber;
            holding.Acquired      = false;
            holding.Note          = "";
            holding.POID          = 0;
            if (holding.Price == null)
            {
                holding.Price = 0;
            }

            // check start holding tồn tại chưa

            if (!IsExistHolding(holding.CopyNumber, holding.LocationID, -1))
            {
                string symbol    = holding.CopyNumber.Substring(0, holding.CopyNumber.Length - 6);
                string strNumber = holding.CopyNumber.Substring(symbol.Length, 6);
                int    number    = Convert.ToInt32(strNumber);

                using (DbContextTransaction transaction = db.Database.BeginTransaction())
                {
                    for (int i = 0; i < numberOfCN; i++)
                    {
                        // tạo list ĐKCB
                        int    length     = 6 - number.ToString().Length;
                        string stringZero = "";
                        for (int j = 0; j < length; j++)
                        {
                            stringZero = stringZero + "0";
                        }
                        string copyNumber = symbol + stringZero + number;

                        if (IsExistHolding(copyNumber, holding.LocationID, -1))
                        {
                            transaction.Rollback();
                            return("Hãy sinh lại giá trị");
                        }
                        ;

                        number++;
                        // procedure đã + 1 giá trị MaxNumber trong HOLDING_LOCATION
                        db.SP_HOLDING_INS(
                            holding.ItemID,
                            holding.LocationID,
                            holding.LibID,
                            holding.UseCount,
                            holding.Volume,
                            // ngày bổ sung
                            holding.AcquiredDate.ToString(),
                            copyNumber,
                            holding.InUsed == true ? 1 : 0,
                            holding.InCirculation == true ? 1 : 0,
                            holding.ILLID,
                            holding.Price,
                            // giá sách
                            holding.Shelf,
                            holding.POID,
                            //ngày sử dụng cuối
                            holding.DateLastUsed.ToString(),
                            holding.CallNumber,
                            holding.Acquired == true ? 1 : 0,
                            holding.Note,
                            holding.LoanTypeID,
                            holding.AcquiredSourceID,
                            holding.Currency,
                            holding.Rate,
                            // số chứng từ
                            holding.RecordNumber,
                            // ngày chứng từ
                            holding.ReceiptedDate.ToString()

                            );
                        holding.CopyNumber = copyNumber;
                        holdings.Add(holding);
                    }
                    transaction.Commit();
                    if (!string.IsNullOrEmpty(recommendID))
                    {
                        InsertRecommend(recommendID, holding.ItemID);
                    }
                    composite = GenerateCompositeHoldings(holding.ItemID);
                }
            }
            else
            {
                return("ĐKCB đã tồn tại hãy sinh giá trị mới");
            }
            return("");
        }