Beispiel #1
0
        private void CreateMenuRow(RowData rowData, Menu menu, DataTable dataTable)
        {
            rowData.SetData(rowData, dataTable);
            rowData.OpenMenu += OpenSubMenu;
            rowData.Reading.WorkerSupportsCancellation = true;
            rowData.Reading.DoWork += ReadMenu_DoWork;
            void ReadMenu_DoWork(object senderDoWork,
                                 DoWorkEventArgs eDoWork)
            {
                int level = (int)eDoWork.Argument;
                BackgroundWorker worker = (BackgroundWorker)senderDoWork;

                eDoWork.Result = Business.Menus.GetData(worker, rowData.TargetFilePath, level);
            }

            rowData.Reading.RunWorkerCompleted += ReadMenu_RunWorkerCompleted;
            void ReadMenu_RunWorkerCompleted(object senderCompleted,
                                             RunWorkerCompletedEventArgs e)
            {
                MenuData menuData = (MenuData)e.Result;

                if (rowData.RestartLoading)
                {
                    rowData.RestartLoading = false;
                    rowData.Reading.RunWorkerAsync(menuData.Level);
                }
                else
                {
                    LoadStopped();
                    if (menuData.Validity != MenuDataValidity.Invalid)
                    {
                        menu = Create(menuData);
                        if (menuData.RowDatas.Count > 0)
                        {
                            menu.SetTypeSub();
                        }
                        else if (menuData.Validity == MenuDataValidity.NoAccess)
                        {
                            menu.SetTypeNoAccess();
                        }
                        else
                        {
                            menu.SetTypeEmpty();
                        }
                        menu.Tag        = rowData;
                        rowData.SubMenu = menu;
                        rowData.MenuLoaded();
                    }
                }
            }
        }