|
|
using CounsellorBL.Common; using CounsellorBL.ConstDefinition; using CounsellorBL.Helper; using MonumentDefine; using OT.COM.ArsenalDB; using OT.COM.ArsenalDB.SQL; using OT.COM.LogisticsUtil; using OT.COM.SignalerMessage; using SoldierData.EnterprizeV4; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; using System.Reflection; using System.Text; using System.Threading.Tasks;
namespace CounsellorBL { public partial class TestService : DBService {
public override string MainTable => GetMainTableName(typeof(tb_sys_translation)); public TestService() { }
public void TestInsert() { tb_sys_org o = new tb_sys_org() { uid = "2", name = "ssss",
};
Command cInsert = Command.SetupInsertCmd(o);
ArsenalInterface ai = ArsenalDBMgr.GetInst(cInsert, GetDefaultSystemColumnInfo());
ai.RunEditSingleCmd(cInsert);
}
public static ConcurrentDictionary<string, string> GetSetting() { return CustomizeDBMgr.SettingData; }
#region Test Aync
public static async Task<string> GetURL(Uri i_url) { using System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
// GetStringAsync returns a Task<string>. That means that when you await the
// task you'll get a string (urlContents).
Task<string> getStringTask = client.GetStringAsync(i_url);
string urlContents = await getStringTask.ConfigureAwait(false);
// The return statement specifies an integer result.
// Any methods that are awaiting AccessTheWebAsync retrieve the length value.
return urlContents; }
public static List<string> GetURLAync(string[] i_url) { List<string> lRes = new List<string>();
if (i_url != null) { List<Task<string>> lts = new List<Task<string>>();
foreach (string sUrl in i_url) { using HttpClient hc = new HttpClient();
// GetStringAsync returns a Task<string>. That means that when you await the
// task you'll get a string (urlContents).
lts.Add(hc.GetStringAsync(new Uri(sUrl)));
}
Task.WaitAll(lts.ToArray());
foreach (Task<string> ts in lts) { string s = ts.Result; lRes.Add(s); } // The return statement specifies an integer result.
// Any methods that are awaiting AccessTheWebAsync retrieve the length value.
} return lRes; }
public static List<string> GetURLOrigin(string[] i_url) { List<string> lRes = new List<string>();
if (i_url != null) { foreach (string sUrl in i_url) { using WebClient wc = new WebClient(); lRes.Add(wc.DownloadString(sUrl));
} } return lRes; }
#endregion
public void FillTrans() { List<Command> lCmdMaster = new List<Command>();
for (int i = 100; i < 200; i++) {
lCmdMaster.Add(Command.SetupInsertCmd( new tb_sys_translation() { create_org_uid = "001", update_org_uid = "001", create_user_uid = "3CE873C2-33AB-41E6-B6FE-4C528DEF5AF8", update_user_uid = "3CE873C2-33AB-41E6-B6FE-4C528DEF5AF8", name = $"Test{i}", language = "zh-Hant", trans = $"測試{i}" })); }
ArsenalInterface ai = ArsenalDBMgr.GetInst(lCmdMaster[0], GetDefaultSystemColumnInfo()); ai.RunEditCmds(lCmdMaster);
}
public static void FindSelfFK() { string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase; codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies() where !f.IsDynamic && f.FullName.IndexOf("SoldierData", StringComparison.OrdinalIgnoreCase) != -1 && f.CodeBase != null && f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase) select f).ToArray<Assembly>();
List<Type> ltAll = new List<Type>(); foreach (Assembly aCur in assemblyArray) { ltAll.AddRange(aCur.GetTypes().Where(f => f.BaseType == typeof(EntityBase))); }
foreach (Type tCur in ltAll) { TableMiscAttribute tm = EntityUtil.GetClassAttribute<TableMiscAttribute>(tCur); List<KeyValuePair<string, ForeignRelation>> lkv = tm.Data.ForeignRelations.Where(f => f.Value.ForeignTable == tCur.Name).ToList();
if (lkv.Count != 0) { foreach (KeyValuePair<string, ForeignRelation> kv in lkv) { int nMatchCount = 0;
foreach (string sKey in kv.Value.Pars.Keys) { if (sKey == kv.Value.Pars[sKey]) { nMatchCount++; } }
if (kv.Value.Pars.Keys.Count == nMatchCount) { System.Diagnostics.Debug.WriteLine(kv.Key); } }
} } }
public void DeleteCascadeData(string i_sTable, Dictionary<string, object> i_dicCond) { string codeBase = Assembly.GetExecutingAssembly().GetName().CodeBase; codeBase = codeBase.Substring(0, codeBase.LastIndexOf("/", StringComparison.OrdinalIgnoreCase));
Assembly[] assemblyArray = (from f in AppDomain.CurrentDomain.GetAssemblies() where !f.IsDynamic && f.FullName.IndexOf("SoldierData", StringComparison.OrdinalIgnoreCase) != -1 && f.CodeBase != null && f.CodeBase.StartsWith(codeBase, StringComparison.OrdinalIgnoreCase) select f).ToArray<Assembly>();
List<Type> ltAll = new List<Type>(); foreach (Assembly aCur in assemblyArray) { ltAll.AddRange(aCur.GetTypes().Where(f => f.BaseType == typeof(EntityBase))); }
List<Tuple<Type, Dictionary<string, object>>> lt = GetTypeFKFromRecursive(ltAll, i_sTable, i_dicCond);
lt.Reverse(); List<Command> lCmds = new List<Command>();
foreach (Tuple<Type, Dictionary<string, object>> ttd in lt) { EntityBase ebCond = ClassHelper.GetInstByType(ttd.Item1) as EntityBase; ebCond.FillData(ttd.Item2); lCmds.Add(Command.SetupDeleteCmd(ebCond)); }
if (lCmds.Count > 0) { ArsenalInterface ai = ArsenalDBMgr.GetInst(lCmds[0], GetDefaultSystemColumnInfo()); ai.RunEditCmds(lCmds);
} }
public List<Tuple<Type, Dictionary<string, object>>> GetTypeFKFromRecursive(List<Type> ltAll, string i_sTable, Dictionary<string, object> i_dicCond, int i_nLevel = 0) { List<Tuple<Type, Dictionary<string, object>>> lRes = new List<Tuple<Type, Dictionary<string, object>>>(); List<Tuple<Type, Dictionary<string, object>>> lTemp = GetTypeFKFromRecursiveItem(ltAll, i_sTable, i_dicCond);
if (lTemp.Count != 0) {
lRes.AddRange(lTemp); foreach (Tuple<Type, Dictionary<string, object>> ttd in lTemp) { lRes.AddRange(GetTypeFKFromRecursive(ltAll, ttd.Item1.Name, ttd.Item2, i_nLevel + 1)); } }
return lRes; }
public static List<Tuple<Type, Dictionary<string, object>>> GetTypeFKFromRecursiveItem(List<Type> ltAll, string i_sTable, Dictionary<string, object> i_dicCond) { List<Tuple<Type, Dictionary<string, object>>> ltRes = new List<Tuple<Type, Dictionary<string, object>>>();
if (ltAll != null && i_dicCond != null) { foreach (Type tCur in ltAll) { TableMiscAttribute tm = EntityUtil.GetClassAttribute<TableMiscAttribute>(tCur);
List<KeyValuePair<string, ForeignRelation>> lkv = tm.Data.ForeignRelations.Where(f => f.Value.ForeignTable == i_sTable).ToList();
if (lkv.Count != 0) { EntityBase oDisply = ClassHelper.GetInstByType(tCur) as EntityBase; oDisply.SetFullDirty();
foreach (KeyValuePair<string, ForeignRelation> kvp in lkv) { if (kvp.Value.Pars.Keys.Count != i_dicCond.Count) { continue; }
bool bNotMatch = false; List<WhereNode> wnCond = new List<WhereNode>();
foreach (string sKey in kvp.Value.Pars.Keys) { string sTargetColumn = kvp.Value.Pars[sKey]; if (!i_dicCond.ContainsKey(sTargetColumn)) { bNotMatch = true; } else { wnCond.Add(new WhereNode(sKey, WhereNode.EColumnOperation.EOT_EQ, tCur, i_dicCond[sTargetColumn].ToString())); } }
if (bNotMatch) { continue; }
Command cSelect = Command.SetupSelectCmd(oDisply, new WhereNode(WhereNode.ENodeOperation.ENO_AND, wnCond.ToArray()));
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect);
QueryDataSet qds = ai.RunQueryDataSet(cSelect);
if (qds.Total > 0) {
foreach (DataRow dr in qds.DATA.Tables[0].Rows) { Dictionary<string, object> dicRow = new Dictionary<string, object> { { BLWording.UID, dr[BLWording.UID] } };
ltRes.Add(Tuple.Create<Type, Dictionary<string, object>>(tCur, dicRow)); } }
}
} } }
return ltRes; }
[Auth(false)] public static CResponseMessage Action(CRequestMessage i_crm) { CResponseMessage crm = new CSuccessResponseMessage("Reach." + DateTime.Now, i_crm); return crm; }
public string Fix() { string sMsg = null; //
do { QueryJsonElementCollection lBlocks = new QueryJsonElementCollection(); QueryJsonElement qjeA = lBlocks.GetInst(); qjeA.table = tb_rpt_apicolumn.TABLENAME; qjeA.displaycols = new List<string>() { tb_rpt_apicolumn.CN_API_UID, tb_rpt_apicolumn.CN_NAME }; lBlocks.Add(qjeA); sMsg = MakeSelectJoinByBlocks(lBlocks, out Command cSelect);
ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
List<tb_rpt_apicolumn> la = ai.RunQueryList<tb_rpt_apicolumn>(cSelect);
if (!cSelect.IsSuccess) { sMsg = cSelect.LastErrorCode; break; }
Dictionary<string, bool> dicColumnReserveColumn = new Dictionary<string, bool>();
string sSpecialColumnName = "reserve_space"; la.ForEach(f => { if (!dicColumnReserveColumn.ContainsKey(f.api_uid)) { dicColumnReserveColumn.Add(f.api_uid, false); }
if (f.name == sSpecialColumnName) { dicColumnReserveColumn[f.api_uid] = true; } });
List<Command> lcCmds = new List<Command>();
foreach (KeyValuePair<string, bool> kvp in dicColumnReserveColumn) { if (!kvp.Value) { lcCmds.Add(Command.SetupInsertCmd(new tb_rpt_apicolumn() { api_uid = kvp.Key, name = sSpecialColumnName, column_type = "nvarchar(100)", remark = "Space", trans_default = "備註" })); } }
DateTime dtNow = DateTime.Now.Date;
// NAME VALUE STATUS_FLAG SYSTEM_FLAG
List<Tuple<string, string, int, int>> ltNewSetting = new List<Tuple<string, string, int, int>>() { new Tuple<string, string, int, int>(BLWording.SYSTEMSETTING_SYSTEMERRORMAIL, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF), new Tuple<string, string, int, int>(BLWording.REPORTLOG_MAILLIST, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF), new Tuple<string, string, int, int>(BLWording.REPORTLOG_ACTIVETIME, "8:10", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF), new Tuple<string, string, int, int>(BLWording.ADINTELOG_MAILLIST, "", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF), new Tuple<string, string, int, int>(BLWording.ADINTELOG_ACTIVETIME, "8:20", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_OFF), new Tuple<string, string, int, int>(BLWording.RPTLOGMAIL_LASTTIME, dtNow.AddDays(-1).ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME), new Tuple<string, string, int, int>(BLWording.ADINTEMAIL_LASTTIME, dtNow.AddDays(-1).ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME), new Tuple<string, string, int, int>(BLWording.SYSTEM_LAUNCH, DateTime.Now.ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_RUNTIME), new Tuple<string, string, int, int>(BLWording.LOG_RANGE, "14", BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_ON), new Tuple<string, string, int, int>(BLWording.REPORT_FLAG_GROUP, BLWording.STATUS_FLAG_OFF.ToString(CultureInfo.CurrentCulture), BLWording.STATUS_FLAG_ON , BLWording.SYSTEM_FLAG_ON)
};
if (CheckAndInserSetting(ltNewSetting, out List<Command> o_lcCmdsSetting) == null && o_lcCmdsSetting.Any()) { lcCmds.AddRange(o_lcCmdsSetting); }
lcCmds.Add(Command.SetupUpdateCmd( new tb_sys_system_setting() { key_value = DateTime.Now.ToString(CultureInfo.CurrentCulture) }, new tb_sys_system_setting() { name = BLWording.SYSTEM_LAUNCH }));
List<Tuple<string, string, string>> ltNewTrans = new List<Tuple<string, string, string>>() { new Tuple<string, string, string>("zh-Hant","common.emptyname","空白名稱"), new Tuple<string, string, string>("zh-Hant","common.duplicate","重複"), new Tuple<string, string, string>("zh-Hant","common.sendmail.success","郵件發送成功"), new Tuple<string, string, string>("zh-Hant","common.timerange_day","一天"), new Tuple<string, string, string>("zh-Hant","common.timerange_week","一週"), new Tuple<string, string, string>("zh-Hant","common.timerange_month","一月"), new Tuple<string, string, string>("zh-Hant","common.timerange_customize","自選"), new Tuple<string, string, string>("zh-Hant","common.timerange","時間區間"), new Tuple<string, string, string>("zh-Hant","system_flag.nonsystem","客製值"), new Tuple<string, string, string>("zh-Hant","system_flag.system","系統值"), new Tuple<string, string, string>("zh-Hant","system_flag.runtime","執行變數"), new Tuple<string, string, string>("zh-Hant","common.download","下載"), new Tuple<string, string, string>("zh-Hant","common.entercode","密碼"), new Tuple<string, string, string>("zh-Hant","common.date_start","開始時間"), new Tuple<string, string, string>("zh-Hant","common.date_end","結束時間"), new Tuple<string, string, string>("zh-Hant","menu.articlemanage2.maintain","發文列表2"), new Tuple<string, string, string>("zh-Hant","grp.article_id","文章ID"), new Tuple<string, string, string>("zh-Hant","grp.article.message","貼文訊息"), new Tuple<string, string, string>("zh-Hant","grp.article_media","貼文媒體檔"),
new Tuple<string, string, string>("zh-Hant","prd.product.maintain","品項維護"), new Tuple<string, string, string>("zh-Hant","prd.wholesale_price","批價"), new Tuple<string, string, string>("zh-Hant","prd.price","單價"),
new Tuple<string, string, string>("zh-Hant","common.invalid_file","失效檔案"), new Tuple<string, string, string>("zh-Hant","common.no_file","無檔案"), new Tuple<string, string, string>("zh-Hant","common.upload_file","檔案上傳"), new Tuple<string, string, string>("zh-Hant","common.no_media_fle","無媒體檔案"), new Tuple<string, string, string>("zh-Hant","grp.no_product","無產品"), new Tuple<string, string, string>("zh-Hant","grp.post_now","立即貼文"), new Tuple<string, string, string>("zh-Hant","grp.post_success","貼文成功"), new Tuple<string, string, string>("zh-Hant","grp.addproduct","新增品項"),
new Tuple<string, string, string>("zh-Hant","prd.copyallspec","複製所有規格"), new Tuple<string, string, string>("zh-Hant","prd.removeallspec","清除規格"),
new Tuple<string, string, string>("zh-Hant","grp.manully_import","手動匯入留言"), new Tuple<string, string, string>("zh-Hant","article.remark","備註"),
}; if (CheckAndInserTrans(ltNewTrans, out List<Command> o_lcCmdsTrans) == null && o_lcCmdsTrans.Any()) { lcCmds.AddRange(o_lcCmdsTrans); }
if (TruncParam(new List<string>() { "system_flag" }, out List<Command> o_lcTrunPara) == null) { lcCmds.AddRange(o_lcTrunPara); }
List<Tuple<string, string, string, int>> ltNewParam = new List<Tuple<string, string, string, int>>() { new Tuple<string, string, string, int>("success_flag","success_flag.fail","0", 0), new Tuple<string, string, string, int>("common.timerange","common.timerange_day","day", 0), new Tuple<string, string, string, int>("common.timerange","common.timerange_week","week", 1), new Tuple<string, string, string, int>("common.timerange","common.timerange_month","month", 2), new Tuple<string, string, string, int>("common.timerange","common.timerange_customize","customize", 3), new Tuple<string, string, string, int>("system_flag","system_flag.nonsystem","0", 0), new Tuple<string, string, string, int>("system_flag","system_flag.system","1", 0), new Tuple<string, string, string, int>("system_flag","system_flag.runtime","2", 0), }; if (CheckAndInserParam(ltNewParam, out List<Command> o_lcCmdsPara) == null && o_lcCmdsPara.Any()) { lcCmds.AddRange(o_lcCmdsPara); }
if (lcCmds.Any()) { ai.RunEditCmds(lcCmds); }
// 搜尋系統參數中REPORT_STATUS
tb_sys_system_setting tReport = new tb_sys_system_setting(); tb_sys_system_setting tReportWhere = new tb_sys_system_setting() { name = BLWording.REPORT_FLAG_GROUP }; tReport.SetDirty(tb_sys_system_setting.CN_KEY_VALUE); Command csSelect = Command.SetupSelectCmd(tReport, tReportWhere); ai = ArsenalDBMgr.GetInst(csSelect, GetDefaultSystemColumnInfo()); tb_sys_system_setting cSetting = ai.RunQuerySingleORM<tb_sys_system_setting>(csSelect);
// 判斷REPORT_STATUS是否為true 及得到需更改的資料
string sFlag = BLWording.STATUS_FLAG_ON.ToString(CultureInfo.CurrentCulture); if (cSetting.key_value != sFlag && CheckAndUpdateReport(out List<Command> o_lcAuth) == null) { tb_sys_system_setting tSettingWhere = new tb_sys_system_setting() { name = BLWording.REPORT_FLAG_GROUP }; tb_sys_system_setting tSettingUpdate = new tb_sys_system_setting() { key_value = sFlag }; Command cUpdae = Command.SetupUpdateCmd(tSettingUpdate, tSettingWhere); o_lcAuth.Add(cUpdae);
ai.RunEditCmds(o_lcAuth); }
} while (false);
return sMsg; }
public string CheckAndInserSetting(List<Tuple<string, string, int, int>> ltChecks, out List<Command> o_lcCmds) { string sMsg = null; List<Command> lcCmds = null;
do { tb_sys_system_setting tDisplay = new tb_sys_system_setting(); tDisplay.SetDirty(tb_sys_system_setting.CN_NAME); Command cSelect = Command.SetupSelectCmd(tDisplay); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
List<tb_sys_system_setting> ltAll = ai.RunQueryList<tb_sys_system_setting>(cSelect);
List<Command> lcCmdsTemp = new List<Command>(); if (ltChecks != null) { foreach (Tuple<string, string, int, int> t in ltChecks) { if (ltAll.FirstOrDefault(f => f.name == t.Item1) == null) { tb_sys_system_setting tsInsert = new tb_sys_system_setting() { name = t.Item1, key_value = t.Item2, status_flag = t.Item3, system_flag = t.Item4 };
lcCmdsTemp.Add(Command.SetupInsertCmd(tsInsert)); } } }
lcCmds = lcCmdsTemp; } while (false);
o_lcCmds = lcCmds; return sMsg; }
public string TruncParam(List<string> ltChecks, out List<Command> o_lcCmds) { string sMsg = null; List<Command> lcCmds = null;
do {
tb_sys_paramcatalog tDisplay = new tb_sys_paramcatalog(); tDisplay.SetDirty(tb_sys_paramcatalog.CN_NAME, tb_sys_paramcatalog.CN_UID); Command cSelect = Command.SetupSelectCmd(tDisplay); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo()); List<tb_sys_paramcatalog> lpcAll = ai.RunQueryList<tb_sys_paramcatalog>(cSelect);
List<Command> lcCmdsTemp = new List<Command>();
if (ltChecks != null) { foreach (string t in ltChecks) { tb_sys_paramcatalog pc = lpcAll.FirstOrDefault(f => f.name == t);
if (pc != null) { lcCmdsTemp.Add(Command.SetupDeleteCmd(new tb_sys_param() { paramcatalog = pc.uid })); } } }
lcCmds = lcCmdsTemp; } while (false);
o_lcCmds = lcCmds; return sMsg; }
public string CheckAndInserParam(List<Tuple<string, string, string, int>> ltChecks, out List<Command> o_lcCmds) { string sMsg = null; List<Command> lcCmds = null;
do { tb_sys_param tpDisplay = new tb_sys_param(); tpDisplay.SetDirty(tb_sys_param.CN_NAME, tb_sys_param.CN_UID); Command cSelectParam = Command.SetupSelectCmd(tpDisplay); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelectParam, GetDefaultSystemColumnInfo()); List<tb_sys_param> lpAll = ai.RunQueryList<tb_sys_param>(cSelectParam);
tb_sys_paramcatalog tDisplay = new tb_sys_paramcatalog(); tDisplay.SetDirty(tb_sys_paramcatalog.CN_NAME, tb_sys_paramcatalog.CN_UID); Command cSelect = Command.SetupSelectCmd(tDisplay); List<tb_sys_paramcatalog> lpcAll = ai.RunQueryList<tb_sys_paramcatalog>(cSelect);
List<Command> lcCmdsTemp = new List<Command>(); Dictionary<string, string> dicCateGoryName2Uid = new Dictionary<string, string>();
if (ltChecks != null) { foreach (Tuple<string, string, string, int> t in ltChecks) {
if (!dicCateGoryName2Uid.ContainsKey(t.Item1)) { tb_sys_paramcatalog pc = lpcAll.FirstOrDefault(f => f.name == t.Item1);
if (pc == null) { string sUID = Guid.NewGuid().ToString(); tb_sys_paramcatalog pcInsert = new tb_sys_paramcatalog() { uid = sUID, name = t.Item1, status_flag = BLWording.STATUS_FLAG_ON, system_flag = BLWording.STATUS_FLAG_OFF, };
dicCateGoryName2Uid.Add(t.Item1, sUID); lcCmdsTemp.Add(Command.SetupInsertCmd(pcInsert)); } else { dicCateGoryName2Uid.Add(pc.name, pc.uid); } }
tb_sys_param p = lpAll.FirstOrDefault(f => f.name == t.Item2 && f.paramcatalog == dicCateGoryName2Uid[t.Item1]); if (p == null) { lcCmdsTemp.Add(Command.SetupDeleteCmd(new tb_sys_param() { name = t.Item2, paramcatalog = dicCateGoryName2Uid[t.Item1], }));
tb_sys_param pInsert = new tb_sys_param() { name = t.Item2, paramcatalog = dicCateGoryName2Uid[t.Item1], param_value = t.Item3, status_flag = BLWording.STATUS_FLAG_ON, system_flag = BLWording.STATUS_FLAG_OFF, seq = t.Item4 }; lcCmdsTemp.Add(Command.SetupInsertCmd(pInsert)); } } }
lcCmds = lcCmdsTemp; } while (false);
o_lcCmds = lcCmds; return sMsg; }
public string CheckAndInserTrans(List<Tuple<string, string, string>> ltChecks, out List<Command> o_lcCmds) { string sMsg = null; List<Command> lcCmds = null;
do { if (ltChecks == null) { sMsg = MessageWording.PARAM_NOT_EXPECTED; break; } tb_sys_translation tDisplay = new tb_sys_translation(); tDisplay.SetDirty(tb_sys_translation.CN_NAME, tb_sys_translation.CN_LANGUAGE); Command cSelect = Command.SetupSelectCmd(tDisplay); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
List<tb_sys_translation> ltAll = ai.RunQueryList<tb_sys_translation>(cSelect);
List<Command> lcCmdsTemp = new List<Command>();
foreach (Tuple<string, string, string> t in ltChecks) { if (ltAll.FirstOrDefault(f => f.language == t.Item1 && f.name == t.Item2) == null) { tb_sys_translation tsInsert = new tb_sys_translation() { language = t.Item1, name = t.Item2, trans = t.Item3 };
lcCmdsTemp.Add(Command.SetupInsertCmd(tsInsert)); } } lcCmds = lcCmdsTemp; } while (false);
o_lcCmds = lcCmds; return sMsg; }
/// <summary>
/// 將原本SWFIT在handle_item的資料搬到group_item
/// </summary>
/// <param name="o_lcCmds"></param>
/// <returns></returns>
public string CheckAndUpdateReport(out List<Command> o_lcCmds) { string sMsg = null; List<Command> lcCmds; do { // 先搜尋authreport的資料
tb_rpt_authreport rDisplay = new tb_rpt_authreport(); rDisplay.SetDirty(tb_rpt_authreport.CN_UID, tb_rpt_authreport.CN_REPORT_TYPE, tb_rpt_authreport.CN_DEPARTMENT_ITEM); tb_rpt_authreport rWhere = new tb_rpt_authreport() { report_type = BseMessageWording.GROUP }; Command cSelect = Command.SetupSelectCmd(rDisplay, rWhere); ArsenalInterface ai = ArsenalDBMgr.GetInst(cSelect, GetDefaultSystemColumnInfo());
List<tb_rpt_authreport> ltAll = ai.RunQueryList<tb_rpt_authreport>(cSelect);
List<Command> lcCmdsTemp = new List<Command>(); if (ltAll.Any()) { foreach (var t in ltAll) { if (t.department_item != null) { // 更新tb_rpt_authreport資料
tb_rpt_authreport uAuth = new tb_rpt_authreport() { uid = t.uid }; tb_rpt_authreport uData = new tb_rpt_authreport() { department_item = null, group_items = t.department_item }; lcCmdsTemp.Add(Command.SetupUpdateCmd(uData, uAuth));
// 更新tb_rpt_authreport_schedule資料
tb_rpt_authreport_schedule uScheduleAuth = new tb_rpt_authreport_schedule() { authreport_uid = t.uid }; tb_rpt_authreport_schedule uScheduleData = new tb_rpt_authreport_schedule() { department_item = null, group_items = t.department_item }; lcCmdsTemp.Add(Command.SetupUpdateCmd(uScheduleData, uScheduleAuth)); } } }
lcCmds = lcCmdsTemp; } while (false);
o_lcCmds = lcCmds; return sMsg; }
public int LogTest() { return LogHelper.DBLog("NNNNNNNNNN"); }
public Command TestSQLLib() { SQLLib mb = new SQLLib(new MSSQLDirectSQLHelper()); mb.GetArticleProduct("aaa", out Command cRes); return cRes; } }
class SQLLib : DirectSQLLibBase { public SQLLib(ADirectSQLHelper i_sqlLibBase) : base(i_sqlLibBase) { }
public virtual string GetArticleProduct(string i_sArticleUid, out Command o_cResult) { ADirectCmdParameter cp = GetParamter();
string sSQL = $@"SELECT a.{tb_prd_product.CN_UID}
, a.{tb_prd_product.CN_NAME} , a.{tb_prd_product.CN_MEMO} FROM {GetFormalTableName<tb_prd_product>()} a LEFT JOIN {GetFormalTableName<tb_prd_article2product>()} b on a.{tb_prd_product.CN_UID} = b.{tb_prd_article2product.CN_PRD_UID} where b.{tb_prd_article2product.CN_ARTICLE_UID} = {cp.Add(i_sArticleUid)}";
return GenerateCommand<tb_prd_product>(sSQL, cp, out o_cResult); } }
}
|