Exemple #1
0
        protected override async Task <string> update()
        {
            if (hasRretrieveAccount)
            {
                //获取账套信息
                string data = await((HsApp)Application.Current).WSUtil.Login(this.ucUserName.ControlValue, this.ucPassword.ControlValue, this.ucDb.ControlValue);

                //登录成功后将用户信息存入Application中,以便全局调用

                XElement xReturnData = XElement.Parse(data);

                ((HsApp)Application.Current).LoginData = new LoginData(
                    xReturnData.GetFirstElementValue("ProgressId"),
                    xReturnData.GetFirstElementValue("UserBh"),
                    xReturnData.GetFirstElementValue("UserName"),
                    xReturnData.GetFirstElementValue("DeptBh"),
                    xReturnData.GetFirstElementValue("DeptMc"),
                    xReturnData.GetFirstElementValue("RoleBhs"),
                    xReturnData.GetFirstElementValue("RoleMcs"));

                XElement xMenus = xReturnData.Element("Menus");

                //将登录信息存入本地
                try
                {
                    XElement xLastLogin = new XElement("Data");

                    xLastLogin.Add(new XElement("UserName", this.ucUserName.ControlValue));
                    xLastLogin.Add(new XElement("Password", this.ucIsSaved.Checked ? this.ucPassword.ControlValue : ""));
                    xLastLogin.Add(new XElement("Account", this.ucDb.ControlValue));
                    xLastLogin.Add(new XElement("IsSaved", this.ucIsSaved.Checked));

                    IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                    //await HsLocalStorageHelper.WriteAllText(LASTLOGINFILENAME, xLastLogin.ToString());
                    await pe.WriteTextFile(LASTLOGINFILENAME, xLastLogin.ToString());
                }
                catch (Exception ex)
                {
                    this.ShowError(ex.Message);
                }

                this.LoginSuccess?.Invoke(this, new HsEventArgs <XElement> {
                    Data = xMenus
                });

                return(null);
            }
            else
            {
                string data = await((HsApp)Application.Current).WSUtil.GetDbs();

                this.ucDb.Datas = data;

                this.hasRretrieveAccount = true;

                try
                {
                    IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                    //读入上次登录配置信息
                    //string lastData = await HsLocalStorageHelper.ReadAllText(LASTLOGINFILENAME, "");
                    string lastData = await pe.ReadTextFile(LASTLOGINFILENAME);

                    if (!string.IsNullOrWhiteSpace(lastData))
                    {
                        XElement xLastLogin = XElement.Parse(lastData);
                        this.ucUserName.ControlValue = xLastLogin.GetFirstElementValue("UserName");
                        this.ucPassword.ControlValue = xLastLogin.GetFirstElementValue("Password");
                        this.ucDb.ControlValue       = xLastLogin.GetFirstElementValue("Account");
                        this.ucIsSaved.Checked       = bool.Parse(xLastLogin.GetFirstElementValue("IsSaved", false.ToString()));
                    }
                }
                catch (Exception e)
                {
                    throw e;
                }

                return(null);
            }
        }
Exemple #2
0
        public override async Task GetItems()
        {
            try
            {
                this.isRetrieveing = true;

                if (string.IsNullOrWhiteSpace(Djlx))
                {
                    throw new HsException($"属性Djlx或未定义");
                }

                if (string.IsNullOrWhiteSpace(DjId))
                {
                    return;
                }

                //
                this.Reset();

                IPlatformExtension pe = DependencyService.Get <IPlatformExtension>(DependencyFetchTarget.GlobalInstance);

                string[] cachePath = new string[] { "Cache", "Images" };

                //获取图像哈希集合
                List <HsLabelValue> items = await GetWSUtil().GetSysImageHashDatas(GetLoginData().ProgressId, Djlx, DjId);

                //逐幅获取图像,如果存在本地缓存则使用本地图片。
                foreach (HsLabelValue item in items)
                {
                    //图片的Hash值
                    string hashData = item.GetValueByLabel("HashData");

                    string imageDataString = await pe.ReadTextFile(hashData, cachePath);

                    //本地缓存中不存在文件,则从网络中获取,并写入本地。
                    if (string.IsNullOrWhiteSpace(imageDataString))
                    {
                        string result = await GetWSUtil().GetSysImageById(GetLoginData().ProgressId, item.GetValueByLabel("ImageId"));

                        XElement xData = XElement.Parse(result);

                        imageDataString = xData.GetFirstElementValue("Data");

                        await pe.WriteTextFile(hashData, imageDataString, cachePath);
                    }

                    datas.Add(new HsImage(imageDataString)
                    {
                        HashData = hashData
                    });
                }

                hasRrtrieve = true;
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                this.isRetrieveing = false;
            }
        }