本文整理汇总了C#中System.Data.DataTable.Select方法的典型用法代码示例。如果您正苦于以下问题:C# System.Data.DataTable.Select方法的具体用法?C# System.Data.DataTable.Select怎么用?C# System.Data.DataTable.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataTable
的用法示例。
在下文中一共展示了System.Data.DataTable.Select方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Solve_Part1
internal static void Solve_Part1()
{
Console.WriteLine("Solving Day 04, Part 1...");
//var input = System.IO.File.ReadAllLines("04_Test.txt");
var input = System.IO.File.ReadAllLines("04.txt");
var validIds = new List<int>();
foreach (var room in input)
{
var idAndSum = room.Split('-').Last();
var roomId = idAndSum.Substring(0, idAndSum.IndexOf('[')).Replace("[", "").Replace("]", "");
var roomCkSum = idAndSum.Substring(idAndSum.IndexOf('[')).Replace("[", "").Replace("]", "");
var roomName = string.Join("", room.Split('-').Where(n => n.IndexOf('[') == -1 && n.IndexOf(']') == -1));
var dt = new System.Data.DataTable();
dt.Columns.Add("letter", typeof(string));
dt.Columns.Add("count", typeof(int));
for (int i = 0; i < 26; i++)
dt.Rows.Add(((char)(i + 97)).ToString(), 0);
foreach (var c in roomName)
{
var dra = dt.Select($"letter= '{((char)c).ToString()}'");
dra[0]["count"] = (int)dra[0]["count"] + 1;
}
var draCt = dt.Select("", "count DESC, letter");
var ckSum = "";
for (int i = 0; i < 5; i++)
ckSum += draCt[i]["letter"].ToString();
if (ckSum == roomCkSum)
validIds.Add(int.Parse(roomId));
}
// correct:
// 278221
Console.WriteLine($"I think the sum of valid sector id's is {validIds.Sum()}.");
}
示例2: Solve_Part2
internal static void Solve_Part2()
{
Console.WriteLine("Solving Day 04, Part 2...");
//var input = System.IO.File.ReadAllLines("04_Test.txt");
var input = System.IO.File.ReadAllLines("04.txt");
var validIds = new List<int>();
foreach (var room in input)
{
var idAndSum = room.Split('-').Last();
var roomId = idAndSum.Substring(0, idAndSum.IndexOf('[')).Replace("[", "").Replace("]", "");
var roomCkSum = idAndSum.Substring(idAndSum.IndexOf('[')).Replace("[", "").Replace("]", "");
var roomName = string.Join("", room.Split('-').Where(n => n.IndexOf('[') == -1 && n.IndexOf(']') == -1));
var nameAndShift = room.Substring(0, room.IndexOf('['));
var dt = new System.Data.DataTable();
dt.Columns.Add("letter", typeof(string));
dt.Columns.Add("count", typeof(int));
for (int i = 0; i < 26; i++)
dt.Rows.Add(((char)(i + 97)).ToString(), 0);
foreach (var c in roomName)
{
var dra = dt.Select($"letter= '{((char)c).ToString()}'");
dra[0]["count"] = (int)dra[0]["count"] + 1;
}
var draCt = dt.Select("", "count DESC, letter");
var ckSum = "";
for (int i = 0; i < 5; i++)
ckSum += draCt[i]["letter"].ToString();
if (ckSum == roomCkSum)
{
var rotCt = int.Parse(nameAndShift.Split('-').Last());
var words = nameAndShift.Substring(0, nameAndShift.LastIndexOf('-')).Split('-');
var newWords = new string[words.Length + 1];
for (int k = 0; k < words.Length; k++)
{
var word = words[k];
for (int i = 0; i < word.Length; i++)
{
var c = word[i];
var intVal = (int)c;
for (int j = 1; j <= rotCt; j++)
{
if ((int)c + 1 < 123)
c = (char)((int)c + 1);
else
c = 'a';
}
newWords[k] += c.ToString();
}
newWords[newWords.Length - 1] = $"({rotCt})";
}
if (newWords.Any(w => w.Contains("object")))
Console.WriteLine(string.Join(" ", newWords));
}
}
// correct:
// 267
}
示例3: GetCostCenterList
private void GetCostCenterList()
{
StringBuilder sb = new StringBuilder();
SAPbobsCOM.Recordset oRS = null;
string expression = string.Empty;
System.Data.DataRow[] foundRows;
int iRow;
bool bModify = false;
try
{
oForm.Freeze(true);
oDB_M = oForm.DataSources.DBDataSources.Item("@KIS_FI0010M_HRD");
oDB_1 = oForm.DataSources.DBDataSources.Item("@KIS_FI00101_HRD");
oMatrix = (SAPbouiCOM.Matrix)oForm.Items.Item("mtx").Specific;
//oMatrix.LoadFromDataSource();
oMatrix.Clear();
FN.SetMatrixIsNullOrEmptDeleteRow(ref oForm, ref oMatrix, "U_PRCCD");
sDataTable = FN.SapDBDataSourceToSystemDataTable(oDB_1);
oRS = (SAPbobsCOM.Recordset)B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
sb.Append(" SELECT Code,Name FROM [@KIS_CO0110M] \r");
if (FN.GetItemValue(ref oForm, "edtCOSTFR") != "" && FN.GetItemValue(ref oForm, "edtCOSTTO") != "")
sb.Append(" WHERE Code BETWEEN '" + FN.GetItemValue(ref oForm, "edtCOSTFR") + "' AND '" + FN.GetItemValue(ref oForm, "edtCOSTTO") + "' \r");
B1Connections.theAppl.StatusBar.SetText("불러오기를 시작합니다.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning);
oRS.DoQuery(sb.ToString());
iRow = oMatrix.VisualRowCount;
if (!oRS.EoF)
{
for (int i = 0; i < oRS.RecordCount; i++)
{
expression = "U_PRCCD = '" + oRS.Fields.Item("Code").Value.ToString() + "'";
foundRows = sDataTable.Select(expression);
if (foundRows.Length < 1)
{
if (iRow != 0)
oDB_1.InsertRecord(iRow-1);
//oDB_1.SetValue("U_LINENUM", iRow, (iRow+1).ToString());
oDB_1.SetValue("U_PRCCD", iRow, oRS.Fields.Item("Code").Value.ToString());
oDB_1.SetValue("U_PRCNM", iRow, oRS.Fields.Item("Name").Value.ToString());
iRow += 1;
bModify = true;
}
oRS.MoveNext();
}
if (bModify)
{
oMatrix.LoadFromDataSource();
if (oForm.Mode == BoFormMode.fm_OK_MODE)
oForm.Mode = BoFormMode.fm_UPDATE_MODE;
}
}
B1Connections.theAppl.StatusBar.SetText("불러오기가 완료 되었습니다.", SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Warning); //데이터 조회중입니다
}
catch (Exception ex)
{
oForm.Freeze(false);
B1Connections.theAppl.StatusBar.SetText("GetCostCenterList " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Short, SAPbouiCOM.BoStatusBarMessageType.smt_Error);
}
finally
{
if (oRS != null)
{
oForm.Freeze(false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oRS);
oRS = null;
}
}
}
示例4: getProximaUnidadeFuncionalByFluxoNova
public System.Data.DataTable getProximaUnidadeFuncionalByFluxoNova(string processoID, string idAssunto, string situacaoID, string undOrcID)
{
SituacaoCtrl controleSituacao = new SituacaoCtrl();
Assunto controleAssunto = new Assunto();
TramiteCtrl controleTramite = new TramiteCtrl();
FluxoAssuntoCtrl controleFluxoAssunto = new FluxoAssuntoCtrl();
string fluxoAtual = controleFluxoAssunto.getFluxoAtual(processoID);
string unidCod = undOrcID.ToString().Substring(2, 2);
string unidORG = undOrcID.ToString().Substring(0, 2);
Situacao situacao = new Situacao();
List<string> UnidadesFuncionais = new List<string>();
string ordenacao = "";
string sqlAssunto = "select * from webassunto where id = " + idAssunto; //Verifica se Assunto tem fluxo definido
FbConnection conn = Persist.GetConn.getConn();
conn.Open();
FbCommand cmdAssunto = new FbCommand(sqlAssunto, conn);
FirebirdSql.Data.FirebirdClient.FbDataReader drAssunto = cmdAssunto.ExecuteReader();
while (drAssunto.Read())
{
ordenacao = drAssunto["EXIGEORDENACAO"].ToString();
}
drAssunto.Close();
drAssunto.Dispose();
cmdAssunto.Dispose();
if (!ordenacao.Equals("1")) //Se não tem fluxo definido...
{
string sqlUND = "Select * from webunidadefuncional where unidorccod = " + unidCod + " unidorcorg = " + unidORG;
FbCommand cmdUND = new FbCommand(sqlUND, conn);
FirebirdSql.Data.FirebirdClient.FbDataReader drUND = cmdUND.ExecuteReader();
while (drUND.Read())
{
UnidadesFuncionais.Add(drUND["UNIDFUNCID"].ToString());
}
drUND.Close();
drUND.Dispose();
cmdUND.Dispose();
}
else//Se tem fluxo definido...
{
if (controleSituacao.ehFinalDeFluxo(situacaoID)) //Se Situação selecionada indicar fim de fluxo
{
UndFuncionalCtrl controleUndFuncional = new UndFuncionalCtrl();
string undFunc = controleUndFuncional.getUnidadeFuncionalArquivo();
UnidadesFuncionais.Add(undFunc);
}
else
{
if (controleSituacao.TramiteTemSituacaoDeExcessao(controleTramite.RetornaUltimoTramite(processoID).ToString())) //Se o tramite indica um Fluxo que não seja natural (volta à um passo a frente)
{
string FlagSituacaoVolta = "";
string sqlExcVolta = "Select FLAG_SITUACAO_VOLTA from WEBTRAMITE WHERE ID = " + controleTramite.RetornaUltimoTramite(processoID).ToString();
FbCommand cmdExcVolta = new FbCommand(sqlExcVolta, conn);
FirebirdSql.Data.FirebirdClient.FbDataReader drEX = cmdExcVolta.ExecuteReader();
while (drEX.Read())
{
FlagSituacaoVolta = drEX["FLAG_SITUACAO_VOLTA"].ToString();
}
drEX.Close();
drEX.Dispose();
cmdExcVolta.Dispose();
string sqlExc = "select * from unidadeorcamentaria uo " +
"join webunidadefuncional uf on uf.unidorccod = uo.undcodigo and uf.unidorcorg = uo.undcodorgao " +
"join webfluxoassunto fa on fa.idundfuncional = uf.unidfuncid " +
"where fa.fluxoID = " + FlagSituacaoVolta + " and fa.idassunto = " + idAssunto;
FbCommand cmdExc = new FbCommand(sqlExc, conn);
FirebirdSql.Data.FirebirdClient.FbDataReader dr = cmdExc.ExecuteReader();
while (dr.Read())
{
UnidadesFuncionais.Add(dr["UNIDFUNCID"].ToString());
}
dr.Close();
dr.Dispose();
cmdExc.Dispose();
}
else
{
object situacaoRetorno = null;
object flagOrigem = null;
string sqlSituacao = "Select * from WEBSITUACAOPROCESSO WHERE ID = " + situacaoID; //Verifica situacao do processo selecionada pelo usuario
FbConnection connSit = Persist.GetConn.getConn();
FbCommand cmdSituacao = new FbCommand(sqlSituacao, connSit);
connSit.Open();
//.........这里部分代码省略.........