コード例 #1
0
        public void DealWithDataReaderInMutipleThread()
        {
            i = 0;
            Database db = MB.Orm.Persistence.DatabaseHelper.CreateDatabase();

            System.Data.Common.DbCommand dbCmd = db.GetSqlStringCommand("SELECT * FROM MTSBW.BF_USER");
            using (IDataReader reader = db.ExecuteReader(dbCmd)) {
                try {
                    //System.Threading.Thread t1 = new System.Threading.Thread(new System.Threading.ThreadStart(() => {
                    //        while (reader.Read()) {
                    //            System.Threading.Interlocked.Add(ref i, 1);
                    //        }
                    //    }));


                    //System.Threading.Thread t2 = new System.Threading.Thread(new System.Threading.ThreadStart(() => {
                    //    try {
                    //        while (reader.Read()) {
                    //            System.Threading.Interlocked.Add(ref i, 1);
                    //        }
                    //    }
                    //    catch (Exception ex) {
                    //        string msg = ex.ToString();
                    //    }
                    //}));



                    double timeElapsed = 0;
                    using (MB.Util.MethodTraceWithTime trace = new Util.MethodTraceWithTime("test")) {
                        Task[] tasks = new Task[3] {
                            Task.Factory.StartNew(() => consumeDataReader(reader, ref i)),
                            Task.Factory.StartNew(() => consumeDataReader(reader, ref i)),
                            Task.Factory.StartNew(() => consumeDataReader(reader, ref i))
                        };

                        Task.WaitAll(tasks);


                        timeElapsed = trace.GetExecutedTimes();
                    }

                    int result = i;
                }


                catch (Exception ex) {
                }
                finally {
                    dbCmd.Dispose();
                }
            }
        }
コード例 #2
0
        void refreshToolsButton()
        {
            using (MB.Util.MethodTraceWithTime track = new Util.MethodTraceWithTime("XtraRibbonMdiMainForm::refreshToolsButton")) {
                try {
                    if (this.ActiveMdiChild != null)
                    {
                        MB.WinBase.IFace.IViewGridForm gridViewForm = this.ActiveMdiChild as MB.WinBase.IFace.IViewGridForm;
                        if (gridViewForm != null)
                        {
                            bool existsUnSave = gridViewForm.ExistsUnSaveData();
                            //if (_LastSetGridForm != null && gridViewForm.Equals(_LastSetGridForm) && _LastSetState == existsUnSave) {
                            //    //setAllButtonEnabled(false);
                            //    return;
                            //}
                            setAllButtonEnabled(true);
                            //_LastSetState = existsUnSave;
                            //_LastSetGridForm = gridViewForm;
                            // MB.Util.TraceEx.Write("开始执行 existsUnSave...");


                            bButSave.Enabled          = existsUnSave && chenckButtonEnable(gridViewForm, bButSave);           // checkExistsRejectCommand(bButSave) && ValidatedCommandButton(bButSave);
                            bButAddNew.Enabled        = !existsUnSave && chenckButtonEnable(gridViewForm, bButAddNew);        //checkExistsRejectCommand(bButAddNew) && ValidatedCommandButton(bButAddNew);
                            bButDelete.Enabled        = !existsUnSave && chenckButtonEnable(gridViewForm, bButDelete);        //checkExistsRejectCommand(bButDelete) && ValidatedCommandButton(bButDelete);
                            bButFilter.Enabled        = !existsUnSave && chenckButtonEnable(gridViewForm, bButFilter);        // checkExistsRejectCommand(bButFilter) && ValidatedCommandButton(bButFilter);
                            bButAdvanceFilter.Enabled = !existsUnSave && chenckButtonEnable(gridViewForm, bButAdvanceFilter); //checkExistsRejectCommand(bButAdvanceFilter) && ValidatedCommandButton(bButAdvanceFilter);
                            bButRefresh.Enabled       = !existsUnSave && chenckButtonEnable(gridViewForm, bButRefresh);       //checkExistsRejectCommand(bButRefresh) && ValidatedCommandButton(bButRefresh);
                            bButOpen.Enabled          = !existsUnSave && chenckButtonEnable(gridViewForm, bButOpen);          //checkExistsRejectCommand(bButOpen) && ValidatedCommandButton(bButOpen);
                            bButImport.Enabled        = !existsUnSave && chenckButtonEnable(gridViewForm, bButImport);        //checkExistsRejectCommand(bButImport) && ValidatedCommandButton(bButImport);

                            //判断动态聚组设定按钮是否需要可用
                            IViewDynamicGroupGridForm dynamicViewForm = gridViewForm as IViewDynamicGroupGridForm;
                            bButDynamicGroupSetting.Enabled = (dynamicViewForm != null) && dynamicViewForm.IsDynamicGroupIsActive;
                            // MB.Util.TraceEx.Write("结束执行 existsUnSave...");
                        }
                        else
                        {
                            setAllButtonEnabled(false);
                        }
                    }
                    else
                    {
                        setAllButtonEnabled(false);
                    }
                }
                catch (Exception ex) {
                    throw new MB.Util.APPException("自动刷新主界面功能菜单项出错" + ex.Message, Util.APPMessageType.SysErrInfo);
                }
            }
        }
