Ejemplo n.º 1
0
        private void MainView_Load(object sender, EventArgs e)
        {
            Common.GetMACs(out LocalMAC);
            Common.GetLocalIpv4(out LocalIP);
            //try { RemoteIP = Common.GetRemoteIP(); } catch { RemoteIP = string.Empty; }
            RemoteIP = string.Empty;
            //检查登录是否是被授权的

            if ((this.CurUser.IgnoreCaseEqual("admin")))
            {
                barBtnSysMnu.Visibility = BarItemVisibility.Always;
            }
            else
            {
                barBtnSysMnu.Visibility = BarItemVisibility.Never;
            }
            this.barLabel.Caption = this.CurUser;
            var skinGallery = new DevExpress.XtraBars.Ribbon.GalleryDropDown();

            skinGallery.Manager            = this.barManager1;
            this.barSkin.ButtonStyle       = BarButtonStyle.DropDown;
            this.barSkin.DropDownControl   = skinGallery;
            this.barSkin.ActAsDropDown     = true;
            skinGallery.Gallery.ItemClick += (obj, se) => {
                this.OptConfig.Set <string>("SkinName", se.Item.Caption);
                Lanucher.ReLoadSkinName();
            };
            SkinHelper.InitSkinGalleryDropDown(skinGallery);
            var mnustyle = OptConfig.Get <string>("Menu");

            if (mnustyle == "Taobao")
            {
                barChkTaobao.Checked = true;
            }
            else
            {
                barChkSys.Checked = true;
            }
            SqlConnectionStringBuilder bld = new SqlConnectionStringBuilder(ConnString);

            barStaticItem2.Caption  = string.Format("{0} {1}", bld.DataSource.ToString(), bld.InitialCatalog);
            barStaticItem2.Caption += " " + RemoteIP;

            //同步服务器时间
            var serverTime = (DateTime)SqlHelper.ExecuteScalar(ConnString, CommandType.Text, "select getdate()");

            TimeSync.Default.StartSync(serverTime);

            //var t = new Thread(() => {
            //    while (true) {
            //        Thread.Sleep(1000);
            //        if (this.IsDisposed)
            //            return;
            //        while (!this.IsHandleCreated) { }
            //        this.Invoke(new Action(() => {
            //            barStaticItem3.Caption = TimeSync.Default.CurrentSyncTime.ToString("yyyy-MM-dd HH:mm:ss");
            //        }));
            //    }
            //});
            //t.IsBackground = true;
            //t.Start();

            //加载菜单
            LoadMenu();
            if (string.Compare(OptConfig.Get <string>("Menu"), "taobao", true) == 0)
            {
                barChkTaobao.Checked = true;
                barChkSys.Checked    = false;
                foreach (NavBarGroup gp in navMenu.Groups)
                {
                    gp.Expanded = true;
                }
            }
            else
            {
                barChkSys.Checked = true; barChkTaobao.Checked = false;
            }
            var w = OptConfig.Get <int>("MenuWidth");

            if (w > 0)
            {
                this.navMenu.Width = w;
            }

            try {
                var mpv = Lanucher.Start("Ultra.MainPage.MainView");
                if (null != mpv)
                {
                    mpv.MdiParent = this;
                    mpv.Show();
                }
            } catch { }
            var threg = new Thread(() => { RegSelfLogin(); });

            threg.IsBackground = true;
            threg.Start();
        }
