Ejemplo n.º 1
0
        void menu_newServer(object sender, System.EventArgs e)
        {
            int nActiveLine = -1;

            if (ListView.SelectedIndices.Count != 0)
            {
                nActiveLine = ListView.SelectedIndices[0];
            }


            // ListViewItem item = listView1.Items[nActiveLine];

            LoginDlg dlg = new LoginDlg();

            dlg.Font = GuiUtil.GetDefaultFont();

            dlg.Text = "新增服务器地址和缺省帐户";

            if (nActiveLine == -1)
            {
                // 无参考事项情形的新增
                dlg.textBox_serverAddr.Text = "http://dp2003.com/dp2kernel";
                dlg.textBox_userName.Text   = "public";
            }
            else
            {
                dlg.textBox_password.Text         = ((Server)Servers[nActiveLine]).DefaultPassword;
                dlg.textBox_serverAddr.Text       = ((Server)Servers[nActiveLine]).Url;
                dlg.textBox_userName.Text         = ((Server)Servers[nActiveLine]).DefaultUserName;
                dlg.checkBox_savePassword.Checked = ((Server)Servers[nActiveLine]).SavePassword;
            }

            dlg.ShowDialog(this);

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

            Server server = Servers.NewServer(nActiveLine);

            server.DefaultPassword = dlg.textBox_password.Text;
            server.Url             = dlg.textBox_serverAddr.Text;
            server.DefaultUserName = dlg.textBox_userName.Text;
            server.SavePassword    = dlg.checkBox_savePassword.Checked;

            Servers.Changed = true;

            FillList();

            // 选择一行
            // parameters:
            //		nIndex	要设置选择标记的行。如果==-1,表示清除全部选择标记但不选择。
            //		bMoveFocus	是否同时移动focus标志到所选择行
            ListViewUtil.SelectLine(ListView,
                                    Servers.Count - 1,
                                    true);

            m_bChanged = true;
        }
Ejemplo n.º 2
0
        // GCAT通道登录 旧的方式
        public void gcat_channel_BeforeLogin(object sender,
                                             DigitalPlatform.GcatClient.BeforeLoginEventArgs e)
        {
            string strUserName = (string)this.DetailForm.MainForm.ParamTable["author_number_account_username"];
            string strPassword = (string)this.DetailForm.MainForm.ParamTable["author_number_account_password"];

            if (String.IsNullOrEmpty(strUserName) == true)
            {
                strUserName = "******";
                strPassword = "";
            }

            // 直接试探
            if (!(e.UserName == strUserName && e.Failed == true) &&
                strUserName != "")
            {
                e.UserName = strUserName;
                e.Password = strPassword;
                return;
            }

            LoginDlg dlg = new LoginDlg();

            GuiUtil.SetControlFont(dlg, this.DetailForm.MainForm.Font);

            if (e.Failed == true)
            {
                dlg.textBox_comment.Text = "登录失败。加著者号码功能需要重新登录";
            }
            else
            {
                dlg.textBox_comment.Text = "加著者号码功能需要登录";
            }

            dlg.textBox_serverAddr.Text       = e.GcatServerUrl;
            dlg.textBox_userName.Text         = strUserName;
            dlg.textBox_password.Text         = strPassword;
            dlg.checkBox_savePassword.Checked = true;

            dlg.textBox_serverAddr.Enabled = false;
            dlg.TopMost = true; // 2009/11/12 因为ShowDialog(null),为了防止对话框被放在非顶部
            dlg.ShowDialog(null);
            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Cancel = true;    // 2009/11/12 如果缺这一句,会造成Cancel后仍然重新弹出登录对话框
                return;
            }

            strUserName = dlg.textBox_userName.Text;
            strPassword = dlg.textBox_password.Text;

            e.UserName = strUserName;
            e.Password = strPassword;

            this.DetailForm.MainForm.ParamTable["author_number_account_username"] = strUserName;
            this.DetailForm.MainForm.ParamTable["author_number_account_password"] = strPassword;
        }
