刚入手 spread组件. 真难. 算是实现了功能,但感觉怪怪的,斑竹给判一下,是否有更好的解决办法?
(通过web service 访问sql数据库)
spread V3
vs2005
pageload code
--------------------------
FpSpread1.DataSource = ObjectDataSource2;
FpSpread1.DataBind();//dataset
foreach (FarPoint.Web.Spread.Column c in FpSpread1.Sheets[0].Columns)
{
if (c.DataField == "DeptBudgetTaskEntryID"
|| c.DataField == "DeptAcctID"
|| c.DataField == "ListOrder"
)
{
c.Visible = false;
}
else
{
switch (c.DataField)
{
case "BudgetName":
c.Label = "预算项目";
break;
case "Num":
c.Label = "数量";
IntegerCellType ict = new IntegerCellType();
ict.ErrorMessage = "请输入正整型数据";
ict.MinimumValue = 0;
c.CellType = ict;
break;
case "price":
c.Label = "单价(元)";
CurrencyCellType cct = new CurrencyCellType();
cct.MinimumValue = 0;
cct.ErrorMessage = "货币数据类型";
cct.NumberFormat = GetNumFormat();
c.CellType = cct;
break;
case "DeptBudgetAmount":
c.Label = "部门预算(元)";
CurrencyCellType cct1 = new CurrencyCellType();
cct1.MinimumValue = 0;
cct1.ErrorMessage = "货币数据类型";
cct1.NumberFormat = GetNumFormat();
c.CellType = cct1;
break;
case "unit":
c.Label = "计量单位(数量)";
break;
case "Location":
c.Label = "地点";
break;
case "note":
c.Label = "必要性支出说明";
break;
}
}
}
--------------------------pageload over
update code
----------------
protected void FpSpread1_UpdateCommand(object sender, FarPoint.Web.Spread.SpreadCommandEventArgs e)
{
string DeptBudgetTaskEntryID = "";
string BudgetName = "";
int Num = 0;
decimal price = 0;
decimal DeptBudgetAmount = 0;
string unit = "";
string Location = "";
string note = "";
for (int i = 0; i < e.EditValues.Count; i++)
{
if (e.EditValues[i].ToString() != "System.Object")//非隐藏列,e.EditValues[i]=object ,此处如何判断 目前的判断感觉太变态
{
switch (FpSpread1.Sheets[0].Columns[i].DataField) //根据绑定列 ,获取字段值
{
case "BudgetName":
BudgetName = e.EditValues[i].ToString();
break;
case "Num":
Num = Convert.ToInt32(e.EditValues[i]);
break;
case "price":
price = Convert.ToDecimal(e.EditValues[i]);
break;
case "DeptBudgetAmount":
DeptBudgetAmount = Convert.ToDecimal(e.EditValues[i]);
break;
case "unit":
unit = e.EditValues[i].ToString();
break;
case "Location":
Location = e.EditValues[i].ToString();
break;
case "note":
note = e.EditValues[i].ToString();
break;
}
}
else//隐藏列,获取主键
{
switch (FpSpread1.Sheets[0].Columns[i].DataField)
{
case "DeptBudgetTaskEntryID":
DeptBudgetTaskEntryID = e.SheetView.GetValue(Convert.ToInt32(e.CommandArgument), i).ToString();
break;
}
}
}
//调用数据访问层(webservice)保存数据
DeptBudgetDataAccess.P7DeptBudgetEntryUpdate(
DeptBudgetTaskEntryID, BudgetName,Num,price,DeptBudgetAmount,unit,Location,note);
e.Handled = true;
}[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i] |
|