|
zde je obsah souboru section.aspx.cs kde se počítám musí volaná událost ošetřit?
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class webSection : System.Web.UI.Page {
public int nSectionID;
public int nTrademarkID;
public string cSearchText;
public int StarVote = 0;
double nDiscountCoef = 0;
int nRoundLevel = 0;
string cPriceType = functions.Instance.getParemeterValueString("shopPriceType");
string StarInit = "";
bool lNotVote = false;
protected void Page_Load(object sender, EventArgs e) {
try {
nSectionID = Convert.ToInt32(Request.QueryString["itemID"]);
} catch {
nSectionID = 0;
}
try {
nTrademarkID = Convert.ToInt32(Request.QueryString["trademarkID"]);
} catch {
nTrademarkID = 0;
}
try {
cSearchText = Server.UrlDecode(Request.QueryString["searchText"].ToString());
} catch {
cSearchText = "";
}
if (!Page.IsPostBack) {
setEnvironment();
if (cSearchText != "") {
searchData();
} else {
if (nSectionID != 0) {
readData();
}
if (nTrademarkID != 0) {
readDataByTrademark();
}
}
}
}
private void setEnvironment() {
}
private void searchData() {
string cSearchTitle;
cSearchTitle = GetGlobalResourceObject("avista", "searchTitle").ToString();
webMasterPage oMaster = (webMasterPage)Master;
oMaster.pageTitle = cSearchTitle;
oMaster.pageDescription = "";
oMaster.pageKeywords = "";
articlesWeb oArticles;
int nCount = 0;
oArticles = new articlesWeb(0, "", 0, cSearchText, oMaster.languageID, true, 0, 0, ref nCount);
if (oArticles.articleList.Count == 0) {
lblSearch.Text = GetGlobalResourceObject("avista", "searchNoArticles").ToString();
grdArticles.Visible = false;
} else {
lblSearch.Text = String.Format("{0}: {1}", GetGlobalResourceObject("avista", "searchStringTitle").ToString(), cSearchText);
grdArticles.Visible = true;
grdArticles.DataSource = oArticles.articleList;
grdArticles.DataBind();
}
if (StarInit != "") ScriptManager.RegisterStartupScript(Page, Page.GetType(), "starInit", StarInit, true);
if (functions.Instance.getParemeterValueString("trackingMode") == "AVISTA") { tracking.Instance.trackingWrite(oMaster.languageID, cSearchTitle); }
}
private void readData() {
lblSearch.Visible = false;
articlesWeb oArticles;
section oSection = new section(nSectionID, false);
if (oSection.parentID == 0) {
sections oSections = new sections(nSectionID, oSection.languageID, false, false, "");
if (oSections.sectionList.Count > 0) {
nSectionID = (int)oSections.sectionList.Table.Rows[0]["sectionID"];
}
}
if (oSection.perex != "" || oSection.perexImage != "") {
pnlPerex.Visible = true;
if (oSection.perex != "") {
lblSectionArticleText.Text = oSection.perex;
}
if (oSection.perexImage != "") {
pnlPerexImage.Visible = true;
hrefSectionPerexImage.NavigateUrl = oSection.url;
string PerexImage = oSection.perexImage;
pnlSectionPerexImage.ToolTip = oSection.title;
try {
pnlSectionPerexImage.Style.Add("background-image", "url(" + functions.Instance.getPicturePerexAbsolutePath(PerexImage) + ")");
} catch {
hrefSectionPerexImage.Visible = false;
}
} else {
pnlPerexImage.Visible = false;
}
}
int nCount = 0;
oArticles = new articlesWeb(oSection.ID, "", 0, "", oSection.languageID, true, 0, 0, ref nCount);
if (oArticles.articleList.Count == 1) {
SqlParameter[] oSqlParams = new SqlParameter[] { new SqlParameter("@UrlItemID", (int)oArticles.articleList.Table.Rows[0]["sectionArticleID"]), };
string cPath = DTO.Instance.ExecuteScalar("SELECT urlValue FROM [url] WHERE urlItemID = @UrlItemID AND urlItemTypeID = 2;", oSqlParams).ToString();
Response.Redirect(cPath);
}
try {
lNotVote = functions.Instance.getSQLValueBool(attributeFunctions.getAttributeValueString(nSectionID, "langNotVote", 1));
} catch {
lNotVote = false;
}
nRoundLevel = Convert.ToInt16(functions.Instance.getParemeterValueNumeric("shopItemDiscountRound", 0.00));
loggedMember oMember = new loggedMember();
if (oMember.ID > 0) {
double nDiscount = Convert.ToDouble(memberFunctions.Instance.getShopMemberSale(oMember.ID));
nDiscountCoef = (100 - nDiscount) / 100;
}
grdArticles.DataSource = oArticles.articleList;
grdArticles.DataBind();
webMasterPage oMaster = (webMasterPage)Master;
oMaster.languageID = oSection.languageID;
oMaster.selectedSectionID = oSection.ID;
oMaster.pageTitle = oSection.title;
oMaster.pageDescription = oSection.pageDescription;
oMaster.pageKeywords = oSection.pageKeywords;
if (oSection.perexImage != "") {
oMaster.perexImage = functions.Instance.getPicturePerexAbsolutePath(oSection.perexImage);
}
if (StarInit != "") ScriptManager.RegisterStartupScript(Page, Page.GetType(), "starInit", StarInit, true);
if (functions.Instance.getParemeterValueString("trackingMode") == "AVISTA") { tracking.Instance.trackingWrite(oSection.languageID, oSection.title); }
}
private void readDataByTrademark() {
lblSearch.Visible = false;
articlesByTrademark oArticles;
trademark oTrademark = new trademark(nTrademarkID);
oArticles = new articlesByTrademark(nTrademarkID, false);
if (oArticles.articleList.Count == 1) {
SqlParameter[] oSqlParams = new SqlParameter[] { new SqlParameter("@UrlItemID", (int)oArticles.articleList.Table.Rows[0]["sectionArticleID"]), };
string cPath = DTO.Instance.ExecuteScalar("SELECT urlValue FROM [url] WHERE urlItemID = @UrlItemID AND urlItemTypeID = 2;", oSqlParams).ToString();
Response.Redirect(cPath);
}
oArticles.articleList.Sort = "sectionArticlePosition DESC";
grdArticles.DataSource = oArticles.articleList;
grdArticles.DataBind();
webMasterPage oMaster = (webMasterPage)Master;
oMaster.languageID = 1;
oMaster.selectedTrademarkID = oTrademark.ID;
oMaster.pageTitle = oTrademark.title;
//oMaster.pageDescription = oTrademark.pageDescription;
//oMaster.pageKeywords = oTrademark.pageKeywords;
if (oTrademark.perexImage != "") {
oMaster.perexImage = functions.Instance.getPicturePerexAbsolutePath(oTrademark.perexImage);
}
if (StarInit != "") ScriptManager.RegisterStartupScript(Page, Page.GetType(), "starInit", StarInit, true);
if (functions.Instance.getParemeterValueString("trackingMode") == "AVISTA") { tracking.Instance.trackingWrite(1, oTrademark.title); }
}
protected void grdArticles_RowDataBound(object sender, GridViewRowEventArgs e) {
SqlParameter[] oSqlParams;
double nPriceShop = 0, nPriceUsual = 0;
int nArticleID;
string cArticleUrl = "", cArticleTitle;
HyperLink hrefArticleTitle, hrefAddToBasket, hrefPerexImage;
HyperLink hrefPoint1, hrefPoint2, hrefPoint3, hrefPoint4, hrefPoint5;
Literal lblLiteral, lblSubTitle;
Label lblLabel, lblRating;
Image imgImage;
Panel pnlPanel, pnlVote;
System.Drawing.Image oImage;
DataView dvPrices = null;
shopStockByPrice oStock = null;
int nPriceID = 0;
if (e.Row.RowType == DataControlRowType.DataRow) {
nArticleID = (int)DataBinder.Eval(e.Row.DataItem, "sectionArticleID");
if (nSectionID == 0) {
// seznam podle Trademark > neni rubrika
try {
lNotVote = functions.Instance.getSQLValueBool(attributeFunctions.getAttributeValueString(sectionFunctions.Instance.getSectionIDbyArticleID(nArticleID), "langNotVote", 1));
} catch {
lNotVote = false;
}
}
articleAttributes oAttributes = new articleAttributes(nArticleID);
oSqlParams = new SqlParameter[] {
new SqlParameter("@ArticleID", nArticleID)
};
cArticleUrl = functions.Instance.getURL(nArticleID, 2);
cArticleTitle = functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticleTitle"));
hrefArticleTitle = (HyperLink)e.Row.FindControl("hrefArticleTitle");
hrefArticleTitle.Text = cArticleTitle;
hrefArticleTitle.ToolTip = hrefArticleTitle.Text;
hrefArticleTitle.NavigateUrl = cArticleUrl + "?referrerID=" + nSectionID.ToString(); ;
lblLiteral = (Literal)e.Row.FindControl("lblPerex");
lblLiteral.Text = functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticlePerex"));
lblSubTitle = (Literal)e.Row.FindControl("lblSubTitle");
lblSubTitle.Text = functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticleSubtitle"));
lblLiteral = (Literal)e.Row.FindControl("lblAuthor");
lblLiteral.Text = prostorFunctions.clearAuthorName(oAttributes.author.Trim());
lblLabel = (Label)e.Row.FindControl("lblStock");
hrefAddToBasket = (HyperLink)e.Row.FindControl("hrefAddToBasket");
lblLiteral = (Literal)e.Row.FindControl("lblAttributes");
pnlPanel = (Panel)e.Row.FindControl("pnlHotNew");
pnlVote = (Panel)e.Row.FindControl("pnlVote");
if (oAttributes.hotNew) {
pnlPanel.CssClass = "hotNew";
}
if (oAttributes.hotNewDotisk) {
pnlPanel.CssClass = "hotNew dotisk";
}
if (functions.Instance.getSQLValueInt(DataBinder.Eval(e.Row.DataItem, "shopPriceCount")) != 0) {
if (lNotVote) {
pnlVote.Visible = false;
} else {
StarVote = 0;
lblRating = (Label)e.Row.FindControl("lblRating");
double nPoints = voteFunctions.getVoteArticlePoints(nArticleID);
if (nPoints == 0) {
lblRating.Visible = false;
} else {
lblRating.Text = Convert.ToInt32((nPoints / 5) * 100).ToString("##0") + "%";
StarVote = Convert.ToInt32(Math.Ceiling(nPoints));
}
hrefPoint1 = (HyperLink)e.Row.FindControl("hrefPoint1");
hrefPoint1.NavigateUrl = String.Format("/voteArticleAdd.aspx?itemID={0}&value=1&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
hrefPoint1.ToolTip = String.Format("{0} (1 bod)", HttpContext.GetGlobalResourceObject("custom", "votePrefix").ToString());
hrefPoint1.Attributes.Add("onmouseout", "star_out(\"" + nArticleID + "\"," + StarVote + ")");
hrefPoint2 = (HyperLink)e.Row.FindControl("hrefPoint2");
hrefPoint2.NavigateUrl = String.Format("/voteArticleAdd.aspx?itemID={0}&value=2&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
hrefPoint2.ToolTip = String.Format("{0} (2 body)", HttpContext.GetGlobalResourceObject("custom", "votePrefix").ToString());
hrefPoint2.Attributes.Add("onmouseout", "star_out(\"" + nArticleID + "\"," + StarVote + ")");
hrefPoint3 = (HyperLink)e.Row.FindControl("hrefPoint3");
hrefPoint3.NavigateUrl = String.Format("/voteArticleAdd.aspx?itemID={0}&value=3&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
hrefPoint3.ToolTip = String.Format("{0} (3 body)", HttpContext.GetGlobalResourceObject("custom", "votePrefix").ToString());
hrefPoint3.Attributes.Add("onmouseout", "star_out(\"" + nArticleID + "\"," + StarVote + ")");
hrefPoint4 = (HyperLink)e.Row.FindControl("hrefPoint4");
hrefPoint4.NavigateUrl = String.Format("/voteArticleAdd.aspx?itemID={0}&value=4&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
hrefPoint4.ToolTip = String.Format("{0} (4 body)", HttpContext.GetGlobalResourceObject("custom", "votePrefix").ToString());
hrefPoint4.Attributes.Add("onmouseout", "star_out(\"" + nArticleID + "\"," + StarVote + ")");
hrefPoint5 = (HyperLink)e.Row.FindControl("hrefPoint5");
hrefPoint5.NavigateUrl = String.Format("/voteArticleAdd.aspx?itemID={0}&value=5&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
hrefPoint5.ToolTip = String.Format("{0} (5 bodů)", HttpContext.GetGlobalResourceObject("custom", "votePrefix").ToString());
hrefPoint5.Attributes.Add("onmouseout", "star_out(\"" + nArticleID + "\"," + StarVote + ")");
StarInit += "star_out(\"" + nArticleID + "\"," + StarVote + ");";
}
switch (cPriceType.ToUpper()) {
case "BRUTTO":
dvPrices = DTO.Instance.GetDataView("SELECT shopPriceID, shopPriceUsualBrutto AS shopPriceUsual, shopPriceShopBrutto AS shopPriceShop, ROUND(shopPriceShopBrutto * " + nDiscountCoef.ToString().Replace(",", ".") + "," + nRoundLevel.ToString() + ") AS shopPriceDiscount FROM shopPrice WHERE shopPriceArticleID = @ArticleID ORDER BY shopPricePosition;", oSqlParams);
break;
case "NETTO":
dvPrices = DTO.Instance.GetDataView("SELECT shopPriceID, shopPriceUsualNetto AS shopPriceUsual, shopPriceShopNetto AS shopPriceShop, ROUND(shopPriceShopNetto * " + nDiscountCoef.ToString().Replace(",", ".") + "," + nRoundLevel.ToString() + ") AS shopPriceDiscount FROM shopPrice WHERE shopPriceArticleID = @ArticleID ORDER BY shopPricePosition;", oSqlParams);
break;
}
switch (cPriceType.ToUpper()) {
case "BRUTTO":
dvPrices = DTO.Instance.GetDataView("SELECT shopPriceID, shopPriceUsualBrutto AS shopPriceUsual, shopPriceShopBrutto AS shopPriceShop, ROUND(shopPriceShopBrutto * " + nDiscountCoef.ToString().Replace(",", ".") + "," + nRoundLevel.ToString() + ") AS shopPriceDiscount FROM shopPrice WHERE shopPriceArticleID = @ArticleID ORDER BY shopPricePosition;", oSqlParams);
break;
case "NETTO":
dvPrices = DTO.Instance.GetDataView("SELECT shopPriceID, shopPriceUsualNetto AS shopPriceUsual, shopPriceShopNetto AS shopPriceShop, ROUND(shopPriceShopNetto * " + nDiscountCoef.ToString().Replace(",", ".") + "," + nRoundLevel.ToString() + ") AS shopPriceDiscount FROM shopPrice WHERE shopPriceArticleID = @ArticleID ORDER BY shopPricePosition;", oSqlParams);
break;
}
nPriceID = Convert.ToInt32(dvPrices[0]["shopPriceID"]);
nPriceShop = Convert.ToDouble(dvPrices[0]["shopPriceShop"]);
nPriceUsual = Convert.ToDouble(dvPrices[0]["shopPriceUsual"]);
string cPriceString = "";
if (oAttributes.bookBinding != "") {
cPriceString = "{0}";
}
if (oAttributes.pages != "") {
if (cPriceString != "") cPriceString += ", ";
cPriceString += "{1} stran";
}
if (nPriceShop != nPriceUsual && nPriceUsual != 0) {
cPriceString += "<div class='priceUsual'>{4} {2} {6}, {7} {8} {6}</div><div class='priceShop'>{5} {3} {6}</div>";
} else {
cPriceString += "<div class='priceShop'>{5} {3} {6}</div>";
}
lblLiteral.Text = String.Format(cPriceString, oAttributes.bookBinding, oAttributes.pages, functions.Instance.formatPrice(nPriceUsual), functions.Instance.formatPrice(nPriceShop), GetGlobalResourceObject("custom", "priceUsualPrefix").ToString(), GetGlobalResourceObject("custom", "priceShopPrefix").ToString(), GetGlobalResourceObject("custom", "shopCurrency").ToString(), GetGlobalResourceObject("custom", "priceUsualSuffix").ToString(), functions.Instance.formatPrice(nPriceUsual - nPriceShop));
oStock = new shopStockByPrice(nPriceID);
string cTitle = oStock.title;
string cButtonTitle = oStock.buttonTitle;
string cButtonToolTip = oStock.buttonToolTip;
if (cButtonToolTip != "") {
try {
cButtonToolTip = HttpContext.GetGlobalResourceObject("custom", cButtonToolTip).ToString();
} catch (Exception ex) {
functions.Instance.sendErrorMsg(ex, "missing resource key: " + cButtonToolTip);
}
}
cButtonToolTip = cButtonToolTip.Replace("{articleTitle}", cArticleTitle);
if (oStock.buttonShow == 0) {
hrefAddToBasket.Visible = false;
} else {
if (cButtonTitle != "") {
try {
cButtonTitle = HttpContext.GetGlobalResourceObject("custom", cButtonTitle).ToString();
} catch (Exception ex) {
functions.Instance.sendErrorMsg(ex, "missing resource key: " + cButtonTitle);
}
hrefAddToBasket.Text = cButtonTitle;
} else {
hrefAddToBasket.Text = " ";
}
if (cButtonToolTip != "") {
hrefAddToBasket.ToolTip = cButtonToolTip;
}
}
switch (oStock.buttonShow) {
case 1: // zobrazit enabled
if (dvPrices.Count > 1) {
hrefAddToBasket.NavigateUrl = cArticleUrl;
hrefAddToBasket.Text = "Vybrat";
} else {
hrefAddToBasket.NavigateUrl = String.Format("/shop/basketAdd.aspx?itemID={0}&referrer={1}&amount=1", nPriceID, Server.UrlEncode(Request.RawUrl));
}
break;
case 2: // zobrazit disabled
hrefAddToBasket.NavigateUrl = "";
break;
case 3: // zobrazit link na contactForm
hrefAddToBasket.NavigateUrl = String.Format("/contactForm.aspx?itemID={0}&referrer={1}", nArticleID, Server.UrlEncode(Request.RawUrl));
break;
}
} else {
if (oAttributes.bookBinding.Trim() != "" || oAttributes.pages.Trim() != "") {
lblLiteral.Text = String.Format("{0}, {1} stran", oAttributes.bookBinding.Trim(), oAttributes.pages.Trim());
}
lblLabel.Visible = false;
hrefAddToBasket.Visible = false;
}
imgImage = (Image)e.Row.FindControl("imgPerexImage");
hrefPerexImage = (HyperLink)e.Row.FindControl("hrefPerexImage");
if (functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticlePerexImage")) != "") {
hrefPerexImage.ToolTip = functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticleTitle"));
hrefPerexImage.NavigateUrl = cArticleUrl;
try {
oImage = System.Drawing.Image.FromFile(functions.Instance.getPicturePerexFullPath(functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticlePerexImage"))));
imgImage.Width = oImage.Width;
imgImage.Height = oImage.Height;
oImage.Dispose();
imgImage.ImageUrl = functions.Instance.getPicturePerexAbsolutePath(functions.Instance.getSQLValueString(DataBinder.Eval(e.Row.DataItem, "sectionArticlePerexImage")));
imgImage.ToolTip = hrefPerexImage.ToolTip;
imgImage.AlternateText = imgImage.ToolTip;
} catch {
imgImage.Visible = false;
}
} else {
hrefPerexImage.Visible = false;
imgImage.Visible = false;
}
}
}
}
|