Database db = DatabaseFactory.CreateDatabase();
string sql = "SELECT COUNT(*) FROM SR_BOI_BanHeDaily WHERE FRiBaoId=" + Bill.ID.ToString();
object o = db.ExecuteScalar(CommandType.Text, sql);
if (o != null && o != DBNull.Value && Convert.ToInt16(o) > 0) return;
//
sql = "select a.FBillDate, a.FOrgId, a.FJGUnitId, a.FJGUnitName, isnull(a.FBeginPart,0) as FBeginPart, isnull(a.FEndPart,0) as FEndPart, ";
sql += " b.FItemId, b.FItemName, b.FModel,c.FUnit, sum(case when a.FState=2 then b.FCostQty else 0 end) as SLQty,sum(b.FCostQty) as FLQty ";
sql += " from SR_BOI_ShanghunFaliao a, SR_BOI_ShanghunFaliaoDtl b, sp_Material c ";
sql += " where a.FBillId=b.FBillId and b.FItemId=c.FItemId and a.FOrgId={0} and a.FJGUnitId={1} and a.FBillDate='{2}' ";
sql += " group by a.FBillDate, a.FOrgId, a.FJGUnitId, a.FJGUnitName, a.FBeginPart, a.FEndPart, b.FItemId, b.FItemName, b.FModel,c.FUnit";
sql += " order by a.FJGUnitId,b.FItemId, a.FbeginPart";
sql = string.Format(sql, Bill.GetPropValue("FOrgId"), Bill.GetPropValue("FJGUnitId"), Bill.GetPropValue("FBillDate"));
DataSet dsData = db.ExecuteDataSet(CommandType.Text, sql);
if (dsData.Tables[0].Rows.Count == 0)
throw new EteamException("没有找到 当前日期及拌和场的 任何砼发料数据");
DataTable newTable = dsData.Tables[0].Clone();
DataRow lastRow = null;
foreach (DataRow row in dsData.Tables[0].Rows)
{
if (lastRow != null && Convert.ToInt32(row["FItemId"]) == Convert.ToInt32(lastRow["FItemId"]) && Convert.ToInt32(row["FBeginPart"]) <= Convert.ToInt32(lastRow["FEndPart"]) + 1)
{
//lastRow["FEndPart"]= row["FEndPart"] lastRow["FLQty"]+row["FLQty"] lastRow["SLQty"]+row["SLQty"]
lastRow["FEndPart"] = row["FEndPart"];
lastRow["FLQty"] =Convert.ToInt32(lastRow["FLQty"])+ Convert.ToInt32(row["FLQty"]);
lastRow["SLQty"] = Convert.ToInt32(lastRow["SLQty"]) + Convert.ToInt32(row["SLQty"]);
}
else
{
lastRow = newTable.NewRow();
foreach (DataColumn column in dsData.Tables[0].Columns)
{
lastRow[column.ColumnName] = row[column.ColumnName];
}
newTable.Rows.Add(lastRow);
}
}
int dtlBillClassId = DataMap.GetTypeInst("").GetItemClassId("SR_BOI_BanHeDaily");
Dictionary<int, Dictionary<int, decimal>> MtrFenTan = new Dictionary<int, Dictionary<int, decimal>>();
foreach (DataRow row in newTable.Rows)
{
sql = "select * from sp_Bom where FItemId=" + row["FItemId"].ToString() + " AND FOrgId=" + Bill.GetPropValue("FOrgId").ToString();
DataSet dsBom = db.ExecuteDataSet(CommandType.Text, sql);
if (dsBom.Tables[0].Rows.Count == 0)
throw new EteamException("没有找到配和比, 砼产品名: " + row["FItemName"].ToString() + ", 砼规格:" + row["FModel"].ToString());
bizBill dtlbill = bizBill.CreateNew(dtlBillClassId);
dtlbill.SetPropValue("FOrgId", Bill.GetPropValue("FOrgId"));
dtlbill.SetPropValue("FOrgName", Bill.GetPropValue("FOrgName"));
dtlbill.SetPropValue("FRiBaoId", Bill.ID);
dtlbill.SetPropValue("FBillDate", Bill.GetPropValue("FBillDate"));
dtlbill.SetPropValue("FJGUnitId", Bill.GetPropValue("FJGUnitId"));
dtlbill.SetPropValue("FJGUnitName", Bill.GetPropValue("FJGUnitName"));
dtlbill.SetPropValue("FListName", Bill.GetPropValue("FListName"));
dtlbill.SetPropValue("FHeight", Bill.GetPropValue("FHeight"));
dtlbill.SetPropValue("FWidth", Bill.GetPropValue("FWidth"));
dtlbill.SetPropValue("FBeginPart", row["FBeginPart"]);
dtlbill.SetPropValue("FEndPart", row["FEndPart"]);
dtlbill.SetPropValue("FProdName", row["FItemName"]);
dtlbill.SetPropValue("FProdId", row["FItemId"]);
dtlbill.SetPropValue("FProdModel", row["FModel"]);
dtlbill.SetPropValue("FUnit", row["FUnit"]);
dtlbill.SetPropValue("FShengChanQty", row["FLQty"]);
dtlbill.SetPropValue("FShouLiaoQty", row["SLQty"]);
dtlbill.SetPropValue("FFangLiangUnit", dsBom.Tables[0].Rows[0]["FUnitName"]);
dtlbill.SetPropValue("FLiLunMiDu", dsBom.Tables[0].Rows[0]["FConvertRate"]);
sql = "select * from sp_BomDtl where FID=" + dsBom.Tables[0].Rows[0]["FID"].ToString();//FBomId
DataSet dsBomDtl = db.ExecuteDataSet(CommandType.Text, sql);
DataTable dtDtl = dtlbill.GetDetailTable("SR_BOI_BanHeDailyDtl");
Dictionary<int, decimal> billMtrUse = new Dictionary<int, decimal>();
foreach (DataRow bomRow in dsBomDtl.Tables[0].Rows)
{
...................
}
}现在是新建的一个表newTable 进行判断后把dsData表中的数据插入newTable中,怎么在dsData表中直接进行判断后修改呢?.NETDATATABLEDATASETrow
string sql = "SELECT COUNT(*) FROM SR_BOI_BanHeDaily WHERE FRiBaoId=" + Bill.ID.ToString();
object o = db.ExecuteScalar(CommandType.Text, sql);
if (o != null && o != DBNull.Value && Convert.ToInt16(o) > 0) return;
//
sql = "select a.FBillDate, a.FOrgId, a.FJGUnitId, a.FJGUnitName, isnull(a.FBeginPart,0) as FBeginPart, isnull(a.FEndPart,0) as FEndPart, ";
sql += " b.FItemId, b.FItemName, b.FModel,c.FUnit, sum(case when a.FState=2 then b.FCostQty else 0 end) as SLQty,sum(b.FCostQty) as FLQty ";
sql += " from SR_BOI_ShanghunFaliao a, SR_BOI_ShanghunFaliaoDtl b, sp_Material c ";
sql += " where a.FBillId=b.FBillId and b.FItemId=c.FItemId and a.FOrgId={0} and a.FJGUnitId={1} and a.FBillDate='{2}' ";
sql += " group by a.FBillDate, a.FOrgId, a.FJGUnitId, a.FJGUnitName, a.FBeginPart, a.FEndPart, b.FItemId, b.FItemName, b.FModel,c.FUnit";
sql += " order by a.FJGUnitId,b.FItemId, a.FbeginPart";
sql = string.Format(sql, Bill.GetPropValue("FOrgId"), Bill.GetPropValue("FJGUnitId"), Bill.GetPropValue("FBillDate"));
DataSet dsData = db.ExecuteDataSet(CommandType.Text, sql);
if (dsData.Tables[0].Rows.Count == 0)
throw new EteamException("没有找到 当前日期及拌和场的 任何砼发料数据");
DataTable newTable = dsData.Tables[0].Clone();
DataRow lastRow = null;
foreach (DataRow row in dsData.Tables[0].Rows)
{
if (lastRow != null && Convert.ToInt32(row["FItemId"]) == Convert.ToInt32(lastRow["FItemId"]) && Convert.ToInt32(row["FBeginPart"]) <= Convert.ToInt32(lastRow["FEndPart"]) + 1)
{
//lastRow["FEndPart"]= row["FEndPart"] lastRow["FLQty"]+row["FLQty"] lastRow["SLQty"]+row["SLQty"]
lastRow["FEndPart"] = row["FEndPart"];
lastRow["FLQty"] =Convert.ToInt32(lastRow["FLQty"])+ Convert.ToInt32(row["FLQty"]);
lastRow["SLQty"] = Convert.ToInt32(lastRow["SLQty"]) + Convert.ToInt32(row["SLQty"]);
}
else
{
lastRow = newTable.NewRow();
foreach (DataColumn column in dsData.Tables[0].Columns)
{
lastRow[column.ColumnName] = row[column.ColumnName];
}
newTable.Rows.Add(lastRow);
}
}
int dtlBillClassId = DataMap.GetTypeInst("").GetItemClassId("SR_BOI_BanHeDaily");
Dictionary<int, Dictionary<int, decimal>> MtrFenTan = new Dictionary<int, Dictionary<int, decimal>>();
foreach (DataRow row in newTable.Rows)
{
sql = "select * from sp_Bom where FItemId=" + row["FItemId"].ToString() + " AND FOrgId=" + Bill.GetPropValue("FOrgId").ToString();
DataSet dsBom = db.ExecuteDataSet(CommandType.Text, sql);
if (dsBom.Tables[0].Rows.Count == 0)
throw new EteamException("没有找到配和比, 砼产品名: " + row["FItemName"].ToString() + ", 砼规格:" + row["FModel"].ToString());
bizBill dtlbill = bizBill.CreateNew(dtlBillClassId);
dtlbill.SetPropValue("FOrgId", Bill.GetPropValue("FOrgId"));
dtlbill.SetPropValue("FOrgName", Bill.GetPropValue("FOrgName"));
dtlbill.SetPropValue("FRiBaoId", Bill.ID);
dtlbill.SetPropValue("FBillDate", Bill.GetPropValue("FBillDate"));
dtlbill.SetPropValue("FJGUnitId", Bill.GetPropValue("FJGUnitId"));
dtlbill.SetPropValue("FJGUnitName", Bill.GetPropValue("FJGUnitName"));
dtlbill.SetPropValue("FListName", Bill.GetPropValue("FListName"));
dtlbill.SetPropValue("FHeight", Bill.GetPropValue("FHeight"));
dtlbill.SetPropValue("FWidth", Bill.GetPropValue("FWidth"));
dtlbill.SetPropValue("FBeginPart", row["FBeginPart"]);
dtlbill.SetPropValue("FEndPart", row["FEndPart"]);
dtlbill.SetPropValue("FProdName", row["FItemName"]);
dtlbill.SetPropValue("FProdId", row["FItemId"]);
dtlbill.SetPropValue("FProdModel", row["FModel"]);
dtlbill.SetPropValue("FUnit", row["FUnit"]);
dtlbill.SetPropValue("FShengChanQty", row["FLQty"]);
dtlbill.SetPropValue("FShouLiaoQty", row["SLQty"]);
dtlbill.SetPropValue("FFangLiangUnit", dsBom.Tables[0].Rows[0]["FUnitName"]);
dtlbill.SetPropValue("FLiLunMiDu", dsBom.Tables[0].Rows[0]["FConvertRate"]);
sql = "select * from sp_BomDtl where FID=" + dsBom.Tables[0].Rows[0]["FID"].ToString();//FBomId
DataSet dsBomDtl = db.ExecuteDataSet(CommandType.Text, sql);
DataTable dtDtl = dtlbill.GetDetailTable("SR_BOI_BanHeDailyDtl");
Dictionary<int, decimal> billMtrUse = new Dictionary<int, decimal>();
foreach (DataRow bomRow in dsBomDtl.Tables[0].Rows)
{
...................
}
}现在是新建的一个表newTable 进行判断后把dsData表中的数据插入newTable中,怎么在dsData表中直接进行判断后修改呢?.NETDATATABLEDATASETrow
解决方案 »
- The hostname could not be parsed(域名不能解析)
- WORD 文件打开的问题
- DataSet内容加入XML中,而不是重写XML内容
- MM求救
- ASP。NET中怎么关闭自己并回到先前页面呢
- 为什么URL重写的时候不能用&传递两个变量?
- 关于MapXtreme2.5在ASP.NET上创建服务器端对象的问题
- 如何在global中取到正在request的页面的名字
- 大家帮我看一下这一点ASP。NET和AJAX代码有什么问题。。。为什么老是不行呢...
- 用<title id="title" runat="server"></title>动态设定网页标题的问题
- 编译器错误消息: CS1061: “ASP.default_aspx”不包含“Button1_Click1”的定义,并且找不到可接受类型为“ASP.defaul
- vs.net2005与sql2005开发的网络项目可以在sql2000下运行吗?
New table or old table' info is alike?
DataTable dt = new DataTable();
dt.Columns.Add("aa");
dt.Columns.Add("bb");
dt.Columns.Add("cc");
dt.Rows.Add(dt.NewRow().ItemArray=new string[3]{"1","2","3"});
dt.Rows[0][0] = "11";
你的这段代码似乎只能让dsData的当前行和newTable中最后一行进行比较,不知道你是不是故意这样还是怎么的。 if (lastRow != null && Convert.ToInt32(row["FItemId"]) == Convert.ToInt32(lastRow["FItemId"]) && Convert.ToInt32(row["FBeginPart"]) <= Convert.ToInt32(lastRow["FEndPart"]) + 1)
{如果不是故意的话,可以改为 DataTable newTable = dsData.Tables[0].Clone();
List<int> saveFitemId=new List<int>();//保存已保存至newTable中的FitemId
List<int> saveFEndPart=new List<int>();//保存已保存至newTable中的FEndPart
foreach (DataRow row in dsData.Tables[0].Rows)
{
if (saveFitemId.Contains(Convert.ToInt32(row["FItemId"])))
{
//获取该行在List中的索引,由此可以找到newTable中的某行
if(saveFEndPart[saveFitemId.IndexOf(Convert.ToInt32(row["FItemId"]))]+1>=
Convert.ToInt32(row["FBeginPart"]))
{
//通过判断就直接定位到newTable中的某行修改
newTable.Rows[saveFitemId.IndexOf(Convert.ToInt32(row["FItemId"]))]["FEndPart"]=row["FEndPart"];
.........
}else{
newTable.Rows.Add(row);//如果报错就用newTable.ImportRow(row);
saveFitemId.Add(Convert.ToInt32(row["FItemId"]));
saveFEndPart.Add(Convert.ToInt32(row["FEndPart"]));
}
}
else
{
//没必要循环,直接将row添加至newTable中,因为两者的表结构一样
//lastRow = newTable.NewRow();
//foreach (DataColumn column in dsData.Tables[0].Columns)
//{
//lastRow[column.ColumnName] = row[column.ColumnName];
//}
//newTable.Rows.Add(lastRow);
//因为saveFitemId保存FItemId以及saveFEndPart的保存FEndPart索引和row保存到newTable中的索引是一样的.可以通过saveFitemId两个list定位到这行
newTable.Rows.Add(row);//如果报错就用newTable.ImportRow(row);
saveFitemId.Add(Convert.ToInt32(row["FItemId"]));
saveFEndPart.Add(Convert.ToInt32(row["FEndPart"]));
}
}