Beispiel #1
0
        protected void btnCopy_Click(object sender, EventArgs e)
        {
            var pid = Request.QueryString["pid"];

            if (eb.CheckPollExistForTerm(Convert.ToInt32(pid), ddlTerms.SelectedItem.Value) == 0)
            {
                if (eb.CopyPoll(Convert.ToInt32(pid), ddlTerms.SelectedItem.Value))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseAndRebind", "CloseAndRebind(true);", true);
                }
                else
                {
                    ShowError("خطا در ثبت اطلاعات! لطفاً مجدداً تلاش نمائید.");
                }
            }
            else
            {
                ShowError("این پرسشنامه قبلاً برای ترم انتخابی ایجاد شده است.");
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var      dateIsValid = true;
            DateTime?toDate      = null;
            DateTime?fromDate    = null;

            if (!string.IsNullOrEmpty(txtToDate.Text))
            {
                var toDateParts = txtToDate.Text.Split('/');
                try
                {
                    toDate = pc.ToDateTime(Convert.ToInt32(toDateParts[0]), Convert.ToInt32(toDateParts[1]), Convert.ToInt32(toDateParts[2]), 0, 0, 0, 0, 0);
                }
                catch (Exception ex)
                {
                    dateIsValid = false;
                }
            }
            if (!string.IsNullOrEmpty(txtFromDate.Text))
            {
                var fromDateParts = txtFromDate.Text.Split('/');
                try
                {
                    fromDate = pc.ToDateTime(Convert.ToInt32(fromDateParts[0]), Convert.ToInt32(fromDateParts[1]), Convert.ToInt32(fromDateParts[2]), 0, 0, 0, 0, 0);
                }
                catch (Exception ex)
                {
                    dateIsValid = false;
                }
            }
            if (dateIsValid && ((toDate == null && fromDate == null) || (toDate != null && fromDate != null && toDate >= fromDate)))
            {
                int pid = 0;
                if (!string.IsNullOrEmpty(Request.QueryString["pid"]))
                {
                    pid = Convert.ToInt32(Request.QueryString["pid"]);
                }
                var duplicate = eb.CheckPollExistForTerm(Convert.ToInt32(pid), ddlTerm.SelectedItem.Value, Convert.ToInt32(ddlTitleType.SelectedItem.Value));
                if (duplicate == 0 || duplicate == pid)
                {
                    if (eb.AddOrUpdatePoll(title: ddlTitleType.SelectedItem.Text, term: ddlTerm.SelectedItem.Value
                                           , description: txtDescription.Text.Replace("&lt;", "<").Replace("&gt;", ">")
                                           , needComment: Convert.ToBoolean(Convert.ToInt32(ddlNeedComment.SelectedItem.Value)), pollId: pid, fromDate: fromDate, toDate: toDate
                                           , pollType: Convert.ToInt32(ddlTitleType.SelectedItem.Value)))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "CloseAndRebind", "CloseAndRebind(true);", true);
                    }
                    else
                    {
                        txtError.Text    = "خطا در ذخیره اطلاعات، لطفاً مجدداً تلاش نمائید.";
                        pnlError.Visible = true;
                    }
                }
                else
                {
                    txtError.Text    = "این پرسشنامه قبلاً برای ترم انتخابی ایجاد شده است.";
                    pnlError.Visible = true;
                }
            }
            else
            {
                txtError.Text    = "بازه زمانی صحیح نیست.";
                pnlError.Visible = true;
            }
        }