Beispiel #1
0
        ServerDlg SetDefaultAccount(
    string strServerUrl,
    string strTitle,
    string strComment,
    IWin32Window owner)
        {
            dp2Server server = this.MainForm.Servers[strServerUrl];

            ServerDlg dlg = new ServerDlg();
            GuiUtil.SetControlFont(dlg, this.Font);

            if (String.IsNullOrEmpty(strServerUrl) == true)
            {
            }
            else
            {
                dlg.ServerUrl = strServerUrl;
            }

            if (owner == null)
                owner = this;

            if (String.IsNullOrEmpty(strTitle) == false)
                dlg.Text = strTitle;

            dlg.Comment = strComment;
            dlg.UserName = server.DefaultUserName;

            this.MainForm.AppInfo.LinkFormState(dlg,
                "dp2_logindlg_state");

            dlg.ShowDialog(owner);

            this.MainForm.AppInfo.UnlinkFormState(dlg);


            if (dlg.DialogResult == DialogResult.Cancel)
            {
                return null;
            }

            server.DefaultUserName = dlg.UserName;
            server.DefaultPassword =
                (dlg.SavePassword == true) ?
                dlg.Password : "";

            server.SavePassword = dlg.SavePassword;

            server.Url = dlg.ServerUrl;
            return dlg;
        }
Beispiel #2
0
        async void menu_refreshServerName(object sender, System.EventArgs e)
        {
            string strError = "";

            if (listView1.SelectedIndices.Count == 0)
            {
                strError = "尚未选择要刷新服务器名的事项 ...";
                goto ERROR1;
            }

            int           change_count = 0;
            List <string> errors       = new List <string>();

            using (MessageBar bar = MessageBar.Create(this, "正在刷新服务器名"))
            {
                foreach (int index in this.listView1.SelectedIndices)
                {
                    dp2Server server = Servers[index] as dp2Server;

                    // 获得服务器 UID
                    string server_name = "";
                    bar.SetMessageText($"正在获取服务器 {server.Url} 的图书馆名 ...");
                    var result = await ServerDlg.GetServerName(server.Url);

                    if (result.Value == -1)
                    {
                        errors.Add($"针对服务器 {server.Url} 获取图书馆名时出错: {result.ErrorInfo}");
                        continue;
                    }
                    else
                    {
                        server_name = result.ErrorCode;
                    }

                    if (server.Name != server_name)
                    {
                        server.Name = server_name;
                        change_count++;
                    }
                }

                // TODO: 刷新后如果发现发生了服务器名重复,怎么处理?

                if (change_count > 0)
                {
                    Servers.Changed = true;
                    // 刷新前保存选择位置
                    var indices = ListViewUtil.GetSelectedIndices(this.listView1);
                    this.listView1.BeginUpdate();
                    FillList();
                    // 刷新后恢复选择位置
                    ListViewUtil.SelectItems(this.listView1, indices);
                    this.listView1.EndUpdate();
                }
            }

            if (errors.Count > 0)
            {
                strError = $"刷新服务器名时出错:\r\n{StringUtil.MakePathList(errors, "\r\n")}";
                goto ERROR1;
            }
            return;

ERROR1:
            // TODO: MessageDlg 应可以指定左上角图标
            MessageDlg.Show(this, strError, "ServersDlg");
        }
