private string giveMeAd(int adStyleId) { string dateNow = DateTime.Now.ToString("yyyyMMdd"); Random ranNumber = new Random(); int ranNum = 0; string ret = ""; tblAdCollection AdTbl = new tblAdCollection(); AdTbl.ReadList(Criteria.NewCriteria(tblAd.Columns.idStyleGrp, CriteriaOperators.Equal, adStyleId)); tblAdPicCollection adPicTbl = new tblAdPicCollection(); if (AdTbl.Count > 0) { while (true) { ranNum = ranNumber.Next(0, AdTbl.Count); int dateAd = Convert.ToInt32(AdTbl[ranNum].dateStart.Substring(0, 2) + AdTbl[ranNum].dateStart.Substring(3, 2) + AdTbl[ranNum].dateStart.Substring(6, 4)); if (dateAd >= Convert.ToInt32(dateNow)) { adPicTbl.ReadList(Criteria.NewCriteria(tblAdPic.Columns.idAd, CriteriaOperators.Equal, AdTbl[ranNum].id)); ret = adPicTbl[0].picAddr + adPicTbl[0].picName; break; } } return(ret); } else { return("none"); } //return ("./img/headadmiddle.jpg"); }
protected void Page_Load(object sender, EventArgs e) { //Add ddl tblAdCollection popupAdTbl = new tblAdCollection(); popupAdTbl.ReadList(); if (!IsPostBack) { } //place data string adString = string.Empty; tblAdPicCollection popoupAdPic = new tblAdPicCollection(); popoupAdPic.ReadList(); for (int i = 0; i < popupAdTbl.Count; i++) { popoupAdPic.ReadList(Criteria.NewCriteria(tblAdPic.Columns.idAd, CriteriaOperators.Equal, popupAdTbl[i].id)); adString += "<div class='col-md-6 graph-2'>" + "<h3 class='inner-tittle'>News " + (i + 1) + " </h3>" + "<div class='panel panel-primary two'>" + "<div class='panel-heading'>" + popupAdTbl[i].adTitle + "(" + popupAdTbl[i].dateStart + " / " + popupAdTbl[i].dateExp + ")" + "</div><div class='panel-body ont two'>" + "<div><img src='../" + popoupAdPic[0].picAddr + "' alt='Hsco corp health care " + i + "' style='width: 100%;' /></div><p>" + popupAdTbl[i].adDetails + "</p></div>" + "<div class='panel-footer'><a href='add-details.aspx?item=" + popupAdTbl[i].id + "'>edit</a></div></div></div>"; } infHtml.InnerHtml = adString; }
protected void Page_Load(object sender, EventArgs e) { string adString = string.Empty; tblAdCollection adTbl = new tblAdCollection(); adTbl.ReadList(); tblAdPicCollection adPicTbl = new tblAdPicCollection(); adString += " <div class='grids_of_4'>"; int counter = 1; for (int i = 0; i < adTbl.Count; i++) { adPicTbl.ReadList(Criteria.NewCriteria(tblAdPic.Columns.idAd, CriteriaOperators.Equal, adTbl[i].id)); if (counter == 4) { adString += " <div class='grids_of_4'>"; } adString += "<div class='grid1_of_4'><div class='content_box'>" + "<a><img src='../images/ad/" + adPicTbl[0].picName + "' class='img-responsive' alt='" + adPicTbl[0].picName + "'></a><h4><a>" + adTbl[i].adTitle + "</a></h4>" + "<p>" + adTbl[i].adDetails + "</p><div class='grid_1 simpleCart_shelfItem'>" + "<div class='item_add'><span class='item_price'><h6>" + adTbl[i].dateStart; if (adTbl[i].periodOfShow > 0) { adString += "FOR " + adTbl[i].periodOfShow + " Days</h6></span></div>"; } else { adString += "TO " + adTbl[i].dateExp + "</h6></span></div>"; } adString += "<div class='item_add'><span class='item_price'><a href='ad-edit.aspx?adId=" + adTbl[i].id + "'>EDIT</a></span><span class='item_price'>" + "<a href='ad-del.aspx?adId=" + adTbl[i].id + " '>DELETE</a></span></div></div></div></div>"; if (counter == 4) { adString += "</div>"; counter = 1; } counter++; } adString += "</div>"; adHtml.InnerHtml = adString; }
protected void btnDel_Click(object sender, EventArgs e) { int itemGet = 0; if (Request.QueryString["adId"] != null) { itemGet = int.Parse(Request.QueryString["adId"]); } else { Response.Redirect("ad.aspx"); } tblAdCollection adTbl = new tblAdCollection(); adTbl.ReadList(Criteria.NewCriteria(tblAd.Columns.id, CriteriaOperators.Equal, itemGet)); adTbl[0].Delete(); Response.Redirect("ad-edit.aspx"); }
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."; } }
protected void Page_Load(object sender, EventArgs e) { int itemGet = 0; if (Request.QueryString["adId"] != null) { itemGet = int.Parse(Request.QueryString["adId"]); } else { Response.Redirect("ad.aspx"); } //fill data tblAdCollection adTbl = new tblAdCollection(); adTbl.ReadList(Criteria.NewCriteria(tblAd.Columns.id, CriteriaOperators.Equal, itemGet)); tblAdPicCollection adPicTbl = new tblAdPicCollection(); adPicTbl.ReadList(Criteria.NewCriteria(tblAdPic.Columns.idAd, CriteriaOperators.Equal, adTbl[0].id)); #region showing data if (adPicTbl[0].picName.Length > 3) { setPicHtml.InnerHtml = "<img src='../images/ad/" + adPicTbl[0].picName + "' class='img-responsive' draggable='false'>"; } string addDataString = string.Empty; addDataString += "<h3 class='farsi-direction farsi-font-title'>" + adTbl[0].adTitle + "</h3><br>" + "<span class='code'>Position: <a>" + adTbl[0].adPosition + "</a></span>" + "<p class='farsi-font-text'><span class='subtitle-news'>Details:</span> " + adTbl[0].adDetails + "</p>" + "<div class='price'>" + "<span class='text'></span>"; addDataString += "<span class='price-new'></span>"; addDataString += "<span class='price-tax'><label class='checkbox'></label></span><br>"; addDataString += "<span class='points'><small>Insert Date: " + adTbl[0].dateInsert + "</small> To " + adTbl[0].dateExp + " / " + adTbl[0].periodOfShow + " Days</span><br>"; addDataString += "</div>"; adHtml.InnerHtml = addDataString; #endregion if (!IsPostBack) { #region filling text boxes txtTitle.Text = adTbl[0].adTitle; ckDetails.Text = adTbl[0].adDetails; txtStart.Text = adTbl[0].dateStart; if (adTbl[0].periodOfShow > 0) { ddlExp.SelectedValue = adTbl[0].periodOfShow.ToString(); Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "disableTextBox()", true); rb2.Checked = true; } else { txtExp.Text = adTbl[0].dateExp; ddlExp.SelectedValue = "0"; Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "disableDropDownList()", true); rb1.Checked = true; } ddlPosition.SelectedValue = adTbl[0].adPosition.Trim(); #endregion } }
protected void btnUpdate_Click(object sender, EventArgs e) { int itemGet = 0; string fileNameUpdate = string.Empty; if (Request.QueryString["adId"] != null) { itemGet = int.Parse(Request.QueryString["adId"]); } else { Response.Redirect("ad.aspx"); } tblAdCollection adTbl = new tblAdCollection(); adTbl.ReadList(Criteria.NewCriteria(tblAd.Columns.id, CriteriaOperators.Equal, itemGet)); tblAdPicCollection adPicTbl = new tblAdPicCollection(); adPicTbl.ReadList(Criteria.NewCriteria(tblAdPic.Columns.idAd, CriteriaOperators.Equal, itemGet)); #region ad table update if (txtTitle.Text.Trim().Length > 0 && txtStart.Text.Trim().Length == 8) { //int dateIns = Convert.ToInt32(adTbl[0].dateInsert.Trim()); adTbl[0].adTitle = txtTitle.Text; string str = ckDetails.Text; adTbl[0].adDetails = Server.HtmlDecode(str); adTbl[0].dateStart = txtStart.Text; adTbl[0].dateInsert = adTbl[0].dateInsert; if (ddlExp.Enabled == true) { adTbl[0].periodOfShow = Convert.ToInt32(ddlExp.SelectedValue); adTbl[0].dateExp = ""; } else { adTbl[0].dateExp = txtExp.Text; adTbl[0].periodOfShow = 0; } adTbl[0].adPayment = 1; adTbl[0].ownerOfBusiness = ""; adTbl[0].allow = "1"; adTbl[0].adPosition = ddlPosition.SelectedValue; adTbl[0].Update(); #endregion #region picture update // file upload start string filename = string.Empty; Boolean fileOK = false; String fileExtension = System.IO.Path.GetExtension(fuGallery.FileName).ToLower(); if (IsPostBack) { String path = Server.MapPath("~/images/ad/"); if (fuGallery.HasFile) { 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 accurred while uplouding picture"; } } else { lblError.Text = "Not valid picture file"; } } // file upload end if (filename.Trim().Length > 0) { adPicTbl[0].picName = filename; } adPicTbl[0].idAd = itemGet; adPicTbl[0].picAddr = "../images/ad/"; adPicTbl[0].picDetail = Server.HtmlDecode(str); adPicTbl[0].allow = "1"; adPicTbl[0].Update(); #endregion } Response.Redirect("ad.aspx"); }
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..."; } }