namespace SalesForecasting.MainPages.Forecast.ControlSections.Platform
{
using System;
using System.Data;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using SalesForecasting.Business;
using SalesForecasting.js;
/// <summary>
/// Summary description for AirtimeDealStructureCPTSingle.
/// </summary>
public class AirtimeDealStructureCPTSingle : PlatformBase, SalesForecasting.MainPages.Forecast.ControlSections.IForecastControl
{
protected System.Web.UI.WebControls.CustomValidator vldPlatformRevenue;
protected System.Web.UI.WebControls.CustomValidator vldCPTDealPriceGross;
protected System.Web.UI.WebControls.Button btnRevPerFeed;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox txtPlatformRevenue;
protected System.Web.UI.WebControls.Label lblCPTNet;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.TextBox txtCPTDealPriceGross;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.Label lblNumImpacts;
private void Page_Load(object sender, System.EventArgs e)
{
if(!this.IsPostBack)
{
this.LoadData();
this.SetIfReadOnly();
}
this.SetJavascriptNetAmountCalcValues();
this.RunJavaScriptCalculationFunctions();
}
private void SetIfReadOnly()
{
if(this.SessionObj.ForecastReadOnly || this.SessionObj.ForecastDataSet.Forecast[0].StatusId >= StatusMeta.DEAL)
{
this.txtCPTDealPriceGross.ReadOnly = true;
this.txtPlatformRevenue.ReadOnly = true;
}
else
{
this.txtCPTDealPriceGross.ReadOnly = false;
this.txtPlatformRevenue.ReadOnly = false;
}
}
private string BuildRevPerFeedString()
{
StringBuilder requestString = new StringBuilder(Request.ApplicationPath);
requestString.Append("/PopupPages/RevPerFeed.aspx?PlatformId=");
requestString.Append(this.PlatformRow.PlatformId);
return requestString.ToString();
}
private void LoadData()
{
this.txtPlatformRevenue.Text = this.PlatformRow.Revenue.ToString();
if(!this.PlatformRow.IsDealPriceNull())
{
this.txtCPTDealPriceGross.Text = this.PlatformRow.DealPrice.ToString();
}
}
private void SetJavascriptNetAmountCalcValues()
{
this.Page.RegisterStartupScript("netamounts",
JSFunctions.SetNetAmountCalcValues(
this.txtCPTDealPriceGross.ClientID,
this.lblCPTNet.ClientID));
//also set them in the session
this.SessionObj.ExternalGrossField = this.txtCPTDealPriceGross.ClientID;
this.SessionObj.ExternalNetField = this.lblCPTNet.ClientID;
}
private void RunJavaScriptCalculationFunctions()
{
this.JavaScriptDivideCellContentsFunction();
this.JavaScriptSetNetValueFunction();
}
private void JavaScriptSetNetValueFunction()
{
this.Page.RegisterStartupScript("setnetvalfunc",
JSFunctions.SetNetValueFunction(
this.txtCPTDealPriceGross.ClientID,
this.lblCPTNet.ClientID));
}
private void JavaScriptDivideCellContentsFunction()
{
this.Page.RegisterStartupScript("divcellcontfunc",
JSFunctions.DivideCellContentsFunction(
this.txtPlatformRevenue.ClientID,
this.txtCPTDealPriceGross.ClientID,
this.lblNumImpacts.ClientID));
}
#region Validation
private bool IsPageValid
{
get
{
bool isValid = true;
if ((!Validation.IsNumber(this.txtPlatformRevenue.Text)) && (this.txtPlatformRevenue.Text.Length > 0))
{
this.vldPlatformRevenue.IsValid = false;
this.vldPlatformRevenue.ErrorMessage = "Platform Revenue must be numerical";
this.vldPlatformRevenue.Text = "*";
isValid = false;
}
if ((!Validation.IsNumber(this.txtCPTDealPriceGross.Text)) && (this.txtCPTDealPriceGross.Text.Length > 0))
{
this.vldCPTDealPriceGross.IsValid = false;
this.vldCPTDealPriceGross.ErrorMessage = "CPS Deal Price Gross must be numerical";
this.vldCPTDealPriceGross.Text = "*";
isValid = false;
}
return isValid;
}
}
#endregion Validation
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnRevPerFeed.Click += new System.EventHandler(this.btnRevPerFeed_Click);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
#region IForecastControl Members
public bool SaveDataToDataSet()
{
bool isValid = this.IsPageValid;
if(isValid)
{
if(this.txtPlatformRevenue.Text.Length > 0)
this.PlatformRow.Revenue = Convert.ToDecimal(this.txtPlatformRevenue.Text);
if(this.txtCPTDealPriceGross.Text.Length > 0)
this.PlatformRow.DealPrice = Convert.ToDecimal(this.txtCPTDealPriceGross.Text);
}
return isValid;
}
#endregion
private void btnRevPerFeed_Click(object sender, System.EventArgs e)
{
if(this.PlatformRow.GetPlatformFeedRows().Length == 0)
{
//must have feeds selected
this.MsgBox.alert("Feeds must be selected before entering Revenue per Feed");
}
else
{
if(Validation.IsNumber(this.txtPlatformRevenue.Text))
this.PlatformRow.Revenue = Convert.ToDecimal(this.txtPlatformRevenue.Text);
else
this.PlatformRow.Revenue = 0m;
this.OpenPopUpNow(
this.BuildRevPerFeedString(),
"Revenue Per Region",
900,
900,
true);
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
this.MsgBox.alert("Pressed");
}
protected override string PlatformType
{
get
{
return "Airtime";
}
}
}
}