private void gvlHistory_MasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e)
        {
            GridView view = sender as GridView;
            MTSymbol c    = (MTSymbol)view.GetRow(e.RowHandle);
            BindingList <MTHistoryM> bindingHistory = new BindingList <MTHistoryM>(c.MTHistoryMS.ToList());

            bindingSource.DataSource = bindingHistory;

            e.ChildList = bindingSource;

            MTProviderEntities db1         = new MTProviderEntities();
            IList <MTHistoryM> mtHistoryMS = db1.MTHistoryMS.Where(a => a.Symbol == c.Name).ToList();

            foreach (MTHistoryM mtHistory in mtHistoryMS)
            {
                MTHistoryM mtHistoryMSOld = c.MTHistoryMS.Where(a => a.ID == mtHistory.ID).FirstOrDefault();

                if (mtHistory.AllTicks != mtHistoryMSOld.AllTicks)
                {
                    mtHistoryMSOld.AllTicks = mtHistory.AllTicks;
                }
                if (mtHistory.MyTicks != mtHistoryMSOld.MyTicks)
                {
                    mtHistoryMSOld.MyTicks = mtHistory.MyTicks;
                }
            }

            //e.ChildList = bindingHistory;
        }
        private void gvDetailHistory_RowUpdated(object sender, DevExpress.XtraGrid.Views.Base.RowObjectEventArgs e)
        {
            GridView view = sender as GridView;

            if (view.IsNewItemRow(e.RowHandle))
            {
                //view.ValidateEditor();
                MTHistoryM c = (MTHistoryM)e.Row;
                symbol = c.Symbol;
                db.MTHistoryMS.Add((MTHistoryM)e.Row);
                //view.CollapseGroupRow(view.SourceRowHandle);
            }
        }
        private void gvControlHistory_ProcessGridKey(object sender, KeyEventArgs e)
        {
            GridControl grid = sender as GridControl;
            GridView    view = grid.FocusedView as GridView;

            if (view.Name.Equals("gvDetailHistory"))
            {
                if (e.KeyData == Keys.Delete)
                {
                    MTHistoryM historyMS = (MTHistoryM)view.GetRow(view.GetSelectedRows()[0]);
                    IEnumerable <MTHistoryDT> historyDTs = db.MTHistoryDTs.Where(a => a.MSID == historyMS.ID).ToArray();
                    if (historyDTs.Count() > 0)
                    {
                        db.MTHistoryDTs.RemoveRange(historyDTs);
                    }
                    db.MTHistoryMS.Remove(historyMS);
                    view.DeleteSelectedRows();
                    e.Handled = true;
                }
            }
        }
        private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            //GridView gridView = gvControlHistory.ViewCollection[0] as GridView;
            // selGV.FocusedRowHandle = e.ProgressPercentage;

            BindingList <MTHistoryM> mtHistoryMSOlds = this.bindingSource.DataSource as BindingList <MTHistoryM>;
            MTHistoryM mtHistory      = e.UserState as MTHistoryM;
            MTHistoryM mtHistoryMSOld = mtHistoryMSOlds.Where(a => a.ID == mtHistory.ID).FirstOrDefault();

            if (mtHistory.AllTicks != mtHistoryMSOld.AllTicks)
            {
                mtHistoryMSOld.AllTicks = mtHistory.AllTicks;
            }
            if (mtHistory.MyTicks != mtHistoryMSOld.MyTicks)
            {
                mtHistoryMSOld.MyTicks = mtHistory.MyTicks;
            }

            selGV.SetRowCellValue(e.ProgressPercentage, "coldtLoading", (int.Parse(mtHistory.MyTicks.ToString()) * 100 / int.Parse(mtHistory.AllTicks.ToString())));

            //gridView.SetRowCellValue(int.Parse(e.UserState.ToString()), "coldtLoading", e.ProgressPercentage);
        }
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            MTProviderEntities db1         = new MTProviderEntities();
            IList <MTHistoryM> mtHistoryMS = db1.MTHistoryMS /*.Where(a => a.AllTicks != a.MyTicks || a.AllTicks == 0)*/.ToList();

            while (mtHistoryMS.Count != 0)
            {
                if (worker.CancellationPending == true)
                {
                    e.Cancel = true;
                    break;
                }
                else
                {
                    // Perform a time consuming operation and report progress.
                    System.Threading.Thread.Sleep(1000);
                    BindingList <MTHistoryM> mtHistoryMSOlds = this.bindingSource.DataSource as BindingList <MTHistoryM>;
                    if (mtHistoryMSOlds != null)
                    {
                        foreach (MTHistoryM mtHistory in mtHistoryMS)
                        {
                            foreach (GridView gridView in gvControlHistory.ViewCollection)
                            {
                                int rowHandle = gridView.LocateByValue("ID", mtHistory.ID);
                                if (rowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
                                {
                                    MTHistoryM mtHistoryMSOld = mtHistoryMSOlds.Where(a => a.ID == mtHistory.ID).FirstOrDefault();
                                    if ((mtHistory.AllTicks != mtHistoryMSOld.AllTicks) || (mtHistory.MyTicks != mtHistoryMSOld.MyTicks))
                                    {
                                        worker.ReportProgress(rowHandle, mtHistory);
                                        selGV = gridView;
                                    }
                                }
                            }



                            //MTHistoryM mtHistoryMSOld = mtHistoryMSOlds.Where(a => a.ID == mtHistory.ID).FirstOrDefault();
                            ////MTHistoryM mtHistoryMSOld = db.MTHistoryMS.Where(a => a.ID == mtHistory.ID).FirstOrDefault();

                            //if (mtHistory.AllTicks != mtHistoryMSOld.AllTicks)
                            //    mtHistoryMSOlds[0].AllTicks = mtHistory.AllTicks;
                            //if (mtHistory.MyTicks != mtHistoryMSOld.MyTicks)
                            //    mtHistoryMSOlds[0].MyTicks = mtHistory.MyTicks;



                            //iterate through each expanded grid
                            //foreach (GridView gridView in gvControlHistory.ViewCollection)
                            //{
                            //    //find row handle within grid that contains the field value you are searching for
                            //    //int rowHandle = gridView.LocateByValue("theFieldName", someObjectVal);

                            //    int rowHandle = gridView.LocateByValue("ID", mtHistory.ID);
                            //    if (rowHandle != DevExpress.XtraGrid.GridControl.InvalidRowHandle)
                            //    {
                            //        MTHistoryM mtHistoryMSOld = db.MTHistoryMS.Where(a => a.ID == mtHistory.ID).FirstOrDefault();
                            //        if (mtHistory.AllTicks != 0)
                            //            gridView.SetRowCellValue(rowHandle, "AllTicks", mtHistory.AllTicks);
                            //        if (mtHistory.MyTicks != 0)
                            //        {
                            //            gridView.SetRowCellValue(rowHandle, "MyTicks", mtHistory.MyTicks);
                            //            //mtHistoryMSOld.MyTicks = mtHistory.MyTicks;
                            //        }
                            //    }
                            //}
                        }
                    }

                    db1         = new MTProviderEntities();
                    mtHistoryMS = db1.MTHistoryMS /*.Where(a => a.AllTicks != a.MyTicks || a.AllTicks == 0)*/.ToList();
                }
            }
        }