Ejemplo n.º 3
0
        void menu_modifyServer(object sender, System.EventArgs e)
        {
            if (ListView.SelectedIndices.Count == 0)
            {
                MessageBox.Show(this, "尚未选择要修改的事项 ...");
                return;
            }

            int nActiveLine = ListView.SelectedIndices[0];
            // ListViewItem item = listView1.Items[nActiveLine];

            LoginDlg dlg = new LoginDlg();

            dlg.Font = GuiUtil.GetDefaultFont();

            dlg.Text = "修改缺省帐户参数";

            dlg.textBox_password.Text         = ((Server)Servers[nActiveLine]).DefaultPassword;
            dlg.textBox_serverAddr.Text       = ((Server)Servers[nActiveLine]).Url;
            dlg.textBox_userName.Text         = ((Server)Servers[nActiveLine]).DefaultUserName;
            dlg.checkBox_savePassword.Checked = ((Server)Servers[nActiveLine]).SavePassword;

            dlg.ShowDialog(this);

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

            ((Server)Servers[nActiveLine]).DefaultPassword = dlg.textBox_password.Text;
            ((Server)Servers[nActiveLine]).Url             = dlg.textBox_serverAddr.Text;
            ((Server)Servers[nActiveLine]).DefaultUserName = dlg.textBox_userName.Text;
            ((Server)Servers[nActiveLine]).SavePassword    = dlg.checkBox_savePassword.Checked;

            Servers.Changed = true;

            FillList();

            // 选择一行
            // parameters:
            //		nIndex	要设置选择标记的行。如果==-1,表示清除全部选择标记但不选择。
            //		bMoveFocus	是否同时移动focus标志到所选择行
            ListViewUtil.SelectLine(ListView,
                                    nActiveLine,
                                    true);

            m_bChanged = true;
        }
Ejemplo n.º 4
0
 private void OnLoginCommand(string prm)
 {
     if (prm?.ToLower() == "add")
     {
         LoginDlg dlg = new LoginDlg(Unit);
         dlg.ShowDialog();
     }
     else if (prm?.ToLower() == "remove")
     {
         if (SelectedLogin != null)
         {
             Unit.Login.Delete(SelectedLogin);
             Unit.Save();
         }
     }
 }
Ejemplo n.º 5
0
        // 修改所选择的账户
        void MenuItem_modifyAccount_Click(object sender, EventArgs e)
        {
            string strError = "";

            if (this.listView_accounts.SelectedItems.Count != 1)
            {
                strError = "请选择一个需要修改的账户行";
                goto ERROR1;
            }

            ListViewItem item = this.listView_accounts.SelectedItems[0];

            using (LoginDlg dlg = new LoginDlg())
            {
                Account account = item.Tag as Account;
                dlg.ServerUrl    = account.ServerUrl;
                dlg.UserName     = account.UserName;
                dlg.Password     = account.Password;
                dlg.SavePassword = account.SavePassword;

                dlg.ShowDialog(this);

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

                account.ServerUrl    = dlg.ServerUrl;
                account.UserName     = dlg.UserName;
                account.Password     = dlg.Password;
                account.SavePassword = dlg.SavePassword;

                if (account.SavePassword == false)
                {
                    account.EncryptPassword = null;
                }

                {
                    ListViewUtil.ChangeItemText(item, COLUMN_SERVERURL, account.ServerUrl);
                    ListViewUtil.ChangeItemText(item, COLUMN_USERNAME, account.UserName);
                }
            }
            return;

ERROR1:
            MessageBox.Show(this, strError);
        }
Ejemplo n.º 6
0
        // 新建账户
        void MenuItem_newAccount_Click(object sender, EventArgs e)
        {
            using (LoginDlg dlg = new LoginDlg())
            {
                dlg.ServerUrl = "http://dp2003.com:8083/dp2mserver";
                dlg.ShowDialog(this);

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

                Account account = new Account
                {
                    ServerUrl    = dlg.ServerUrl,
                    UserName     = dlg.UserName,
                    Password     = dlg.Password,
                    SavePassword = dlg.SavePassword,
                };

                if (account.SavePassword == false)
                {
                    account.EncryptPassword = null;
                }

                AddItem(account);

                /*
                 * {
                 *  ListViewItem item = new ListViewItem();
                 *  ListViewUtil.ChangeItemText(item, COLUMN_SERVERURL, dlg.ServerUrl);
                 *  ListViewUtil.ChangeItemText(item, COLUMN_USERNAME, dlg.UserName);
                 *  Account account = new Account
                 *  {
                 *      ServerUrl = dlg.ServerUrl,
                 *      UserName = dlg.UserName,
                 *      Password = dlg.Password
                 *  };
                 *  item.Tag = account;
                 *  this.listView_accounts.Items.Add(item);
                 * }
                 */
            }
        }