Beispiel #3
0
		void menu_modifyServer(object sender, System.EventArgs e)
		{
			if (listView1.SelectedIndices.Count == 0)
			{
				MessageBox.Show(this, "尚未选择要修改的事项 ...");
				return;
			}


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

            ServerDlg dlg = new ServerDlg();
            // GuiUtil.AutoSetDefaultFont(dlg); 
            GuiUtil.SetControlFont(dlg, this.Font);

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

            dlg.ServerName = ((dp2Server)Servers[nActiveLine]).Name;
            dlg.Password = ((dp2Server)Servers[nActiveLine]).DefaultPassword;
            dlg.ServerUrl = ((dp2Server)Servers[nActiveLine]).Url;
            dlg.UserName = ((dp2Server)Servers[nActiveLine]).DefaultUserName;
            dlg.SavePassword = ((dp2Server)Servers[nActiveLine]).SavePassword;

			dlg.ShowDialog(this);

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

            ((dp2Server)Servers[nActiveLine]).Name = dlg.ServerName;
            ((dp2Server)Servers[nActiveLine]).DefaultPassword = dlg.Password;
            ((dp2Server)Servers[nActiveLine]).Url = dlg.ServerUrl;
            ((dp2Server)Servers[nActiveLine]).DefaultUserName = dlg.UserName;
            ((dp2Server)Servers[nActiveLine]).SavePassword = dlg.SavePassword;

			Servers.Changed = true;

			FillList();

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

			m_bChanged = true;

		}
Beispiel #4
0
		void menu_newServer(object sender, System.EventArgs e)
		{
			int nActiveLine = -1;
			if (listView1.SelectedIndices.Count != 0)
			{
				nActiveLine = listView1.SelectedIndices[0];
			}

			ServerDlg dlg = new ServerDlg();
            // GuiUtil.AutoSetDefaultFont(dlg); 
            GuiUtil.SetControlFont(dlg, this.Font);

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

            if (nActiveLine == -1)
            {   
                // 无参考事项情形的新增
                dlg.ServerName = "社科院联合编目中心";
                dlg.ServerUrl = "http://ssucs.org/dp2library";
                dlg.UserName = "******";
            }
            else
			{
                dlg.ServerName = ((dp2Server)Servers[nActiveLine]).Name;
                dlg.Password = ((dp2Server)Servers[nActiveLine]).DefaultPassword;
                dlg.ServerUrl = ((dp2Server)Servers[nActiveLine]).Url;
                dlg.UserName = ((dp2Server)Servers[nActiveLine]).DefaultUserName;
                dlg.SavePassword = ((dp2Server)Servers[nActiveLine]).SavePassword;
			}

			dlg.ShowDialog(this);

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

            dp2Server server = Servers.NewServer(nActiveLine);
            server.Name = dlg.ServerName;
			server.DefaultPassword = dlg.Password;
			server.Url = dlg.ServerUrl;
			server.DefaultUserName = dlg.UserName;
			server.SavePassword = dlg.SavePassword;

			Servers.Changed = true;

			FillList();

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

			m_bChanged = true;

		}
Beispiel #5
0
        void menu_newServer(object sender, System.EventArgs e)
        {
            int nActiveLine = -1;

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

            ServerDlg dlg = new ServerDlg();

            // GuiUtil.AutoSetDefaultFont(dlg);
            GuiUtil.SetControlFont(dlg, this.Font);

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

            if (nActiveLine == -1)
            {
                // 无参考事项情形的新增
#if NO
                dlg.ServerName = "社科院联合编目中心";
                dlg.ServerUrl  = "http://ssucs.org/dp2library";
                dlg.UserName   = "******";
#endif
                dlg.ServerName = "单机版服务器";
                dlg.ServerUrl  = "net.pipe://localhost/dp2library/xe";
                dlg.UserName   = "******";
            }
            else
            {
                dlg.ServerName   = ((dp2Server)Servers[nActiveLine]).Name;
                dlg.Password     = ((dp2Server)Servers[nActiveLine]).DefaultPassword;
                dlg.ServerUrl    = ((dp2Server)Servers[nActiveLine]).Url;
                dlg.UserName     = ((dp2Server)Servers[nActiveLine]).DefaultUserName;
                dlg.SavePassword = ((dp2Server)Servers[nActiveLine]).SavePassword;
            }

            dlg.ShowDialog(this);

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

            dp2Server server = Servers.NewServer(nActiveLine);
            server.Name            = dlg.ServerName;
            server.DefaultPassword = dlg.Password;
            server.Url             = dlg.ServerUrl;
            server.DefaultUserName = dlg.UserName;
            server.SavePassword    = dlg.SavePassword;

            Servers.Changed = true;

            FillList();

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

            m_bChanged = true;
        }