Ejemplo n.º 1
0
        private void OnGUI()
        {
            GUILayout.Label(dir);

            GUI.SetNextControlName("textField");
            name = GUILayout.TextField(name);
            GUI.FocusControl("textField");

            if (GUILayout.Button("Save"))
            {
                scriptableObject.SaveNew(dir, name);
            }

            var evt = Event.current;

            if (evt.keyCode == KeyCode.Escape)
            {
                Close();
            }
            if (evt.keyCode == KeyCode.Return)
            {
                scriptableObject.SaveNew(dir, name);
                OnSaved?.Invoke(scriptableObject);
                Close();
            }
        }
        /// <summary>
        /// Persist object list into *.xml file
        /// </summary>
        public void Save(bool reload = false)
        {
            if (OnSaving != null)
            {
                OnSaving.Invoke();
            }

            lock (List)
            {
                using (var writer = new StreamWriter(FilePath, false, System.Text.Encoding.GetEncoding("utf-8")))
                {
                    new XmlSerializer(List.GetType()).Serialize(writer, List);
                }
            }

            if (OnSaved != null)
            {
                OnSaved.Invoke();
            }

            if (reload)
            {
                Load();
            }
        }
        /// <summary>
        /// Persist object list into *.xml file
        /// </summary>
        public void Save(bool reload = false)
        {
            if (OnSaving != null)
            {
                OnSaving.Invoke();
            }

            lock (List)
            {
                using (var writer = File.Create(FilePath))
                {
                    new XmlSerializer(List.GetType()).Serialize(writer, List);
                }
            }

            if (OnSaved != null)
            {
                OnSaved.Invoke();
            }

            if (reload)
            {
                Load();
            }
        }
Ejemplo n.º 4
0
        public void Save()
        {
            if (CurrentHostFileEntry == null)
            {
                return;
            }

            ViewToHostFile();
            OnSaved?.Invoke(this, null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Сохранить наблюдаемый класс.
        /// </summary>
        public void Save()
        {
            using (StreamWriter sw = new StreamWriter("temp.txt", false, Encoding.Default))
            {
                sw.WriteLine(Name);
            }

            // Такая форма записи используется для того, чтобы избежать исключения NullReferenceException,
            // если нет ни одного подписчика у события.
            OnSaved?.Invoke(this, EventArgs.Empty);
        }
        private async void BtnRegister_Clicked(object sender, EventArgs e)
        {
            if (viewModel.Bank == null)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_ngan_hang, Language.dong);

                return;
            }
            if (viewModel.Province == null)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_tinh_thanh, Language.dong);

                return;
            }
            loadingPopup.IsVisible = true;

            BankEmployee bankEmployee = new BankEmployee();

            bankEmployee.BankId     = viewModel.Bank.Id;
            bankEmployee.ProvinceId = viewModel.Province.Id;
            if (viewModel.District != null)
            {
                bankEmployee.DistrictId = viewModel.District.Id;
                bankEmployee.Address    = viewModel.District.Name + ", " + viewModel.Province.Name;
            }
            else
            {
                bankEmployee.Address = viewModel.Province.Name;
            }

            ApiResponse apiResponse = null;

            if (viewModel.Id == Guid.Empty)
            {
                apiResponse = await ApiHelper.Post(ApiRouter.BANK_EMPLOYEE_REGISTER, bankEmployee, true);
            }
            else
            {
                bankEmployee.Id = viewModel.Id;
                apiResponse     = await ApiHelper.Put(ApiRouter.BANK_EMPLOYEE_UPDATE, bankEmployee, true);
            }

            if (apiResponse.IsSuccess)
            {
                OnSaved?.Invoke(this, EventArgs.Empty);
                loadingPopup.IsVisible = false;
            }
            else
            {
                loadingPopup.IsVisible = false;
                await Shell.Current.DisplayAlert("", apiResponse.Message, Language.dong);
            }
        }
Ejemplo n.º 7
0
 protected void InvokeOnSaved()
 {
     IsSaving = false; OnSaved.SafeInvoke();
 }
 protected virtual void RaiseOnSavedEvent(string filename)
 {
     OnSaved?.Invoke(this, new OnSavedEventArgs(filename));
 }
