/// <summary>
 /// Find first company name using starts with case insensitive
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="companyName"></param>
 /// <returns></returns>
 public static CompanyItem FindCompanyByNameStartsWith(this SortableBindingList <CustomerEntity> sender, string companyName)
 {
     return(sender.Select((customerEntity, index) => new CompanyItem
     {
         RowIndex = index,
         Entity = customerEntity
     }).FirstOrDefault((item) => item.Entity.CompanyName.StartsWith(companyName, StringComparison.InvariantCultureIgnoreCase)));
 }
 /// <summary>
 /// Find CustomerEntity by contact first and last name
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="firstName">Contact first name</param>
 /// <param name="lastName">Contact last name</param>
 /// <returns>CustomerEntity if found in list or Nothing if not found in list</returns>
 /// <remarks>
 /// The BindingSource set to the SortableBindingList(Of CustomerEntity) does not support Find method
 /// which means either modifying the SortableBindingList or have this extension method. Using
 /// and extension method makes sense here than modify the SortableBindingList.
 /// </remarks>
 public static CompanyItem FindCompanyByContactName(this SortableBindingList <CustomerEntity> sender, string firstName, string lastName)
 {
     return(sender.Select((customerEntity, index) => new CompanyItem
     {
         RowIndex = index,
         Entity = customerEntity
     }).FirstOrDefault((companyItem) => companyItem.Entity.FirstName == firstName && companyItem.Entity.LastName == lastName));
 }
Exemple #3
0
        public ImportedGeometryManager()
        {
            InitializeComponent();

            _correctColor = dataGridView.BackColor.MixWith(Color.LimeGreen, 0.55);
            _wrongColor   = dataGridView.BackColor.MixWith(Color.DarkRed, 0.55);

            dataGridView.CellMouseDoubleClick += dataGridView_CellMouseDoubleClick;

            // Initialize sound path data grid view
            dataGridViewControls.DataGridView = dataGridView;
            dataGridViewControls.Enabled      = true;
            dataGridViewControls.CreateNewRow = delegate
            {
                List <string> paths = LevelFileDialog.BrowseFiles(this, null, PathC.GetDirectoryNameTry(LevelSettings.LevelFilePath),
                                                                  "Select 3D files that you want to see imported.", ImportedGeometry.FileExtensions).ToList();

                // Load imported geometries
                var importInfos = new List <KeyValuePair <ImportedGeometry, ImportedGeometryInfo> >();
                foreach (string path in paths)
                {
                    using (var settingsDialog = new GeometryIOSettingsDialog(new IOGeometrySettings()))
                    {
                        settingsDialog.AddPreset(IOSettingsPresets.GeometryImportSettingsPresets);
                        settingsDialog.SelectPreset("Normal scale to TR scale");

                        if (settingsDialog.ShowDialog(this) == DialogResult.Cancel)
                        {
                            continue;
                        }

                        var info = new ImportedGeometryInfo(LevelSettings.MakeRelative(path, VariableType.LevelDirectory), settingsDialog.Settings);
                        importInfos.Add(new KeyValuePair <ImportedGeometry, ImportedGeometryInfo>(new ImportedGeometry(), info));
                    }
                }

                LevelSettings.ImportedGeometryUpdate(importInfos);
                LevelSettings.ImportedGeometries.AddRange(importInfos.Select(entry => entry.Key));
                return(importInfos.Select(entry => new ImportedGeometryWrapper(this, entry.Key)));
            };
            dataGridView.DataSource = _dataGridViewDataSource;
            dataGridViewControls.DeleteRowCheckIfCancel = MessageUserAboutHimDeletingRows;
            _dataGridViewDataSource.ListChanged        += delegate(object sender, ListChangedEventArgs e)
            {
                switch (e.ListChangedType)
                {
                case ListChangedType.ItemDeleted:
                    var remainingElements = new HashSet <ImportedGeometry>(_dataGridViewDataSource.Select(wrapper => wrapper.Object));
                    LevelSettings.ImportedGeometries.RemoveAll(obj => !remainingElements.Contains(obj));         // Don't use indices here, the wrapper indices might not match with the real object if sorting was enabled.
                    break;
                }
            };
            Enabled = true;
        }
        public SortableBindingList<Auctions> GetBidsandOffers()
        {
            var auctions = new SortableBindingList<Auctions>();

            const string strUrl = @"https://auctions.godaddy.com/trpMessageHandler.aspx ";
            var postData = string.Format("sec=Bi&sort=7&dir=A&page=1&at=3&rpp=50&rnd={0}",
                randomDouble(0, 1).ToString("0.00000000000000000"));
            var request = (HttpWebRequest)WebRequest.Create(strUrl);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = postData.Length;
            request.Accept = "gzip,deflate,sdch";
            request.Accept = "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/msword, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/x-silverlight, application/x-silverlight-2-b2, application/x-ms-application, application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*";
            request.UserAgent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)";
            request.Headers.Add("Accept-Encoding", "deflate");
            request.Referer = "https://auctions.godaddy.com/trpMyAccount.aspx?ci=22373&s=2&sc=Bi";
            request.Headers.Add("Accept-Encoding", "");
            request.KeepAlive = true;
            request.Timeout = Timeout.Infinite;

            request.CookieContainer = cookies;

            var stOut = new StreamWriter(request.GetRequestStream());
            stOut.Write(postData);
            stOut.Flush();
            stOut.Close();

            var response = (HttpWebResponse)request.GetResponse();
            response.Cookies = request.CookieContainer.GetCookies(request.RequestUri);

            var encoding = new UTF8Encoding();
            var responseReader = new StreamReader(response.GetResponseStream(), encoding, true);

            var responseData = responseReader.ReadToEnd();
            response.Close();
            responseReader.Close();
            //responseData;

            var doc = new HtmlDocument();
            doc.LoadHtml(responseData);

            foreach (var row in QuerySelectorAll(doc.DocumentNode, "tr[class^=marow]"))
            {
                var auction = GenerateAuction();
                auction.AuctionRef = QuerySelector(row, "td:nth-child(2) > a").Attributes["href"].Value.Split(new char[] { '=' })[1];
                auction.DomainName = HttpUtility.HtmlDecode(QuerySelector(row, "td:nth-child(2)").InnerText).Trim();
                auction.MinBid = TryParse_INT(HttpUtility.HtmlDecode(QuerySelector(row, "td:nth-child(5)").InnerText).Trim().Replace("$", "").Replace("C", ""));
                auction.Status = HttpUtility.HtmlDecode(QuerySelector(row, "td:nth-child(7)").InnerText.Trim());
                GetMyOfferDetails(ref auction);

                if (LoadMyLocalBids() != null)
                {
                    foreach (var auc in LoadMyLocalBids())
                    {
                        if (auc.AuctionRef == auction.AuctionRef)
                        {
                            auction.MyBid = auc.MyBid;
                        }
                    }
                }
                if (auction.MyBid == 0)
                {
                    auction.MyBid = auction.MinBid;
                }
                auctions.Add(auction);

            }

            foreach (var auction in LoadMyLocalBids())
            {

                if (!auctions.Select(s => s.AuctionRef).Distinct().Contains(auction.AuctionRef) &&
                    auction.EndDate > GetPacificTime)
                {
                    var searchList = Search(auction.DomainName).ToList();
                    if (searchList != null && searchList.Count > 0)
                    {
                        auction.BidCount = searchList[0].BidCount;
                        auction.MinBid = searchList[0].MinBid;
                        auction.Traffic = searchList[0].Traffic;
                        auction.Status = searchList[0].Status;
                        auction.Price = searchList[0].Price;
                    }
                    auctions.Add(auction);
                }

            }

            return auctions;
        }
