示例#1
0
        private void BindData()
        {
            mac.Text      = LocalMachineInfomationProvider.GetMac();
            hostname.Text = LocalMachineInfomationProvider.GetHostname();
            var printers = LocalMachineInfomationProvider.GetPrinter();

            cb_A4Printer.DataSource      = new List <String>(printers);
            cb_A5Printer.DataSource      = new List <String>(printers);
            cb_BarcodePrinter.DataSource = new List <String>(printers);
            cb_PDFPrinter.DataSource     = new List <String>(printers);

            //bind user printer config.
            var userInfo = PrintingApp.CurrentUserInfo;

            cb_A4Printer.SelectedItem      = userInfo.UserPrinterConfig.A4Printer;
            cb_A5Printer.SelectedItem      = userInfo.UserPrinterConfig.A5Printer;
            cb_BarcodePrinter.SelectedItem = userInfo.UserPrinterConfig.BarcodePrinter;
            cb_PDFPrinter.SelectedItem     = userInfo.UserPrinterConfig.PdfPrinter;
        }
示例#2
0
        private void DoWorkInBackgroud()
        {
            try
            {
                string username = txtUsername.Text;
                string password = txtPassword.Text;

                BeginInvoke(new Action <String, MessageType>(ShowMessage), "用户认证中...", MessageType.Infomation);
                var userService          = ServiceFactory.GetClientApplicationService();
                var authenticateResponse = userService.Authenticate(new AuthenticateRequest()
                {
                    Username = username,
                    Password = password,
                    HostMac  = LocalMachineInfomationProvider.GetMac(),
                });
                if (authenticateResponse.ResultType != ResultTypes.Ok)
                {
                    Log.Info("Authenticate fail.");
                    Invoke(new Action <String, MessageType>(ShowMessage), "用户认证失败...", MessageType.Warning);
                    Invoke(new Action <bool>(ControlButtons), true);
                    return;
                }
                Log.Info("Authenticate OK.");
                PrintingApp.CurrentUserInfo = authenticateResponse.UserInfo;
                PrintingApp.UserCredential  = new UserCredential()
                {
                    UserName = username, Password = password
                };


                BeginInvoke(new Action <String, MessageType>(ShowMessage), "用户授权中...", MessageType.Infomation);
                var authorizeResponse = userService.Authorize(new AuthorizeRequest()
                {
                    Username = username,
                    Password = password,
                });
                if (authorizeResponse.ResultType != ResultTypes.Ok)
                {
                    Log.Info("Authorize fail.");
                    Invoke(new Action <String, MessageType>(ShowMessage), "用户授权失败...", MessageType.Warning);
                    Invoke(new Action <bool>(ControlButtons), true);
                    return;
                }
                Log.Info("Authorize OK.");
                PrintingApp.LabAssociations          = authorizeResponse.LabAssociations.ToList();
                PrintingApp.OrganizationAssociations = authorizeResponse.OrganizationAssociations.ToList();
                PrintingApp.ReportTemplates          = authorizeResponse.ReportTemplates.ToList();

                Log.Info("Check updates");
                BeginInvoke(new Action <String, MessageType>(ShowMessage), "检查更新中...", MessageType.Infomation);
                ApplicationUpdateChecker updateChecker = new ApplicationUpdateChecker();
                updateChecker.Initialize();

                var applicationUpdateEventInfo = updateChecker.CheckUpdates();
                if (applicationUpdateEventInfo.Type == ApplicationUpdateEventType.ApplicationVersionChanged)
                {
                    Log.Info("New application version detected.");
                    string url = applicationUpdateEventInfo.LatestVersion.DownloadUrl;
                    Invoke(new Action <string>(ShowAutoUpdateForm), url);
                    return; // stop process to forbid login to system
                }
                else if (applicationUpdateEventInfo.Type == ApplicationUpdateEventType.ReportTemplateVersionChanged)
                {
                    var applicationVersionManager = PrintingApp.GetVersionManager();
                    applicationVersionManager.UpdateReportTemplateVersion(applicationUpdateEventInfo.LatestVersion.ReportTemplateVersion);
                }

                Invoke(new Action <String, MessageType>(ShowMessage), "登陆成功...", MessageType.Infomation);
                Invoke(new Action(ShowMainForm));
            }
            catch (Exception ex)
            {
                Invoke(new Action <String, MessageType>(ShowMessage), "发生登陆异常,请联系管理员...", MessageType.Warning);
                Invoke(new Action <bool>(ControlButtons), true);
                Log.Error("Login fail.", ex);
            }
        }