Example #1
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        Upload_doc   bl = new Upload_doc();
        Notice_Entry n  = new Notice_Entry();

        ReturnClass.ReturnBool rb = new ReturnClass.ReturnBool();

        if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
        {
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
            if (ddlPermanent.SelectedValue == "Y")
            {
                RequiredFieldValidator10.Enabled             = false;
                RequiredFieldValidator10.ValidationGroup     = "x";
                RequiredFieldValidator9.Enabled              = false;
                RequiredFieldValidator9.ValidationGroup      = "x";
                RegularExpressionValidator10.Enabled         = false;
                RegularExpressionValidator10.ValidationGroup = "x";
                RegularExpressionValidator17.Enabled         = false;
                RegularExpressionValidator17.ValidationGroup = "x";

                RequiredFieldValidator7.Enabled             = true;
                RequiredFieldValidator7.ValidationGroup     = "a";
                RegularExpressionValidator1.Enabled         = true;
                RegularExpressionValidator1.ValidationGroup = "a";
            }
            else if (ddlPermanent.SelectedValue == "N")
            {
                RequiredFieldValidator10.Enabled             = true;
                RequiredFieldValidator9.Enabled              = true;
                RequiredFieldValidator10.ValidationGroup     = "a";
                RequiredFieldValidator9.ValidationGroup      = "a";
                RegularExpressionValidator10.Enabled         = true;
                RegularExpressionValidator10.ValidationGroup = "a";
                RegularExpressionValidator17.Enabled         = true;
                RegularExpressionValidator17.ValidationGroup = "a";

                RequiredFieldValidator7.Enabled             = false;
                RequiredFieldValidator7.ValidationGroup     = "x";
                RegularExpressionValidator1.Enabled         = false;
                RegularExpressionValidator1.ValidationGroup = "x";
            }
            if (ddlHyperlink.SelectedValue == "Y")
            {
                RequiredFieldValidator3.Enabled         = true;
                RequiredFieldValidator3.ValidationGroup = "a";
            }
            else if (ddlHyperlink.SelectedValue == "N")
            {
                RequiredFieldValidator3.Enabled         = false;
                RequiredFieldValidator3.ValidationGroup = "x";
                RequiredFieldValidator6.Enabled         = false;
                RequiredFieldValidator6.ValidationGroup = "x";
                RequiredFieldValidator4.Enabled         = false;
                RequiredFieldValidator4.ValidationGroup = "x";
                regUrl.ValidationGroup = "x";
                regUrl.Enabled         = false;
            }
            if (ddlType.SelectedValue == "E")
            {
                RequiredFieldValidator6.Enabled         = false;
                RequiredFieldValidator6.ValidationGroup = "x";
                RequiredFieldValidator4.Enabled         = true;
                RequiredFieldValidator4.ValidationGroup = "a";
                regUrl.ValidationGroup = "a";
                regUrl.Enabled         = true;
            }
            else if (ddlType.SelectedValue == "I")
            {
                RequiredFieldValidator6.Enabled         = true;
                RequiredFieldValidator6.ValidationGroup = "a";
                RequiredFieldValidator4.Enabled         = false;
                RequiredFieldValidator4.ValidationGroup = "x";
                regUrl.ValidationGroup = "x";
                regUrl.Enabled         = false;
            }
            if (HiddenField1.Value == "0" || HiddenField1.Value == "Select")
            {
                RFV_Image_Icon.ValidationGroup = "a";
                RFV_Image_Icon.Enabled         = true;
            }
            else
            {
                RFV_Image_Icon.ValidationGroup = "x";
                RFV_Image_Icon.Enabled         = false;
            }

            if (Page.IsValid)
            {
                Boolean st = true;
                try
                {
                    using (TransactionScope ts = new TransactionScope())
                    {
                        n.District_id  = ddl_district.SelectedValue;// Session["Dist_Code"].ToString();
                        n.Base_dept_id = ddl_department.SelectedValue;
                        n.Office_id    = ddl_office.SelectedValue;

                        n.Header    = txtHeader.Text.Trim();
                        n.Permanent = ddlPermanent.SelectedValue;
                        n.Active    = ddlActive.SelectedValue;
                        n.Hyperlink = ddlHyperlink.SelectedValue.ToString();
                        n.Client_ip = util.GetClientIpAddress(this.Page);
                        n.User_id   = Session["username"].ToString();
                        //  n.Datetime = Convert.ToDateTime(System.DateTime.Now).ToString("yyyy/MM/dd HH:mm:ss");
                        DateTime today = DateTime.Today;
                        n.Datetime = today.ToString("yyyy/MM/dd");
                        if (ddlPermanent.SelectedValue == "N")
                        {
                            n.Publish_date = null;
                            //string datefrom = Convert.ToDateTime(txtDateFrom.Text.Trim()).ToString("yyyy/MM/dd HH:mm:ss");
                            //string dateto = Convert.ToDateTime(txtDateTo.Text.Trim()).ToString("yyyy/MM/dd HH:mm:ss");
                            //n.Datefrom = datefrom.ToString();
                            //n.Dateto = dateto.ToString();

                            DateTime datefrom = DateTime.ParseExact(txtDateFrom.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            n.Datefrom = datefrom.ToString("yyyy/MM/dd HH:mm:ss");
                            DateTime dateto = DateTime.ParseExact(txtDateTo.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            n.Dateto = dateto.ToString("yyyy/MM/dd HH:mm:ss");
                        }
                        else if (ddlPermanent.SelectedValue == "Y")
                        {
                            DateTime Publish_date = DateTime.ParseExact(txtPublishDate.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
                            n.Publish_date = Publish_date.ToString("yyyy/MM/dd HH:mm:ss");

                            //n.Publish_date = Convert.ToDateTime(txtPublishDate.Text.Trim()).ToString("yyyy/MM/dd HH:mm:ss");
                            n.Datefrom = null;
                            n.Dateto   = null;
                        }

                        if (ddlHyperlink.SelectedValue == "Y")
                        {
                            n.Filetype = ddlType.SelectedValue;
                            if (ddlType.SelectedValue == "I")
                            {
                                if (FileUpload1.HasFile)
                                {
                                    if (FileUpload1.PostedFile.ContentType == "application/x-pdf" || FileUpload1.PostedFile.ContentType == "application/pdf")
                                    {
                                        if (FileUpload1.PostedFile.ContentLength > maxSizePdf)
                                        {
                                            if (Session["language"].ToString() == "en-GB")
                                            {
                                                Utilities.MessageBoxShow("This PDF File Is too Big...Maximum Size allowed is 10 Mb");
                                            }
                                            else
                                            {
                                                Utilities.MessageBoxShow("यह PDF बहुत बड़ा है...अधिकतम साइज़ 10 Mb की अनुमति है");
                                            }
                                            //  Utilities.MessageBoxShow("This PDF File Is too Big...Maximum Size allowed is 10 Mb");
                                            st = false;
                                            preview();
                                        }
                                    }
                                    else if (FileUpload1.PostedFile.ContentType == "image/jpg" || FileUpload1.PostedFile.ContentType == "image/jpeg")
                                    {
                                        if (FileUpload1.PostedFile.ContentLength > maxSizeJpg)
                                        {
                                            if (Session["language"].ToString() == "en-GB")
                                            {
                                                Utilities.MessageBoxShow("This JPG File Is too Big...Maximum Size allowed is 1 Mb");
                                            }
                                            else
                                            {
                                                Utilities.MessageBoxShow("यह JPG बहुत बड़ा है...अधिकतम साइज़ 1 Mb की अनुमति है");
                                            }
                                            //Utilities.MessageBoxShow("This JPG File Is too Big...Maximum Size allowed is 1 Mb");
                                            st = false;
                                            preview();
                                        }
                                    }
                                    if (st)
                                    {
                                        if (FileUpload1.PostedFile.ContentType == "application/x-pdf" || FileUpload1.PostedFile.ContentType == "application/pdf" || FileUpload1.PostedFile.ContentType == "image/jpg" || FileUpload1.PostedFile.ContentType == "image/jpeg")
                                        {
                                            //string content_type = FileUpload1.PostedFile.ContentType.ToString();
                                            string file_ext = Path.GetExtension(FileUpload1.PostedFile.FileName).ToString();

                                            Stream fs = default(Stream);
                                            fs = FileUpload1.PostedFile.InputStream;
                                            BinaryReader br1      = new BinaryReader(fs);
                                            byte[]       pdfbytes = br1.ReadBytes(FileUpload1.PostedFile.ContentLength);
                                            bl.File_Extn = file_ext;
                                            bl.File_Data = pdfbytes;
                                            bl.URL       = null;
                                            bl.Filename  = FileUpload1.PostedFile.FileName;
                                        }
                                        else
                                        {
                                            if (Session["language"].ToString() == "en-GB")
                                            {
                                                Utilities.MessageBoxShow("Only PDF and JPG files are allowed");
                                            }
                                            else
                                            {
                                                Utilities.MessageBoxShow(" केवल PDF और JPG फाईल की अनुमति है");
                                            }
                                            // Utilities.MessageBoxShow("Only PDF and JPG files are allowed");
                                            st = false;
                                            preview();
                                        }
                                    }
                                }
                            }
                            else if (ddlType.SelectedValue == "E")
                            {
                                n.File_id = null;
                                n.url     = txtUrl.Text.Trim();
                            }
                        }
                        else if (ddlHyperlink.SelectedValue == "N")
                        {
                            bl.File_id      = null;
                            bl.File_Extn    = null;
                            bl.Content_type = null;
                            bl.File_Data    = new byte[] { };
                            bl.URL          = null;
                            bl.Filename     = null;
                        }
                        if (FileUpload1.HasFiles)
                        {
                            if (st)
                            {
                                bl.Filename    = FileUpload1.PostedFile.FileName;
                                bl.Client_ip   = util.GetClientIpAddress(this.Page);
                                bl.User_id     = Session["username"].ToString();
                                bl.Upload_Date = Convert.ToDateTime(System.DateTime.Now).ToString("yyyy/MM/dd HH:mm:ss");


                                rb = dl.Insert_FileDetails(bl); // inserting file details..

                                if (rb.status == true)
                                {
                                    n.file_ID = Convert.ToInt32(dl.Get_Max_ID().table.Rows[0][0].ToString());
                                }
                            }
                        }

                        if (st)
                        {
                            //new
                            if (RadioButtonListbold.SelectedValue == "Yes")
                            {
                                n.Bold = "Y";
                            }
                            else
                            {
                                n.Bold = "N";
                            }
                            if (RadioButtonListblink.SelectedValue == "Yes")
                            {
                                n.Blink = "Y";
                            }
                            else
                            {
                                n.Blink = "N";
                            }
                            n.Priority = ddlpriority.SelectedValue;
                            n.Color    = color.Text.Trim();
                            // n.Image = ddlimage.SelectedItem.Text;
                            string imgPath     = HiddenField1.Value.ToString();
                            string cut_imgPath = imgPath.Remove(0, 3);
                            n.Image  = cut_imgPath; //HiddenField1.Value;
                            n.status = "P";

                            rb = dl.Insert_Notice(n); // inserting notice details
                        }

                        if (rb.status == true)
                        {
                            ts.Complete();
                            if (Session["language"].ToString() == "en-GB")
                            {
                                Utilities.MessageBoxShow_Redirect("Record Saved Successfully", "../admin/notice_entry.aspx");
                            }
                            else
                            {
                                Utilities.MessageBoxShow_Redirect("रिकार्ड सफलतापूर्वक सुरक्षित हुआ", "../admin/notice_entry.aspx");
                            }
                            // Utilities.MessageBoxShow_Redirect("Record Save Successfully", "../admin/notice_entry.aspx");
                            clear();

                            // BindDropDownList();
                            // BindTitles();
                        }
                    }
                }
                catch (Exception ex)
                {
                    rb.status = false;
                    if (Session["language"].ToString() == "en-GB")
                    {
                        Utilities.MessageBoxShow("Record could not be saved.");
                    }
                    else
                    {
                        Utilities.MessageBoxShow("रिकार्ड सुरक्षित नहीं हुआ |");
                    }
                    //  Utilities.MessageBoxShow("Record could not be saved.");
                    Gen_Error_Rpt.Write_Error("Notice_Entry.aspx_btnSubmit_Click", ex);
                }
            }
        }
    }