Beispiel #1
0
        protected void gridBookingEntries_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
        {
            try
            {
                string   code        = (string)e.NewValues["Code"];
                string   description = (string)e.NewValues["Description"];
                DateTime issuedDate  = (DateTime)e.NewValues["IssueDate"];
                double   amount      = (double)e.NewValues["Amount"];

                ManualBookingTransactionBO manualBookingTransactionBO = new ManualBookingTransactionBO();
                //Create manual booking transaction
                manualBookingTransactionBO.CreateTransaction(code, issuedDate, amount, description);

                gridBookingEntries.JSProperties["cpDataChanged"] = true;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                e.Cancel = true;
                gridBookingEntries.CancelEdit();
            }
        }
        protected void grdGeneralBookingJournal_InitNewRow(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
        {
            Guid transactionId = (Guid)Session["TransactionId"];

            m_Transaction = m_Session.GetObjectByKey <Transaction>(transactionId);
            if (m_Transaction == null)
            {
                Session["TransactionId"] = m_ManualBookingTransactionBO.CreateTransaction(m_Code, m_IssuedDate, m_Amount, m_Description);
                transactionId            = (Guid)Session["TransactionId"];
            }
            else
            {
                bool isBooked = m_TransactionBOBase.IsBookedTransaction(m_Session, (Guid)Session["TransactionId"], out m_Transaction);
                if (isBooked)
                {
                    string message = String.Format("Bút toán '{0}' đã được ghi sổ", m_Transaction.Code);
                    throw new Exception(message);
                }
            }
        }
        protected void PanelGeneralBooking_Callback(object sender, DevExpress.Web.ASPxClasses.CallbackEventArgsBase e)
        {
            m_ParamCallBack = e.Parameter.Split('|');

            switch (m_ParamCallBack[0])
            {
            case "edit":

                txtGeneralBookingCode.Text        = "";
                txtGeneralBookingDate.Value       = DateTime.Now;
                txtGeneralBookingStatus.Text      = "Chưa ghi sổ";
                txtGeneralBookingAmount.Value     = null;
                txtGeneralBookingDescription.Text = "";

                m_TransactionId = Guid.Parse(m_ParamCallBack[1].ToString());
                m_Transaction   = m_Session.GetObjectByKey <Transaction>(m_TransactionId);
                if (m_Transaction != null)
                {
                    txtGeneralBookingCode.Text        = m_Transaction.Code;
                    txtGeneralBookingAmount.Value     = m_Transaction.Amount;
                    txtGeneralBookingDate.Value       = m_Transaction.IssueDate;
                    txtGeneralBookingDescription.Text = m_Transaction.Description;
                    txtGeneralBookingStatus.Text      = "";

                    gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                    gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                    grdGeneralBookingJournal.DataBind();
                }
                else
                {
                    m_TransactionId = Guid.NewGuid();
                }

                Session["TransactionId"]           = m_TransactionId;
                PopupGeneralBooking.ShowOnPageLoad = true;

                gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                break;

            case "cancel":
                Session["TransactionId"]           = null;
                PopupGeneralBooking.ShowOnPageLoad = false;
                break;

            case "book":
                UnitOfWork uow = XpoHelper.GetNewUnitOfWork();


                string      message;
                Transaction transaction = null;
                bool        isBooked    = m_TransactionBOBase.IsBookedTransaction(m_Session, (Guid)Session["TransactionId"], out transaction);
                if (isBooked)
                {
                    message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                    throw new Exception(message);
                }
                if (!CanBookEntry(transaction, out message))
                {
                    throw new Exception(message);
                }
                if (transaction != null)
                {
                    if (!m_TransactionBOBase.BookEntry(uow, transaction.TransactionId))
                    {
                        throw new Exception("Xử lý ghi sổ phát sinh lỗi");
                    }

                    m_BusinessObjectBO.CreateBusinessObject(uow,
                                                            Utility.Constant.BusinessObjectType_FinancialTransaction,
                                                            transaction.TransactionId,
                                                            transaction.IssueDate);
                }

                uow.CommitChanges();
                PanelGeneralBooking.JSProperties.Add("cpBooked", "Complete");
                Session["TransactionId"] = null;
                break;

            case "save":

                if (txtGeneralBookingCode.Text == "" ||
                    txtGeneralBookingDate.Value == null ||
                    txtGeneralBookingAmount.Value == null)
                {
                    return;
                }

                m_TransactionId = (Guid)Session["TransactionId"];

                m_Code        = txtGeneralBookingCode.Text;
                m_Description = txtGeneralBookingDescription.Text;
                m_IssuedDate  = (DateTime)txtGeneralBookingDate.Value;
                m_Amount      = double.Parse(txtGeneralBookingAmount.Value.ToString());

                m_ManualBookingTransactionBO = new ManualBookingTransactionBO();

                m_Transaction = m_Session.GetObjectByKey <Transaction>(m_TransactionId);
                if (m_Transaction != null)
                {
                    isBooked = m_TransactionBOBase.IsBookedTransaction(m_Session, (Guid)Session["TransactionId"], out transaction);
                    if (isBooked)
                    {
                        message = String.Format("Bút toán '{0}' đã được ghi sổ", transaction.Code);
                        throw new Exception(message);
                    }

                    m_ManualBookingTransactionBO.UpdateTransaction(m_TransactionId, m_Code, m_IssuedDate, m_Amount, m_Description);
                }
                else
                {
                    m_TransactionId = m_ManualBookingTransactionBO.CreateTransaction(m_Code, m_IssuedDate, m_Amount, m_Description);
                }

                Session["TransactionId"] = m_TransactionId;

                gridviewGeneralJournal.CriteriaParameters.Add("TransactionId", m_TransactionId.ToString());
                gridviewGeneralJournal.CriteriaParameters.Add("RowStatus", Utility.Constant.ROWSTATUS_ACTIVE.ToString());

                break;
            }
        }