Last active
August 17, 2022 07:26
-
-
Save ritacse/27100f331f7048971189f8732e6f50e8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///----Order By Descending & then OrderBy Ascending (with 2 columns) | |
DataTable dtOrderTemp = DTAllPODetails.AsEnumerable().Where(i => i.Field<String>("Order Code").Contains( | |
dtOrderCollection.Rows[ordercount][0].ToString().Trim())).OrderByDescending(i => i.Field<String>("GroupCode")).ThenBy(i => i.Field<int>("SerialNo")).CopyToDataTable(); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var distinctPOValues = excelDataTable.AsEnumerable().Select(row => new | |
{ | |
DistinctPO = row.Field<string>("PO Code"), | |
DistinctOrderNo = row.Field<string>("Order NO") | |
}).Distinct().ToList(); | |
// Distinct with where condition | |
for (int i = 0; i < distinctPOValues.Count; i++) | |
{ | |
var DistinctOrder = excelDataTable.AsEnumerable().Where(r => r.Field<string>("Buyer PO") == distinctPOValues[i].DistinctPO.ToString() | |
).Select(row => new | |
{ | |
DistinctOrderCode = row.Field<string>("Order Code"), | |
DistinctOrderNo = row.Field<string>("Order NO") | |
}).Distinct().ToList(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Get cell value from dataTable with where condition. | |
decimal cst08 = dtOthers.AsEnumerable().First(x => x.Field<string>("Cost For") == "00008").Field<decimal>("Total Cost"); | |
decimal cst49 = dtOthers.AsEnumerable().First(x => iManipulator.GetCode(x.Field<string>("Cost For")) == "00049").Field<decimal>("Total Cost"); | |
string headName = dtCstHead.AsEnumerable().First(x => x.Field<string>("code") == "00049").Field<string>("name") + "(00049)"; | |
MessageBox.Show("Provided cost seem not valid. Please provide valid cost for " + headName + " on Others Tab"); | |
// get value from dataTable | |
var price = orderInfoDataTable.AsEnumerable().Where(p => p.Field<string>("Product Code") == cmbBin.Text.Trim()).Select(p => p.Field<decimal>("Price")).FirstOrDefault(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
decimal cstSum = dtOthers.AsEnumerable().Where(c => iManipulator.GetCode(c.Field<string>("Cost For")) == "00021" | |
|| iManipulator.GetCode(c.Field<string>("Cost For")) == "00038" | |
iManipulator.GetCode(c.Field<string>("Cost For")) == "00046" | |
|| iManipulator.GetCode(c.Field<string>("Cost For")) == "00053").Sum(c => c.Field<decimal>("Total Cost")); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
1. You can't query against the DataTable's Rows collection, since DataRowCollection doesn't implement IEnumerable<T>. You need to use the AsEnumerable() extension for DataTable | |
2. AsEnumerable() returns IEnumerable<DataRow>. If you need to convert IEnumerable<DataRow> to a DataTable, use the CopyToDataTable() extension. | |
*/ | |
EnumerableRowCollection<DataRow> lcCombDataSource; | |
EnumerableRowCollection<DataRow> scCombDataSource; | |
DataTable dtLcScTempList = new DataTable(); | |
if (!ChkAllLcSc.Checked) | |
dtLcScTempList = dtLcScList.AsEnumerable().Where(c => c.Field<string>("Companycode") == iManipulator.GetCode(cmbCompany.Text.Trim()) | |
&& c.Field<string>("Buyer_code") == iManipulator.GetCode(cmbByerName.Text)).CopyToDataTable(); | |
else | |
dtLcScTempList = dtLcScList; | |
if (lcScId == 0) | |
{ | |
lcCombDataSource = dtLcScList.AsEnumerable().Where(c => c.Field<int>("Type") == (int)LcScType.Lc); | |
scCombDataSource = dtLcScList.AsEnumerable().Where(c => c.Field<int>("Type") == (int)LcScType.Sc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment