/// <summary> /// 处理上级页面传过来的参数 /// </summary> protected override void InitVariables() { Bundle bundle = Intent.Extras; if (bundle != null) { var jsonStr = bundle.GetString("ShopManagerJsonStr"); if (!string.IsNullOrEmpty(jsonStr)) { currShopManager = JsonSerializer.ToObject <ShopManagerList>(jsonStr); } AreaCodes = bundle.GetString("areaCodes"); AreaNames = bundle.GetString("areaNames"); } }
/// <summary> /// 初始化页面上的控件 /// </summary> protected override void InitViews() { imgbtnBack = (ImageButton)FindViewById(Resource.Id.imgBtn_back); rlAreas = (RelativeLayout)FindViewById(Resource.Id.rl_areas); etName = FindViewById <EditText>(Resource.Id.et_name); etEmail = FindViewById <EditText>(Resource.Id.et_email); tvTitle = FindViewById <TextView>(Resource.Id.tv_title); tvSave = FindViewById <TextView>(Resource.Id.tv_save); btnAdd = FindViewById <Button>(Resource.Id.btn_add); btnDelete = FindViewById <Button>(Resource.Id.btn_delete); tvAreaNames = FindViewById <TextView>(Resource.Id.tv_areaNames); tvAreaCodes = FindViewById <TextView>(Resource.Id.tv_areaCodes); // 添加 if (currShopManager == null || string.IsNullOrEmpty(currShopManager.Name)) { btnAdd.Visibility = ViewStates.Visible; btnDelete.Visibility = ViewStates.Gone; tvAreaNames.Text = AreaNames ?? "未设置"; tvAreaCodes.Text = AreaCodes ?? ""; currShopManager = new ShopManagerList(); } else { isNewAdd = false; tvTitle.Text = currShopManager.Name; btnAdd.Visibility = ViewStates.Gone; btnDelete.Visibility = ViewStates.Visible; etName.Enabled = false; etEmail.Enabled = false; etName.Text = currShopManager.Name; etEmail.Text = currShopManager.Email; tvAreaNames.Text = AreaNames; tvAreaCodes.Text = AreaCodes; } }
/// <summary> /// 添加/编辑店长信息 /// </summary> /// <param name="isContinueAdd">isContinueAdd=true:连续保存</param> private void DoSave(bool isContinueAdd) { if (!NetUtil.CheckNetWork(CurrActivity)) { ToastUtil.ShowWarningToast(CurrActivity, "网络未连接!"); return; } try { var tname = etName.Text.Trim(); var temail = etEmail.Text.Trim(); if (string.IsNullOrEmpty(tname)) { ToastUtil.ShowWarningToast(this, "请输入姓名"); etName.RequestFocus(); return; } if (!CheckUtil.IsValidEmail(temail)) { ToastUtil.ShowWarningToast(this, "邮箱格式不正确"); etEmail.RequestFocus(); return; } if (string.IsNullOrEmpty(tvAreaCodes.Text.Trim())) { ToastUtil.ShowWarningToast(this, "请选择门店"); return; } LoadingDialogUtil.ShowLoadingDialog(this, "保存中..."); new Thread(new ThreadStart(() => { //新增操作 var model = new ManagerUserInfo(); model.Email = etEmail.Text; model.Name = etName.Text; model.UserType = Convert.ToInt32(UserType.ShopManager); model.IsCanLogin = true; model.SchoolId = CurrUserInfo.SchoolId; model.Creator = CurrUserInfo.Name; model.Modifier = CurrUserInfo.Name; model.DistrictCode = CurrUserInfo.DistrictCode; DataEntity.Result resultData = new DataEntity.Result(); if (isNewAdd) { resultData = _meService.AddShopManager(model, AreaCodes, AreaNames); } else { var codeArr = AreaCodes.Split(','); var nameArr = AreaNames.Split(','); var list = new List <UserAreaRelationModel>(); for (int i = 0; i < codeArr.Length; i++) { var relation = new UserAreaRelationModel(); relation.AreaCode = codeArr[i]; relation.AreaName = nameArr[i]; relation.Email = etEmail.Text; relation.UserType = (int)UserType.ShopManager; relation.Creator = CurrUserInfo.Name; relation.Modifier = CurrUserInfo.Name; relation.SchoolId = CurrUserInfo.SchoolId; list.Add(relation); } resultData = _meService.SaveUserArea(list); } RunOnUiThread(() => { LoadingDialogUtil.DismissLoadingDialog(); if (resultData.State == 1) { ToastUtil.ShowSuccessToast(this, "操作成功"); //保存并继续添加 if (isContinueAdd) { currShopManager = new ShopManagerList(); etName.Text = ""; etEmail.Text = ""; tvAreaNames.Text = "未设置"; } //完成 else { new Handler().PostDelayed(() => { Finish(); OverridePendingTransition(Resource.Animation.left_in, Resource.Animation.right_out); }, 1000); } } else { ToastUtil.ShowErrorToast(this, (string.IsNullOrEmpty(resultData.Error) ? "操作失败" : resultData.Error)); } }); })).Start(); } catch (Exception ex) { var msg = ex.Message.ToString(); ToastUtil.ShowErrorToast(this, "操作失败"); LoadingDialogUtil.DismissLoadingDialog(); } }