public short AddAnnouncementGroup(SuAnnouncementGroup announcementGroup, SuAnnouncementGroupLang announcementGroupLang)
        {
            #region Validate SuAnnouncementGroup
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            if (announcementGroup.DisplayOrder == null)
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("DisplayOrderTypeMissMatch"));
            }
            else if (announcementGroup.DisplayOrder.GetValueOrDefault(0) == 0)
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("DisplayOrderRequired"));
            }
            if (string.IsNullOrEmpty(announcementGroupLang.AnnouncementGroupName))
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("AnnouncementGroupNameRequired"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
            #endregion

            short announcementGroupId = DaoProvider.SuAnnouncementGroupDao.Save(announcementGroup);
            DaoProvider.SuAnnouncementGroupLangDao.Save(announcementGroupLang);

            return(announcementGroupId);
        }
예제 #2
0
        protected void ctlSubmit_Click(object sender, EventArgs e)
        {
            IList <SuAnnouncementGroupLang> list  = new List <SuAnnouncementGroupLang>();
            short announcementGroupId             = UIHelper.ParseShort(ctlAnnouncementGroupGrid.SelectedValue.ToString());
            SuAnnouncementGroup announcementGroup = QueryProvider.SuAnnouncementGroupQuery.FindProxyByIdentity(announcementGroupId);

            foreach (GridViewRow row in ctlAnnouncementGroupLangGrid.Rows)
            {
                TextBox  ctlAnnouncementGroupName = row.FindControl("ctlAnnouncementGroupName") as TextBox;
                TextBox  ctlComment = row.FindControl("ctlComment") as TextBox;
                CheckBox ctlActive  = row.FindControl("ctlActive") as CheckBox;

                if (!string.IsNullOrEmpty(ctlAnnouncementGroupName.Text))
                {
                    short languageId = UIHelper.ParseShort(ctlAnnouncementGroupLangGrid.DataKeys[row.RowIndex].Values["LanguageId"].ToString());

                    SuAnnouncementGroupLang announcementGroupLang = new SuAnnouncementGroupLang();
                    announcementGroupLang.Active                = ctlActive.Checked;
                    announcementGroupLang.Language              = DbLanguageService.FindProxyByIdentity(languageId);
                    announcementGroupLang.AnnouncementGroup     = announcementGroup;
                    announcementGroupLang.Comment               = ctlComment.Text;
                    announcementGroupLang.AnnouncementGroupName = ctlAnnouncementGroupName.Text;
                    announcementGroupLang.CreBy   = 0;
                    announcementGroupLang.CreDate = DateTime.Now;
                    announcementGroupLang.UpdBy   = 0;
                    announcementGroupLang.UpdDate = DateTime.Now;
                    announcementGroupLang.UpdPgm  = ProgramCode;

                    list.Add(announcementGroupLang);
                }
            }

            // Update AnnouncementGroupLang.
            SuAnnouncementGroupLangService.UpdateAnnouncementGroupLang(list);

            ctlMessage.Message = GetMessage("SaveSuccessFully");;

            // Set data source of ctlAnnouncementGroupLangGrid.
            //ctlAnnouncementGroupLangGrid.DataSource = null;
            //ctlAnnouncementGroupLangGrid.DataBind();

            // Bind ctlAnnouncementGroupGrid without SelectedIndex set.
            //ctlAnnouncementGroupGrid.SelectedIndex = -1;
            //ctlAnnouncementGroupGrid.DataCountAndBind();
            //ctlUpdPanelAnnGrp.Update();
            //ctlSubmit.Visible = false;
        }
        public short AddAnnouncementGroup(SuAnnouncementGroup announcementGroup, SuAnnouncementGroupLang announcementGroupLang, HttpPostedFile imageFile)
        {
            #region Validate SuAnnouncementGroup
            Spring.Validation.ValidationErrors errors = new Spring.Validation.ValidationErrors();
            if (announcementGroup.DisplayOrder == null)
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("DisplayOrderTypeMissMatch"));
            }
            else if (announcementGroup.DisplayOrder.GetValueOrDefault(0) == 0)
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("DisplayOrderRequired"));
            }
            if (string.IsNullOrEmpty(announcementGroupLang.AnnouncementGroupName))
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("AnnouncementGroupNameRequired"));
            }
            // Check file Type of imageFile.
            if ((!imageFile.ContentType.Equals("image/gif")) && (!imageFile.ContentType.Equals("image/jpeg")) && (!imageFile.ContentType.Equals("image/jpg")) && (!imageFile.ContentType.Equals("image/pjpeg")))
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("FileTypeError"));
            }
            // Check file Size of imageFile.
            if (imageFile.ContentLength > maxFileSize)
            {
                // File size exceed 50KB.
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("FileSizeError"));
            }
            // Check file Dimension of imageFile
            Image uploadImage = Image.FromStream(imageFile.InputStream);
            if ((uploadImage.Width > maxImageWidth) || (uploadImage.Height > maxImageHeight))
            {
                errors.AddError("AnnouncementGroup.Error", new Spring.Validation.ErrorMessage("DimensionError"));
            }
            if (!errors.IsEmpty)
            {
                throw new ServiceValidationException(errors);
            }
            #endregion

            short announcementGroupId = DaoProvider.SuAnnouncementGroupDao.Save(announcementGroup);
            DaoProvider.SuAnnouncementGroupLangDao.Save(announcementGroupLang);

            return(announcementGroupId);
        }
        protected void rptAnnouncementGroup_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            RepeaterItem item = e.Item;

            if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rptAnnouncement = (Repeater)item.FindControl("rptAnnouncement");
                Image    ctlImage        = item.FindControl("ctlImage") as Image;
                SuAnnouncementGroupLang suAnnouncementGroupLang = (SuAnnouncementGroupLang)item.DataItem;
                short announcementGroupId       = suAnnouncementGroupLang.AnnouncementGroupid;
                short languageId                = suAnnouncementGroupLang.Language.Languageid;
                IList <SuAnnouncementLang> list = QueryProvider.SuAnnouncementLangQuery.FindByAnnouncementLanguageId(languageId, announcementGroupId);
                string imageName                = suAnnouncementGroupLang.AnnouncementGroup.ImagePath;
                string filePath = ParameterServices.AnnouncementGoupUploadFilePath;
                ctlImage.ImageUrl = filePath + imageName.Trim();
                // bind the Child Repeater
                rptAnnouncement.DataSource = list;
                rptAnnouncement.DataBind();
            }
        }
