Exemplo n.º 1
0
        private void PrepareLogos()
        {
            if (SaveLogos.Any())
            {
                SaveLogos.Clear();
            }
            if (DeleteLogos.Any())
            {
                DeleteLogos.Clear();
            }

            foreach (int logoType in Enum.GetValues(typeof(CompanyLogoType)))
            {
                var pictureBox = new PictureBox();
                if (logoType == (int)CompanyLogoType.Logo)
                {
                    pictureBox = picLogo;
                }
                else if (logoType == (int)CompanyLogoType.SquareSeal)
                {
                    pictureBox = picSquareSeal;
                }
                else if (logoType == (int)CompanyLogoType.RoundSeal)
                {
                    pictureBox = picRoundSeal;
                }

                if (CompanyLogos != null &&
                    CompanyLogos.Any(x => x.LogoType == logoType) &&
                    pictureBox.Image == null)
                {
                    //削除対象
                    var deleteLogo = CompanyLogos.FirstOrDefault(x => x.LogoType == logoType);
                    DeleteLogos.Add(deleteLogo);
                    continue;
                }

                var hasLogo     = true;
                var companyLogo = new CompanyLogo();
                companyLogo.Logo = new byte[0];
                var filePath = pictureBox.ImageLocation;

                if (!string.IsNullOrEmpty(filePath))
                {
                    companyLogo.Logo     = ChangeImageToBinary(filePath);
                    companyLogo.UpdateAt = DateTime.Now;
                }
                else if (pictureBox.Image != null)
                {
                    var currentLogo = CompanyLogos.Where(x => x.LogoType == logoType).FirstOrDefault();
                    companyLogo.Logo     = currentLogo.Logo;
                    companyLogo.UpdateAt = currentLogo.UpdateAt;
                }
                else
                {
                    hasLogo = false;
                }

                if (hasLogo)
                {
                    companyLogo.CompanyId = Company.Id;
                    companyLogo.CreateBy  = Login.UserId;
                    companyLogo.UpdateBy  = Login.UserId;
                    companyLogo.LogoType  = logoType;
                    SaveLogos.Add(companyLogo);
                }
            }
        }
Exemplo n.º 2
0
        private void UpdateCompany()
        {
            ClearStatusMessage();
            if (!ValidateInputData())
            {
                return;
            }

            ZeroLeftPaddingWithoutValidated();

            if (!ShowConfirmDialog(MsgQstConfirmSave))
            {
                DispStatusMessage(MsgInfProcessCanceled);
                return;
            }

            try
            {
                var result = false;
                PrepareUpdateData();
                Task task = SaveCompanyInfoAsync()
                            .ContinueWith(async t =>
                {
                    result = t.Result.ProcessResult.Result;
                    if (result)
                    {
                        PrepareLogos();
                        if (SaveLogos.Any())
                        {
                            result = await SaveCompanyLogosAsync();
                        }
                        if (result && DeleteLogos.Any())
                        {
                            result = await DeleteCompanyLogos();
                        }
                        if (result)
                        {
                            await LoadCompanyLogosAsync();
                        }
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext())
                            .Unwrap();
                ProgressDialog.Start(ParentForm, task, false, SessionKey);

                if (result)
                {
                    SettingFormData();
                    DispStatusMessage(MsgInfSaveSuccess);
                }
                else
                {
                    ShowWarningDialog(MsgErrSaveError);
                }
            }
            catch (Exception ex)
            {
                ShowWarningDialog(MsgErrSaveError);
                Debug.Fail(ex.ToString());
                NLogHandler.WriteErrorLog(this, ex, SessionKey);
            }
        }