private void btnAddToList_Click(object sender, EventArgs e)
        {
            if (spnAmount.EditValue == null || Math.Abs(Convert.ToDouble(spnAmount.EditValue)) < 0.0001)
            {
                return;
            }

            if (CashBoxInOutTransactionsList == null)
            {
                CashBoxInOutTransactionsList = new List <CashBoxInOutTransaction>();
            }

            CashBoxInOutTransaction cashBoxInOutTransaction = DBCommon.CreateNewDBEntity <CashBoxInOutTransaction>();

            if (CashBoxTransactionType_P_ID != null)
            {
                cashBoxInOutTransaction.CashBoxTransactionType_P_ID = Convert.ToInt32(CashBoxTransactionType_P_ID);
            }
            if (TransactionAmount != null)
            {
                cashBoxInOutTransaction.TransactionAmount = chkExpenses.Checked || chkReverseRevenue.Checked
                                        ? Convert.ToDouble(TransactionAmount) * -1
                                        : Convert.ToDouble(TransactionAmount);
            }
            if (TranscationSerial != null)
            {
                cashBoxInOutTransaction.TranscationSerial = TranscationSerial.ToString();
            }
            if (Description != null)
            {
                cashBoxInOutTransaction.Description = Description.ToString();
            }
            if (TranscationDate != null)
            {
                cashBoxInOutTransaction.TranscationDate = Convert.ToDateTime(TranscationDate);
            }
            if (ApplicationStaticConfiguration.ActiveCashBox != null)
            {
                cashBoxInOutTransaction.CashBox_CU_ID = ApplicationStaticConfiguration.ActiveCashBox.ID;
            }

            cashBoxInOutTransaction.AddedType = AddedType.NewelyAdded;

            CashBoxInOutTransactionsList.Add(cashBoxInOutTransaction);
            listToBeViewedOnly.Clear();

            listToBeViewedOnly.AddRange(CashBoxInOutTransaction.ItemsList.FindAll(item =>
                                                                                  !Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.Removed))));
            listToBeViewedOnly.AddRange(CashBoxInOutTransactionsList.FindAll(item =>
                                                                             !Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.Removed))));

            grdCashBoxInOutTransactions.DataSource = listToBeViewedOnly.OrderByDescending(item => item.TranscationDate);
            grdCashBoxInOutTransactions.RefreshDataSource();
            gridView7.SelectRow(-1);
            ClearControls();
        }
Esempio n. 2
0
        public override bool SaveChanges(DB_CommonTransactionType commonTransactionType)
        {
            if (ActiveCollector.ActiveDBItem == null)
            {
                return(false);
            }

            if (CashBoxInOutTransactionsList != null && CashBoxInOutTransactionsList.FindAll(item =>
                                                                                             Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.NewelyAdded))).Count > 0)
            {
                foreach (CashBoxInOutTransaction cashBoxInOutTransaction in CashBoxInOutTransactionsList.FindAll(item =>
                                                                                                                 Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.NewelyAdded))))
                {
                    cashBoxInOutTransaction.DBCommonTransactionType = DB_CommonTransactionType.SaveNew;
                    cashBoxInOutTransaction.InsertedBy       = Convert.ToInt32(UserID);
                    cashBoxInOutTransaction.PaymentType_P_ID = (int)DB_PaymentType.CashPayment;
                    cashBoxInOutTransaction.IsCancelled      = false;

                    if (UserID != null)
                    {
                        cashBoxInOutTransaction.InsertedBy = Convert.ToInt32(UserID);
                    }

                    cashBoxInOutTransaction.IsOnDuty = true;
                    switch (((ICashBoxInOutTransactionViewer)ActiveCollector.ActiveViewer).CommonTransactionType)
                    {
                    case DB_CommonTransactionType.DeleteExisting:
                        cashBoxInOutTransaction.IsOnDuty = false;
                        break;
                    }

                    cashBoxInOutTransaction.SaveChanges();
                }
            }

            if (CashBoxInOutTransaction.ItemsList != null && CashBoxInOutTransaction.ItemsList.FindAll(item =>
                                                                                                       Convert.ToInt32(item.DBCommonTransactionType)
                                                                                                       .Equals(Convert.ToInt32(DB_CommonTransactionType.DeleteExisting))).Count > 0)
            {
                foreach (CashBoxInOutTransaction cashBoxInOutTransaction in CashBoxInOutTransaction.ItemsList.FindAll(
                             item => Convert.ToInt32(item.DBCommonTransactionType)
                             .Equals(Convert.ToInt32(DB_CommonTransactionType.DeleteExisting))))
                {
                    cashBoxInOutTransaction.IsOnDuty = false;
                    cashBoxInOutTransaction.SaveChanges();
                }
            }


            ((CashBoxInOutTransaction)ActiveCollector.ActiveDBItem).LoadItemsList();

            return(true);
        }
        private void btnRemoveFromList_Click(object sender, EventArgs e)
        {
            if (SelectedRow == null)
            {
                return;
            }

            CashBoxInOutTransaction tobeDeleted = null;

            foreach (CashBoxInOutTransaction cashBoxInOutTransaction in CashBoxInOutTransaction.ItemsList)
            {
                if (SelectedRow.ID == cashBoxInOutTransaction.ID)
                {
                    cashBoxInOutTransaction.AddedType = AddedType.Removed;
                    cashBoxInOutTransaction.DBCommonTransactionType = DB_CommonTransactionType.DeleteExisting;
                    break;
                }
            }

            foreach (CashBoxInOutTransaction cashBoxInOutTransaction in CashBoxInOutTransactionsList)
            {
                if (SelectedRow.TranscationSerial.Equals(cashBoxInOutTransaction.TranscationSerial))
                {
                    cashBoxInOutTransaction.AddedType = AddedType.Removed;
                    break;
                }
            }

            listToBeViewedOnly.Clear();

            listToBeViewedOnly.AddRange(CashBoxInOutTransaction.ItemsList.FindAll(item =>
                                                                                  !Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.Removed))));
            listToBeViewedOnly.AddRange(CashBoxInOutTransactionsList.FindAll(item =>
                                                                             !Convert.ToInt32(item.AddedType).Equals(Convert.ToInt32(AddedType.Removed))));

            grdCashBoxInOutTransactions.DataSource = listToBeViewedOnly.OrderByDescending(item => item.TranscationDate);
            grdCashBoxInOutTransactions.RefreshDataSource();
            gridView7.SelectRow(-1);
            ClearControls();
        }