Friday, 17 April 2015

How to calculate Totalfield value at client side(Quotation file)

ASPX...............
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server"><script type="text/javascript">function OnCalculateTotal(visibleIndex, keyValue) {
var controlCollection = ASPxClientControl.GetControlCollection();
var RatePerUnit = controlCollection.GetByName("seClientPrice_" + visibleIndex).GetNumber();
var NoOfUnits = controlCollection.GetByName("seClientQuantity_" + visibleIndex).GetNumber();
var total = RatePerUnit * NoOfUnits;controlCollection.GetByName(
"tbClientTotal_" + visibleIndex).SetText(total.toFixed(2));hfChanges.Set(
"#" + visibleIndex.toString(), keyValue + "|" + RatePerUnit + "|" + NoOfUnits);}

// <![CDATA[var key;
var price;
function ProcessValueChanged(key, OfferPrice) {
var currentKey = "key" + key.toString();
if (!TxtChangeHiddenField.Contains(currentKey)) {TxtChangeHiddenField.Add(currentKey, key +
";" + OfferPrice);
// alert("Added to Change Hidden Field")
}
else {TxtChangeHiddenField.Set(currentKey, key +
";" + OfferPrice);
// alert("Updated change Hidden Field")}
}
 
function ASPxGridView2_SelectionChanged(s, e) {
if (e.isSelected) {s.GetRowValues(e.visibleIndex,
'DisplayDetailsID;DisplayListPrice', OnGetRowValues);}

if (!e.isSelected) {s.GetRowValues(e.visibleIndex,
'DisplayDetailsID;DisplayListPrice', OnGetKeyValue); 
}
}

function OnGetRowValues(values) {
var key = values[0].toString()
var currentKey = "key" + key;
var listprice = values[1].toString();
if (!clientHiddenField.Contains(currentKey)) {clientHiddenField.Add(currentKey, key +
";" + listprice);}

else {clientHiddenField.Set(currentKey, currentKey +
";" + listprice);}
}

function OnGetKeyValue(values) {
var currentKey = "key" + values[0].toString();
if (clientHiddenField.Contains(currentKey)) {clientHiddenField.Remove(currentKey);
}
}


// ]]> </script>
<style type="text/css">.style10{
width: 209px;}

.style11{
width: 174px;}

</style></
asp:Content><
asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"><script type="text/javascript">// <![CDATA[var keyValue;
function OnMoreInfoClick(element, key) {callbackPanel.SetContentHtml(
"");popup.ShowAtPos(10,10);;
keyValue = key;
}

function popup_Shown(s, e) {callbackPanel.PerformCallback(keyValue);
}

// ]]>
</script>

 
C#.........
 


// }// }// }//}//Product GirdView data saving.....................................................................................

decimal total = 0;
void pivot_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e){
 

if (e.DataField.FieldName != "Discount")
return;
decimal DLP = Convert.ToDecimal(e.GetFieldValue(((XRPivotGrid)sender).Fields["DisplayListPrice"]));
decimal OP = Convert.ToDecimal(e.GetFieldValue(((XRPivotGrid)sender).Fields["QuotedPrice"]));
if (DLP == 0)
return;
decimal result = ((DLP - OP) / DLP) * 100;e.DisplayText =
string.Format("{0:n2} %", result);}

void pivot1_CustomCellDisplayText(object sender, PivotCellDisplayTextEventArgs e){
 

if (e.DataField.FieldName == "TotalPrice"){

decimal v1 = Convert.ToDecimal(e.GetFieldValue(((XRPivotGrid)sender).Fields["ProductRate"]));
decimal v2 = Convert.ToDecimal(e.GetFieldValue(((XRPivotGrid)sender).Fields["ProductQuantity"]));
decimal result = v1 * v2;
if (result != 0){
e.DisplayText =
string.Format("Rs.{0:n2}", result);total += result;
}

if (result == 0){
e.DisplayText =
string.Format("Rs.{0:n2}", total);}
}
}

protected void ASPxCheckBox1_ShowHodePID(object sender, EventArgs e){

if (ASPxCheckBox1.Checked == true){
DropDownList1.Visible =
true;lblProposalID.Visible =
true;upDatePanel.Update();
}

else{
DropDownList1.Visible =
false;lblProposalID.Visible =
false;Response.Redirect(
"CreateQuotation.aspx");upDatePanel.Update();
}
}
 

protected void OfferPrice_Init(object sender, EventArgs e){

ASPxTextBox OfferPrice = sender as ASPxTextBox;
GridViewDataItemTemplateContainer container = OfferPrice.NamingContainer as GridViewDataItemTemplateContainer;OfferPrice.ClientInstanceName =
String.Format("OfferPrice{0}", container.VisibleIndex);OfferPrice.ClientSideEvents.TextChanged =
"function(s, e) { alert(s.GetText());}";}

protected void OfferPrice_Load(object sender, EventArgs e){

GridViewDataItemTemplateContainer c = ((ASPxTextBox)sender).NamingContainer
as GridViewDataItemTemplateContainer;((
ASPxTextBox)sender).ClientInstanceName = "OfferPrice" + c.KeyValue.ToString();((
ASPxTextBox)sender).ClientSideEvents.TextChanged = "function(s,e){ProcessValueChanged(" + c.KeyValue.ToString() + ",s.GetText());}";
string hfKey = "key" + c.KeyValue.ToString();
if (hiddenField.Contains(hfKey)){

string[] pars = Convert.ToString(hiddenField[hfKey]).Split(';');((
ASPxTextBox)sender).Text = pars[0];}
 
}
 

protected void ProductGridView_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e){

if (e.Column.FieldName == "Total"){

decimal price = (decimal)e.GetListSourceFieldValue("RatePerUnit");
int quantity = Convert.ToInt32(e.GetListSourceFieldValue("NoOfUnits"));e.Value = price * quantity;
}
}

protected void tbTotal_Init(object sender, EventArgs e){

ASPxTextBox textBox = sender as ASPxTextBox;
GridViewDataItemTemplateContainer container = textBox.NamingContainer as GridViewDataItemTemplateContainer;textBox.Text = container.Text;
textBox.ClientInstanceName =
String.Format("tbClientTotal_{0}", container.VisibleIndex);}

protected void NoOfUnits_Init(object sender, EventArgs e){

ASPxSpinEdit spinEdit = (ASPxSpinEdit)sender;
GridViewDataItemTemplateContainer container = spinEdit.NamingContainer as GridViewDataItemTemplateContainer;spinEdit.ClientInstanceName =
String.Format("seClientQuantity_{0}", container.VisibleIndex);spinEdit.ClientSideEvents.NumberChanged =
String.Format("function(s, e) {{ OnCalculateTotal({0},{1}); }}", container.VisibleIndex, container.KeyValue);}

protected void RatePerUnit_Init(object sender, EventArgs e){

ASPxSpinEdit spinEdit = (ASPxSpinEdit)sender;
GridViewDataItemTemplateContainer container = spinEdit.NamingContainer as GridViewDataItemTemplateContainer;spinEdit.ClientInstanceName =
String.Format("seClientPrice_{0}", container.VisibleIndex);spinEdit.ClientSideEvents.NumberChanged =
String.Format("function(s, e) {{ OnCalculateTotal({0},{1}); }}", container.VisibleIndex, container.KeyValue);}
 
 
}
}

No comments:

Post a Comment