//بدنه مربوط به متد اینیشیالایز #region Initialize() /// <summary> /// متد ذیل در هنگام بارگزاری صفحه اتفاق میفتد /// </summary> private void Initialize() { // تکميل فيلد {0} الزامی است rfvPost.ErrorMessage = string.Format(Resources.Messages.ErrorMessage002, Resources.Captions.Post); // تکميل فيلد {0} الزامی است rfvPostTypeId.ErrorMessage = string.Format(Resources.Messages.ErrorMessage002, Resources.Captions.PostTypeId); // تکميل فيلد {0} الزامی است rfvPostCategoryId.ErrorMessage = string.Format(Resources.Messages.ErrorMessage002, Resources.Captions.PostCategoryId); // تکميل فيلد {0} الزامی است rfvTitle.ErrorMessage = string.Format(Resources.Messages.ErrorMessage002, Resources.Captions.Title); // تکميل فيلد {0} الزامی است rfvKeyword1.ErrorMessage = string.Format(Resources.Messages.ErrorMessage002, Resources.Captions.Keyword); try { //تعریف یک رشته که حاوی یوزر آی دی از آدرس بار میباشد string strPostId = Request.Params["PostId"]; txtPostID.Text = strPostId; //با استفاده از دیتا تیبل و تیبل آدابتر مقادیر را در صورت وجود از دیتا بیس خوانده و در یک خط قرار میدهیم DataAccessLayer.DataSet.PostsDataTable oPostDataTable = new DataAccessLayer.DataSet.PostsDataTable(); DataAccessLayer.DataSetTableAdapters.PostsTableAdapter oPostTableAdapter = new DataAccessLayer.DataSetTableAdapters.PostsTableAdapter(); oPostTableAdapter.FillByPostId(oPostDataTable, Convert.ToInt32(strPostId)); if (oPostDataTable.Count == 0) { string strErrorMessage = string.Format(Resources.Messages.ErrorMessage020); DisplayErrorMessage(strErrorMessage); return; } DataAccessLayer.DataSet.PostsRow oPostRow = oPostDataTable[0]; ////مقدار دهی کنترل های صفحه از دیتابیس توسط خط ایجاد شده txtPost.Text = oPostRow.Body; txtTitle.Text = oPostRow.Title; txtPostTypeId.Text = oPostRow.PostTypeId.ToString(); txtPostCategoryId.Text = oPostRow.PostCategoryId.ToString(); txtKeyword1.Text = oPostRow.Keywords; txtPublishTime.Text = oPostRow.PublishTime.ToString(); txtUpdateTime.Text = oPostRow.UpdateTime.ToString(); txtInsertTime.Text = oPostRow.InsertTime.ToString(); chkIsCommentEnabled.Checked = oPostRow.IsCommentEnabled; chkIsHot.Checked = oPostRow.IsHot; chkIsPostActive.Checked = oPostRow.IsPostActive; ddlPostCategory.SelectedIndex = oPostRow.PostCategoryId; ddlPostType.SelectedIndex = oPostRow.PostTypeId; //بروز رسانی تیبل آدابتر و بانک اطلاعات oPostTableAdapter.Update(oPostDataTable); } catch (ApplicationException ex0) { //متغیر ای ایکس را لاگ کنید throw (new ApplicationException(Resources.Messages.ErrorMessage020)); } catch (Exception ex) { //متغیر ای ایکس را لاگ کنید string strErrorMessage = string.Format(Resources.Messages.ErrorMessage020); DisplayErrorMessage(strErrorMessage); return; } }
//بدنه متد اینیشیالایز #endregion Initialize() //بدنه ایونت ویرایش پست #region btnEdit_Click(object sender, EventArgs e) /// <summary> /// ایونت ویرایش پست /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnEdit_Click(object sender, EventArgs e) { try { //با استفاده از دیتا تیبل و تیبل آدابتور یک خط جدید ایجاد میکنیم DataAccessLayer.DataSet.PostsDataTable oPostDataTable = new DataAccessLayer.DataSet.PostsDataTable(); DataAccessLayer.DataSetTableAdapters.PostsTableAdapter oPostTableAdapter = new DataAccessLayer.DataSetTableAdapters.PostsTableAdapter(); oPostTableAdapter.FillByPostId(oPostDataTable, Convert.ToInt32(txtPostID.Text)); DataAccessLayer.DataSet.PostsRow oPostRow = oPostDataTable[0]; if (oPostDataTable.Count != 1) { string strErrorMessage = Resources.Messages.ErrorMessage017; DisplayErrorMessage(strErrorMessage); return; } System.DateTime dtmNow = Tools.Utility.GetNow(); //مقدار دهی به خط ایجاد شده oPostRow.Body = txtPost.Text; oPostRow.ExtendedBody = string.Empty;; oPostRow.InsertTime = dtmNow; oPostRow.UpdateTime = dtmNow; oPostRow.PostCategoryId = Convert.ToInt32(txtPostCategoryId.Text); oPostRow.PostTypeId = Convert.ToInt32(txtPostTypeId.Text); oPostRow.Title = txtTitle.Text; oPostRow.UserId = (int)Session["UserID"]; oPostRow.PublishTime = dtmNow; oPostRow.PostVisitedCount += 1; oPostRow.Keywords = txtKeyword1.Text; if (chkIsHot.Checked == true) { oPostRow.IsHot = true; } else { oPostRow.IsHot = false; } if (chkIsPostActive.Checked == true) { oPostRow.IsPostActive = true; } else { oPostRow.IsPostActive = false; } if (chkIsCommentEnabled.Checked == true) { oPostRow.IsCommentEnabled = true; } else { oPostRow.IsCommentEnabled = false; } //تیبل آدابتر و بروز رسانی دیتا بیس oPostTableAdapter.Update(oPostDataTable); //نمایش پیام موفقیت string strInformationMessage = Resources.Messages.InformationMessage012; DisplayInformationMessage(strInformationMessage); } catch (ApplicationException ex0) { //متغیر ای ایکس را لاگ کنید throw (new ApplicationException(Resources.Messages.ErrorMessage020)); } catch (Exception ex) { //متغیر ای ایکس را لاگ کنید string strErrorMessage = string.Format(Resources.Messages.ErrorMessage020); DisplayErrorMessage(strErrorMessage); return; } }