예제 #5
0
        protected void ctlAnnouncementGroupForm_ItemInserting(object sender, FormViewInsertEventArgs e)
        {
            SuAnnouncementGroup announcementGroup = new SuAnnouncementGroup();
            HttpPostedFile      imageFile;

            GetSuAnnouncementGroupInfo(announcementGroup, out imageFile);

            SuAnnouncementGroupLang announcementGroupLang = new SuAnnouncementGroupLang();
            TextBox ctlTxtName = ctlAnnouncementGroupForm.FindControl("ctlTxtName") as TextBox;
            short   languageId = UserAccount.CurrentLanguageID;

            announcementGroupLang.Language              = DbLanguageService.FindByIdentity(languageId);
            announcementGroupLang.AnnouncementGroup     = announcementGroup;
            announcementGroupLang.AnnouncementGroupName = ctlTxtName.Text;
            announcementGroupLang.Active  = announcementGroup.Active;
            announcementGroupLang.CreBy   = 0;
            announcementGroupLang.CreDate = DateTime.Now;
            announcementGroupLang.UpdPgm  = ProgramCode;
            announcementGroupLang.UpdBy   = 0;
            announcementGroupLang.UpdDate = DateTime.Now;

            try
            {
                if (imageFile == null)
                {
                    SuAnnouncementGroupService.AddAnnouncementGroup(announcementGroup, announcementGroupLang);
                }
                else
                {
                    // If imageFile is not null.
                    short newAnnouncementGroupId = SuAnnouncementGroupService.AddAnnouncementGroup(announcementGroup, announcementGroupLang, imageFile);

                    // Get file path from Database DbParameter.
                    // Save new file to stored directory.
                    //string filePath = "D:\\DotNetStandard\\main\\program\\NHibernate\\SCG.eAccounting.Web\\ImageFiles\\Announcement\\";
                    string filePath = ParameterServices.AnnouncementGoupUploadFilePath;
                    filePath = AppDomain.CurrentDomain.BaseDirectory + filePath.Replace("~", string.Empty).Replace("/", "\\");
                    if (Directory.Exists(filePath))
                    {
                        // imagePath contain FileName of each AnnouncementGroup.
                        imageFile.SaveAs(filePath + announcementGroup.ImagePath);
                    }
                    else
                    {
                        Directory.CreateDirectory(filePath);
                        imageFile.SaveAs(filePath + announcementGroup.ImagePath);
                    }
                }
            }
            catch (ServiceValidationException ex)
            {
                ValidationErrors.MergeErrors(ex.ValidationErrors);
            }

            // Check if no validation error then changemode to default mode.
            if (ValidationErrors.IsEmpty)
            {
                ctlAnnouncementGroupForm.ChangeMode(FormViewMode.ReadOnly);
                ClosePopUp();
                ctlAnnouncementGroupGrid.DataCountAndBind();
            }
        }