wxr
2020-07-06 23c075a9c27946773feccf05abc90489a6bf5203
HDL_ON/UI/UI2/4-PersonalCenter/MemberManagement/ChooseShareMemberTargetListPage.cs
@@ -1,150 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using HDL_ON.DAL.Server;
using System.Collections.Generic;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Newtonsoft.Json.Linq;
using Shared;
namespace HDL_ON.UI
{
    public class ChooseShareMemberTargetListPage : FrameLayout
    /// <summary>
    /// 加载需要分享到子账号的选择界面
    /// </summary>
    public partial class ChooseShareMemberTargetListPage : FrameLayout
    {
        ChooseShareMemberTargetListPage bodyView;
        VerticalScrolViewLayout contentView;
        Button btnOption;
        Loading waitPage;
        byte[] sharedBytes;
        List<ResidenceMemberInfo> residenceMemberInfos;
        public ChooseShareMemberTargetListPage(byte[] sd)
        List<ShareData> addFuns;
        List<ResidenceMemberInfo> memberList;
        public ChooseShareMemberTargetListPage(List<ShareData> funs)
        {
            residenceMemberInfos = new List<ResidenceMemberInfo>();
            sharedBytes = sd;
            memberList = new List<ResidenceMemberInfo>();
            addFuns = funs;
            bodyView = this;
        }
        /// <summary>
        /// 调用获取住宅子账号信息
        /// </summary>
        bool LoadMethod_GetResidenceMemberAccount()
        {
            var result = false;
            ResponsePack responePack = new HttpServerRequest().GetResidenceMemberAccount();
            if (responePack.StateCode.ToUpper() == "SUCCESS")
            {
                var responeObj = Newtonsoft.Json.JsonConvert.DeserializeObject<List<ResidenceMemberInfo>>(responePack.ResponseData.ToString());
                foreach (var mInfo in responeObj)
                {
                    ResponsePack memberInfoResponePack = new HttpServerRequest().GetResidenceMemberAccountInfo(mInfo.Account);
                    var dataStr = JObject.FromObject(memberInfoResponePack.ResponseData);
                    FileStream fs = null;
                    try
                    {
                        var headImageString = dataStr.GetValue("HeadImage").ToString();
                        var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(headImageString);
                        var headImageBytes = Newtonsoft.Json.JsonConvert.DeserializeObject<byte[]>(jsonString);
                        var filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "/", mInfo.DistributedMark + ".png");
                        fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
                        fs.Write(headImageBytes, 0, headImageBytes.Length);
                        fs.Flush();
                        mInfo.headImagePagePath = filePath;
                    }
                    catch (Exception ex)
                    {
                        MainPage.Log($"download headImage error : {ex.Message}");
                    }
                    finally
                    {
                        if (fs != null)
                        {
                            fs.Close();
                        }
                    }
                    residenceMemberInfos.Add(mInfo);
                }
                result = true;
            }
            //失败
            else
            {
                string tipStr = "Sever erorr";
                switch (responePack.StateCode)
                {
                    case "ValidCodeAndPhoneNoEqual":
                        tipStr = Language.StringByID(StringId.VerificationCodeError);
                        break;
                    case "USERNAMEORPWDERROR":
                        tipStr = Language.StringByID(StringId.LoginFailed_AccountOrPasswordError);
                        break;
                    case "ACCOUNTNOEXISTS":
                        tipStr = Language.StringByID(StringId.ACCOUNTNOEXISTS);
                        break;
                    case "NoRecord":
                        tipStr = Language.StringByID(StringId.PlsGetTheVerificationCode);
                        break;
                    case "Self:Net_Error":
                        tipStr = Language.StringByID(StringId.NetworkAnomaly);
                        break;
                }
                //账号或者密码错误
                Application.RunOnMainThread(() =>
                {
                    waitPage.Hide();
                    //提示原因
                    var tip = new Tip()
                    {
                        Text = tipStr,
                        CloseTime = 3,
                        Direction = AMPopTipDirection.None
                    };
                    tip.Show(bodyView);
                });
            }
            Application.RunOnMainThread(() =>
            {
                waitPage?.Hide();
            });
            return result;
        }
        /// <summary>
        /// 加载获取住宅子账号信息线程
        /// </summary>
        Thread LoadThread_GetResidenceMemberAccount()
        {
            var thread = new Thread(() =>
            {
                try
                {
                    residenceMemberInfos.Clear();
                    var loginResult = LoadMethod_GetResidenceMemberAccount();
                    if (loginResult)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            LoadMemberRow();
                        });
                    }
                }
                catch (Exception ex)
                {
                    MainPage.Log($"LoadThread_GetResidenceMemberAccount : {ex.Message}");
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        if (waitPage != null)
                        {
                            waitPage.RemoveFromParent();
                            waitPage = null;
                        }
                    });
                }
            })
            { IsBackground = true };
            return thread;
        }
        public void LoadPage()
@@ -153,7 +30,6 @@
            var thread = LoadThread_GetResidenceMemberAccount();
            waitPage = new Loading();
            new PublicAssmebly().LoadPage_WaitPage(thread, bodyView, waitPage);
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.Shared)).LoadTopView();
@@ -214,9 +90,8 @@
            };
            bodyView.AddChidren(btnOption);
            LoadEvent_SharedData();
        }
        Button btnOption;
        /// <summary>
        /// 加载成员列表区域
@@ -225,9 +100,8 @@
        {
            contentView.RemoveAll();
            //List<ResidenceMemberInfo> residenceMemberInfos = new List<ResidenceMemberInfo>();
            int index = 1;
            foreach (var mInfo in residenceMemberInfos)
            foreach (var mInfo in memberList)
            {
                FrameLayout memberRow = new FrameLayout()
                {
@@ -251,7 +125,7 @@
                {
                    X = Application.GetRealWidth(64),
                    Y = Application.GetRealWidth(10),
                    Width = Application.GetRealWidth(300),
                    //Width = Application.GetRealWidth(300),
                    Height = Application.GetRealWidth(24),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
@@ -264,7 +138,7 @@
                {
                    X = Application.GetRealWidth(64),
                    Y = btnMemberName.Bottom,
                    Width = Application.GetRealWidth(300),
                    //Width = Application.GetRealWidth(300),
                    Height = Application.GetRealWidth(21),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.PromptingColor1,
@@ -285,7 +159,7 @@
                };
                memberRow.AddChidren(btnChoose);
                if (residenceMemberInfos.Count > index)
                if (memberList.Count > index)
                {
                    memberRow.AddChidren(new Button()
                    {
@@ -298,14 +172,11 @@
                }
                index++;
                var eventHandler = LoadEvent_ChangeSharedList(btnChoose, mInfo);
                btnChoose.MouseUpEventHandler = eventHandler;
                btnMemberName.MouseUpEventHandler = eventHandler;
                btnMemberMail.MouseUpEventHandler = eventHandler;
            }
        }
        void LoadEvent_SharedFunction()
        {
            //btnOption
        }
    }
}