Ejemplo n.º 7
0
        void channels_AskAccountInfo(object sender, AskAccountInfoEventArgs e)
        {
            e.Owner = this;

            LoginDlg dlg = new LoginDlg();

            GuiUtil.AutoSetDefaultFont(dlg);

            dlg.textBox_serverAddr.Text       = this.textBox_kernelUrl.Text;
            dlg.textBox_serverAddr.ReadOnly   = true;
            dlg.textBox_comment.Text          = e.Comment;
            dlg.textBox_userName.Text         = this.ManagerUserName;
            dlg.textBox_password.Text         = this.ManagerPassword;
            dlg.checkBox_savePassword.Checked = this.SavePassword;
            dlg.ShowDialog(this);

            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Result = 0;
                return;
            }

            this.ManagerPassword = dlg.textBox_userName.Text;

            if (dlg.checkBox_savePassword.Checked == true)
            {
                this.ManagerPassword = dlg.textBox_password.Text;
            }
            else
            {
                this.ManagerPassword = "";
            }

            e.UserName = dlg.textBox_userName.Text;
            e.Password = dlg.textBox_password.Text;

            e.Result = 1;
        }
Ejemplo n.º 8
0
        void _channelPool_BeforeLogin(object sender, BeforeLoginEventArgs e)
        {
            bool bIsReader = false;

            if (e.FirstTry == true)
            {
                Debug.Assert(_currentAccount != null, "");

                if (IsDot(_currentAccount.ServerUrl) == true)
                {
                    e.LibraryServerUrl = Program.MainForm.LibraryServerUrl;
                }
                else
                {
                    e.LibraryServerUrl = _currentAccount.ServerUrl;
                }

                if (IsDot(_currentAccount.UserName) == true)
                {
                    e.UserName = Program.MainForm.AppInfo.GetString(
                        "default_account",
                        "username",
                        "");

                    e.Password = Program.MainForm.AppInfo.GetString(
                        "default_account",
                        "password",
                        "");
                    e.Password = Program.MainForm.DecryptPasssword(e.Password);

                    bIsReader =
                        Program.MainForm.AppInfo.GetBoolean(
                            "default_account",
                            "isreader",
                            false);
                }
                else
                {
                    e.UserName = _currentAccount.UserName;

                    e.Password = _currentAccount.Password;

                    bIsReader = string.IsNullOrEmpty(_currentAccount.IsReader) == true ? false : DomUtil.IsBooleanTrue(_currentAccount.IsReader);
                }

#if NO
                if (IsDot(_currentAccount.IsReader) == true)
                {
                    bIsReader =
                        Program.MainForm.AppInfo.GetBoolean(
                            "default_account",
                            "isreader",
                            false);
                }
                else
                {
                    bIsReader = DomUtil.IsBooleanTrue(_currentAccount.IsReader);
                }
#endif
                Debug.Assert(Program.MainForm != null, "");

                string strLocation = Program.MainForm.AppInfo.GetString(
                    "default_account",
                    "location",
                    "");
                e.Parameters = "location=" + strLocation;
                if (bIsReader == true)
                {
                    e.Parameters += ",type=reader";
                }

                // 2014/9/13
                e.Parameters += ",mac=" + StringUtil.MakePathList(SerialCodeForm.GetMacAddress(), "|");

#if SN
                // 从序列号中获得 expire= 参数值
                string strExpire = Program.MainForm.GetExpireParam();
                if (string.IsNullOrEmpty(strExpire) == false)
                {
                    e.Parameters += ",expire=" + strExpire;
                }
#endif

                e.Parameters += ",client=dp2circulation|" + Program.ClientVersion;

                if (String.IsNullOrEmpty(e.UserName) == false)
                {
                    return; // 立即返回, 以便作第一次 不出现 对话框的自动登录
                }
            }

            // TODO: 可以出现对话框,但要注意跨线程的问题

            DialogResult result = (DialogResult)Program.MainForm.Invoke((Func <DialogResult>)(() =>
            {
                using (LoginDlg dlg = new LoginDlg())
                {
                    Hashtable table = StringUtil.ParseParameters(e.Parameters, ',', '=');
                    string type     = (string)table["type"];
                    bIsReader       = type == "reader";
                    // TODO: Url 不让修改
                    dlg.UserName     = bIsReader ? "~" + e.UserName : e.UserName;
                    dlg.Comment      = e.ErrorInfo;
                    dlg.SavePassword = e.SavePasswordLong;
                    dlg.ServerUrl    = e.LibraryServerUrl;
                    dlg.ShowDialog(Program.MainForm);
                    if (dlg.DialogResult == DialogResult.OK)
                    {
                        if (dlg.UserName.StartsWith("~"))
                        {
                            e.UserName = dlg.UserName.Substring(1);
                            bIsReader  = true;
                        }
                        else
                        {
                            e.UserName = dlg.UserName;
                            bIsReader  = false;
                        }
                        e.Password         = dlg.Password;
                        e.SavePasswordLong = dlg.SavePassword;

                        // 同步到当前账户
                        if (IsDot(_currentAccount.UserName) == false)
                        {
                            _currentAccount.UserName = e.UserName;
                            _currentAccount.Password = e.Password;
                            _currentAccount.IsReader = bIsReader ? "yes" : "no";
                        }

                        // 长期保存密码,写回到 servers.xml 中
                        if (e.SavePasswordLong)
                        {
                            // 保存对账户的修改
                            var changed = SaveAccountInfo(this._servers_dom, _currentAccount);
                            if (changed == true)
                            {
                                this.ServersDomChanged = true;
                            }
                        }

                        table["type"] = bIsReader ? "reader" : "worker";
                        e.Parameters  = StringUtil.BuildParameterString(table, ',', '=');
                    }
                    return(dlg.DialogResult);
                }
            }));

            if (result == DialogResult.Cancel)
            {
                e.Cancel = true;
                return;
            }
        }
