今天实在无聊,上午应朋友之约请半天假去喝茶聊天下午没事就回公司像老牛一样干活,偶然翻很久起以做的项目,翻过之后一阵感概:唉,又是一堆垃圾....(实在无耐,常常在项目结束后有这种感觉---太失败了)本人比较菜做的东东也不怎么样所以请高人莫笑...
财务报表中常见明细表都是很通俗易懂的,如在明细表中可以表现出相应的日汇总、月汇总、任一时间段的汇总
仓库图:
这个报表都是全部采用grid做的,原因是我比较讨厌asp中的tr/td/table/tr/td<%xxxx%>这种方式,同样也很讨厌asp.net里的<% =xx %>,这所以讨厌是后期维护特烦还有就是想把UI和业务分开...grid.datasource=ds;grid.databind();只要两句话就搞定了这种多省事啊
如何把上面的UI层的数据封装一个DataSet呢,这就是重点,其实也很简单无非是数据的分解和再组合的过程.熟悉DataSet对象的朋友应该慌然大悟了吧
下面贴出仓库报表的部分代码
/// <summary>
/// 材料流水
/// </summary>
/// <param name="vc_materialid">材料ID</param>
/// <param name="isStandard">是否按国标数量</param>
/// <param name="dt"></param>
/// <returns></returns>
public int stockpileList(string vc_materialid,bool isStandard,out DataTable dt){
if(isStandard)
strQuery="SELECT c_plantype,vc_billtype,dec_standnumber,dec_standprice,dec_total,dt_billdate,vc_billcode FROM sto_billmaterial WHERE vc_materialid='"+vc_materialid+"' ORDER BY dt_billdate ASC,c_plantype DESC,vc_billcode ASC";
else
strQuery="SELECT c_plantype,vc_billtype,dec_standnumber,dec_specprice,dec_total,dt_billdate,vc_billcode FROM sto_billmaterial WHERE vc_materialid='"+vc_materialid+"' ORDER BY dt_billdate ASC,c_plantype DESC,vc_billcode ASC";
if(cadb==null)cadb=new DataBaseAccess.CADB();
int j=cadb.getDataTable(strCon,strQuery,out dt,ref strErr);
if(j>0){
//按报表格式添加出库&&结库部分的字段
dt.Columns.Add("_standnumber",typeof(Decimal));
dt.Columns.Add("_standprice",typeof(Decimal));
dt.Columns.Add("_total",typeof(Decimal));
dt.Columns.Add("finallyNumber",typeof(Decimal));
dt.Columns.Add("finallyPrice",typeof(Decimal));
dt.Columns.Add("finallyTotal",typeof(Decimal));
//定义交换变量
decimal num,price,total,_num=0,_total=0;
string direction;//单据方向
for(int i=0;i<j;i++){
direction=dt.Rows[i][0].ToString().Trim();
num=Convert.ToDecimal(dt.Rows[i]["dec_standnumber"].ToString());
price=Convert.ToDecimal(dt.Rows[i]["dec_standprice"].ToString());
total=Convert.ToDecimal(dt.Rows[i]["dec_total"].ToString());
if(direction=="出库"){
dt.Rows[i]["_standnumber"]=num;
dt.Rows[i]["_standprice"]=price;
dt.Rows[i]["_total"]=total;
dt.Rows[i]["dec_standnumber"]=DBNull.Value;
dt.Rows[i]["dec_standprice"]=DBNull.Value;
dt.Rows[i]["dec_total"]=DBNull.Value;
}
if(i==0){
dt.Rows[0]["finallyNumber"]=num;
dt.Rows[0]["finallyPrice"]=price;
dt.Rows[0]["finallyTotal"]=total;
//计算结存数量
_num=num;
_total=total;
}else{
if(direction=="出库"){
dt.Rows[i]["finallyNumber"]=_num-num;
dt.Rows[i]["finallyPrice"]=(_total-total)==0?0:(_total-total)/(_num-num);
dt.Rows[i]["finallyTotal"]=(_total-total);
//计算结存数量
_num=_num-num;
_total=_total-total;
}else{
dt.Rows[i]["finallyNumber"]=num;
dt.Rows[i]["finallyPrice"]=price;
dt.Rows[i]["finallyTotal"]=total;
//计算结存数量
_num=_num+num;
_total=_total+total;
}
}
}
dt.Columns.Remove("c_plantype");
dt.AcceptChanges();
}
return j;
}
/// 材料流水
/// </summary>
/// <param name="vc_materialid">材料ID</param>
/// <param name="isStandard">是否按国标数量</param>
/// <param name="dt"></param>
/// <returns></returns>
public int stockpileList(string vc_materialid,bool isStandard,out DataTable dt){
if(isStandard)
strQuery="SELECT c_plantype,vc_billtype,dec_standnumber,dec_standprice,dec_total,dt_billdate,vc_billcode FROM sto_billmaterial WHERE vc_materialid='"+vc_materialid+"' ORDER BY dt_billdate ASC,c_plantype DESC,vc_billcode ASC";
else
strQuery="SELECT c_plantype,vc_billtype,dec_standnumber,dec_specprice,dec_total,dt_billdate,vc_billcode FROM sto_billmaterial WHERE vc_materialid='"+vc_materialid+"' ORDER BY dt_billdate ASC,c_plantype DESC,vc_billcode ASC";
if(cadb==null)cadb=new DataBaseAccess.CADB();
int j=cadb.getDataTable(strCon,strQuery,out dt,ref strErr);
if(j>0){
//按报表格式添加出库&&结库部分的字段
dt.Columns.Add("_standnumber",typeof(Decimal));
dt.Columns.Add("_standprice",typeof(Decimal));
dt.Columns.Add("_total",typeof(Decimal));
dt.Columns.Add("finallyNumber",typeof(Decimal));
dt.Columns.Add("finallyPrice",typeof(Decimal));
dt.Columns.Add("finallyTotal",typeof(Decimal));
//定义交换变量
decimal num,price,total,_num=0,_total=0;
string direction;//单据方向
for(int i=0;i<j;i++){
direction=dt.Rows[i][0].ToString().Trim();
num=Convert.ToDecimal(dt.Rows[i]["dec_standnumber"].ToString());
price=Convert.ToDecimal(dt.Rows[i]["dec_standprice"].ToString());
total=Convert.ToDecimal(dt.Rows[i]["dec_total"].ToString());
if(direction=="出库"){
dt.Rows[i]["_standnumber"]=num;
dt.Rows[i]["_standprice"]=price;
dt.Rows[i]["_total"]=total;
dt.Rows[i]["dec_standnumber"]=DBNull.Value;
dt.Rows[i]["dec_standprice"]=DBNull.Value;
dt.Rows[i]["dec_total"]=DBNull.Value;
}
if(i==0){
dt.Rows[0]["finallyNumber"]=num;
dt.Rows[0]["finallyPrice"]=price;
dt.Rows[0]["finallyTotal"]=total;
//计算结存数量
_num=num;
_total=total;
}else{
if(direction=="出库"){
dt.Rows[i]["finallyNumber"]=_num-num;
dt.Rows[i]["finallyPrice"]=(_total-total)==0?0:(_total-total)/(_num-num);
dt.Rows[i]["finallyTotal"]=(_total-total);
//计算结存数量
_num=_num-num;
_total=_total-total;
}else{
dt.Rows[i]["finallyNumber"]=num;
dt.Rows[i]["finallyPrice"]=price;
dt.Rows[i]["finallyTotal"]=total;
//计算结存数量
_num=_num+num;
_total=_total+total;
}
}
}
dt.Columns.Remove("c_plantype");
dt.AcceptChanges();
}
return j;
}
呵呵,其实就这么简单