|
|
|
ช่วยดู CODE C# หน่อยครับ เรื่อง sum column ใน datagrid ที่ select มา |
|
|
|
|
|
|
|
Code (C#)
String sql = @"select org.organization_name org_name
,msi.organization_id org_id
,mc.segment1 pj
,msi.item_type
,oh.inventory_item_id
,msi.segment1 item
,msi.description
,msi.primary_uom_code uom
,oh.subinventory_code wh
,oh.lot_number lot
,msi.attribute5 Location
,msi.attribute15 Store_Keeper
,sum(oh.primary_transaction_quantity) onhand
,(loc.segment2||decode(loc.segment2,null,null,'.')||loc.segment3||decode(loc.segment3,null,null,'.')||loc.segment4) locator
from apps.mtl_onhand_quantities_detail oh
,apps.mtl_system_items msi
,apps.mtl_item_categories mic
,apps.mtl_categories mc
,apps.org_organization_definitions org
,apps.cst_item_cost_details cst
,apps.mtl_item_locations loc
where oh.organization_id in (131,132,134,135)
and oh.organization_id = msi.organization_id
and oh.inventory_item_id = msi.inventory_item_id
and msi.organization_id = mic.organization_id
and msi.inventory_item_id = mic.inventory_item_id
and mic.category_id = mc.category_id
and mic.category_set_id = 1100000003 ---(MEW Item)
and msi.organization_id = org.organization_id
and msi.organization_id = cst.organization_id(+)
and msi.inventory_item_id = cst.inventory_item_id(+)
and cst.cost_type_id(+) = 1023 -- MEWSTD
and oh.organization_id = loc.organization_id(+)
and oh.locator_id = loc.inventory_location_id(+)
and oh.primary_transaction_quantity > 0
and msi.segment1 like '%' || :item_no || '%' -- 'AAARCP9012'
and oh.subinventory_code like '%' || :sub_code || '%'
and oh.lot_number like '%' || :lot || '%'
group by org.organization_name
,msi.organization_id
,mc.segment1
,msi.segment1
,msi.item_type
,msi.description
,msi.primary_uom_code
,oh.subinventory_code
,oh.lot_number
,msi.attribute5
,msi.attribute15
,(loc.segment2||decode(loc.segment2,null,null,'.')||loc.segment3||decode(loc.segment3,null,null,'.')||loc.segment4)
,cst.usage_rate_or_amount
,msi.inventory_item_id
,oh.inventory_item_id
order by oh.subinventory_code
,mc.segment1
,oh.lot_number";
try
{
Cursor.Current = Cursors.WaitCursor;
objConn = DBFactory.GetDBConnection();
//OracleConnection objConn = DBFactory.GetDBConnection();
//OracleCommand objCmd = null;
OracleDataAdapter objAdap = null;
DataSet ds = new DataSet();
objCmd = objConn.CreateCommand();
objCmd.CommandText = sql;
objCmd.CommandType = CommandType.Text;
objCmd.Parameters.Add(DBFactory.CreateOracleParameterInput("item_no",
OracleDbType.VarChar, txtItem.Text));
objCmd.Parameters.Add(DBFactory.CreateOracleParameterInput("sub_code",
OracleDbType.VarChar, txtWH.Text));
objCmd.Parameters.Add(DBFactory.CreateOracleParameterInput("lot",
OracleDbType.VarChar, txtLot.Text));
objAdap = new OracleDataAdapter(objCmd);
objAdap.Fill(ds);
Grd1.DataSource = ds.Tables[0];
DataGridTableStyle tableStyle = new DataGridTableStyle();
tableStyle.MappingName = ds.Tables[0].TableName;
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("WH", "WH", 35));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("LOCATOR", "LOCATOR", 55));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("ITEM", "ITEM", 90));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("DESCRIPTION", "DESCRIPTION", 85));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("UOM", "UOM", 30));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("ONHAND", "ONHAND1", 60));
tableStyle.GridColumnStyles.Add(DisplayUtil.CreateDataGridTextBoxColumn("LOT", "LOT", 45));
Grd1.TableStyles.Clear();
Grd1.TableStyles.Add(tableStyle);
Grd1.Refresh();
Cursor.Current = Cursors.Default;
// Grd1.DataSource = myDataTable;
// Total //
//DataRow[] CountRows = myDataTable.Select();
// decimal total = (decimal)myDataTable.Compute("sum(ONHAND)", null);
// SumQty.Text = total.ToString("#,##0.##");
int sum = 0;
for (int i = 0; i < Grd1.Rows.ONHAND1; ++i)
{
sum += Convert.ToInt32(Grd1.Rows[i].Cells[1].Value);
}
SumQty.Text = sum.ToString();
Tag : .NET, C#
|
|
|
|
|
|
Date :
2012-12-10 22:27:24 |
By :
alvis2006 |
View :
1097 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|