Ejemplo n.º 2
0
        private void MainView_Load(object sender, EventArgs e)
        {
            Common.GetMACs(out LocalMAC);
            Common.GetLocalIpv4(out LocalIP);
            //try { RemoteIP = Common.GetRemoteIP(); } catch { RemoteIP = string.Empty; }
            RemoteIP = string.Empty;
            //检查登录是否是被授权的
            if (!IsAllowLogin())
            {
                SqlHelper.ExecuteNonQuery(ConnString, CommandType.Text, Sql_AddLoginFail,
                                          new SqlParameter("@LoginMAC", LocalMAC),
                                          new SqlParameter("@ExternalIP", RemoteIP),
                                          new SqlParameter("@LocalIP", LocalIP),
                                          new SqlParameter("@UserName", CurUser)
                                          );
                this.Invoke(new Action(() => {
                    this.navMenu.Enabled = false;
                    this.bar1.Visible    = false;
                    this.Text           += " 未被授权的登录";
                }));
                return;
            }
            if ((this.CurUser.IgnoreCaseEqual("admin")))
            {
                barBtnSysMnu.Visibility = BarItemVisibility.Always;
            }
            else
            {
                barBtnSysMnu.Visibility = BarItemVisibility.Never;
            }
            this.barLabel.Caption = this.CurUser;
            var skinGallery = new DevExpress.XtraBars.Ribbon.GalleryDropDown();

            skinGallery.Manager            = this.barManager1;
            this.barSkin.ButtonStyle       = BarButtonStyle.DropDown;
            this.barSkin.DropDownControl   = skinGallery;
            this.barSkin.ActAsDropDown     = true;
            skinGallery.Gallery.ItemClick += (obj, se) => {
                this.OptConfig.Set <string>("SkinName", se.Item.Caption);
                Lanucher.ReLoadSkinName();
            };
            SkinHelper.InitSkinGalleryDropDown(skinGallery);
            var mnustyle = OptConfig.Get <string>("Menu");

            if (mnustyle == "Taobao")
            {
                barChkTaobao.Checked = true;
            }
            else
            {
                barChkSys.Checked = true;
            }
            SqlConnectionStringBuilder bld = new SqlConnectionStringBuilder(ConnString);

            barStaticItem2.Caption  = string.Format("{0} {1}", bld.DataSource.ToString(), bld.InitialCatalog);
            barStaticItem2.Caption += " " + RemoteIP;

            //同步服务器时间
            var serverTime = (DateTime)SqlHelper.ExecuteScalar(ConnString, CommandType.Text, "select getdate()");

            TimeSync.Default.StartSync(serverTime);

            var t = new Thread(() => {
                while (true)
                {
                    Thread.Sleep(1000);
                    if (this.IsDisposed)
                    {
                        return;
                    }
                    while (!this.IsHandleCreated)
                    {
                    }
                    this.Invoke(new Action(() => {
                        barStaticItem3.Caption = TimeSync.Default.CurrentSyncTime.ToString("yyyy-MM-dd HH:mm:ss");
                    }));
                }
            });

            t.IsBackground = true;
            t.Start();

            t = new Thread(() => {
                while (true)
                {
                    Thread.Sleep(60 * 1000);
                    if (SqlHelper.ExecuteScalar(ConnString, CommandType.Text, "select 1 from t_forcedoffline where LoginMAC=@LoginMAC", new SqlParameter("@LoginMAC", LocalMAC)) != null)
                    {
                        MsgBox.ShowMessage("", "您已被管理员强制下线!");
                        GC.Collect();
                        System.Diagnostics.Process.GetCurrentProcess().Kill();
                    }
                }
            });
            t.IsBackground = true;
            t.Start();
            //加载菜单
            LoadMenu();
            if (string.Compare(OptConfig.Get <string>("Menu"), "taobao", true) == 0)
            {
                barChkTaobao.Checked = true;
                barChkSys.Checked    = false;
                foreach (NavBarGroup gp in navMenu.Groups)
                {
                    gp.Expanded = true;
                }
            }
            else
            {
                barChkSys.Checked = true; barChkTaobao.Checked = false;
            }
            var w = OptConfig.Get <int>("MenuWidth");

            if (w > 0)
            {
                this.navMenu.Width = w;
            }

            try {
                var mpv = Lanucher.Start("LS.ERP.MainPage.MainView");
                if (null != mpv)
                {
                    mpv.MdiParent = this;
                    mpv.Show();
                }
            } catch { }
            var threg = new Thread(() => { RegSelfLogin(); });

            threg.IsBackground = true;
            threg.Start();
        }