protected void btnAdd_Click(object sender, EventArgs e)
    {
        tblAd    popoupTbl = new tblAd();
        DateTime dateTime  = DateTime.UtcNow.Date;
        string   datedate  = dateTime.ToString("yyyyMMdd");



        if (txtTitle.Text.Trim().Length > 0)
        {
            popoupTbl.adTitle = txtTitle.Text;

            if (ckDetails.Text.Trim().Length > 0)
            {
                string str = ckDetails.Text;
                popoupTbl.adDetails = Server.HtmlDecode(str);
            }
            else
            {
                popoupTbl.adDetails = "";
            }

            popoupTbl.dateInsert = datedate;

            if (txtYearFrom.Text.Length < 4 || txtMonthFrom.Text.Length < 2 || txtDayFrom.Text.Length < 2)
            {
                popoupTbl.dateStart = datedate;
            }
            else
            {
                popoupTbl.dateStart = txtYearFrom.Text + txtMonthFrom.Text + txtDayFrom.Text;
            }

            if (txtYearTo.Text.Length < 4 || txtMonthTo.Text.Length < 2 || txtDayTo.Text.Length < 2)
            {
                popoupTbl.dateExp = datedate;
            }
            else
            {
                popoupTbl.dateExp = txtYearTo.Text + txtMonthTo.Text + txtDayTo.Text;
            }

            popoupTbl.allow           = "1";
            popoupTbl.periodOfShow    = 1;
            popoupTbl.adPayment       = 1;
            popoupTbl.ownerOfBusiness = "";

            popoupTbl.Create();


            tblAdCollection popupAdCountIdTbl = new tblAdCollection();
            popupAdCountIdTbl.ReadList();


            tblAdPic popupAdPicTbl = new tblAdPic();

            // file upload start
            string filename = string.Empty;
            if (IsPostBack)
            {
                Boolean fileOK = false;
                String  path   = Server.MapPath("~/images/");
                if (fuGallery.HasFile)
                {
                    String   fileExtension     = System.IO.Path.GetExtension(fuGallery.FileName).ToLower();
                    String[] allowedExtensions = { ".jpg" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }
                }

                if (fileOK)
                {
                    try
                    {
                        fuGallery.PostedFile.SaveAs(path + fuGallery.FileName);
                        filename = fuGallery.FileName;
                    }
                    catch (Exception ex)
                    {
                        lblError.Text = "A promblem with uplouding picture";
                    }
                }
                else
                {
                    lblError.Text = "Not valid picture";
                }
            }

            //file upload end
            if (filename.Trim().Length > 0)
            {
                popupAdPicTbl.picAddr = "images/" + filename;
            }
            //else error

            popupAdPicTbl.idAd      = popupAdCountIdTbl[popupAdCountIdTbl.Count - 1].id;
            popupAdPicTbl.allow     = "1";
            popupAdPicTbl.picName   = "";
            popupAdPicTbl.picDetail = "";

            popupAdPicTbl.Create();



            tblAdStyle popupAdStyle = new tblAdStyle();

            //popupAdStyle.idAd = popupAdCountIdTbl[popupAdCountIdTbl.Count - 1].id;
            popupAdStyle.styleTitle   = rbStyle.SelectedValue;
            popupAdStyle.styleContent = "";
            popupAdStyle.styleDetails = "";



            popupAdStyle.Create();



            Response.Redirect("popuppage.aspx");
        }
        else
        {
            lblError.Text = "* please enter title frist.";
        }
    }
Ejemplo n.º 2
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        tblAd    adTbl    = new tblAd();
        tblAdPic adPicTbl = new tblAdPic();

        string dateInsert = DateTime.Now.ToString("yyyy/MM/dd");

        if (txtTitle.Text.Trim().Length > 0 && txtStart.Text.Trim().Length == 8)
        {
            try
            {
                adTbl.adTitle = txtTitle.Text;

                string str = ckDetails.Text;
                adTbl.adDetails = Server.HtmlDecode(str);

                adTbl.dateInsert = dateInsert;
                adTbl.dateStart  = txtStart.Text;
                if (ddlExp.Enabled == true)
                {
                    adTbl.periodOfShow = Convert.ToInt32(ddlExp.SelectedValue);
                    adTbl.dateExp      = "";
                }
                else
                {
                    adTbl.dateExp      = txtExp.Text;
                    adTbl.periodOfShow = 0;
                }
                adTbl.adPayment       = 1;
                adTbl.ownerOfBusiness = "";
                adTbl.allow           = "1";
                adTbl.adPosition      = ddlPosition.SelectedValue;

                #region File upload
                Boolean fileOK   = false;
                String  path     = Server.MapPath("~/images/ad/");
                string  filename = string.Empty;

                if (fuGallery.HasFile)
                {
                    String   fileExtension     = System.IO.Path.GetExtension(fuGallery.FileName).ToLower();
                    String[] allowedExtensions = { ".jpg", ".png", ".bmp", ".gif" };
                    for (int i = 0; i < allowedExtensions.Length; i++)
                    {
                        if (fileExtension == allowedExtensions[i])
                        {
                            fileOK = true;
                        }
                    }
                }

                if (fileOK)
                {
                    try
                    {
                        fuGallery.PostedFile.SaveAs(path + fuGallery.FileName);
                        filename = fuGallery.FileName;
                    }
                    catch (Exception ex)
                    {
                        lblError.Text = "A problem with uplouding picture";
                    }
                }
                else
                {
                    lblError.Text = "Not valid picture";
                }
                #endregion

                if (filename.Length > 0)
                {
                    adTbl.Create();
                }

                tblAdCollection adIdTbl = new tblAdCollection();
                adIdTbl.ReadList();

                adPicTbl.idAd      = adIdTbl[adIdTbl.Count - 1].id;
                adPicTbl.picName   = filename;
                adPicTbl.picAddr   = "~/images/ad/";
                adPicTbl.picDetail = Server.HtmlDecode(str);
                adPicTbl.allow     = "1";

                adPicTbl.Create();
            }
            catch (Exception ex)
            {
                lblError.Text = "There was an error and function has droped, " + ex.ToString();
            }
        }
        else
        {
            lblError.Text = "Requierd filds must be completed...";
        }
    }