Ejemplo n.º 9
0
 protected void InvokeOnSaved()
 {
     Saving = false; OnSaved?.Invoke();
 }
Ejemplo n.º 10
0
        public async Task DangKyMoiGioi()
        {
            if (!viewModel.MoiGioiModel.StartYear.HasValue)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_kinh_nghiem, Language.dong);

                return;
            }
            if (!viewModel.MoiGioiModel.TypeId.HasValue)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_loai_hinh_moi_gioi, Language.dong);

                return;
            }
            if (!viewModel.MoiGioiModel.DistrictId.HasValue || !viewModel.MoiGioiModel.ProvinceId.HasValue)
            {
                await Shell.Current.DisplayAlert("", Language.vui_long_chon_khu_vuc_hoat_dong, Language.dong);

                return;
            }

            viewModel.MoiGioi.Id           = viewModel.MoiGioiModel.Id;
            viewModel.MoiGioi.Introduction = viewModel.MoiGioiModel.Introduction;
            viewModel.MoiGioi.StartYear    = viewModel.MoiGioiModel.StartYear.Value;
            viewModel.MoiGioi.Type         = viewModel.MoiGioiModel.TypeId.Value;
            viewModel.MoiGioi.ProvinceId   = viewModel.MoiGioiModel.ProvinceId.Value;
            viewModel.MoiGioi.DistrictId   = viewModel.MoiGioiModel.DistrictId.Value;
            viewModel.MoiGioi.Address      = viewModel.MoiGioiModel.District.Name + ", " + viewModel.MoiGioiModel.Province.Name;

            ApiResponse response = null;

            if (IsUpdate == false)
            {
                response = await ApiHelper.Post(ApiRouter.MOIGIOI_REGISTER, viewModel.MoiGioi, true);
            }
            else
            {
                response = await ApiHelper.Put(ApiRouter.MOIGIOI_GETBYID, viewModel.MoiGioi, true);
            }

            if (response.IsSuccess)
            {
                // set null.
                viewModel.MoiGioi.Province = viewModel.MoiGioiModel.Province;
                viewModel.MoiGioi.District = viewModel.MoiGioiModel.District;

                if (!IsUpdate)
                {
                    UserLogged.Type = 1;
                    await Shell.Current.DisplayAlert("", Language.dang_ky_moi_gioi_thanh_cong, Language.dong);

                    // them menu.
                    var appShell = (AppShell)Shell.Current;
                    appShell.AddMenu_QuanLyMoiGioi();
                }
                else
                {
                    await Shell.Current.DisplayAlert("", Language.cap_nhat_moi_gioi_thanh_cong, Language.dong);
                }
                OnSaved?.Invoke(this, null);
            }
            else
            {
                await Shell.Current.DisplayAlert("", response.Message, Language.dong);
            }
        }
        /// <summary>
        /// 更新一个对象信息
        /// </summary>
        /// <param name="info">更新对象</param>
        /// <param name="logonInfo">登录人信息</param>
        /// <returns></returns>
        public virtual ResultView Update(T info, TokenLogonInfo logonInfo)
        {
            if (info == null)
            {
                ApiException.ThrowBadRequest("更新对象不能为空");
            }
            _logger.LogTrace($"更新一个对象信息 ==> 类型为:[{typeof(T).FullName}]\r\n操作人信息:[{logonInfo.ToJson()}]\r\n更新对象:[{info.ToJson()}]");

            try
            {
                // 根据ID获取原数据信息
                var old = _SearchById(info.Id);
                // 更新数据前的预制数据
                info.CreateDate  = old.CreateDate;
                info.CreaterId   = old.CreaterId;
                info.CreaterName = old.CreaterName;
                info.UpdateDate  = DateTime.Now;
                info.UpdaterId   = logonInfo.Id;
                info.UpdaterName = logonInfo.Name;
                info.IsDelete    = false;
                if (info.ProcessState == ProcessState.None)
                {
                    info.ProcessState = ProcessState.Edit;
                }

                #region 保存验证
                // 保存的数据校验,可以被重写
                SavingCheck(info, logonInfo);
                // 判断是否可以执行新增操作,可以被重写
                if (!IsExecuteUpdate(info, old, logonInfo))
                {
                    return(ResultView.Success());
                }
                OnUpdateCheck?.Invoke(info, old, logonInfo);
                OnSaveCheck?.Invoke(info, logonInfo);
                #endregion

                #region 保存的前置处理
                // 更新的前置操作,可以被重写
                Updating(info, old, logonInfo);
                // 新增/保存的通用前置操作,可以被重写
                Saving(info, logonInfo);
                // 事件处理
                OnUpdating?.Invoke(info, old, logonInfo);
                OnSaving?.Invoke(info, logonInfo);
                #endregion

                // 持久化数据
                _Dal.UpdateObject(info);

                #region 保存后置处理
                // 更新的后置操作,可以被重写
                Updated(info, old, logonInfo);
                // 新增/保存的通用后置操作,可以被重写
                Saved(info, logonInfo);
                // 新增后的后置事件处理
                OnUpdated?.Invoke(info, old, logonInfo);
                OnSaved?.Invoke(info, logonInfo);
                #endregion

                // 返回保存结果
                return(ResultView.Success(info.IdString));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"更新一个对象信息异常 ==> 类型为:[{typeof(T).FullName}]\r\n操作人信息:[{logonInfo.ToJson()}]\r\n更新对象:[{info.ToJson()}]");
                throw;
            }
        }
        /// <summary>
        /// 创建一个对象信息
        /// </summary>
        /// <param name="info">新增对象</param>
        /// <param name="logonInfo">登录人信息</param>
        /// <returns></returns>
        public virtual ResultView Create(T info, TokenLogonInfo logonInfo)
        {
            if (info == null)
            {
                ApiException.ThrowBadRequest("新增对象不能为空");
            }
            _logger.LogTrace($"新增一个对象信息 ==> 类型为:[{typeof(T).FullName}]\r\n新增对象:[{info.ToJson()}]");

            try
            {
                // 新增数据前的预制数据
                info.CreateDate   = DateTime.Now;
                info.UpdateDate   = DateTime.Now;
                info.UpdaterId    = logonInfo.Id;
                info.UpdaterName  = logonInfo.Name;
                info.CreaterId    = logonInfo.Id;
                info.CreaterName  = logonInfo.Name;
                info.IsDelete     = false;
                info.ProcessState = ProcessState.Edit;

                #region 保存验证
                // 保存的数据校验
                SavingCheck(info, logonInfo);
                // 判断是否可以执行新增操作
                if (!IsExecuteCreate(info, logonInfo))
                {
                    return(ResultView.Success());
                }
                // 保存数据验证的事件处理
                OnCreateCheck?.Invoke(info, logonInfo);
                OnSaveCheck?.Invoke(info, logonInfo);
                #endregion

                #region 保存的前置处理
                // 新增的前置操作,可以被重写
                Creating(info, logonInfo);
                // 新增/保存的通用前置操作,可以被重写
                Saving(info, logonInfo);
                // 新增时的前置事件处理
                OnCreating?.Invoke(info, logonInfo);
                OnSaving?.Invoke(info, logonInfo);
                #endregion

                // 持久化数据
                _Dal.InsertObject(info);

                #region 保存后置处理
                // 新增的通用后置操作,可以被重写
                Created(info, logonInfo);
                // 新增/保存的通用后置操作,可以被重写
                Saved(info, logonInfo);
                // 新增后的后置事件处理
                OnCreated?.Invoke(info, logonInfo);
                OnSaved?.Invoke(info, logonInfo);
                #endregion

                // 返回保存结果
                return(ResultView.Success(info.IdString));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"新增一个对象信息异常 ==> 类型为:[{typeof(T).FullName}]\r\n操作人信息:[{logonInfo.ToJson()}]\r\n新增对象:[{info.ToJson()}]");
                throw;
            }
        }
        // luu nhat ky
        public async void AddProjectDiary_Clicked(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(entTitleProjectDiary.Text))
            {
                await Shell.Current.DisplayAlert(Language.thong_bao, Language.vui_long_nhap_tieu_de_nhat_ky, Language.dong);

                return;
            }
            if (string.IsNullOrWhiteSpace(edtModalDescriptionDiary.Text))
            {
                await Shell.Current.DisplayAlert(Language.thong_bao, Language.vui_long_nhap_noi_dung_nhat_ky, Language.dong);

                return;
            }
            loadingPopup.IsVisible = true;
            // set image va avatar
            MultipartFormDataContent form = new MultipartFormDataContent();

            string[] imageList = new string[viewModel.MediaDiary.Count];
            if (imageList.Length > 8)
            {
                await Shell.Current.DisplayAlert(Language.thong_bao, Language.vui_long_upload_toi_da_8_hinh_anh_bat_dong_san, Language.dong);

                loadingPopup.IsVisible = false;
                return;
            }
            if (imageList.Count() != 0)
            {
                for (int i = 0; i < viewModel.MediaDiary.Count; i++)
                {
                    var item = viewModel.MediaDiary[i];
                    // chua upload. upload roi link = null
                    if (string.IsNullOrEmpty(item.Path) == false) // co link la co chon tu dien thoai.
                    {
                        imageList[i] = $"{Guid.NewGuid().ToString()}.jpg";
                        var stream  = new MemoryStream(File.ReadAllBytes(item.Path));
                        var content = new StreamContent(stream);
                        content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                        {
                            Name     = "files" + i,
                            FileName = imageList[i]
                        };
                        form.Add(content);
                    }
                    else
                    {
                        imageList[i] = item.PreviewPath.Replace(Configuration.ApiConfig.CloudStorageApiCDN + "/project/diary/", "");
                    }
                }
                viewModel.ProjectDiary.Image = string.Join(",", imageList);
            }
            else
            {
                viewModel.ProjectDiary.Image = null;
            }


            bool ImageUploaded = true;

            if (viewModel.MediaDiary.Any(x => x.Path != null))
            {
                ApiResponse uploadImageResponse = await UploadImageDiary(form);

                if (!uploadImageResponse.IsSuccess)
                {
                    await Shell.Current.DisplayAlert("", Language.hinh_anh_vuot_qua_dung_luong_vui_long_thu_lai, Language.dong);

                    ImageUploaded = false;
                }
            }
            else
            {
                ImageUploaded = true; // ko can upload
            }
            if (ImageUploaded)
            {
                if (viewModel.ProjectDiary.Id == Guid.Empty)
                {
                    viewModel.ProjectDiary.Id        = Guid.NewGuid();
                    viewModel.ProjectDiary.ProjectId = _projectId;
                    ApiResponse apiResponse = await ApiHelper.Post(ApiRouter.PROJECT_DIARY_ADD_PROJECTDIARY, viewModel.ProjectDiary, true);

                    if (apiResponse.IsSuccess)
                    {
                        OnSaved?.Invoke(this, EventArgs.Empty);
                        loadingPopup.IsVisible = false;
                    }
                    else
                    {
                        await Shell.Current.DisplayAlert(Language.thong_bao, apiResponse.Message, Language.dong);
                    }
                }
                else
                {
                    ApiResponse apiResponse = await ApiHelper.Put($"{ApiRouter.PROJECT_DIARY_UPDATE}", viewModel.ProjectDiary, true);

                    if (apiResponse.IsSuccess)
                    {
                        OnSaved?.Invoke(this, EventArgs.Empty);
                        if (!string.IsNullOrWhiteSpace(OldImages) && OldImages != viewModel.ProjectDiary.Image && viewModel.ProjectDiary.Image != null)
                        {
                            string[]      arrOldImages   = OldImages.Split(',');
                            List <string> ImagesToDelete = new List <string>();
                            for (int i = 0; i < arrOldImages.Length; i++)
                            {
                                if (!imageList.Any(x => x == arrOldImages[i]))
                                {
                                    ImagesToDelete.Add(arrOldImages[i]);
                                }
                            }

                            await ApiHelper.Delete(ApiRouter.DELETE_IMAGE + "?bucketName=sundihome/project/diary&files=" + string.Join(",", ImagesToDelete.ToArray()));
                        }
                        loadingPopup.IsVisible = false;
                    }
                    else
                    {
                        await Shell.Current.DisplayAlert(Language.thong_bao, apiResponse.Message, Language.dong);
                    }
                }
            }
            loadingPopup.IsVisible = false;
        }
Ejemplo n.º 14
0
 public void Save()
 {
     ViewToModel();
     OnSaved?.Invoke(this, null);
 }