public void Delete(RefillInventoryDetailDataEntity p_inventory)
        {
            using(var session = NHibernateHelper.OpenSession())
            {
                using(var transaction = session.BeginTransaction())
                {
                    try
                    {
                        session.Delete(p_inventory);
                        transaction.Commit();
                    }
                    catch(Exception ex)
                    {
                        transaction.Rollback();
                        throw ex;
                    }

                }
            }
        }
 public void Update(RefillInventoryDetailDataEntity p_inventory	)
 {
     using(var session = NHibernateHelper.OpenSession())
     {
         using(var transaction = session.BeginTransaction())
         {
             session.Update(p_inventory);
             transaction.Commit();
         }
     }
 }
 private RefillInventoryDetailDataEntity CreateNewInventoryDetail(RefillInventoryHeaderDataEntity header, int returnedQty, DateTime daystamp)
 {
     RefillInventoryDetailDataEntity detail = new RefillInventoryDetailDataEntity();
     detail.Header = header;
     detail.QtyOnHand += returnedQty;
     detail.QtyReleased -= returnedQty;
     detail.Date = daystamp;
     return detail;
 }
        private List<RefillInventoryHeaderDataEntity> GetRefillInvDataValueChange(List<int> rowIndexChange, out string errorMessage)
        {
            List<RefillInventoryHeaderDataEntity> refillInvs = new List<RefillInventoryHeaderDataEntity>();
            RefillInventoryHeaderDataEntity refillInv = new RefillInventoryHeaderDataEntity();
            List<string> updatedRefillInv = new List<string>();
            string errorMsg = string.Empty;
            int addStocks = 0;
            int removeStocks = 0;
            string name = string.Empty;

            foreach(int rowIndex in rowIndexChange)
            {
                if(!this.dgvRefillInventory.Rows[rowIndex].Cells["AddStocks"].Value.ToString().Trim().Equals(string.Empty))
                    addStocks = (int)this.dgvRefillInventory.Rows[rowIndex].Cells["AddStocks"].Value;
                if(!this.dgvRefillInventory.Rows[rowIndex].Cells["RemoveStocks"].Value.ToString().Trim().Equals(string.Empty))
                    removeStocks = (int)this.dgvRefillInventory.Rows[rowIndex].Cells["RemoveStocks"].Value;

                if(rowIndex <= refillInvMaxRowIndex)
                {
                    int ID = (int)this.dgvRefillInventory.Rows[rowIndex].Cells["InvHeaderID"].Value;
                    refillInv = m_refillInvEntity.Find(m_refillInv => m_refillInv.InvHeaderID == ID);
                    RefillInventoryDetailDataEntity invDetail = new RefillInventoryDetailDataEntity();

                    bool detailFound = false;
                    foreach(RefillInventoryDetailDataEntity detail in refillInv.DetailEntities)
                    {
                        if(detail.Date == DateTime.Now.Date)
                        {
                            detail.QtyAdded += addStocks;
                            detail.QtyRemoved += removeStocks;
                            detail.QtyOnHand += addStocks - removeStocks;
                            detail.TotalQty += addStocks - removeStocks;
                            detailFound = true;
                            break;
                        }
                    }
                    if(!detailFound){
                        invDetail = new RefillInventoryDetailDataEntity();
                        invDetail.Date = DateTime.Now.Date;
                        invDetail.QtyAdded += addStocks;
                        invDetail.QtyRemoved += removeStocks;
                        invDetail.QtyOnHand += addStocks - removeStocks;
                        invDetail.TotalQty += addStocks - removeStocks;
                        invDetail.Header = refillInv;
                        refillInv.DetailEntities.Add(invDetail);
                    }
                    refillInv.QtyOnHand += addStocks - removeStocks;
                    refillInv.TotalAdded += addStocks;
                    refillInv.TotalRemoved += removeStocks;
                    refillInv.TotalQty += addStocks - removeStocks;

                    refillInvs.Add(refillInv);
                    updatedRefillInv.Add(refillInv.Name.ToUpper());
                }
                else
                {
                    RefillInventoryHeaderDataEntity header = new RefillInventoryHeaderDataEntity();
                    RefillInventoryHeaderDataEntity newHeader = new RefillInventoryHeaderDataEntity();
                    RefillInventoryDetailDataEntity detail = new RefillInventoryDetailDataEntity();
                    name = this.dgvRefillInventory.Rows[rowIndex].Cells["Name"].Value.ToString().Trim();

                    newHeader = m_refillInvEntity.Find(m_refillInv => m_refillInv.Name.ToUpper() == name.ToUpper());

                    if((newHeader == null || newHeader.InvHeaderID == 0) && !updatedRefillInv.Contains(name.ToUpper()))
                    {
                        header.Name = name;
                        header.QtyOnHand += addStocks;
                        header.TotalAdded += addStocks;
                        header.TotalQty += addStocks;

                        detail.Header = header;
                        detail.Date = DateTime.Now.Date;
                        detail.QtyAdded += addStocks;
                        detail.QtyOnHand += addStocks;
                        detail.TotalQty += addStocks;

                        header.DetailEntities.Add(detail);
                        refillInvs.Add(header);
                        updatedRefillInv.Add(header.Name.ToUpper());
                    }
                    else
                    {
                        errorMsg += name + " , ";
                    }
                }
            }

            errorMessage = errorMsg;
            return refillInvs;
        }
 public void UpdateInventoryDetail(RefillInventoryHeaderDataEntity p_inventoryHeader)
 {
     if(p_inventoryHeader != null){
         DateTime today = Convert.ToDateTime(DateTime.Now.ToShortDateString());
         RefillInventoryDetailDataEntity inventoryDetail = m_refillInvDetailDao.GetDetailDay(p_inventoryHeader, today);
         if(inventoryDetail == null){
             inventoryDetail = new RefillInventoryDetailDataEntity();
         }
         inventoryDetail.Header = p_inventoryHeader;
         inventoryDetail.Date = today;
         inventoryDetail.QtyAdded = 0;
         inventoryDetail.QtyOnHand = p_inventoryHeader.QtyOnHand;
         inventoryDetail.QtyReleased = p_inventoryHeader.QtyReleased;
         inventoryDetail.QtyRemoved = 0;
         inventoryDetail.TotalQty = p_inventoryHeader.TotalQty;
         m_refillInvDetailDao.SaveOrUpdate(inventoryDetail);
     }
 }