Пример #1
0
        /// <summary>
        /// Remove/Update Datagrid
        /// </summary>
        private void RemoveValue()
        {
            try
            {
                Update = false;
                int        SelectedIndex = DGRates.SelectedIndex;
                Rates.Rate GridRates     = ((SmallPdf_Converter.Rates.Rate)DGRates.Items[SelectedIndex]);

                if (dtConverter.ContainsKey(GridRates.KeyBaseCurrency) == true)
                {
                    dict = dtConverter[GridRates.KeyBaseCurrency.ToString().Trim()];

                    if (dict.ContainsKey(GridRates.KeyCurrency.ToString().Trim()) == true)
                    {
                        dict.Remove(GridRates.KeyCurrency.ToString().Trim());
                        dtConverter[GridRates.KeyBaseCurrency.ToString().Trim()] = dict;

                        DGRates.Items.RemoveAt(DGRates.SelectedIndex);
                        Rates.Serialization(dtConverter, path);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Fatal("Fatal Error: MainWindow.RemoveValue: " + ex.InnerException.ToString());
            }
        }
Пример #2
0
 /// <summary>
 /// Update Button
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ButtonUpdate_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         Update = true;
         int        SelectedIndex = DGRates.SelectedIndex;
         Rates.Rate GridRates     = ((SmallPdf_Converter.Rates.Rate)DGRates.Items[SelectedIndex]);
         txtValue.Text              = GridRates.Values.Trim();
         cmbBaseCurrency.Text       = GridRates.KeyBaseCurrency.Trim();
         cmbCurrency.Text           = GridRates.KeyCurrency.Trim();
         cmbBaseCurrency.IsReadOnly = true;
     }
     catch (Exception ex)
     {
         Log.Fatal("Fatal Error: MainWindow.ButtonUpdate_Click: " + ex.InnerException.ToString());
     }
 }
