Ejemplo n.º 1
0
        /// <summary>
        /// Binds the form.
        /// </summary>
        /// <param name="reset">if set to <c>true</c> [reset].</param>
        private void BindForm(bool reset)
        {
            if (CurrencyRateId == 0)
            {
                ToCurrencyLabel.Visible             = false;
                ToCurrenciesList.Visible            = true;
                ToCurrencyRequiredValidator.Enabled = true;

                BindCurrenciesList();

                if (String.IsNullOrEmpty(SelectedCurrencyField.Value) || SelectedCurrencyField.Value == "0")
                {
                    SelectedCurrencyField.Value = ToCurrenciesList.SelectedValue;
                }
            }
            else
            {
                ToCurrencyLabel.Visible             = true;
                ToCurrenciesList.Visible            = false;
                ToCurrencyRequiredValidator.Enabled = false;
            }

            CurrencyDto.CurrencyRateRow selectedRow = null;
            if (CurrencyRateId != 0)
            {
                selectedRow = _Currency.CurrencyRate.FindByCurrencyRateId(CurrencyRateId);
            }

            if (selectedRow != null)
            {
                if (reset)
                {
                    SetFormFieldsValues(selectedRow.FromCurrencyId,
                                        selectedRow.EndOfDayRate,
                                        selectedRow.AverageRate,
                                        selectedRow.CurrencyRateDate,
                                        ManagementHelper.GetUserDateTime(selectedRow.ModifiedDate),
                                        selectedRow.ToCurrencyId);
                }

                // set ToCurrencyLabel text
                string toCurrencyLabelText = String.Empty;

                CurrencyDto.CurrencyRow toCurrencyRow = _Currency.Currency.FindByCurrencyId(selectedRow.ToCurrencyId);
                if (toCurrencyRow != null)
                {
                    toCurrencyLabelText = MakeCurrencyText(toCurrencyRow);
                }
                ToCurrencyLabel.Text = toCurrencyLabelText;
            }
            else if (reset)
            {
                SetFormFieldsValues(CurrencyId, 0, 0, DateTime.Now, DateTime.Now, 0);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Processes the table events.
        /// </summary>
        /// <param name="dto">The dto.</param>
        private void ProcessTableEvents(CurrencyDto dto)
        {
            if (dto == null)
            {
                return;
            }

            foreach (GridItem item in _removedItems)
            {
                int id = 0;
                if (item[_GridCurrencyRateIdString] != null && Int32.TryParse(item[_GridCurrencyRateIdString].ToString(), out id))
                {
                    // find the rate
                    CurrencyDto.CurrencyRateRow rate = dto.CurrencyRate.FindByCurrencyRateId(id);
                    if (rate != null)
                    {
                        rate.Delete();
                    }
                }
            }

            _removedItems.Clear();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handles the Click event of the SaveChangesButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void SaveChangesButton_Click(object sender, EventArgs e)
        {
            CurrencyDto.CurrencyRateRow rateRow = null;

            if (CurrencyRateId != 0)             // find existing
            {
                CurrencyDto.CurrencyRateRow[] rateRows = (CurrencyDto.CurrencyRateRow[])_Currency.CurrencyRate.Select(String.Format("CurrencyRateId={0}", CurrencyRateId));
                if (rateRows != null && rateRows.Length > 0)
                {
                    rateRow = rateRows[0];
                }
            }

            // if not found, create new
            if (rateRow == null)
            {
                rateRow = _Currency.CurrencyRate.NewCurrencyRateRow();
                rateRow.FromCurrencyId = CurrencyId;
                rateRow.ToCurrencyId   = Int32.Parse(SelectedCurrencyField.Value);
            }

            // update lineItem fields
            if (rateRow != null)
            {
                rateRow.EndOfDayRate     = Double.Parse(tbRate.Text);
                rateRow.AverageRate      = Double.Parse(tbAverageRate.Text);
                rateRow.CurrencyRateDate = CurrencyRateDate.Value;                 //.ToUniversalTime(); - don't need to convert to Utc here since we need only Date, without time
                rateRow.ModifiedDate     = DateTime.UtcNow;
            }

            if (rateRow.RowState == DataRowState.Detached)
            {
                _Currency.CurrencyRate.AddCurrencyRateRow(rateRow);
            }

            ScriptManager.RegisterStartupScript(SaveChangesButton, typeof(CurrencyRateEditPopup), "DialogClose", "CurrencyRateDialog_CloseDialog();", true);
        }