Exemple #1
0
        static public void SetConfig(QueueConfig qc, string sectionName)
        {
            AppSetting.BatchBegin();
            try
            {
                SettingItem queueSetting = AppSettingHelper.GetSpecifySection(sectionName);

                queueSetting.WriteSetting("DefaultQueueName", qc.DefaultQueueName);

                AppSetting.BatchCommit();
            }
            catch (Exception ex)
            {
                AppSetting.BatchCancel();

                MsgBox.ShowException(ex);
            }
        }
Exemple #2
0
        static public void SetConfig(PedalConfig cc)
        {
            AppSetting.BatchBegin();
            try
            {
                AppSetting.WriteSetting("PealDeviceName", cc.PealDeviceName);
                AppSetting.WriteSetting("TouchWay", cc.TouchWay.ToString());
                AppSetting.WriteInt("TouchInterval", cc.TouchInterval);
                AppSetting.WriteInt("SignCount", cc.SignCount);

                AppSetting.BatchCommit();
            }
            catch (Exception ex)
            {
                AppSetting.BatchCancel();

                MsgBox.ShowException(ex);
            }
        }
        private void sbutLogin_Click(object sender, EventArgs e)
        {
            try
            {
                ServerInfo si = _sm.FindAlias(cbxServer.Text);



                if (si == null)
                {
                    MessageBox.Show("未找到对应的服务器配置信息。", "提示");
                    return;
                }

                if (string.IsNullOrEmpty(si.ServerDriverFile))
                {
                    MessageBox.Show("未配置数据访问程序集。", "提示");
                    return;
                }

                IDBProvider dbProvider = null;


                string modulePath = System.Windows.Forms.Application.StartupPath + @"\" + si.ServerDriverFile;

                if (File.Exists(modulePath) == true)
                {
                    FileInfo fi = new FileInfo(modulePath);

                    string   assemblyName = fi.Name.Replace(fi.Extension, "");
                    string[] tmp          = ("..." + assemblyName).Split('.');
                    string   objName      = tmp[tmp.Length - 1];

                    dbProvider = (IDBProvider)Assembly.LoadFile(modulePath).CreateInstance(assemblyName + "." + objName);
                }

                if (dbProvider == null)
                {
                    MessageBox.Show("数据访问实例创建失败。", "提示");
                    return;
                }


                dbProvider.Init(si.ServerIP, si.ServerPort, si.ServerInstance, si.GrantAccount, si.GrantPwd);

                string        strErr = "";
                IDbConnection dc     = dbProvider.Open(ref strErr);

                if (dc == null)
                {
                    MessageBox.Show("数据服务访问失败:" + strErr, "提示");
                    return;
                }


                //身份验证...
                IVerify verify = null;
                if (string.IsNullOrEmpty(si.AuthenticationWay.Trim()) || _allowThridVerify == false)
                {
                    //未配置认证或不允许三方认证时,使用系统默认认证方式
                    if (_verifyDefault != null)
                    {
                        verify = _verifyDefault;
                    }
                }
                else
                {
                    modulePath = System.Windows.Forms.Application.StartupPath + @"\" + si.AuthenticationDirverFile;
                    if (File.Exists(modulePath) == true)
                    {
                        FileInfo fiVerify = new FileInfo(modulePath);

                        string   assemblyName = fiVerify.Name.Replace(fiVerify.Extension, "");
                        string[] tmp          = ("..." + assemblyName).Split('.');
                        string   objName      = tmp[tmp.Length - 1];

                        verify = (IVerify)Assembly.LoadFile(modulePath).CreateInstance(assemblyName + "." + objName);
                    }
                    else
                    {
                        MessageBox.Show("认证驱动文件不存在,暂不能登录。", "提示");
                        return;
                    }
                }

                if (verify == null)
                {
                    MessageBox.Show("认证对象不能实例化。", "提示");
                    return;
                }

                string attachInfo = "";

                verify.Init(dbProvider);
                _loginUser = verify.StartVerify(txtUser.Text, txtPwd.Text, out attachInfo, out strErr);

                if (_loginUser == null)
                {
                    if (string.IsNullOrEmpty(strErr) == false)
                    {
                        MessageBox.Show("认证失败:" + strErr, "提示");
                    }
                    return;
                }

                _serverName = cbxServer.Text;
                _password   = txtPwd.Text;

                _dbProvider = dbProvider;

                if (_businessVerify?.Invoke(_dbProvider, _loginUser) == false)
                {
                    _dbProvider = null;
                    _loginUser  = null;
                    _password   = "";
                    _serverName = "";

                    return;
                }

                try
                {
                    AppSetting.BatchBegin();
                    try
                    {
                        AppSetting.WriteSetting("loginserver", cbxServer.Text);
                        AppSetting.WriteSetting("loginuser", txtUser.Text);
                    }
                    finally
                    {
                        AppSetting.BatchCommit();
                    }
                }
                catch (Exception ex)
                {
                    MsgBox.ShowException(ex, this);
                }

                Close();
            }
            catch (Exception ex)
            {
                MsgBox.ShowException(ex, this);
            }
        }