Exemple #5
0
        private void ReCalculateAmount(StockTemplate template)
        {
            double[] weights     = _spotDataSource.Select(p => p.SettingWeight / 100).ToArray();
            double   totalWeight = weights.Sum();
            double   minusResult = 1.0 - totalWeight;

            double[] mweights = _spotDataSource.Select(p => p.MarketCapWeight / 100).ToArray();
            double   mtotal   = mweights.Sum();
            double   mDiff    = 1.0 - mtotal;

            //如果不为100%,则需要调整比例; 依据市值调整
            if (Math.Abs(minusResult) > 0.001 && mDiff > 0.001)
            {
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    weights[i] = stock.MarketCapWeight / mtotal;
                }
            }

            List <SecurityItem> secuList = GetSecurityItems(template);

            var    benchmarkItem = _securityInfoList.Find(p => p.SecuCode.Equals(template.Benchmark) && p.SecuType == SecurityType.Index);
            var    benchmarkData = QuoteCenter.Instance.GetMarketData(benchmarkItem);
            var    benchmark     = _benchmarkList.Find(p => p.BenchmarkId.Equals(benchmarkItem.SecuCode));
            double bmkPrice      = 0f;
            double totalValue    = 0f;

            if (!FloatUtil.IsZero(benchmarkData.CurrentPrice))
            {
                bmkPrice = benchmarkData.CurrentPrice;
            }
            else if (!FloatUtil.IsZero(benchmarkData.PreClose))
            {
                bmkPrice = benchmarkData.PreClose;
            }

            //指数基准当期总市值
            //上证50、沪深300、中证500每一个点数对应不同的价格
            totalValue = bmkPrice * benchmark.ContractMultiple;
            totalValue = totalValue * template.MarketCapOpt / 100;

            var prices  = GetPrices(secuList);
            var amounts = CalcUtil.CalcStockAmountPerCopyRound(totalValue, weights, prices, 0);
            var mktCaps = GetMarketCap(prices, amounts);

            switch (template.EWeightType)
            {
            case Model.EnumType.WeightType.ProportionalWeight:
            {
                double totalCap = mktCaps.Sum();
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    stock.Amount          = amounts[i];
                    stock.MarketCap       = mktCaps[i];
                    stock.MarketCapWeight = 100 * stock.MarketCap / totalCap;
                }
            }
            break;

            case Model.EnumType.WeightType.AmountWeight:
            {
                var    totalAmount = amounts.Sum();
                double totalCap    = mktCaps.Sum();
                for (int i = 0, count = _spotDataSource.Count; i < count; i++)
                {
                    var stock = _spotDataSource[i];
                    stock.Amount          = amounts[i];
                    stock.MarketCap       = mktCaps[i];
                    stock.MarketCapWeight = 100 * stock.MarketCap / totalCap;
                    stock.SettingWeight   = 100 * (double)stock.Amount / (double)totalAmount;
                }
            }
            break;

            default:
                break;
            }
        }
Exemple #6
0
        private void clipboardButton_Click(object sender, EventArgs e)
        {
            string text = String.Join(",", ThreadListBindingSource.Select(thread => thread.URL)).Replace("\n", "").Replace("\r", "");

            Clipboard.SetText(text);
        }