thewar_server/Server/Git/XlsxToJson.cs

75 lines
3.3 KiB
C#

using Newtonsoft.Json;
namespace Server.Git
{
public class XlsxToJson : AbstractGit
{
public override string ChangeScript()
{
//저장경로 : repositoryPath
List<string> fileList = GetFiles(repositoryPath, ".xlsx");
Dictionary<string, Dictionary<long, Dictionary<string, object>>> clientSheetList = new Dictionary<string, Dictionary<long, Dictionary<string, object>>>();
List<Sheet> serverSheetList = new List<Sheet>();
for (int n = 0; n < fileList.Count; n++)
{
ExcelManager em = new ExcelManager(fileList[n]);
if (em.Play())
{
//나의 sheet가 아니라 em에 들어있는 시트만으로 처리되도록 해야함.
sheets = em.sheets;
for (int m = 0; m < sheets.Count; m++)
{
switch (sheets[m].dataEnum[0])
{
case "server":
serverSheetList.Add(sheets[m]);
break;
case "client":
clientSheetList.Add(sheets[m].name, sheets[m].dicViewer);
break;
case "all":
string name = sheets[m].name;
Dictionary<long, Dictionary<string, object>> clientSheet = new Dictionary<long, Dictionary<string, object>>();
foreach (KeyValuePair<long, Dictionary<string, object>> item in sheets[m].dicViewer)
{
clientSheet.Add(item.Key, new Dictionary<string, object>(item.Value));
}
for (int i = 1; i < sheets[m].dataEnum.Count; i++)
{
if (sheets[m].dataEnum[i] == "server")
{
foreach (var item in clientSheet)
{
item.Value.Remove(sheets[m].variable[i]);
}
}
}
clientSheetList.Add(name, clientSheet);
serverSheetList.Add(sheets[m]);
break;
}
}
}
else
{
//Console.WriteLine("-1 : NotUpdate");
return "";
}
}
//현재 서버는 PostgreSQL기준으로 쿼리를 생성하는 코드와 패키지가 세팅되어 있습니다 이점 참고바랍니다
//추가로 해당 기능을 사용하려면 서버에 excel이라는 스키마가 존재하여야 합니다.
if (sheets != null && serverSheetList.Count != 0)
{
ExcelSQL sql = new ExcelSQL(serverSheetList);
sql.DataUpdate();
}
return JsonConvert.SerializeObject(clientSheetList);
}
}
}