Exemplo n.º 1
0
    protected void DoSave(object sender, ImageClickEventArgs e)
    {
        try
        {
            #region Validate Controls
            bool NewsTypeSelected = true;
            //for (int i = 0; i < treWorkGroups.Items.Count; i++)
            //{
            //    CheckBox CurCheckbox = (CheckBox)dlNewsTypes.Items[i].FindControl("chkNewsType");
            //    if (CurCheckbox.Checked)
            //    {
            //        NewsTypeSelected = true;
            //        break;
            //    }

            //}
            if (!NewsTypeSelected)
            {
                msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error;
                msgBox.Text            = "لطفا حداقل یک گروه انتخاب کنید.";
                return;
            }

            if (NewMode && uplPicFile2.UploadedFiles.Count == 0)
            {
                msgBox.MessageTextMode = AKP.Web.Controls.Common.MessageMode.Error;
                msgBox.Text            = "لطفا عکس خبر را انتخاب کنید.";
                return;
            }
            #endregion

            int ReturnCode = SaveControls("~/Main/Default.aspx?BaseID=" + BaseID);
            Code = ReturnCode;

            BOLNews NewsBOL = new BOLNews();
            if (ReturnCode != -1)
            {
                DateTime dtNewsDate;
                News     CurNews = ((IBaseBOL <News>)NewsBOL).GetDetails(ReturnCode);
                #region Save News Date
                if (NewMode)
                {
                    dtNewsDate = (DateTime)dteNewsDate.SelectedDateChristian;
                    dtNewsDate = new DateTime(dtNewsDate.Year, dtNewsDate.Month, dtNewsDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);
                }
                else
                {
                    dtNewsDate = (DateTime)dteNewsDate.SelectedDateChristian;
                    dtNewsDate = new DateTime(dtNewsDate.Year, dtNewsDate.Month, dtNewsDate.Day, CurNews.NewsDate.Hour, CurNews.NewsDate.Minute, CurNews.NewsDate.Second);
                }
                NewsBOL.SaveNewsDate(ReturnCode, dtNewsDate);
                #endregion

                if (uplPicFile2.UploadedFiles.Count > 0 || string.IsNullOrEmpty(CurNews.PicFile1))
                {
                    Guid   newGd        = Guid.NewGuid();
                    string RandSmallPic = newGd.ToString().Replace("-", "") + ".jpg";

                    PersianCalendar pc       = new PersianCalendar();
                    DateTime        thisTime = DateTime.Now;
                    string          UplPath  = "~/Files/News/" + pc.GetYear(thisTime) + "-" + pc.GetMonth(thisTime) + "-" + pc.GetDayOfMonth(thisTime);
                    if (!Directory.Exists(HttpContext.Current.Request.MapPath(UplPath)))
                    {
                        Directory.CreateDirectory(HttpContext.Current.Request.MapPath(UplPath));
                    }


                    SavePic(CurNews.PicFile2, RandSmallPic, HttpContext.Current.Request.MapPath(UplPath), 100);
                    NewsBOL.ChangeSmallPic(ReturnCode, UplPath + "/" + RandSmallPic);
                }

                #region Save Keywords
                string Keywords = txtKeywords.Text;
                Keywords = Keywords.Trim();
                while (Keywords.IndexOf("  ") != -1)
                {
                    Keywords = Keywords.Replace("  ", " ");
                }
                while (Keywords.IndexOf("\n\n") != -1)
                {
                    Keywords = Keywords.Replace("\n\n", "\n");
                }
                string[]        KeywordsArray   = Keywords.Split('\n');
                BOLNewsKeywords NewsKeywordsBOL = new BOLNewsKeywords(1);
                NewsKeywordsBOL.DeleteAllKeywords((int)Code);
                for (int i = 0; i < KeywordsArray.Length; i++)
                {
                    if (KeywordsArray[i].Trim() != "")
                    {
                        NewsKeywordsBOL.Insert((int)Code, KeywordsArray[i]);
                    }
                }
                #endregion

                ShowDetails();
            }
            if (cboPriorityTypeCode.SelectedIndex != 0 && ReturnCode != -1)
            {
                News CurNews = ((IBaseBOL <News>)NewsBOL).GetDetails(ReturnCode);

                if (NewMode)
                {
                    int PriorityTypeCode = Convert.ToInt32(cboPriorityTypeCode.SelectedValue);
                    int NewPririty       = 0;
                    NewPririty = NewsBOL.GetLatestPriority(PriorityTypeCode - 1) + 100;
                    if (PriorityTypeCode > 1)
                    {
                        NewsBOL.MoveTopNews(NewPririty);
                    }

                    NewsBOL.SetNewPriority(ReturnCode, NewPririty);
                }
                else
                {
                    int NewsToBeReplaceCode = NewsBOL.GetPriorityByOrder(cboPriorityTypeCode.SelectedIndex - 1);
                    if (NewsToBeReplaceCode != ReturnCode)
                    {
                        NewsBOL.ChangePririties(ReturnCode, NewsToBeReplaceCode);
                    }
                }

                txtNewsNumber.Text = CurNews.NewsNumber;
                NewMode            = false;
                Code = ReturnCode;
                ShowDetails();
            }
        }
        catch
        {
        }
    }