Пример #3
0
        private void LoadSetting(string path)
        {
            try
            {
                if (Rates.Deserialize(path) != null)
                {
                    List <Rates.Rate> lstRates = Rates.Deserialize(path);
                    IDictionary <string, Dictionary <string, string> > IdtSettings = new Dictionary <string, Dictionary <string, string> >();
                    Dictionary <string, string> dtSetting = new Dictionary <string, string>();
                    foreach (var items in lstRates)
                    {
                        var data = new Rates.Rate {
                            KeyBaseCurrency = items.KeyBaseCurrency, KeyCurrency = items.KeyCurrency, Values = items.Values
                        };

                        DGRates.Items.Add(data);
                        if (!IdtSettings.ContainsKey(items.KeyBaseCurrency))
                        {
                            dtSetting = new Dictionary <string, string>();
                            dtSetting.Add(items.KeyCurrency, items.Values);
                            IdtSettings.Add(items.KeyBaseCurrency, dtSetting);
                        }
                        else
                        {
                            if (!dtSetting.ContainsKey(items.KeyCurrency))
                            {
                                dtSetting.Add(items.KeyCurrency, items.Values);
                                IdtSettings[items.KeyBaseCurrency] = dtSetting;
                            }
                            else
                            {
                                dtSetting[items.KeyCurrency]       = items.Values;
                                IdtSettings[items.KeyBaseCurrency] = dtSetting;
                            }
                        }
                    }
                    dtConverter = IdtSettings;
                }
            }
            catch (Exception ex)
            {
                Log.Error("Error: MainWindow.LoadSetting: " + ex.InnerException.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Delete  Grid Information
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ButtonDelete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                int        SelectedIndex = DGRates.SelectedIndex;
                Rates.Rate GridRates     = ((SmallPdf_Converter.Rates.Rate)DGRates.Items[SelectedIndex]);

                MessageBoxResult result = MessageBox.Show("Are you sure?" + "\n\nBase Currency: " + GridRates.KeyBaseCurrency + "\nCurrency: " + GridRates.KeyCurrency + "\nExcahange Rate: " + GridRates.Values, "DELETE", MessageBoxButton.YesNo, MessageBoxImage.Information);

                if (result == MessageBoxResult.Yes)
                {
                    RemoveValue();
                }
                DataRatesFill();
            }
            catch (Exception ex)
            {
                Log.Error("Error: MainWindow.ButtonDelete_Click: " + ex.InnerException.ToString());
            }
        }
Пример #5
0
        /// <summary>
        /// Add new row in Datagrid
        /// </summary>
        private void AddValue()
        {
            try
            {
                if (dtConverter.ContainsKey(cmbBaseCurrency.SelectedValue.ToString()) == true)
                {
                    dict = dtConverter[cmbBaseCurrency.SelectedValue.ToString().Trim()];

                    if (!dict.ContainsKey(cmbCurrency.SelectedValue.ToString().Trim()))
                    {
                        dict.Add(cmbCurrency.SelectedValue.ToString().Trim(), txtValue.Text.ToString().Trim());
                        dtConverter[cmbBaseCurrency.SelectedValue.ToString().Trim()] = dict;
                        var data = new Rates.Rate {
                            KeyBaseCurrency = cmbBaseCurrency.SelectedValue.ToString().Trim(), KeyCurrency = cmbCurrency.SelectedValue.ToString().Trim(), Values = txtValue.Text.ToString().Trim()
                        };
                        DGRates.Items.Add(data);
                    }
                    else
                    {
                        MessageBox.Show("Duplicate Value!!!", "INFORMATION", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    dict = new Dictionary <string, string>();
                    dict.Add(cmbCurrency.SelectedValue.ToString().Trim(), txtValue.Text.ToString().Trim());
                    dtConverter.Add(cmbBaseCurrency.SelectedValue.ToString(), dict);
                    var data = new Rates.Rate {
                        KeyBaseCurrency = cmbBaseCurrency.SelectedValue.ToString().Trim(), KeyCurrency = cmbCurrency.SelectedValue.ToString().Trim(), Values = txtValue.Text.ToString().Trim()
                    };
                    DGRates.Items.Add(data);
                }
                Rates.Serialization(dtConverter, path);
                InicializeControlls();
            }
            catch (Exception ex)
            {
                Log.Error("Error: MainWindow.ADD: " + ex.InnerException.ToString());
            }
        }
Пример #6
0
        private void DataRatesFill()
        {
            try
            {
                DGRates.Items.Clear();
                foreach (var item in dtConverter)
                {
                    foreach (var item2 in item.Value)
                    {
                        var data = new Rates.Rate {
                            KeyBaseCurrency = item.Key.Trim(), KeyCurrency = item2.Key.Trim(), Values = item2.Value.Trim()
                        };

                        DGRates.Items.Add(data);
                    }
                }
                DGRates.Items.Refresh();
            }
            catch (Exception ex)
            {
                Log.Error("Error: MainWindow.ButtonUpdate_Click: " + ex.InnerException.ToString());
            }
        }
Пример #7
0
 /// <summary>
 /// Serialize Json
 /// </summary>
 /// <param name="Rates"></param>
 /// <param name="path"></param>
 public void Serialization(IDictionary <string, Dictionary <string, string> > Rates, string path)
 {
     try
     {
         List <Rates.Rate> lstRates = new List <Rates.Rate>();
         foreach (var item in Rates)
         {
             foreach (var item2 in item.Value)
             {
                 Rates.Rate rates = new Rates.Rate();
                 rates.KeyBaseCurrency = item.Key.ToString();
                 rates.KeyCurrency     = item2.Key.ToString();
                 rates.Values          = item2.Value.ToString();
                 lstRates.Add(rates);
             }
         }
         string json = JsonConvert.SerializeObject(lstRates);
         files.CreateJson(json, path);
     }
     catch (Exception ex)
     {
         Log.Error("Error: Rates.Serialization: " + ex.InnerException.ToString());
     }
 }