|
Rank: Newbie Groups: Member
Joined: 8/9/2011 Posts: 7
|
Hi there, I have a grid in callback running mode. I have everything hooked up so that I can have a large data set and the items are actually saving (cell by cell) without a postback. Yay! However, I am accomplishing this by calling the grid.raiseItemCommandEvent method. The save works swimmingly well but when the event completes the grid always scrolls to the top and the user would have to scroll back down to find the next cell to edit. I've created a video to illustrate the issue and posted it for your review. http://www.screencast.com/t/fbX4Vwc4hrHere is the aspx code:
Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" MaintainScrollPositionOnPostback="true" CodeBehind="productWorksheetEO.aspx.cs" Inherits="IOP.productWorksheetEO" %>
<%@ Register assembly="EO.Web" namespace="EO.Web" tagprefix="eo" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="IOP.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<eo:Callback ID="Callback1" runat="server">
</eo:Callback>
<script type="text/javascript">
var g_curItemIndex = -1;
var i = 0;
function on_begin_edit(cell) {
//Store the current item index so that we can use
//it later in on_product_change
g_curItemIndex = cell.getItemIndex();
}
//By default a custom column supports edit. Since
//we don't need to edit this column, so we handle
//ClientSideBeginEdit and always return false to
//prevent the cell enters edit mode
function custombegin_edit() {
return false;
}
function on_end_edit(cell, newValue) {
var colname = cell.getColumn().getName();
g_curItemIndex = cell.getItemIndex();
if (g_curItemIndex >= 0) {
if (cell.getValue() != newValue) {
setTimeout(function () {
var grid = eo_GetObject("Grid1");
grid.raiseItemCommandEvent(g_curItemIndex, colname);
}, 10);
setTimeout(function () {
var grid = eo_GetObject("Grid1");
grid.getItem(g_curItemIndex).ensureVisible();
}, 500);
setTimeout(function () {
var grid = eo_GetObject("Grid1");
grid.getItem(g_curItemIndex).ensureVisible();
}, 1000);
setTimeout(function () {
var grid = eo_GetObject("Grid1");
grid.getItem(g_curItemIndex).ensureVisible();
}, 2000);
setTimeout(function () {
var grid = eo_GetObject("Grid1");
grid.getItem(g_curItemIndex).ensureVisible();
}, 3000);
}
return newValue;
}
return null;
}
function Grid1_OnItemCommand(grid, itemIndex, colIndex, commandName) {
var item = grid.getItem(itemIndex);
var cell = item.getCell(4);
window.alert("Topic:" + cell.getValue());
if (popYesNo('Recalculate?', 'Would you like to run the numbers again?')) {
g_curItemIndex = itemIndex;
if (g_curItemIndex >= 0) {
setTimeout(function () {
grid.raiseItemCommandEvent(g_curItemIndex, "listprice");
}, 10);
}
}
}
</script>
<table border="1" cellpadding="3" style="border-collapse:collapse"><tr style="font-family:Verdana;font-size:9pt"><td style="background-color:#FFFFC8">Product</td><td style="background-color:#F0A0A1">Product With Invalid Math</td><td style="background-color:#C8FFFF">Option</td><td style="background-color:#D8CA88">Option Not Shown</td></tr></table>
<eo:Grid ID="Grid1" runat="server" BorderColor="#828790" BorderWidth="1px" AllowColumnReorder="false" AllowPaging="false"
ColumnHeaderAscImage="00050204" ColumnHeaderDescImage="00050205" ScrollBars="Auto"
ColumnHeaderDividerImage="00050203" ColumnHeaderHeight="24" KeyField="fid"
FixedColumnCount="1" Font-Bold="False" Font-Italic="False" Font-Names="Tahoma"
ClientSideOnItemCommand="Grid1_OnItemCommand"
Font-Overline="False" Font-Size="8pt" Font-Strikeout="False" EnableKeyboardNavigation="true"
Font-Underline="False" FullRowMode="False" GridLineColor="240, 240, 240" OnItemCommand="Grid1_ItemCommand"
GridLines="Both" Height="500px" ItemHeight="19" Width="100%" StyleIDField="StyleSet"
StyleSetIDField="StyleSet" RunningMode="Callback">
<ItemStyles>
<eo:GridItemStyleSet>
<ItemStyle CssText="background-color: #FFFFC8" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<CellStyle CssText="padding-left:8px;padding-top:2px;white-space:nowrap;" />
<FixedColumnCellStyle CssText="border-right: #d6d2c2 1px solid; padding-right: 10px; border-top: #faf9f4 1px solid; border-left: #faf9f4 1px solid; border-bottom: #d6d2c2 1px solid; background-color: #ebeadb; text-align: left; color: black;"></FixedColumnCellStyle>
</eo:GridItemStyleSet>
<eo:GridItemStyleSet StyleSetID="spec">
<ItemStyle CssText="background-color: #C8FFFF" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<CellStyle CssText="padding-left:8px;padding-top:2px;white-space:nowrap;" />
<FixedColumnCellStyle CssText="border-right: #d6d2c2 1px solid; padding-right: 10px; border-top: #faf9f4 1px solid; border-left: #faf9f4 1px solid; border-bottom: #d6d2c2 1px solid; background-color: #ebeadb; text-align: left; color: black;"></FixedColumnCellStyle>
</eo:GridItemStyleSet>
<eo:GridItemStyleSet StyleSetID="specnoinclude">
<ItemStyle CssText="background-color: #D8CA88" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<CellStyle CssText="padding-left:8px;padding-top:2px;white-space:nowrap;" />
<FixedColumnCellStyle CssText="border-right: #d6d2c2 1px solid; padding-right: 10px; border-top: #faf9f4 1px solid; border-left: #faf9f4 1px solid; border-bottom: #d6d2c2 1px solid; background-color: #ebeadb; text-align: left; color: black;"></FixedColumnCellStyle>
</eo:GridItemStyleSet>
<eo:GridItemStyleSet StyleSetID="invalidmath">
<ItemStyle CssText="background-color: #F0A0A1" />
<ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
<SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
<CellStyle CssText="padding-left:8px;padding-top:2px;white-space:nowrap;" />
<FixedColumnCellStyle CssText="border-right: #d6d2c2 1px solid; padding-right: 10px; border-top: #faf9f4 1px solid; border-left: #faf9f4 1px solid; border-bottom: #d6d2c2 1px solid; background-color: #ebeadb; text-align: left; color: black;"></FixedColumnCellStyle>
</eo:GridItemStyleSet>
</ItemStyles>
<ColumnHeaderStyle CssText="background-image:url('00050201');padding-left:8px;padding-top:4px;" />
<ColumnHeaderHoverStyle CssText="background-image:url('00050202');padding-left:8px;padding-top:4px;" />
<Columns>
<eo:RowNumberColumn Visible="false">
</eo:RowNumberColumn>
<eo:StaticColumn DataField="furnid" Name="furnid" HeaderText="ID" Width="60">
</eo:StaticColumn>
<eo:ButtonColumn ButtonText="CMD" HeaderText="CMD" CommandName="CMD" Width="30"></eo:ButtonColumn>
<eo:CheckBoxColumn DataField="isfullyspecd" HeaderText="'images/checkbox_checked.gif' title='Fully Specd / Include On Spec Sheet (Options)' />" Name="isfullyspecd" Width="30" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit"></eo:CheckBoxColumn>
<eo:CheckBoxColumn DataField="islocked" HeaderText="'images/lock.gif' title='Locked' />" Name="islocked" Width="30" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit"></eo:CheckBoxColumn>
<eo:CheckBoxColumn DataField="isflagged" HeaderText="'images/flag1.gif' title='Flagged' />" Name="isflagged" Width="30" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit"></eo:CheckBoxColumn>
<eo:StaticColumn DataField="manufacturername" HeaderText="MFG">
</eo:StaticColumn>
<eo:StaticColumn DataField="quantity" HeaderText="#" Name="quantity" Width="40">
</eo:StaticColumn>
<eo:TextBoxColumn DataField="modelno" Name="modelno" HeaderText="Model #" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit">
</eo:TextBoxColumn>
<eo:TextBoxColumn DataField="productdesc" Name="productdesc" HeaderText="Description" Width="350" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit">
</eo:TextBoxColumn>
<eo:TextBoxColumn DataField="listprice" DataFormat="{0:c}" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit"
HeaderText="Unit List" Name="listprice" Width="65">
</eo:TextBoxColumn>
<eo:StaticColumn DataField="speccost" Width="65" DataFormat="{0:c}" HeaderText="Spec Cost" Name="speccost">
</eo:StaticColumn>
<eo:StaticColumn DataField="totallistprice" DataFormat="{0:c}"
HeaderText="List+Spec" Name="totallistprice" Width="65">
</eo:StaticColumn>
<eo:StaticColumn DataField="extendedlistprice" Width="65" HeaderText="Ext. List" DataFormat="{0:c}"
Name="extlistprice">
</eo:StaticColumn>
<eo:TextBoxColumn HeaderText="Buy%" Width="45" Name="discountstructure" DataField="discountstructure" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit">
</eo:TextBoxColumn>
<eo:TextBoxColumn DataField="purchasecost" Width="65" HeaderText="Buy$" DataFormat="{0:c}"
Name="purchasecost">
</eo:TextBoxColumn>
<eo:StaticColumn DataField="extendedpurchasecost" Width="65" HeaderText="Ext. Buy$" DataFormat="{0:c}"
Name="extendedpurchasecost">
</eo:StaticColumn>
<eo:TextBoxColumn HeaderText="MarkUp%" Width="65" Name="marginmarkuppercentage" DataField="marginmarkuppercentage" DataFormat="{0:N3}" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit">
</eo:TextBoxColumn>
<eo:TextBoxColumn DataField="sellprice" Width="65" HeaderText="Sell$" Name="sellprice" DataFormat="{0:c}" ClientSideBeginEdit="on_begin_edit" ClientSideEndEdit="on_end_edit">
</eo:TextBoxColumn>
<eo:StaticColumn DataField="extendedsellprice" Width="65" HeaderText="Ext. Sell$" DataFormat="{0:c}"
Name="extendedsellprice">
</eo:StaticColumn>
<eo:StaticColumn HeaderText="Margin%" Name="marginpercentage" DataField="marginpercentage" DataFormat="{0:N3}" >
</eo:StaticColumn>
</Columns>
<ColumnTemplates>
<eo:TextBoxColumn>
<TextBoxStyle CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; FONT-SIZE: 8.75pt; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; FONT-FAMILY: Tahoma" />
</eo:TextBoxColumn>
<eo:DateTimeColumn>
<DatePicker ControlSkinID="None" DayCellHeight="16" DayCellWidth="19"
DayHeaderFormat="FirstLetter" DisabledDates="" OtherMonthDayVisible="True"
SelectedDates="" TitleLeftArrowImageUrl="DefaultSubMenuIconRTL"
TitleRightArrowImageUrl="DefaultSubMenuIcon">
<PickerStyle CssText="border-bottom-color:#7f9db9;border-bottom-style:solid;border-bottom-width:1px;border-left-color:#7f9db9;border-left-style:solid;border-left-width:1px;border-right-color:#7f9db9;border-right-style:solid;border-right-width:1px;border-top-color:#7f9db9;border-top-style:solid;border-top-width:1px;font-family:Courier New;font-size:8pt;margin-bottom:0px;margin-left:0px;margin-right:0px;margin-top:0px;padding-bottom:1px;padding-left:2px;padding-right:2px;padding-top:2px;" />
<CalendarStyle CssText="background-color: white; border-right: #7f9db9 1px solid; padding-right: 4px; border-top: #7f9db9 1px solid; padding-left: 4px; font-size: 9px; padding-bottom: 4px; border-left: #7f9db9 1px solid; padding-top: 4px; border-bottom: #7f9db9 1px solid; font-family: tahoma" />
<TitleStyle CssText="background-color:#9ebef5;font-family:Tahoma;font-size:12px;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;" />
<TitleArrowStyle CssText="cursor:hand" />
<MonthStyle CssText="font-family: tahoma; font-size: 12px; margin-left: 14px; cursor: hand; margin-right: 14px" />
<DayHeaderStyle CssText="font-family: tahoma; font-size: 12px; border-bottom: #aca899 1px solid" />
<DayStyle CssText="font-family: tahoma; font-size: 12px; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<DayHoverStyle CssText="font-family: tahoma; font-size: 12px; border-right: #fbe694 1px solid; border-top: #fbe694 1px solid; border-left: #fbe694 1px solid; border-bottom: #fbe694 1px solid" />
<TodayStyle CssText="font-family: tahoma; font-size: 12px; border-right: #bb5503 1px solid; border-top: #bb5503 1px solid; border-left: #bb5503 1px solid; border-bottom: #bb5503 1px solid" />
<SelectedDayStyle CssText="font-family: tahoma; font-size: 12px; background-color: #fbe694; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<DisabledDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
<OtherMonthDayStyle CssText="font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid" />
</DatePicker>
</eo:DateTimeColumn>
<eo:MaskedEditColumn>
<MaskedEdit ControlSkinID="None"
TextBoxStyle-CssText="BORDER-RIGHT: #7f9db9 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7f9db9 1px solid; PADDING-LEFT: 2px; PADDING-BOTTOM: 1px; MARGIN: 0px; BORDER-LEFT: #7f9db9 1px solid; PADDING-TOP: 2px; BORDER-BOTTOM: #7f9db9 1px solid; font-family:Courier New;font-size:8pt;">
</MaskedEdit>
</eo:MaskedEditColumn>
</ColumnTemplates>
<FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" />
</eo:Grid>
</div>
</form>
</body>
</html>
Here is the .cs code:
Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace IOP
{
public partial class productWorksheetEO : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["height"] != "")
Grid1.Height = new Unit((Convert.ToDouble(Request["height"]) - 50), UnitType.Pixel);
d D = new d(Session["db"].ToString());
try
{
DataTable dtMain = D.GetDataSet("exec spProductWorksheet").Tables[0];
dtMain.Columns.Add("StyleSet");
DataTable dtSpecs = D.GetDataSet("select fid,furnspecid,specification,code,cost,includeonspecsheet from tbl_furniture_specs order by fid,furnspecid").Tables[0];
DataTable dtCopy = dtMain.Clone();
foreach (DataRow dr in dtMain.Rows)
{
dr["StyleSet"] = "";
dtCopy.ImportRow(dr);
//now go get the specs
DataRow[] draTheseSpecs = dtSpecs.Select("fid=" + dr["fid"].ToString());
foreach (DataRow drs in draTheseSpecs)
{
DataRow drn = dtCopy.NewRow();
drn["fid"] = drs["fid"].ToString() + "^" + drs["furnspecid"].ToString();
drn["modelno"] = drs["code"];
drn["productdesc"] = drs["specification"];
drn["listprice"] = drs.IsNull("cost") ? 0.0 : drs["cost"];
if (Convert.ToBoolean(drs["includeonspecsheet"]))
drn["styleset"] = "spec";
else
drn["styleset"] = "specnoinclude";
drn["isfullyspecd"] = drs["includeonspecsheet"];
dtCopy.Rows.Add(drn);
}
}
Grid1.DataSource = dtCopy;
Grid1.DataBind();
}
finally
{
D = null;
}
}
else
{
}
//Response.Write(System.Guid.NewGuid().ToString());
}
protected void Grid1_ItemCommand(object sender, EO.Web.GridCommandEventArgs e)
{
if (e.Item.Key.ToString().Contains("^"))
{
SpecRowChanged(e);
}
else
{
ProductRowChanged(e);
}
}//function
protected void ProductRowChanged(EO.Web.GridCommandEventArgs e)
{
EO.Web.GridItem Item = e.Item;
string CommandName = e.CommandName;
ChangeProductRow(Item, CommandName);
}
protected void SpecRowChanged(EO.Web.GridCommandEventArgs e)
{
EO.Web.GridItem Item = e.Item;
string CommandName = e.CommandName;
//get the product row that goes with this spec bullet
EO.Web.GridItem ProductItem = Item.Grid.Items[FindParentProductRowBySpecRow(Item)];
ChangeSpecRow(Item, ProductItem, CommandName);
ChangeProductRow(ProductItem, "listprice");
}
int FindParentProductRowBySpecRow(EO.Web.GridItem Item)
{
int ret = -1;
int itemIndex = Item.Index - 1;
EO.Web.GridItemCollection items = Item.Grid.Items;
//go up the grid in index until you find the product row
for (int i = itemIndex; i > -1; i--)
{
try
{
EO.Web.GridItem item = items[i];
string keyVal = item.Key.ToString();
if (!keyVal.Contains("^"))
{
//found it
ret = i;
break;
}
}
catch { }
}
return ret;
}
protected void ChangeSpecRow(EO.Web.GridItem Item, EO.Web.GridItem ParentItem, string CommandName)
{
d D = new d(Session["db"].ToString());
try
{
string sql = "";
///gather the data from the grid ---------------
//get product fid and furnspecid
string fid = Item.Key.ToString().Split('^')[0];
string furnspecid = Item.Key.ToString().Split('^')[1];
//get code
string code = Item.Cells["modelno"].Value != null ? Item.Cells["modelno"].Value.ToString() : "";
//get spec
string specification = Item.Cells["productdesc"].Value != null ? Item.Cells["productdesc"].Value.ToString() : "";
//get cost
decimal cost = Item.Cells["listprice"].Value != null ? Convert.ToDecimal(Item.Cells["listprice"].Value) : 0.0M;
switch (CommandName.ToLower())
{
case "listprice":
case "modelno":
case "productdesc":
///update the database with new values -----------
sql = string.Format("update tbl_furniture_specs set " +
"cost={0}," +
"code={1}," +
"specification={2} " +
" where furnspecid={3}",
commonFunctions.fqq(cost.ToString()), commonFunctions.fqq(code),
commonFunctions.fqq(specification),
commonFunctions.fqq(furnspecid));
D.RunSQL(sql);
string calcValue = D.GetSQLVal(string.Format("select dbo.SumSpecCost_Typed({0},-1)", fid));
if (!commonFunctions.IsNumeric(calcValue))
calcValue = "0.0";
///set cell values based on calculations
ParentItem.Cells["speccost"].Value = Math.Round(Convert.ToDecimal(calcValue), 2);
break;
case "isfullyspecd":
//using this for "show on spec"
bool isFullySpecd = Convert.ToBoolean(Item.Cells["isfullyspecd"].Value);
sql = string.Format("update tbl_furniture_specs set " +
"includeonspecsheet={0} " +
" where furnspecid={1}",
commonFunctions.boolToInt(isFullySpecd),
commonFunctions.fqq(furnspecid));
D.RunSQL(sql);
if (isFullySpecd)
Item.StyleSetID = "spec";
else
Item.StyleSetID = "specnoinclude";
break;
}//switch
}
finally
{
D = null;
}
}
protected void ChangeProductRow(EO.Web.GridItem Item, string CommandName)
{
d D = new d(Session["db"].ToString());
try
{
string sql = "";
///gather the data from the grid ---------------
//get product furnid
string furnid = Item.Cells["furnid"].Value.ToString();
//get number of products
int qty = Convert.ToInt32(Item.Cells["quantity"].Value);
//get listprice
decimal lp = Convert.ToDecimal(Item.Cells["listprice"].Value);
//get speccost
decimal speccost = Convert.ToDecimal(Item.Cells["speccost"].Value);
//get totallistprice
decimal lpandspec = lp + speccost;
//get extended list price
decimal elp = Math.Round(lpandspec * qty, 2);
//get the discount structure
string discountstructure = Item.Cells["discountstructure"].Value.ToString();
//get description
string productdesc = Item.Cells["productdesc"].Value != null ? Item.Cells["productdesc"].Value.ToString() : "";
//get modelnumber
string modelno = Item.Cells["modelno"].Value != null ? Item.Cells["modelno"].Value.ToString() : "";
//convert 50/20 stuff to a real percentage
decimal discountpercentage = Convert.ToDecimal(commonFunctions.Price_ConvertDealerDiscountStructureToPercentage(discountstructure));
if (discountpercentage > 1) discountpercentage = discountpercentage / 100;
//get multiplier (for example, if they get 60% off I need to know to multiply the list by .4 to get the purchase amount.
decimal discountpercentagemultiplier = 1.0M - discountpercentage;
//calc purchase cost
decimal purchasecost = Math.Round(lpandspec * discountpercentagemultiplier, 2);
//calc extended purchase cost
decimal extendedpurchasecost = Math.Round(purchasecost * qty, 2);
//default markup to 1 (as in 1 * 100 would still be 100)
decimal percMarkup = 1.0M;
//set markup perc to whatever they have if it's entered
decimal.TryParse(Item.Cells["marginmarkuppercentage"].Value.ToString(), out percMarkup);
//if it's a whole number we need to divide by 100 to get the decimal equivalent
if (percMarkup > 1.0M)
percMarkup = percMarkup / 100.0M;
//regardless we will be multiplying by 1.[whatever the percentage is] to get the sell price
//so add 1 if needed.
if (percMarkup < 1) percMarkup += 1.0M;
//get the raw percentage so 68.50% should be 1.6850 by now and therefore .6850 would be what I need.
decimal percMarkupRaw = percMarkup - 1;
//calculate sell
decimal sellprice = Math.Round(purchasecost * percMarkup, 2);
//calculate ext sell
decimal extendedsellprice = Math.Round(sellprice * qty, 2);
//calculate markup dollars
decimal markupdollars = 0.0M;
markupdollars = Math.Round(sellprice - purchasecost, 2);
//calculate margin % by comparing purchase cost to sell price
decimal marginperc = 0.0M;
try { marginperc = Math.Round(Math.Abs((purchasecost / sellprice) - 1) * 100, 3); }
catch { }
bool isfullyspecd = Convert.ToBoolean(Item.Cells["isfullyspecd"].Value);
bool islocked = Convert.ToBoolean(Item.Cells["islocked"].Value);
bool isflagged = Convert.ToBoolean(Item.Cells["isflagged"].Value);
switch (CommandName.ToLower())
{
case "listprice":
case "discountstructure":
case "marginmarkuppercentage":
///set cell values based on calculations
Item.Cells["totallistprice"].Value = lpandspec;
Item.Cells["extlistprice"].Value = elp;
Item.Cells["purchasecost"].Value = purchasecost;
Item.Cells["extendedpurchasecost"].Value = extendedpurchasecost;
Item.Cells["sellprice"].Value = sellprice;
Item.Cells["extendedsellprice"].Value = extendedsellprice;
Item.Cells["marginpercentage"].Value = marginperc;
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"listprice={0}," +
"dbl5={1}," + //sellprice
"dbl4={2}," + //margin/markup percentage
"dbl1={3}," + //dealer or purchase cost
"cur4={4}," + //margin/markup dollars
"cur5={3}," + //dealer or purchase cost also - no freight and install on this
"text1={5} " + //discountstructure
"where furnid={6}",
lp.ToString(), sellprice.ToString(), (percMarkupRaw * 100).ToString(), purchasecost.ToString(), markupdollars.ToString(), commonFunctions.fqq(discountstructure),
commonFunctions.fqq(furnid));
D.RunSQL(sql);
Item.StyleSetID = "";
break;
case "isfullyspecd":
case "islocked":
case "isflagged":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"isfullyspecd={0}," +
"islocked={1}," +
"isflagged={2} " +
"where furnid={3}",
commonFunctions.boolToInt(isfullyspecd), commonFunctions.boolToInt(islocked), commonFunctions.boolToInt(isflagged), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "productdesc":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"productdesc={0} " +
"where furnid={1}",
commonFunctions.fqq(productdesc), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "modelno":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"modelno={0} " +
"where furnid={1}",
commonFunctions.fqq(modelno), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "sellprice":
///update the database with new values -----------
//manual sell price entered
decimal manualsell = 0.0M;
try { manualsell = Convert.ToDecimal(Item.Cells["sellprice"].Value); }
catch { }
if (manualsell != sellprice)//sellprice was calculated above based on normal rules
Item.StyleSetID = "invalidmath";
else
Item.StyleSetID = "";
sql = string.Format("update tbl_furniture set " +
"dbl5={0} " +
"where furnid={1}",
commonFunctions.fqq(Item.Cells["sellprice"].Value != null ? Item.Cells["sellprice"].Value.ToString() : "0"), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
}//switch
}
finally
{
D = null;
}
}
}//class
}//namespace
Thanks for your help in advance! TJ
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi, You don't want to do that. ; ) The reason that the Grid reset to the top is because everytime you call raisesServerEvent, the whole Grid is being updated. In callback mode, this means all grid items are being reloaded. Callback mode works well for scenarios like paging and sorting, where user expects all items to be refreshed. But it does not work well for cell editing. The easiest solution for you is to make the update call through another AJAX channel instead of through the Grid. That way the Grid does not reload/refresh at all (you still can refresh certain cells with JavaScript if you wish). You can use a CallbackPanel and a ScriptEvent to trigger the call back to your server. Instead of calling raisesServerEvent on the Grid, you would call eo_TriggerServerEvent through the ScriptEvent control: http://doc.essentialobjects.com/library/1/eo.web.scriptevent.aspxTo avoid full page reload, you would need to modify the CallbackPanel’s Triggers collection to include the ScriptEvent control. That way the call will go through CallbackPanel. You may also need to pass additional arguments to eo_TriggerServerEvent such as Grid item index, key value, etc. These arguments will be passed to the server side as the ScriptEvent’s Command event arguments. Hope this helps. Please feel free to let us know if you have any more questions. Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/9/2011 Posts: 7
|
Ok, the only demo I can find that uses the scriptevent is for the spellchecker. It doesn't use a callbackpanel. Could you give me a simple example of a one or two column grid with a simple ajax cell save using the method you described above? I'm just not sure if the grid should be wrapped in the callback panel, and the scriptevent has me scratching my head.
|
|
Rank: Newbie Groups: Member
Joined: 8/9/2011 Posts: 7
|
Here is my attempt at doing what you said with the callback panel. I must be missing something crucial because it all acts exactly like it did before I made the changes. The grid still scrolls to the top after each save. Here is my code now:
And the .cs
Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace IOP
{
public partial class productWorksheetEO : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["height"] != "")
Grid1.Height = new Unit((Convert.ToDouble(Request["height"]) - 50), UnitType.Pixel);
d D = new d(Session["db"].ToString());
try
{
DataTable dtMain = D.GetDataSet("exec spProductWorksheet").Tables[0];
dtMain.Columns.Add("StyleSet");
DataTable dtSpecs = D.GetDataSet("select fid,furnspecid,specification,code,cost,includeonspecsheet from tbl_furniture_specs order by fid,furnspecid").Tables[0];
DataTable dtCopy = dtMain.Clone();
foreach (DataRow dr in dtMain.Rows)
{
dr["StyleSet"] = "";
dtCopy.ImportRow(dr);
//now go get the specs
DataRow[] draTheseSpecs = dtSpecs.Select("fid=" + dr["fid"].ToString());
foreach (DataRow drs in draTheseSpecs)
{
DataRow drn = dtCopy.NewRow();
drn["fid"] = drs["fid"].ToString() + "^" + drs["furnspecid"].ToString();
drn["modelno"] = drs["code"];
drn["productdesc"] = drs["specification"];
drn["listprice"] = drs.IsNull("cost") ? 0.0 : drs["cost"];
if (Convert.ToBoolean(drs["includeonspecsheet"]))
drn["styleset"] = "spec";
else
drn["styleset"] = "specnoinclude";
drn["isfullyspecd"] = drs["includeonspecsheet"];
dtCopy.Rows.Add(drn);
}
}
Grid1.DataSource = dtCopy;
Grid1.DataBind();
}
finally
{
D = null;
}
}
else
{
}
//Response.Write(System.Guid.NewGuid().ToString());
}
protected void Grid1_ItemCommand(object sender, EO.Web.GridCommandEventArgs e)
{
if (e.Item.Key.ToString().Contains("^"))
{
SpecRowChanged(e);
}
else
{
ProductRowChanged(e);
}
}//function
protected void ProductRowChanged(EO.Web.GridCommandEventArgs e)
{
EO.Web.GridItem Item = e.Item;
string CommandName = e.CommandName;
ChangeProductRow(Item, CommandName);
}
protected void SpecRowChanged(EO.Web.GridCommandEventArgs e)
{
EO.Web.GridItem Item = e.Item;
string CommandName = e.CommandName;
//get the product row that goes with this spec bullet
EO.Web.GridItem ProductItem = Item.Grid.Items[FindParentProductRowBySpecRow(Item)];
ChangeSpecRow(Item, ProductItem, CommandName);
ChangeProductRow(ProductItem, "listprice");
}
protected void ProductRowChanged2(EO.Web.GridItem Item, string CommandName)
{
ChangeProductRow(Item, CommandName);
}
protected void SpecRowChanged2(EO.Web.GridItem Item, string CommandName)
{
//get the product row that goes with this spec bullet
EO.Web.GridItem ProductItem = Item.Grid.Items[FindParentProductRowBySpecRow(Item)];
ChangeSpecRow(Item, ProductItem, CommandName);
ChangeProductRow(ProductItem, "listprice");
}
int FindParentProductRowBySpecRow(EO.Web.GridItem Item)
{
int ret = -1;
int itemIndex = Item.Index - 1;
EO.Web.GridItemCollection items = Item.Grid.Items;
//go up the grid in index until you find the product row
for (int i = itemIndex; i > -1; i--)
{
try
{
EO.Web.GridItem item = items[i];
string keyVal = item.Key.ToString();
if (!keyVal.Contains("^"))
{
//found it
ret = i;
break;
}
}
catch { }
}
return ret;
}
protected void ChangeSpecRow(EO.Web.GridItem Item, EO.Web.GridItem ParentItem, string CommandName)
{
d D = new d(Session["db"].ToString());
try
{
string sql = "";
///gather the data from the grid ---------------
//get product fid and furnspecid
string fid = Item.Key.ToString().Split('^')[0];
string furnspecid = Item.Key.ToString().Split('^')[1];
//get code
string code = Item.Cells["modelno"].Value != null ? Item.Cells["modelno"].Value.ToString() : "";
//get spec
string specification = Item.Cells["productdesc"].Value != null ? Item.Cells["productdesc"].Value.ToString() : "";
//get cost
decimal cost = Item.Cells["listprice"].Value != null ? Convert.ToDecimal(Item.Cells["listprice"].Value) : 0.0M;
switch (CommandName.ToLower())
{
case "listprice":
case "modelno":
case "productdesc":
///update the database with new values -----------
sql = string.Format("update tbl_furniture_specs set " +
"cost={0}," +
"code={1}," +
"specification={2} " +
" where furnspecid={3}",
commonFunctions.fqq(cost.ToString()), commonFunctions.fqq(code),
commonFunctions.fqq(specification),
commonFunctions.fqq(furnspecid));
D.RunSQL(sql);
string calcValue = D.GetSQLVal(string.Format("select dbo.SumSpecCost_Typed({0},-1)", fid));
if (!commonFunctions.IsNumeric(calcValue))
calcValue = "0.0";
///set cell values based on calculations
ParentItem.Cells["speccost"].Value = Math.Round(Convert.ToDecimal(calcValue), 2);
break;
case "isfullyspecd":
//using this for "show on spec"
bool isFullySpecd = Convert.ToBoolean(Item.Cells["isfullyspecd"].Value);
sql = string.Format("update tbl_furniture_specs set " +
"includeonspecsheet={0} " +
" where furnspecid={1}",
commonFunctions.boolToInt(isFullySpecd),
commonFunctions.fqq(furnspecid));
D.RunSQL(sql);
if (isFullySpecd)
Item.StyleSetID = "spec";
else
Item.StyleSetID = "specnoinclude";
break;
}//switch
}
finally
{
D = null;
}
}
protected void ChangeProductRow(EO.Web.GridItem Item, string CommandName)
{
d D = new d(Session["db"].ToString());
try
{
string sql = "";
///gather the data from the grid ---------------
//get product furnid
string furnid = Item.Cells["furnid"].Value.ToString();
//get number of products
int qty = Convert.ToInt32(Item.Cells["quantity"].Value);
//get listprice
decimal lp = Convert.ToDecimal(Item.Cells["listprice"].Value);
//get speccost
decimal speccost = Convert.ToDecimal(Item.Cells["speccost"].Value);
//get totallistprice
decimal lpandspec = lp + speccost;
//get extended list price
decimal elp = Math.Round(lpandspec * qty, 2);
//get the discount structure
string discountstructure = Item.Cells["discountstructure"].Value.ToString();
//get description
string productdesc = Item.Cells["productdesc"].Value != null ? Item.Cells["productdesc"].Value.ToString() : "";
//get modelnumber
string modelno = Item.Cells["modelno"].Value != null ? Item.Cells["modelno"].Value.ToString() : "";
//convert 50/20 stuff to a real percentage
decimal discountpercentage = Convert.ToDecimal(commonFunctions.Price_ConvertDealerDiscountStructureToPercentage(discountstructure));
if (discountpercentage > 1) discountpercentage = discountpercentage / 100;
//get multiplier (for example, if they get 60% off I need to know to multiply the list by .4 to get the purchase amount.
decimal discountpercentagemultiplier = 1.0M - discountpercentage;
//calc purchase cost
decimal purchasecost = Math.Round(lpandspec * discountpercentagemultiplier, 2);
//calc extended purchase cost
decimal extendedpurchasecost = Math.Round(purchasecost * qty, 2);
//default markup to 1 (as in 1 * 100 would still be 100)
decimal percMarkup = 1.0M;
//set markup perc to whatever they have if it's entered
decimal.TryParse(Item.Cells["marginmarkuppercentage"].Value.ToString(), out percMarkup);
//if it's a whole number we need to divide by 100 to get the decimal equivalent
if (percMarkup > 1.0M)
percMarkup = percMarkup / 100.0M;
//regardless we will be multiplying by 1.[whatever the percentage is] to get the sell price
//so add 1 if needed.
if (percMarkup < 1) percMarkup += 1.0M;
//get the raw percentage so 68.50% should be 1.6850 by now and therefore .6850 would be what I need.
decimal percMarkupRaw = percMarkup - 1;
//calculate sell
decimal sellprice = Math.Round(purchasecost * percMarkup, 2);
//calculate ext sell
decimal extendedsellprice = Math.Round(sellprice * qty, 2);
//calculate markup dollars
decimal markupdollars = 0.0M;
markupdollars = Math.Round(sellprice - purchasecost, 2);
//calculate margin % by comparing purchase cost to sell price
decimal marginperc = 0.0M;
try { marginperc = Math.Round(Math.Abs((purchasecost / sellprice) - 1) * 100, 3); }
catch { }
bool isfullyspecd = Convert.ToBoolean(Item.Cells["isfullyspecd"].Value);
bool islocked = Convert.ToBoolean(Item.Cells["islocked"].Value);
bool isflagged = Convert.ToBoolean(Item.Cells["isflagged"].Value);
switch (CommandName.ToLower())
{
case "listprice":
case "discountstructure":
case "marginmarkuppercentage":
///set cell values based on calculations
Item.Cells["totallistprice"].Value = lpandspec;
Item.Cells["extlistprice"].Value = elp;
Item.Cells["purchasecost"].Value = purchasecost;
Item.Cells["extendedpurchasecost"].Value = extendedpurchasecost;
Item.Cells["sellprice"].Value = sellprice;
Item.Cells["extendedsellprice"].Value = extendedsellprice;
Item.Cells["marginpercentage"].Value = marginperc;
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"listprice={0}," +
"dbl5={1}," + //sellprice
"dbl4={2}," + //margin/markup percentage
"dbl1={3}," + //dealer or purchase cost
"cur4={4}," + //margin/markup dollars
"cur5={3}," + //dealer or purchase cost also - no freight and install on this
"text1={5} " + //discountstructure
"where furnid={6}",
lp.ToString(), sellprice.ToString(), (percMarkupRaw * 100).ToString(), purchasecost.ToString(), markupdollars.ToString(), commonFunctions.fqq(discountstructure),
commonFunctions.fqq(furnid));
D.RunSQL(sql);
Item.StyleSetID = "";
break;
case "isfullyspecd":
case "islocked":
case "isflagged":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"isfullyspecd={0}," +
"islocked={1}," +
"isflagged={2} " +
"where furnid={3}",
commonFunctions.boolToInt(isfullyspecd), commonFunctions.boolToInt(islocked), commonFunctions.boolToInt(isflagged), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "productdesc":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"productdesc={0} " +
"where furnid={1}",
commonFunctions.fqq(productdesc), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "modelno":
///update the database with new values -----------
sql = string.Format("update tbl_furniture set " +
"modelno={0} " +
"where furnid={1}",
commonFunctions.fqq(modelno), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
case "sellprice":
///update the database with new values -----------
//manual sell price entered
decimal manualsell = 0.0M;
try { manualsell = Convert.ToDecimal(Item.Cells["sellprice"].Value); }
catch { }
if (manualsell != sellprice)//sellprice was calculated above based on normal rules
Item.StyleSetID = "invalidmath";
else
Item.StyleSetID = "";
sql = string.Format("update tbl_furniture set " +
"dbl5={0} " +
"where furnid={1}",
commonFunctions.fqq(Item.Cells["sellprice"].Value != null ? Item.Cells["sellprice"].Value.ToString() : "0"), commonFunctions.fqq(furnid));
D.RunSQL(sql);
break;
}//switch
}
finally
{
D = null;
}
}
protected void ScriptEvent1_Command(object sender, CommandEventArgs e)
{
EO.Web.GridItem item = Grid1.Items[Convert.ToInt32(e.CommandArgument)];
if (item.Key.ToString().Contains("^"))
{
SpecRowChanged2(item, e.CommandName.ToString());
}
else
{
ProductRowChanged2(item, e.CommandName.ToString());
}
}
}//class
}//namespace
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
Do not put the Grid inside the CallbackPanel. The CallbackPanel is just a "data channel" here. So it shouldn't contain anything at all.
Thanks
|
|
Rank: Newbie Groups: Member
Joined: 8/9/2011 Posts: 7
|
Ok, I think I understand now. Any updates to the cell need to be handled by javascript or else I will have the scroll issue. Thanks.
|
|