现在在做一个工资的查询系统,有两个有关问题,请问大神
现在在做一个工资的查询系统,有两个问题,请教大神
第一,能不能把图中的0.00替换成---,并且还能保持计算。
计算代码
gridview里面的数据是通过sqldatasources来绑定数据的。
第二,现在上传是通过SQL里面的导入功能,从EXCEL导入到数据库,问下大神,有没有办法可以在网页端导入。
谢谢。。
我是新手,请大神说的明白一点,谢谢。
------解决方案--------------------
1.格式的校验自己补充完整
2.导入excel
第一,能不能把图中的0.00替换成---,并且还能保持计算。
计算代码
public decimal ReturnTotal(int col)
{
decimal char_total = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
if (null != gvr.Cells[col].Text)
{
char_total += Convert.ToDecimal(gvr.Cells[col].Text);
}
}
return char_total;
}
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = "小计";
e.Row.Cells[3].Text = ReturnTotal(3).ToString();
e.Row.Cells[4].Text = ReturnTotal(4).ToString();
e.Row.Cells[5].Text = ReturnTotal(5).ToString();
e.Row.Cells[7].Text = "合计:"+ Convert.ToString(ReturnTotal(3) + ReturnTotal(4) + ReturnTotal(5));
}
}
gridview里面的数据是通过sqldatasources来绑定数据的。
第二,现在上传是通过SQL里面的导入功能,从EXCEL导入到数据库,问下大神,有没有办法可以在网页端导入。
谢谢。。
我是新手,请大神说的明白一点,谢谢。
------解决方案--------------------
1.格式的校验自己补充完整
public decimal ReturnTotal(int col)
{
decimal char_total = 0;
foreach (GridViewRow gvr in GridView1.Rows)
{
if (null != gvr.Cells[col].Text && gvr.Cells[col].Text != "---")
{
char_total += Convert.ToDecimal(gvr.Cells[col].Text);
}
}
return char_total;
}
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.DataRow)
{
e.Row.Cells[3].Text = e.Row.Cells[3].Text == "0.00" ? "---" : e.Row.Cells[3].Text;
e.Row.Cells[4].Text = e.Row.Cells[4].Text == "0.00" ? "---" : e.Row.Cells[4].Text;
e.Row.Cells[5].Text = e.Row.Cells[5].Text == "0.00" ? "---" : e.Row.Cells[5].Text;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[2].Text = "小计";
e.Row.Cells[3].Text = ReturnTotal(3).ToString();
e.Row.Cells[4].Text = ReturnTotal(4).ToString();
e.Row.Cells[5].Text = ReturnTotal(5).ToString();
e.Row.Cells[7].Text = "合计:"+ Convert.ToString(ReturnTotal(3) + ReturnTotal(4) + ReturnTotal(5));
}
}
2.导入excel
private static string connectionString = string.Empty;
private static ExcelExtention excelExtention = ExcelExtention.xls;
/// <summary>
/// 将数据源读成数据源
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static DataSet Read(string filename)
{
excelExtention = GetExcelExtention(filename);
return Read(filename, GetWorkSheets(GetConnectionString(filename)));
}
private static ExcelExtention GetExcelExtention(string filename)
{
string extention = filename.Split('.')[filename.Split('.').Length - 1];
if (extention.Trim() == ExcelExtention.xlsx.ToString())
return ExcelExtention.xlsx;
else