Ejemplo n.º 9
0
        protected override void Run()
        {
            bRunning = true;
            _isLogin = false;

            DateTime lastAdjustTime = DateTime.Now - new TimeSpan(1, 0, 0, 0);

            while (bRunning)
            {
                try
                {
                    if ((DateTime.Now - lastAdjustTime).TotalSeconds > 30 && _curState != OptStatus.NOT_LOGIN)
                    {
                        lastAdjustTime = DateTime.Now;
                        string strAdjustResp = MaskService.JiaoZhun(SysConfig.GetInstance().UserName);
                        if (!string.IsNullOrEmpty(strAdjustResp))
                        {
                            string[] vecAdjust = strAdjustResp.Split(new char[] { '*' });
                            if (vecAdjust.Length < 3)
                            {
                                continue;
                            }
                            else
                            {
                                int  todayCntr = 0;
                                bool bSucc     = int.TryParse(vecAdjust[0], out todayCntr);
                                if (bSucc)
                                {
                                    ShowData.GetInstance().TodayCntr = todayCntr;
                                }
                                else
                                {
                                    ShowData.GetInstance().TodayCntr = 0;
                                }


                                int rightCntr = 0;
                                bSucc = int.TryParse(vecAdjust[1], out rightCntr);
                                if (bSucc)
                                {
                                    ShowData.GetInstance().SuccCntr = rightCntr;
                                }
                                else
                                {
                                    ShowData.GetInstance().SuccCntr = 0;
                                }



                                int errorCntr = 0;
                                bSucc = int.TryParse(vecAdjust[2], out errorCntr);
                                if (bSucc)
                                {
                                    ShowData.GetInstance().FailCntr = errorCntr;
                                }
                                else
                                {
                                    ShowData.GetInstance().FailCntr = 0;
                                }

                                //发送消息
                                Win32API.PostMessage(HWnd, MsgDef.CNTR_MSG, 0, 0);

                                if (vecAdjust.Length < 5)
                                {
                                    continue;
                                }

                                //扫描间隔
                                int scanIntervalSecond = 1000;
                                bSucc = int.TryParse(vecAdjust[3], out scanIntervalSecond);

                                if (bSucc)
                                {
                                    _scanIntervalSecond = scanIntervalSecond;
                                }
                                else
                                {
                                    _scanIntervalSecond = 1000;
                                }

                                //打码时常
                                int inputMaskSecond = 15;
                                bSucc = int.TryParse(vecAdjust[4], out inputMaskSecond);
                                if (bSucc)
                                {
                                    _inputMaskSecond = inputMaskSecond;
                                }
                                else
                                {
                                    _inputMaskSecond = 15;
                                }
                            }
                        }
                    }



                    if (_curState == OptStatus.RUNNING_NOMASK)
                    {
                        //没有码, 每隔1秒拉一次码,拉倒码, 展示,变化状态为有码,启动计时器
                        byte[] arrRslt = MaskService.GetMask(SysConfig.GetInstance().UserName, SysConfig.GetInstance().Token);
                        if (arrRslt.Length < 800)
                        {
                            try
                            {
                                string str = System.Text.Encoding.Default.GetString(arrRslt);
                                if (str == "false")
                                {
                                    Win32API.PostMessage(HWnd, MsgDef.HEART_BEAT_MSG, 0, 0);
                                    Thread.Sleep(_scanIntervalSecond);
                                }
                                else if (str == "relogin")
                                {
                                    _curState = OptStatus.NOT_LOGIN;
                                }
                                else
                                {
                                    _curState = OptStatus.NOT_START;
                                }
                            }
                            catch (Exception ex)
                            {
                                _curState = OptStatus.NOT_START;
                            }
                        }
                        else
                        {
                            try
                            {
                                Stream stream = new MemoryStream(arrRslt);
                                Image  img    = Image.FromStream(stream);

                                _inputMaskStartTime = DateTime.Now;
                                _curState           = OptStatus.RUNNING_HAVEMASK;

                                ShowData.GetInstance().Pic = img;
                                Win32API.PostMessage(HWnd, MsgDef.UPDATE_IMG, 0, 0);
                            }
                            catch (Exception ex)
                            {
                                Thread.Sleep(_scanIntervalSecond);
                            }
                        }
                    }
                    else if (_curState == OptStatus.RUNNING_HAVEMASK)
                    {
                        TimeSpan span      = DateTime.Now - _inputMaskStartTime;
                        int      curSecond = (int)span.TotalSeconds;
                        if (curSecond > _inputMaskSecond)
                        {
                            _curState = OptStatus.RUNNING_NOMASK;
                            if (++_notInputCntr >= 2)
                            {
                                //停止扫描
                                Win32API.PostMessage(HWnd, MsgDef.START_BTN_MSG, 1, 1);
                                return;
                            }
                        }
                        else
                        {
                            bool bWaitEvent = ResetEvent.WaitOne(1000);
                            if (bWaitEvent)
                            {
                                _notInputCntr = 0;
                                //发送码
                                string strResp = MaskService.SendMaskRslt(ShowData.GetInstance().MaskCode, SysConfig.GetInstance().UserName);
                                if (!string.IsNullOrEmpty(strResp))
                                {
                                    string[] vec = strResp.Split(new char[] { '*' });
                                    if (vec.Length <= 3)
                                    {
                                        _curState = OptStatus.RUNNING_NOMASK;
                                        continue;
                                    }
                                    else
                                    {
                                        if (vec[0] == "true")
                                        {
                                            ShowData.GetInstance().SuccCntr++;
                                        }
                                        else
                                        {
                                            ShowData.GetInstance().FailCntr++;
                                        }
                                        ShowData.GetInstance().TodayCntr++;

                                        SysConfig.GetInstance().Token = vec[vec.Length - 1];
                                        SysConfig.GetInstance().SaveToken();

                                        int  typeCntr = 0;
                                        bool bSucc    = int.TryParse(vec[1], out typeCntr);
                                        if (bSucc)
                                        {
                                            ShowData.GetInstance().TyperCntr = typeCntr;
                                        }
                                        else
                                        {
                                            ShowData.GetInstance().TyperCntr = 0;
                                        }

                                        int remainCntr = 0;
                                        bSucc = int.TryParse(vec[2], out remainCntr);
                                        if (bSucc)
                                        {
                                            ShowData.GetInstance().RemainCntr = remainCntr;
                                        }
                                        else
                                        {
                                            ShowData.GetInstance().RemainCntr = 0;
                                        }

                                        if (remainCntr / typeCntr > 4 && typeCntr > 0)
                                        {
                                            ShowData.GetInstance().WarnMsg = "请增加打码人员!";
                                        }
                                        else
                                        {
                                            ShowData.GetInstance().WarnMsg = "";
                                        }


                                        //发送消息
                                        Win32API.PostMessage(HWnd, MsgDef.CNTR_MSG, 0, 0);
                                    }
                                }

                                _curState = OptStatus.RUNNING_NOMASK;
                            }
                            else
                            {
                                ShowData.GetInstance().CurSeconds = curSecond;
                                Win32API.PostMessage(HWnd, MsgDef.REMAIN_SECONDS_MSG, _inputMaskSecond - curSecond - 1, 0);
                            }
                        }
                    }
                    else if (_curState == OptStatus.NOT_LOGIN)
                    {
                        Win32API.PostMessage(HWnd, MsgDef.LOGIN_MSG, 0, 0);
                        LoginDlg dlg = new LoginDlg();

                        DialogResult rst = dlg.ShowDialog();
                        if (rst == DialogResult.OK)
                        {
                            SysConfig.GetInstance().LoginAddr = dlg.ServerIp.Trim();
                            bool bLoginSucc = MaskService.Login(dlg.UserName.Trim(), dlg.Pwd.Trim());
                            if (bLoginSucc)
                            {
                                Win32API.PostMessage(HWnd, MsgDef.LOGIN_MSG, 1, 0);
                                SysConfig.GetInstance().UserName = dlg.UserName.Trim();


                                SysConfig.GetInstance().PassWord = dlg.Pwd.Trim();
                                SysConfig.GetInstance().SaveLoginInfo();
                                _userName = dlg.UserName;
                                _curState = OptStatus.NOT_START;
                                _isLogin  = true;
                            }
                            else
                            {
                                _isLogin = false;
                                if (++_loginFailCntr > 2)
                                {
                                    CurState = OptStatus.NOT_START;
                                    Win32API.PostMessage(HWnd, MsgDef.CLOSE_MSG, 0, 0);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            Win32API.PostMessage(HWnd, MsgDef.CLOSE_MSG, 0, 0);
                            //退出程序
                            return;
                        }
                    }
                    else if (_curState == OptStatus.NOT_START)
                    {
                        if (!_isStoped)
                        {
                            _isStoped = true;
                            MaskService.StopInput(SysConfig.GetInstance().UserName);
                        }
                        Thread.Sleep(1000);
                    }
                }
                catch (Exception ex)
                {
                }
            }

            if (_isLogin)
            {
                MaskService.Close(_userName);
            }
        }
Ejemplo n.º 10
0
        // 获得缺省帐户信息
        // return:
        //		2	already login succeed
        //		1	dialog return OK
        //		0	dialog return Cancel
        //		-1	other error
        public void OnAskAccountInfo(object sender,
                                     AskAccountInfoEventArgs e)
        {
            bool bFirst = true;

            bool bAutoLogin   = (e.LoginStyle & LoginStyle.AutoLogin) == LoginStyle.AutoLogin;
            bool bFillDefault = (e.LoginStyle & LoginStyle.FillDefaultInfo) == LoginStyle.FillDefaultInfo;

            e.Owner    = this.ownerForm;
            e.UserName = "";
            e.Password = "";

            LoginDlg dlg = new LoginDlg();

            dlg.Font = GuiUtil.GetDefaultFont();

            Server server = this[e.Url];

            dlg.textBox_serverAddr.Text = e.Url;
            if (bFillDefault == true)
            {
                if (server != null)
                {
                    dlg.textBox_userName.Text         = (server.DefaultUserName == "" ? "public" : server.DefaultUserName);
                    dlg.textBox_password.Text         = server.DefaultPassword;
                    dlg.checkBox_savePassword.Checked = server.SavePassword;
                }
                else
                {
                    dlg.textBox_userName.Text         = "public";
                    dlg.textBox_password.Text         = "";
                    dlg.checkBox_savePassword.Checked = false;
                }
            }

            if (e.Comment != null)
            {
                dlg.textBox_comment.Text = e.Comment;
            }

DOLOGIN:
            if (e.Channels != null)
            {
                if (bAutoLogin == false && bFirst == true)
                {
                    goto REDOINPUT;
                }

                // 找到Channel
                RmsChannel channel = e.Channel; // 2013/2/14
                if (channel == null)
                {
                    channel = e.Channels.GetChannel(dlg.textBox_serverAddr.Text);
                }

                Debug.Assert(channel != null, "Channels.GetChannel()异常...");

                string strError;
                // 登录
                int nRet = channel.Login(dlg.textBox_userName.Text,
                                         dlg.textBox_password.Text,
                                         out strError);

                if (nRet != 1)
                {
                    strError = "以用户名 '" + dlg.textBox_userName.Text + "' 登录到 '" + dlg.textBox_serverAddr.Text + "' 失败: " + strError;

                    if (this.ownerForm != null)
                    {
                        MessageBox.Show(this.ownerForm, strError);
                    }
                    else
                    {
                        e.ErrorInfo = strError;
                        e.Result    = -1;
                    }

                    goto REDOINPUT;
                }
                else // 登录成功
                {
                    if (String.Compare(e.Url, dlg.textBox_serverAddr.Text, true) != 0)
                    {
                        // 创建一个新的Server对象
                        // return:
                        //		-1	出错
                        //		0	加入了
                        //		1	发现重复,没有加入
                        nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1);
                        if (nRet == 0)
                        {
                            e.Url = channel.Url;
                        }
                    }

                    server = this[dlg.textBox_serverAddr.Text];

                    if (server == null) // 2006/8/19 add
                    {
                        // 创建一个新的Server对象
                        // return:
                        //		-1	出错
                        //		0	加入了
                        //		1	发现重复,没有加入
                        nRet = this.NewServer(dlg.textBox_serverAddr.Text, -1);
                        if (nRet == 0)
                        {
                            e.Url = channel.Url;
                        }

                        server = this[dlg.textBox_serverAddr.Text];
                    }

                    Debug.Assert(server != null, "此时server不可能为null");

                    server.DefaultUserName = dlg.textBox_userName.Text;
                    server.DefaultPassword = dlg.textBox_password.Text;
                    server.SavePassword    = dlg.checkBox_savePassword.Checked;
                    this.m_bChanged        = true;

                    e.Result = 2;
                    return;
                }
            }


REDOINPUT:
            bFirst = false;

            dlg.ShowDialog(ownerForm);

            if (dlg.DialogResult != DialogResult.OK)
            {
                e.Result = 0;
                return;
            }

            if (e.Channels == null)
            {
                e.UserName = dlg.textBox_userName.Text;
                e.Password = dlg.textBox_password.Text;

                e.Result = 1;
                return;
            }


            goto DOLOGIN;
        }
Ejemplo n.º 11
0
        void channelArray_AskAccountInfo(object sender,
                                         AskDtlpAccountInfoEventArgs e)
        {
            e.Owner    = null;
            e.UserName = "";
            e.Password = "";

            LoginDlg dlg = new LoginDlg();

            GuiUtil.SetControlFont(dlg, this.Font);

            AccountItem item = (AccountItem)AccountTable[e.Path];

            if (item == null)
            {
                item = new AccountItem();
                AccountTable.Add(e.Path, item);

                // 从配置文件中得到缺省账户
                item.UserName = MainForm.AppInfo.GetString(
                    "preference",
                    "defaultUserName",
                    "public");
                item.Password = MainForm.AppInfo.GetString(
                    "preference",
                    "defaultPassword",
                    "");
            }

            dlg.textBox_serverAddr.Text = e.Path;
            dlg.textBox_userName.Text   = item.UserName;
            dlg.textBox_password.Text   = item.Password;

            // 先登录一次再说
            {
                byte[] baResult = null;
                int    nRet     = e.Channel.API_ChDir(dlg.textBox_userName.Text,
                                                      dlg.textBox_password.Text,
                                                      e.Path,
                                                      out baResult);

                // 登录成功
                if (nRet > 0)
                {
                    e.Result = 2;
                    return;
                }
            }


            dlg.StartPosition = FormStartPosition.CenterScreen;
            dlg.ShowDialog(this);

            if (dlg.DialogResult == DialogResult.OK)
            {
                item.UserName = dlg.textBox_userName.Text;
                item.Password = dlg.textBox_password.Text;

                e.UserName = dlg.textBox_userName.Text;
                e.Password = dlg.textBox_password.Text;
                e.Owner    = this;
                e.Result   = 1;
                return;
            }

            e.Result = 0;
            return;
        }
Ejemplo n.º 12
0
		void menu_newServer(object sender, System.EventArgs e)
		{
			int nActiveLine = -1;
			if (ListView.SelectedIndices.Count != 0)
			{
				nActiveLine = ListView.SelectedIndices[0];
			}


			// ListViewItem item = listView1.Items[nActiveLine];

			LoginDlg dlg = new LoginDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

			dlg.Text = "新增服务器地址和缺省帐户";

            if (nActiveLine == -1)
            {   
                // 无参考事项情形的新增
                dlg.textBox_serverAddr.Text = "http://dp2003.com/dp2kernel";
                dlg.textBox_userName.Text = "public";
            }
            else
			{
				dlg.textBox_password.Text = ((Server)Servers[nActiveLine]).DefaultPassword;
				dlg.textBox_serverAddr.Text = ((Server)Servers[nActiveLine]).Url;
				dlg.textBox_userName.Text = ((Server)Servers[nActiveLine]).DefaultUserName;
				dlg.checkBox_savePassword.Checked = ((Server)Servers[nActiveLine]).SavePassword;
			}

			dlg.ShowDialog(this);

			if (dlg.DialogResult != DialogResult.OK)
				return;

			Server server = Servers.NewServer(nActiveLine);
			server.DefaultPassword = dlg.textBox_password.Text;
			server.Url = dlg.textBox_serverAddr.Text;
			server.DefaultUserName = dlg.textBox_userName.Text;
			server.SavePassword = dlg.checkBox_savePassword.Checked;

			Servers.Changed = true;

			FillList();

			// 选择一行
			// parameters:
			//		nIndex	要设置选择标记的行。如果==-1,表示清除全部选择标记但不选择。
			//		bMoveFocus	是否同时移动focus标志到所选择行
			ListViewUtil.SelectLine(ListView, 
				Servers.Count - 1,
				true);

			m_bChanged = true;

		}
Ejemplo n.º 13
0
		void menu_modifyServer(object sender, System.EventArgs e)
		{
			if (ListView.SelectedIndices.Count == 0)
			{
				MessageBox.Show(this, "尚未选择要修改的事项 ...");
				return;
			}

			int nActiveLine = ListView.SelectedIndices[0];
			// ListViewItem item = listView1.Items[nActiveLine];

			LoginDlg dlg = new LoginDlg();
            dlg.Font = GuiUtil.GetDefaultFont();

			dlg.Text = "修改缺省帐户参数";

			dlg.textBox_password.Text = ((Server)Servers[nActiveLine]).DefaultPassword;
			dlg.textBox_serverAddr.Text = ((Server)Servers[nActiveLine]).Url;
			dlg.textBox_userName.Text = ((Server)Servers[nActiveLine]).DefaultUserName;
			dlg.checkBox_savePassword.Checked = ((Server)Servers[nActiveLine]).SavePassword;

			dlg.ShowDialog(this);

			if (dlg.DialogResult != DialogResult.OK)
				return;

			((Server)Servers[nActiveLine]).DefaultPassword = dlg.textBox_password.Text;
			((Server)Servers[nActiveLine]).Url = dlg.textBox_serverAddr.Text;
			((Server)Servers[nActiveLine]).DefaultUserName = dlg.textBox_userName.Text;
			((Server)Servers[nActiveLine]).SavePassword = dlg.checkBox_savePassword.Checked;

			Servers.Changed = true;

			FillList();

		// 选择一行
		// parameters:
		//		nIndex	要设置选择标记的行。如果==-1,表示清除全部选择标记但不选择。
		//		bMoveFocus	是否同时移动focus标志到所选择行
			ListViewUtil.SelectLine(ListView, 
				nActiveLine,
				true);

			m_bChanged = true;

		}