Beispiel #1
0
        private void btnRegister_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(ectDept.SelectValue.ToString()))
            {
                MessageBox.Show("您没有选择需要注册的部门,请重新选择!");
                return;
            }

            try
            {
                SysRegister rg = SqlBaseProvider.GetSysRegister(Publics.GetRegisterNumber(Program.CpuInfo));

                if (String.IsNullOrEmpty(rg.DeptID))
                {
                    rg.DeptID    = ectDept.SelectValue.ToString();
                    rg.CpuCode   = Program.CpuInfo;
                    rg.CrtDate   = DateTime.Now;
                    rg.RegNumber = Publics.GetRegisterNumber(Program.CpuInfo);
                    rg.RegCode   = rg.RegNumber;

                    SqlBaseProvider.SaveSysRegister(rg, DataProviderAction.Create);

                    if (rg.RegID > 0)
                    {
                        MessageBox.Show("该终端已经在系统里注册成功!");
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        throw new Exception("注册时数据库发生错误!");
                    }
                }
                else
                {
                    if (rg.DeptID != ectDept.SelectValue.ToString())
                    {
                        MessageBox.Show("该终端已经在系统里被其它部门注册完成,不能被重复注册!");
                        return;
                    }
                    else
                    {
                        MessageBox.Show("该终端已经在系统里注册完成,不需要再次注册,确认后直接进入系统!");
                        this.DialogResult = DialogResult.OK;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("注册时产生错误,请与系统管理员联系!" + ex.Message);
                return;
            }
        }
Beispiel #2
0
 private void btnView_Click(object sender, EventArgs e)
 {
     MessageBox.Show(Publics.GetRegisterNumber(Program.CpuInfo), "查看注册码");
 }
Beispiel #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (String.IsNullOrEmpty(txtManID.Text))
                {
                    MessageBox.Show("用户名不能为空!", PublicConsts.PC_Tip);
                    txtManID.Focus();
                    return;
                }

                if (String.IsNullOrEmpty(txtPassword.Text))
                {
                    MessageBox.Show("密码不能为空!", PublicConsts.PC_Tip);
                    txtPassword.Focus();
                    return;
                }

                SysOnline so = SqlBaseProvider.GetSysOnline(txtManID.Text);

                if (!String.IsNullOrEmpty(so.ManID))
                {
                    MessageBox.Show("您的用户名已经登陆,不能重复登录!", PublicConsts.PC_Tip);
                    txtManID.Focus();
                    return;
                }

                UserCache uc = SqlBaseProvider.GetLoginInfo(txtManID.Text, String.Empty, String.Empty);

                if (String.IsNullOrEmpty(uc.Company.CoID) || String.IsNullOrEmpty(uc.Dept.DeptID) || String.IsNullOrEmpty(uc.Man.ManID))
                {
                    MessageBox.Show("您的员工资料不正确,不能登录本系统!", PublicConsts.PC_Tip);
                    txtManID.Focus();
                    return;
                }

                if (Crypto.MD5Crypto(txtPassword.Text) != uc.Man.OperPassword)
                {
                    MessageBox.Show("密码输入错误,请核实!", PublicConsts.PC_Tip);
                    txtPassword.Focus();
                    txtPassword.Text = String.Empty;
                    return;
                }

                //Program.ManInfo = uc;

                if (uc.Man.IsFirst)
                {
                    MessageBox.Show("您的用户名第一次登录本系统,请修改原始密码后重新登录!", PublicConsts.PC_Tip);
                    txtPassword.Text  = String.Empty;
                    this.DialogResult = DialogResult.Yes;
                }
                else
                {
                    SysRegister sr = SqlBaseProvider.GetSysRegister(Publics.GetRegisterNumber(Program.CpuInfo));

                    short ml = SqlBaseProvider.GetSetManLevel();

                    if (uc.Man.IsLock)
                    {
                        Global.ShowSysInfo("您的用户名被锁定,不能登录系统!" + StringHelper.WriteEnter(1) + "请与部门负责人或者系统管理员联系进行解锁!");
                        txtManID.Focus();
                        this.DialogResult = DialogResult.Cancel;
                        return;
                    }

                    so.ManID = txtManID.Text;
                    so.RegID = sr.RegID;

                    SqlBaseProvider.LoginSysOnline(so, DataProviderAction.Create);


                    Publics.UpdateConfig(Application.ExecutablePath, "IsRememberMe", chbRemember.Checked.ToString());
                    Publics.UpdateConfig(Application.ExecutablePath, "RememberUser", txtManID.Text);
                    ConfigurationManager.RefreshSection("appSettings");

                    uc.Register     = sr;
                    Program.ManInfo = uc;

                    this.DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, PublicConsts.PC_Tip);
                return;
            }
        }
Beispiel #4
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);


            System.Diagnostics.Process[] papp = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);
            if (papp.Length > 1)
            {
                SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            }
            else
            {
                SetForegroundWindow(Process.GetCurrentProcess().MainWindowHandle);
            }

            Program.NowLoginMan = String.Empty;

            if (true)
            {
                bool isDB = true;
                while (isDB)
                {
                    try
                    {
                        SqlConnection conn = DBUtils.GetConnection();
                        if (conn.State == ConnectionState.Open)
                        {
                            conn.Close();
                            conn.Dispose();
                            isDB = false;
                        }
                        else
                        {
                            throw new Exception("指定的数据库不存在或者数据库配置错误!");
                        }
                    }
                    catch (Exception)
                    {
                        Global.ShowSysInfo("指定的数据库不存在或者数据库配置错误!");
                        DBConfig     dbconfig    = new DBConfig();
                        DialogResult dbconfigrtn = dbconfig.ShowDialog();
                        dbconfig.Dispose();

                        if (dbconfigrtn != DialogResult.OK)
                        {
                            return;
                        }
                    }
                }

                Program.CpuInfo = Publics.GetFirstMacAddress();
                // 判断是否首次注册
                SysRegister sr = SqlBaseProvider.GetSysRegister(Publics.GetRegisterNumber(Program.CpuInfo));

                // 如果未注册则进行注册
                if (String.IsNullOrEmpty(sr.DeptID))
                {
                    Register rgForm = new Register();
                    if (rgForm.ShowDialog() != DialogResult.OK)
                    {
                        Application.Exit();
                    }
                }
            }

            Login lg = new Login();

FirstLogined:
            DialogResult rtn = lg.ShowDialog();

            Program.NowLoginMan = lg.txtManID.Text;

            if (rtn == DialogResult.OK)
            {
GotoMain:
                Application.Run(new MainForm());
                if (isCancel)
                {
                    isCancel = false;
                    goto GotoMain;
                }
            }
            else if (rtn == DialogResult.Yes)
            {
                FirstLogin first = new FirstLogin();

                if (first.ShowDialog() == DialogResult.OK)
                {
                    goto FirstLogined;
                }
                else
                {
                    Application.Exit();
                }
            }
            else
            {
                Application.Exit();
            }
        }
Beispiel #5
0
 private void Register_Load(object sender, EventArgs e)
 {
     lblRegNumber.Text = Publics.GetRegisterNumber(Program.CpuInfo);
 }