//建立字典
public Dictionary<string, string> MyDic = new Dictionary<string, string>();
//比對Aras的欄位相對應是Excel的第幾個column
public void CreateDictionary(List<string> Aras_property_list, List<string> key_column)
{
for (int i = 0; i < Aras_property_list.Count(); i++)
{
for (int j = 0; j < key_column.Count(); j++)
{
//比對Aras的屬性欄位與相對應Excel的column寫入字典中
if (Aras_property_list[i] == key_column[j])
{
MyDic.Add(Aras_property_list[i], "" + j);
}
}
}
}
//定義foreach迴圈次數
int counts = 0;
// 查巡整個字典
foreach (var OneItem in lib.MyDic)
{
key = OneItem.Key;
value = OneItem.Value;
//判斷欄位型態是否為item,若是則反查Item類的id
if (Aras_type_list[counts] == "item")
{
for (int count = 0; count < Aras_type_property_list.Count(); count++)
{
if (key == Aras_type_property_list[count])
{
Item item = inn.newItem(Aras_related_key_type_list[count], "get");
item.setAttribute("select", "id");
item.setAttribute("where", "[" + Aras_related_key_type_list[count] + "]." +
Aras_related_key_list[count] + "= '" + Excel_value_row[int.Parse(value)] + "'");
item = item.apply();
item_id = item.getProperty("id", "");
item_type_add.setProperty(key, item_id);
}
else if (key != Aras_type_property_list[count] && Aras_type_list[counts] != "item")
{
item_type_add.setProperty(key, Excel_value_row[int.Parse(value)]);
}
}
}
else
{
item_type_add.setProperty(key, Excel_value_row[int.Parse(value)]);
}
counts++;
}