protected void btnAdd_Click(object sender, EventArgs e)
 {
     bool existing = false;
     using (CatalogManager cm = new CatalogManager())
     {
         Stationery stationery = cm.FindStationeryByID(int.Parse(ddlDescription.SelectedValue));
         foreach (StockLogTransaction adj in adjustments)
         {
             if (adj.StationeryID == stationery.StationeryID)
                 existing = true;
         }
         if (!existing)
         {
             StockLogTransaction adj = new StockLogTransaction();
             adj.Reason = txtReason.Text.ToString();
             adj.Quantity = int.Parse(txtQuantity.Text.ToString());
             adj.StationeryID = stationery.StationeryID;
             adj.Balance = stationery.QuantityInHand;
             adj.Price = 0.0m;
             adj.DateCreated = DateTime.Now;
             adj.Type = int.Parse(ddlType.SelectedValue);
             adjustments.Add(adj);
         }
         txtQuantity.Text = "";
         txtReason.Text = "";
         Populate();
     }
 }
 public StockLogTransaction CreateStockLogTransaction(StockLogTransaction stockLogTransaction)
 {
     try
     {
         return adjustmentVoucherDAO.CreateStockLogTransaction(stockLogTransaction);
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Transaction Creation Failed" + ex.Message);
     }
 }
 //(Create, Update, Delete) (GetAll,GetID,GetCriteria)
 public StockLogTransaction CreateStockLogTransaction(StockLogTransaction stockLogTransaction)
 {
     try
     {
         context.AddToStockLogTransactions(stockLogTransaction);
         return stockLogTransaction;
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Transaction Creation Error" + ex.Message);
     }
 }
 public StockLogTransaction UpdateStockLogTransaction(StockLogTransaction stockLogTransaction)
 {
     try
     {
         var temp = (from ri in context.StockLogTransactions
                     where ri.StockLogTransactionID == stockLogTransaction.StockLogTransactionID
                     select ri).FirstOrDefault<StockLogTransaction>();
         temp.Type = stockLogTransaction.Type;
         temp.Reason = stockLogTransaction.Reason;
         temp.Quantity = stockLogTransaction.Quantity;
         temp.Balance = stockLogTransaction.Balance;
         context.SaveChanges();
         return stockLogTransaction;
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Transaction Update Error" + ex.Message);
     }
 }
        public void DeleteStockLogTransaction(StockLogTransaction stockLogTransaction)
        {
            try
            {
                var temp = (from ri in context.StockLogTransactions
                            where ri.StockLogTransactionID == stockLogTransaction.StockLogTransactionID
                            select ri).FirstOrDefault<StockLogTransaction>();

                using (TransactionScope ts = new TransactionScope())
                {
                    context.StockLogTransactions.DeleteObject(temp);
                    context.SaveChanges();
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Stock Log Transaction Delete Error" + ex.Message);
            }
        }
 public void DeleteStockLogTransaction(StockLogTransaction stockLogTransaction)
 {
     try
     {
         adjustmentVoucherDAO.DeleteStockLogTransaction(stockLogTransaction);
     }
     catch (Exception ex)
     {
         throw new Exception("Stock Log Transaction Delete Failed" + ex.Message);
     }
 }
        //To write the data in the table into database
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (ltMessage.Text != "")
            {
                ltMessage.Text = "Data saved already saved. No further action taken";
            }
            if (ltMessage.Text == "")
            {
                using (AdjustmentVoucherManager adjustmentVoucherManager = new AdjustmentVoucherManager())
                {
                    AdjustmentVoucherTransaction adjustmentVoucherTransaction = new AdjustmentVoucherTransaction();

                    foreach (GridViewRow r in GridView1.Rows)
                    {
                        StockLogTransaction item = new StockLogTransaction();
                        item.AdjustmentVoucherTransactionID = adjustmentVoucherTransaction.AdjustmentVoucherTransactionID;
                        item.StationeryID = Convert.ToInt32(r.Cells[1].Text);
                        item.Type = Convert.ToInt32(r.Cells[3].Text.ToString());
                        item.Quantity = Convert.ToInt32(r.Cells[4].Text);
                        item.Reason = r.Cells[5].Text;

                        adjustmentVoucherManager.CreateStockLogTransaction(item);

                        adjustmentVoucherTransaction.DateIssued = DateTime.Now;
                        adjustmentVoucherTransaction.VoucherNumber = "ME001"; //Must be unique system generated number
                        adjustmentVoucherTransaction.CreatedBy = 1; //Must be the userid of the person who creates it

               //         AdjustmentVoucherTransaction newAdjustmentVoucherTransaction = adjustmentVoucherManager.CreateAdjustmentVoucherTransaction(adjustmentVoucherTransaction);

                        ltMessage.Text = "Data saved";
                    }
                }
            }
        }
        protected void UpdateRetrievedQuantity()
        {
            GridView StationeryRetrievalFormItemGridView =
                StationeryRetrievalFormView.FindControl("StationeryRetrievalFormItemGridView") as GridView;

            if (StationeryRetrievalFormItemGridView != null)
            {
                try
                {
                    int srfID = Convert.ToInt32(this.StationeryRetrievalFormView.DataKey.Value);

                    AdjustmentVoucherTransaction adj = new AdjustmentVoucherTransaction();
                    List<Stationery> stationeries = new List<Stationery>();
                    List<SpecialStationery> specialStationeries = new List<SpecialStationery>();

                    using (StationeryRetrievalManager srm = new StationeryRetrievalManager())
                    {
                        DAL.StationeryRetrievalForm srf = srm.GetStationeryRetrievalFormByID(srfID);
                        List<StationeryRetrievalFormItem> srfis = srf.StationeryRetrievalFormItems.ToList();
                        foreach (GridViewRow row in StationeryRetrievalFormItemGridView.Rows)
                        {
                            HiddenField StationeryRetrievalFormItemIDHiddenField =
                                row.FindControl("StationeryRetrievalFormItemIDHiddenField") as HiddenField;
                            int srfiID = Convert.ToInt32(StationeryRetrievalFormItemIDHiddenField.Value);
                            TextBox QtyRetrieved = row.FindControl("QuantityRetrievedTextBox") as TextBox;
                            StationeryRetrievalFormItem srfi = (from s in srfis
                                                                where s.StationeryRetrievalFormItemID == srfiID
                                                                select s).FirstOrDefault();

                            int quantityRetrieved = Convert.ToInt32(QtyRetrieved.Text);
                            srfi.QuantityRetrieved = quantityRetrieved;

                            StockLogTransaction stockLogTransaction = new StockLogTransaction();
                            stockLogTransaction.Reason = "";
                            stockLogTransaction.Quantity = quantityRetrieved;

                            if (srfi.Stationery != null)
                            {
                                Stationery stationery = srfi.Stationery;
                                stockLogTransaction.StationeryID = srfi.Stationery.StationeryID;
                                StationeryPrice price = stationery.StationeryPrices.First();
                                stockLogTransaction.Price = price.Price;
                                stationery.QuantityInHand -= quantityRetrieved;
                                stationeries.Add(stationery);
                             stockLogTransaction.Balance = stationery.QuantityInHand;
                           }
                            else
                            {
                                SpecialStationery specialStationery = srfi.SpecialStationery;
                                stockLogTransaction.SpecialStationeryID = srfi.SpecialStationery.SpecialStationeryID;
                                stockLogTransaction.Price = 0.0m;
                                specialStationery.Quantity -= quantityRetrieved;
                                stockLogTransaction.Balance = specialStationery.Quantity;
                                specialStationeries.Add(specialStationery);
                            }

                            stockLogTransaction.DateCreated = DateTime.Now;
                            stockLogTransaction.Type = (int) AdjustmentType.Consumption;
                            adj.StockLogTransactions.Add(stockLogTransaction);

                        }
                        StationeryRetrievalForm newSRF = srm.UpdateReceivedQuantity(srf);
                        newSRF = srm.SetRecommendedQuantity(newSRF.StationeryRetrievalFormID);
                        using(CatalogManager cm = new CatalogManager())
                        {
                            foreach (Stationery stationery in stationeries)
                            {
                                cm.UpdateStationery(stationery);
                            }
                            foreach (SpecialStationery specialStationery in specialStationeries)
                            {
                                cm.UpdateSpecialStationery(specialStationery);
                            }
                        }
                    }
                }
                catch (Exception exception)
                {
                    this.ErrorMessage.Text = exception.Message;
                }
            }
        }
        protected void UpdateButton_Click(object sender, EventArgs e)
        {
            try
            {
                AdjustmentVoucherTransaction adjustmentVoucher = new AdjustmentVoucherTransaction();
                for (int i = 0; i < DisbursementGridView.Rows.Count; i++)
                {
                    GridViewRow gridViewRow = DisbursementGridView.Rows[i];
                    int disbursementItemID = (int)DisbursementGridView.DataKeys[gridViewRow.RowIndex].Value;
                    DisbursementItem item = null;
                    using (DisbursementManager dm = new DisbursementManager())
                    {
                        item = dm.FindDisbursementItemByID(disbursementItemID);
                    }

                    if (item != null && item.QuantityDamaged > 0)
                    {
                        Stationery stationery = item.Stationery;

                        StockLogTransaction adj = new StockLogTransaction();
                        adj.Reason = item.Reason;
                        adj.Quantity = item.QuantityDamaged ?? 0;

                        if (item.StationeryID != null && item.StationeryID > 0)
                        {
                            adj.StationeryID = item.StationeryID;
                            StationeryPrice price = stationery.StationeryPrices.First();
                            adj.Price = price.Price;
                            adj.Balance = stationery.QuantityInHand;
                        }
                        else
                        {
                            adj.SpecialStationeryID = item.SpecialStationeryID;
                            adj.Price = 0.0m;
                            adj.Balance = 0;
                        }

                        adj.DateCreated = DateTime.Now;
                        adj.Type = (int)AdjustmentType.Damage;
                        adjustmentVoucher.StockLogTransactions.Add(adj);
                    }
                    if (adjustmentVoucher.StockLogTransactions.Count > 0)
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            using (AdjustmentVoucherManager avm = new AdjustmentVoucherManager())
                            {
                                adjustmentVoucher.VoucherNumber = avm.GenerateVoucherNumber();
                                adjustmentVoucher.DateIssued = DateTime.Now;
                                adjustmentVoucher.CreatedBy = Utilities.Membership.LoggedInuser.UserID;
                                avm.CreateAdjustmentVoucherTransaction(adjustmentVoucher);
                            }
                            using (DisbursementManager dm = new DisbursementManager())
                            {
                                DAL.Disbursement disbursement = dm.FindDisbursementByID(this.DisbursementId);
                                disbursement.IsDistributed = true;
                                dm.UpdateDisbursement(disbursement);
                            }
                            ts.Complete();
                        }
                        Response.Redirect("~/HandleRequest/Disbursements.aspx");
                    }
                    else
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            using (DisbursementManager dm = new DisbursementManager())
                            {
                                DAL.Disbursement disbursement = dm.FindDisbursementByID(this.DisbursementId);
                                disbursement.IsCompleted = true;
                                dm.UpdateDisbursement(disbursement);
                            }
                            ts.Complete();
                        }
                        Response.Redirect("~/HandleRequest/Disbursements.aspx");
                    }
                }
            }
            catch (Exception exception)
            {
                this.ErrorMessage.Text = exception.Message;
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the StockLogTransactions EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToStockLogTransactions(StockLogTransaction stockLogTransaction)
 {
     base.AddObject("StockLogTransactions", stockLogTransaction);
 }
 /// <summary>
 /// Create a new StockLogTransaction object.
 /// </summary>
 /// <param name="stockLogTransactionID">Initial value of the StockLogTransactionID property.</param>
 /// <param name="adjustmentVoucherTransactionID">Initial value of the AdjustmentVoucherTransactionID property.</param>
 /// <param name="type">Initial value of the Type property.</param>
 /// <param name="reason">Initial value of the Reason property.</param>
 /// <param name="quantity">Initial value of the Quantity property.</param>
 /// <param name="balance">Initial value of the Balance property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="dateCreated">Initial value of the DateCreated property.</param>
 public static StockLogTransaction CreateStockLogTransaction(global::System.Int32 stockLogTransactionID, global::System.Int32 adjustmentVoucherTransactionID, global::System.Int32 type, global::System.String reason, global::System.Int32 quantity, global::System.Int32 balance, global::System.Decimal price, global::System.DateTime dateCreated)
 {
     StockLogTransaction stockLogTransaction = new StockLogTransaction();
     stockLogTransaction.StockLogTransactionID = stockLogTransactionID;
     stockLogTransaction.AdjustmentVoucherTransactionID = adjustmentVoucherTransactionID;
     stockLogTransaction.Type = type;
     stockLogTransaction.Reason = reason;
     stockLogTransaction.Quantity = quantity;
     stockLogTransaction.Balance = balance;
     stockLogTransaction.Price = price;
     stockLogTransaction.DateCreated = dateCreated;
     return stockLogTransaction;
 }