public void Field_IndexVersion_NegativeIndexThrows() { DataTable table = new DataTable("test"); DataRow row = table.NewRow(); Assert.Throws <IndexOutOfRangeException>(() => DataRowExtensions.Field <int>(row, columnIndex: -1, version: DataRowVersion.Default)); }
public void Field_ColumnVersion_NullColumnThrows() { DataTable table = new DataTable("test"); DataRow row = table.NewRow(); AssertExtensions.Throws <ArgumentNullException>("column", () => DataRowExtensions.Field <int>(row, column: null, version: DataRowVersion.Default)); }
public void Field_String_NullColumnNameThrows() { DataTable table = new DataTable("test"); DataRow row = table.NewRow(); AssertExtensions.Throws <ArgumentNullException>("name", () => DataRowExtensions.Field <int>(row, columnName: null)); }
public void Field_NullSource_ThrowsArgumentNullException() { var table = new DataTable(); DataColumn column = table.Columns.Add("Column"); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, column)); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, 0)); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, "Column")); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, column, DataRowVersion.Current)); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, 0, DataRowVersion.Current)); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, "Column", DataRowVersion.Current)); }
//選択された日付の日記を探すメソッド public void FindDiary() { //2箇所のdateTextBoxに表示するメソッドを呼び出す SetDate(); Form1Data.diaryEditTextBoxText = null; //選択された日付の日記を探す var row = dataSet.diaryDataTable.Rows.Find(Form1Data.date); var colum = dataSet.diaryDataTable.Columns.IndexOf("日記"); //選択された日付の日記が存在しなければ return if (row == null) { return; } //選択された日付の日記が存在していれば、内容を TextBox に代入 var value = DataRowExtensions.Field <string>(row, colum); Form1Data.diaryEditTextBoxText = value; }
public void Field_ColumnVersion_NullRowThrows() { DataColumn column = new DataColumn(); AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, column: column, version: DataRowVersion.Default)); }
public void Field_NameVersion_NullRowThrows() { AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, columnName: "foo", version: DataRowVersion.Default)); }
public void Field_Index_NullRowThrows() { AssertExtensions.Throws <ArgumentNullException>("row", () => DataRowExtensions.Field <int>(null, 0)); }
public DataTable getLigsPick() { DataTable dt1; try { DataTable dt = (DataTable)this.Session[this._nameSessionData]; if (dt == null || dt.Rows.Count == 0) { return(new DataTable()); } dt1 = DataTableExtensions.CopyToDataTable <DataRow>((IEnumerable <DataRow>)EnumerableRowCollectionExtensions.Where <DataRow>(DataTableExtensions.AsEnumerable(dt), (Func <DataRow, bool>)(x => DataRowExtensions.Field <string>(x, "liq_estid").Equals("PM") || DataRowExtensions.Field <string>(x, "liq_estid").Equals("PF")))); return(dt1); //return DataTableExtensions.CopyToDataTable<DataRow>((IEnumerable<DataRow>)EnumerableRowCollectionExtensions.Where<DataRow>(DataTableExtensions.AsEnumerable(dt), (Func<DataRow, bool>)(x => DataRowExtensions.Field<string>(x, "liq_estid").Equals("PF")))); } catch { return(new DataTable()); } }
/// <summary> /// Calculo de totales /// </summary> /// <param name="gv"></param> /// <param name="dt"></param> /// <param name="printLabels"></param> protected void calculateTotals(GridView gv, DataTable dt, bool printLabels, bool showAlert) { try { if (dt == null || dt.Rows.Count <= 0) { return; } var fAnonymousType3 = Enumerable.FirstOrDefault(Enumerable.Select(Enumerable.GroupBy <DataRow, DataTable>((IEnumerable <DataRow>)DataTableExtensions.AsEnumerable(dt), (Func <DataRow, DataTable>)(x => x.Table)), y => { var local_0 = new { x1 = Enumerable.Count <DataRow>((IEnumerable <DataRow>)y), x2 = Enumerable.Sum <DataRow>((IEnumerable <DataRow>)y, (Func <DataRow, Decimal>)(x => DataRowExtensions.Field <Decimal>(x, "Cantidad"))), x3 = Enumerable.Count <DataRow>(Enumerable.Where <DataRow>((IEnumerable <DataRow>)y, (Func <DataRow, bool>)(x => !string.IsNullOrEmpty(x["pin_employee"].ToString())))), x4 = Enumerable.Sum <DataRow>(Enumerable.Where <DataRow>((IEnumerable <DataRow>)y, (Func <DataRow, bool>)(x => !string.IsNullOrEmpty(x["pin_employee"].ToString()))), (Func <DataRow, Decimal>)(x => DataRowExtensions.Field <Decimal>(x, "Cantidad"))) }; return(local_0); })); gv.FooterRow.Cells[0].Text = "TOTALES:"; gv.FooterRow.Cells[1].Text = fAnonymousType3.x1.ToString("N0"); gv.FooterRow.Cells[6].Text = fAnonymousType3.x2.ToString("N0"); // Pedidos sin asignacion de marcacion if (showAlert) { int num = (fAnonymousType3.x1 - fAnonymousType3.x3); if (num > 0) { string script = string.Empty; script += "dialogInfo('Marcación de pedidos','Nuevos pedidos en marcación','Tiene <b> " + num + " nuevos pedidos </b>');"; System.Web.UI.ScriptManager.RegisterStartupScript(upMsg, Page.GetType(), "dialogInfo", script, true); } } if (printLabels) { Label label1 = this.lblLiqInPick; int num1 = fAnonymousType3.x3; string str1 = num1.ToString("N0"); label1.Text = str1; Label label2 = this.lblQtysInPick; Decimal num2 = fAnonymousType3.x4; string str2 = num2.ToString("N0"); label2.Text = str2; Label label3 = this.lblLiqNotPick; num1 = fAnonymousType3.x1 - fAnonymousType3.x3; string str3 = num1.ToString("N0"); label3.Text = str3; Label label4 = this.lblQtyNotPick; num2 = fAnonymousType3.x2 - fAnonymousType3.x4; string str4 = num2.ToString("N0"); label4.Text = str4; } } catch { } }
public DataTable getLiqsHalls() { try { DataTable dt = (DataTable)this.Session[this._nameSessionData]; if (dt == null || dt.Rows.Count == 0) { return(new DataTable()); } return(DataTableExtensions.CopyToDataTable <DataRow>((IEnumerable <DataRow>)EnumerableRowCollectionExtensions.Where <DataRow>(DataTableExtensions.AsEnumerable(dt), (Func <DataRow, bool>)(x => !DataRowExtensions.Field <string>(x, "lhv_status").Equals("PM"))))); } catch { return(new DataTable()); } }
protected void ProcessZip() { //TODO: Add functionality to just upload .csv var fileName = Path.GetFileName(FileInput.PostedFile.FileName); if (int.TryParse(ddlCompetitorName.SelectedValue, out var id)) { if (fileName.EndsWith(".zip")) { var saveLocation = Server.MapPath("~/App_Data/") + fileName; if (!CheckFileRecords(id, fileName)) { try { FileInput.PostedFile.SaveAs(saveLocation); } catch (Exception ex) { Response.Write("Error: " + ex.Message); } var dtHeartRateZones = GetHeartRateZones(); var dtPointsPerMinute = GetPointsPerMinute(); var totalPoints = 0; var userRange1Lb = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone1LowerBound"]; var userRange1Ub = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone1UpperBound"]; var userRange2Lb = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone2LowerBound"]; var userRange2Ub = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone2UpperBound"]; var userRange3Lb = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone3LowerBound"]; var userRange3Ub = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone3UpperBound"]; var userRange4Lb = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone4LowerBound"]; var userRange4Ub = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone4UpperBound"]; var userRange5Lb = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone5LowerBound"]; var userRange5Ub = (int)dtHeartRateZones.AsEnumerable().FirstOrDefault(x => DataRowExtensions.Field <int>(x, "CompetitorID").Equals(id))?["Zone5UpperBound"]; using (var archive = ZipFile.OpenRead(saveLocation)) { foreach (var entry in archive.Entries) { int range2Seconds, range3Seconds, range4Seconds, range5Seconds; var range1Seconds = range2Seconds = range3Seconds = range4Seconds = range5Seconds = 0; if (!entry.FullName.EndsWith(".csv", StringComparison.OrdinalIgnoreCase)) { continue; } try { var dt = new DataTable(); using (var sr = new StreamReader(entry.Open())) //build dt from .csv { sr.ReadLine(); sr.ReadLine(); var headers = sr.ReadLine().Split(','); foreach (var header in headers) { dt.Columns.Add(header); } while (!sr.EndOfStream) { var rows = sr.ReadLine().Split(','); var dr = dt.NewRow(); for (var i = 0; i < headers.Length; i++) { dr[i] = rows[i]; } var heartrate = int.TryParse(dr[2].ToString(), out var s) ? s : 0; if (heartrate >= userRange1Lb && heartrate <= userRange1Ub) { range1Seconds++; } else if (heartrate >= userRange2Lb && heartrate <= userRange2Ub) { range2Seconds++; } else if (heartrate >= userRange3Lb && heartrate <= userRange3Ub) { range3Seconds++; } else if (heartrate >= userRange4Lb && heartrate <= userRange4Ub) { range4Seconds++; } else if (heartrate >= userRange5Lb && heartrate <= userRange5Ub) { range5Seconds++; } dt.Rows.Add(dr); } } //all done with csv, calculate points. var range1Minutes = decimal.Divide(range1Seconds, 60); var range2Minutes = decimal.Divide(range2Seconds, 60); var range3Minutes = decimal.Divide(range3Seconds, 60); var range4Minutes = decimal.Divide(range4Seconds, 60); var range5Minutes = decimal.Divide(range5Seconds, 60); var range1Points = range1Minutes * ((int)dtPointsPerMinute.AsEnumerable().FirstOrDefault(x => x.Field <int>("HeartRateZone").Equals(1))["Points"]); var range2Points = range2Minutes * ((int)dtPointsPerMinute.AsEnumerable().FirstOrDefault(x => x.Field <int>("HeartRateZone").Equals(2))["Points"]); var range3Points = range3Minutes * ((int)dtPointsPerMinute.AsEnumerable().FirstOrDefault(x => x.Field <int>("HeartRateZone").Equals(3))["Points"]); var range4Points = range4Minutes * ((int)dtPointsPerMinute.AsEnumerable().FirstOrDefault(x => x.Field <int>("HeartRateZone").Equals(4))["Points"]); var range5Points = range5Minutes * ((int)dtPointsPerMinute.AsEnumerable().FirstOrDefault(x => x.Field <int>("HeartRateZone").Equals(5))["Points"]); var pointsToAdd = int.Parse(Math.Round(range1Points + range2Points + range3Points + range4Points + range5Points).ToString()); totalPoints += pointsToAdd; RecordFileName(entry.Name, pointsToAdd); } catch (Exception ex) { Response.Write("Processing Error: " + ex.Message + " "); } } } ////Write final total UpdateTotalPoints(); Response.Write($"The file has been uploaded. {totalPoints.ToString()} points have been added to your total score."); //RecordFileName(FileName, TotalPoints); //Delete CSV from Server Data File.Delete(saveLocation); } else { ClientScript.RegisterStartupScript(GetType(), "alert", "repeatedUpload();", true); } } else { ClientScript.RegisterStartupScript(GetType(), "alert", "improperType();", true); } } else { ClientScript.RegisterStartupScript(GetType(), "alert", "improperID();", true); } }
public DataSourse GetData(string constr) { DataSourse dataSourse = new DataSourse(); string dbName = constr.Substring(0, constr.IndexOf(";")).Substring(constr.IndexOf("=") + 1); IDbObject dbObject = (IDbObject) new DataAccess(); dbObject.DbConnectStr = constr; List <string> tables = dbObject.GetTables(dbName); List <TableData> list1 = new List <TableData>(); List <Reference> list2 = new List <Reference>(); if (tables != null && tables.Count > 0) { foreach (string tableName in tables) { TableData tableData = new TableData(); tableData.Code = tableName; tableData.Name = tableName; tableData.Id = tableName; List <string> list3 = new List <string>(); DataTable columnInfoList = dbObject.GetColumnInfoList(dbName, tableName); List <Column> list4 = new List <Column>(); foreach (DataRow row in (InternalDataCollectionBase)columnInfoList.Rows) { Column column1 = new Column(); column1.Code = DataRowExtensions.Field <string>(row, 1).Trim(); column1.Comment = DataRowExtensions.Field <string>(row, 15).Trim(); column1.DataType = DataRowExtensions.Field <string>(row, 2).Trim(); column1.Displayed = "true"; Column column2 = column1; string str1 = tableName; int num = DataRowExtensions.Field <int>(row, 0); string str2 = num.ToString(); string str3 = str1 + str2; column2.Id = str3; Column column3 = column1; num = DataRowExtensions.Field <int>(row, 3); string str4 = num.ToString(); column3.Length = str4; column1.Mandatory = DataRowExtensions.Field <string>(row, 13).Trim() == "√" ? "" : "1"; column1.Name = DataRowExtensions.Field <string>(row, 1).Trim(); column1.TableCode = tableName; column1.TableId = tableData.Id; if (DataRowExtensions.Field <string>(row, 7).Trim() != "d") { list3.Add(column1.Id); } list4.Add(column1); } tableData.Columns = list4; if (list3.Count > 0) { tableData.PrimaryKey = new Key() { KeyId = Guid.NewGuid().ToString(), ColumnRef = list3.ToArray() } } ; list1.Add(tableData); } } if (list1 != null && list1.Count > 0) { foreach (TableData tableData in list1) { TableData tab = tableData; foreach (DataRow dataRow in (InternalDataCollectionBase)dbObject.GetTableRefrence(dbName, tab.Code).Rows) { DataRow item = dataRow; Reference r = new Reference(); r.ParentTable = Enumerable.SingleOrDefault <string>(Enumerable.Select <TableData, string>(Enumerable.Where <TableData>((IEnumerable <TableData>)list1, (Func <TableData, bool>)(t => t.Code == DataRowExtensions.Field <string>(item, 1).Trim())), (Func <TableData, string>)(t => t.Id))); r.ParentTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) => { var fAnonymousType2 = new { t = t, f = f }; return(fAnonymousType2); }), param0 => param0.t.Id == r.ParentTable), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 2).Trim()), param0 => param0.f.Id)); r.Id = Guid.NewGuid().ToString(); r.ChildTable = tab.Id; r.ChildTableColumnRef = Enumerable.SingleOrDefault <string>(Enumerable.Select(Enumerable.Where(Enumerable.Where(Enumerable.SelectMany((IEnumerable <TableData>)list1, (Func <TableData, IEnumerable <Column> >)(t => (IEnumerable <Column>)t.Columns), (t, f) => { var fAnonymousType2 = new { t = t, f = f }; return(fAnonymousType2); }), param0 => param0.t.Id == tab.Id), param0 => param0.f.Code == DataRowExtensions.Field <string>(item, 0).Trim()), param0 => param0.f.Id)); list2.Add(r); } } } dataSourse.ListTable = list1; dataSourse.ListReference = list2; DataTable vieWs = dbObject.GetVIEWs(dbName); List <ViewData> list5 = new List <ViewData>(); if (vieWs != null && vieWs.Rows != null && vieWs.Rows.Count > 0) { foreach (DataRow row in (InternalDataCollectionBase)vieWs.Rows) { string str = DataRowExtensions.Field <string>(row, 0); if (!string.IsNullOrWhiteSpace(str)) { string objectViewInfo = dbObject.GetObjectViewInfo(dbName, str); DataTable dataTable = dbObject.QueryViewInfo(dbName, str); ViewData viewData = new ViewData(); viewData.Code = str; viewData.Name = str; viewData.Id = str; viewData.SQLQuery = objectViewInfo; List <Column> list3 = new List <Column>(); foreach (DataColumn dataColumn in (InternalDataCollectionBase)dataTable.Columns) { list3.Add(new Column() { Name = dataColumn.ColumnName, Code = dataColumn.ColumnName, Id = Guid.NewGuid().ToString() }); } viewData.Columns = list3; list5.Add(viewData); } } } dataSourse.ListView = list5; return(dataSourse); } }