- form 이름 변경
- UI 수정 - Result Panel Column 연동
This commit is contained in:
146
DataHandler.cs
Normal file
146
DataHandler.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using OfficeOpenXml;
|
||||
using System.IO;
|
||||
using System.Data;
|
||||
|
||||
namespace friction
|
||||
{
|
||||
public class DataHandler
|
||||
{
|
||||
DataTable m_Data = new DataTable();
|
||||
|
||||
string m_strFileName = "";
|
||||
string m_strFilePath = "";
|
||||
|
||||
List<string> m_ColumnsNames = new List<string>();
|
||||
List<string> m_ActiveColumns = new List<string>();
|
||||
List<string> m_NonactiveColumns = new List<string>();
|
||||
List<string> m_Material1 = new List<string>();
|
||||
List<string> m_Material2 = new List<string>();
|
||||
|
||||
Dictionary<string, string> m_ColumnMap = new Dictionary<string, string>();
|
||||
|
||||
public DataHandler()
|
||||
{
|
||||
m_ColumnMap["spring"] = "Material spring";
|
||||
m_ColumnMap["table"] = "material 2 table";
|
||||
m_ColumnMap["priority"] = "Risk priority number";
|
||||
m_ColumnMap["force"] = "normal force";
|
||||
m_ColumnMap["temp"] = "Temperature";
|
||||
m_ColumnMap["humidity"] = "Relative humidity";
|
||||
m_ColumnMap["velocity"] = "Relative velocity";
|
||||
}
|
||||
|
||||
public void LoadData2(string strFilePath)
|
||||
{
|
||||
using (ExcelPackage package = new ExcelPackage())
|
||||
{
|
||||
using (var stream = new FileStream(strFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
package.Load(stream);
|
||||
ExcelWorksheet Sheet = package.Workbook.Worksheets[1];
|
||||
|
||||
m_Data.Columns.Clear();
|
||||
m_Data.Rows.Clear();
|
||||
|
||||
// read column
|
||||
for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++)
|
||||
{
|
||||
string strCol = (string)Sheet.Cells[Sheet.Dimension.Start.Row, iCol].Value;
|
||||
m_Data.Columns.Add(new DataColumn(strCol));
|
||||
}
|
||||
|
||||
// read data
|
||||
for (int iRow = Sheet.Dimension.Start.Row + 1; iRow <= Sheet.Dimension.End.Row; iRow++)
|
||||
{
|
||||
DataRow newRow = m_Data.NewRow();
|
||||
|
||||
for (int iCol = Sheet.Dimension.Start.Column; iCol <= Sheet.Dimension.End.Column; iCol++)
|
||||
{
|
||||
var value = Sheet.Cells[iRow, iCol].Value;
|
||||
|
||||
if (value is double)
|
||||
{
|
||||
float fData = (float)(double)value;
|
||||
newRow[iCol - 1] = fData;
|
||||
}
|
||||
else
|
||||
{
|
||||
string strData = "";
|
||||
if (value != null)
|
||||
{
|
||||
strData = (string)value;
|
||||
strData = strData.Trim();
|
||||
}
|
||||
|
||||
newRow[iCol - 1] = strData;
|
||||
}
|
||||
}
|
||||
|
||||
m_Data.Rows.Add(newRow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
m_Material1 = (from r in m_Data.AsEnumerable()
|
||||
select r[m_ColumnMap["spring"]]).Distinct().Cast<string>().ToList();
|
||||
|
||||
m_Material2 = (from r in m_Data.AsEnumerable()
|
||||
select r[m_ColumnMap["table"]]).Distinct().Cast<string>().ToList();
|
||||
|
||||
m_ColumnsNames = (from c in m_Data.Columns.Cast<DataColumn>()
|
||||
select c.ColumnName).ToList<string>();
|
||||
|
||||
|
||||
m_ActiveColumns.Clear();
|
||||
m_NonactiveColumns.Clear();
|
||||
for (int i=0; i< m_ColumnsNames.Count; i++)
|
||||
{
|
||||
if(m_Data.Columns[i].DataType == typeof(string))
|
||||
{
|
||||
if(m_Data.AsEnumerable().Any(r => (string)r[i] != ""))
|
||||
m_ActiveColumns.Add(m_ColumnsNames[i]);
|
||||
else
|
||||
m_NonactiveColumns.Add(m_ColumnsNames[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ActiveColumns.Add(m_ColumnsNames[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public DataTable GetData()
|
||||
{
|
||||
return m_Data;
|
||||
}
|
||||
|
||||
public List<string> GetMaterialSpring()
|
||||
{
|
||||
return m_Material1;
|
||||
}
|
||||
|
||||
public List<string> GetMaterialTable()
|
||||
{
|
||||
return m_Material2;
|
||||
}
|
||||
|
||||
public List<string> GetColumns()
|
||||
{
|
||||
return m_ColumnsNames;
|
||||
}
|
||||
|
||||
public List<string> GetActiveColumns()
|
||||
{
|
||||
return m_ActiveColumns;
|
||||
}
|
||||
|
||||
public List<string> GetNonactiveColumns()
|
||||
{
|
||||
return m_NonactiveColumns;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user