コード例 #3
0
        private void RibbonMdiMainForm_MdiChildActivate(object sender, EventArgs e)
        {
            using (MB.Util.MethodTraceWithTime track = new Util.MethodTraceWithTime("XtraRibbonMdiMainForm::MdiChildActivate")) {
                var moduleInfo = GetFocusedNodeInfo(trvListMain.FocusedNode);
                if (moduleInfo == null)
                {
                    return;
                }
                ModuleTreeNodeInfo nodeInfo = moduleInfo;
                var afrm = this.GetActiveMdiChildForm();
                if (afrm != null && afrm.ClientRuleObject != null)
                {
                    nodeInfo = afrm.ClientRuleObject.ModuleTreeNodeInfo;
                }

                refreshToolsButtonItem(nodeInfo);

                refreshToolsButton();
            }
        }
コード例 #4
0
        //根据当前活动的子窗口 格式化操作的菜单项
        private void refreshToolsButtonItem(MB.Util.Model.ModuleTreeNodeInfo moduleInfo)
        {
            using (MB.Util.MethodTraceWithTime track = new Util.MethodTraceWithTime("XtraRibbonMdiMainForm::refreshToolsButtonItem")) {
                _RejectCommandItems.Clear();

                foreach (DevExpress.XtraBars.BarButtonItem butItem in _AllCreateMenuItems.Keys)
                {
                    butItem.Enabled = true;
                }
                //2009-21-29主要从兼容的角度来处理,以后需要去掉 (新订货会系统中有需要)
                if (!string.IsNullOrEmpty(moduleInfo.RejectCommands))
                {
                    string[] rejects = moduleInfo.RejectCommands.Split(',');
                    foreach (DevExpress.XtraBars.BarButtonItem butItem in _AllCreateMenuItems.Keys)
                    {
                        System.ComponentModel.Design.CommandID cmdID = _AllCreateMenuItems[butItem];
                        UICommandType cType = (UICommandType)cmdID.ID;
                        if (Array.IndexOf(rejects, cType.ToString()) >= 0)
                        {
                            butItem.Enabled = false;
                            if (!_RejectCommandItems.ContainsKey(butItem))
                            {
                                _RejectCommandItems.Add(butItem, false);
                            }
                            else
                            {
                                _RejectCommandItems[butItem] = false;
                            }
                        }
                    }
                }
                MB.WinBase.IFace.IForm activeForm = this.GetActiveMdiChildForm();
                if (activeForm == null || activeForm.ClientRuleObject == null)
                {
                    foreach (DevExpress.XtraBars.BarButtonItem butItem in _AllCreateMenuItems.Keys)
                    {
                        butItem.Enabled = false;
                    }
                    return;
                }

                //根据业务类上的配置项来进行约束操作菜单项。
                var rejectCfg = MB.WinBase.Atts.AttributeConfigHelper.Instance.GetModuleRejectCommands(activeForm.ClientRuleObject.GetType());
                if (rejectCfg != null)
                {
                    foreach (DevExpress.XtraBars.BarButtonItem butItem in _AllCreateMenuItems.Keys)
                    {
                        System.ComponentModel.Design.CommandID cmdID = _AllCreateMenuItems[butItem];
                        UICommandType cType = (UICommandType)cmdID.ID;
                        if ((rejectCfg.RejectCommands & cType) != 0)
                        {
                            butItem.Enabled = false;
                            if (!_RejectCommandItems.ContainsKey(butItem))
                            {
                                _RejectCommandItems.Add(butItem, false);
                            }
                            else
                            {
                                _RejectCommandItems[butItem] = false;
                            }
                        }
                    }
                }

                //如果是分析界面的话要屏蔽掉操作功能菜单项。
                MB.WinBase.IFace.IClientRule editRule = activeForm.ClientRuleObject as MB.WinBase.IFace.IClientRule;
                if (editRule != null)
                {
                    return;
                }

                foreach (DevExpress.XtraBars.BarButtonItem butItem in _AllCreateMenuItems.Keys)
                {
                    System.ComponentModel.Design.CommandID cmdID = _AllCreateMenuItems[butItem];
                    var info = CommandGroups.EditCommands.FirstOrDefault(o => o.CommandID.Equals(cmdID));
                    if (info != null)
                    {
                        butItem.Enabled = false;
                        if (!_RejectCommandItems.ContainsKey(butItem))
                        {
                            _RejectCommandItems.Add(butItem, false);
                        }
                        else
                        {
                            _RejectCommandItems[butItem] = false;
                        }

                        continue;
                    }
                    if (cmdID.Equals(UICommands.DataImport))
                    {
                        butItem.Enabled = false;
                        if (!_RejectCommandItems.ContainsKey(butItem))
                        {
                            _RejectCommandItems.Add(butItem, false);
                        }
                        else
                        {
                            _RejectCommandItems[butItem] = false;
                        }

                        continue;
                    }
                }
            }
        }