Exemplo n.º 1
0
        public Form1()
        {
            InitializeComponent();
            Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture =
                CultureInfo.CreateSpecificCulture("en-US");

            notifyIcon1.Icon = Digits.GetIcon();
            button1_Click(this, null);
        }
Exemplo n.º 2
0
        private void DirectComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                // cbItem - exchtype напраления
                var cbItem = ((ComboBox)sender).SelectedValue as string ?? "1";
                var id     = int.Parse(cbItem);
                // направления идут парами => чётность меняется.
                _backIndex = id % 2 == 0 ? id - 1 : id + 1;
                _backIndex = cBitems.OrderBy(d => d.Direct).ToList().IndexOf(cBitems.First(i => i.Exchtype.Equals(_backIndex.ToString())));

                var xmlDocument = XmlHelper.GetXmlByUrl(WMLIST_URL + cbItem);

                string backDirect;
                float  floatValue;
                var    inout    = float.Parse(xmlDocument.LastChild.LastChild.FirstChild.Attributes["inoutrate"].Value.Replace(',', '.'));
                var    outin    = float.Parse(xmlDocument.LastChild.LastChild.FirstChild.Attributes["outinrate"].Value.Replace(',', '.'));
                var    baseRate = xmlDocument.DocumentElement.InnerText;

                if (outin > inout)
                {
                    floatValue = outin;
                    direct     = xmlDocument.LastChild.FirstChild.Attributes["direction"].Value;
                    backDirect = direct.Substring(4, 3) + "/" + direct.Substring(0, 3);
                }
                else
                {
                    floatValue = inout;
                    backDirect = xmlDocument.LastChild.FirstChild.Attributes["direction"].Value;
                    direct     = backDirect.Substring(4, 3) + "/" + backDirect.Substring(0, 3);
                }

                int showRecords = 0;
                list = new List <WMListItem>();
                foreach (var element in xmlDocument.LastChild.LastChild)
                {
                    try
                    {
                        //DateTime datetime;
                        //DateTime.TryParse(((XmlElement)element).Attributes["querydate"].Value, out datetime);
                        list.Add(
                            new WMListItem(
                                //int.Parse(((XmlElement)element).Attributes["id"].Value),
                                float.Parse(((XmlElement)element).Attributes["amountin"].Value.Replace(',', '.')),
                                float.Parse(((XmlElement)element).Attributes["amountout"].Value.Replace(',', '.')),
                                float.Parse(((XmlElement)element).Attributes["inoutrate"].Value.Replace(',', '.')),
                                float.Parse(((XmlElement)element).Attributes["outinrate"].Value.Replace(',', '.')),
                                //float.Parse(((XmlElement)element).Attributes["procentbankrate"].Value.Replace(',', '.')),
                                float.Parse(((XmlElement)element).Attributes["allamountin"].Value.Replace(',', '.'))
                                //,datetime
                                )
                            );
                        // прекратить вывод при достижении определённой суммы (_maxSumToDisplay)

                        if (outin > inout)
                        {
                            if (list.Last().Allamountin > _maxSumToDisplay && showRecords == 0)
                            {
                                showRecords = list.Count;
                            }
                        }
                        else
                        {
                            if (list.Last().Allamountin / float.Parse(baseRate.Replace(',', '.')) > _maxSumToDisplay &&
                                showRecords == 0)
                            {
                                showRecords = list.Count;
                            }
                        }
                    }


                    catch (Exception ex)
                    {
                        MessageBox.Show("Ошибко: \r\n" + ex.Message);
                    }
                }
                if (!ServerModeCheckBox.Checked)
                {
                    if (showRecords == 0)
                    {
                        showRecords = list.Count;
                    }
                    dataGridView.DataSource = list.Take(showRecords).ToList();
                    var reverseFloatValue =
                        GetValueByexchtype(((CBitem)((ComboBox)sender).SelectedItem).ReverseExchtype);
                    var txt = string.Format("{0} {1} {2}", direct, floatValue, list.First().Allamountin);
                    if (!string.IsNullOrEmpty(lastValue) && lastValue != txt)
                    {
                        float amount;
                        if (float.TryParse(SumToRateMaskedTextBox.Text, out amount))
                        {
                            var r = GetRateForAmount(amount).ToString();
                            notifyIcon1.ShowBalloonTip(3, "Rate for " + amount + " - " + r, txt, ToolTipIcon.Info);
                        }
                        else
                        {
                            notifyIcon1.ShowBalloonTip(3, txt, " ", ToolTipIcon.Info);
                        }
                    }
                    lastValue          = txt;
                    txt                = string.Format("{0} {1}, back: {2} {3}", direct, floatValue, backDirect, reverseFloatValue);
                    BaseRatelabel.Text = txt;
                    notifyIcon1.Text   = txt;
                    notifyIcon1.Icon   = Digits.GetIcon(floatValue, reverseFloatValue);
                }
                else
                {
                    Text             = string.Format("{0} {1}", direct, floatValue);
                    notifyIcon1.Text = Text;
                    notifyIcon1.Icon = Digits.GetIcon(floatValue, 0);

                    if (fileInfo != null)
                    {
                        AddToLog();
                    }
                    else
                    {
                        WriteLog();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Ошибко: \r\n" + ex.Message);
            }
            ServerModeCheckBox.Enabled = true;
            TimerCheckBox.Enabled      = true;
        }