diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 277831c..119ee73 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -56,16 +56,136 @@ namespace Journeys_WantHome.Controllers this._httpContextAccessor = httpContextAccessor; } + [Route("updateTags")] + public ActionResult UpdateTags(IFormCollection obj) { + updatTagResult ret = new updatTagResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string search = obj["search"].ToString(); + + if (search.Length < 2) { + ret.ret = "no"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + tags tag = conn.QueryFirstOrDefault("select * from tags where tag_text = @tag_text", new { tag_text = search }); + + + + if (tag == null) + { + tags newTag = new tags(); + newTag.tag_uid = "tag_" + GlobalClass.CreateRandomCode(12); + newTag.tag_text = search; + + conn.Insert(newTag); + + ret.data.id = newTag.tag_uid; + ret.data.text = search; + ret.ret = "yes"; + } + else { + ret.data.id = tag.tag_uid; + ret.data.text = search; + ret.ret = "yes"; + } + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("queryTags")] + public ActionResult QueryTags(IFormCollection obj) { + tagListResult ret = new tagListResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string search = obj["search"].ToString(); + + search = "%" + search + "%"; + + List tagList = conn.Query("select * from tags where tag_text like @tag_text", new { tag_text = search }).ToList(); + + foreach (tags tag in tagList) + { + optionData item = new optionData(); + + item.id = tag.tag_uid; + item.text = tag.tag_text; + + ret.data.Add(item); + } + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + [Route("queryPrmFile")] + public ActionResult QueryPrmFile(IFormCollection obj) { + prmFileResult ret = new prmFileResult(); + + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + ret.ret = "no"; + ret.err_code = "99999"; + ret.message = "非登入狀態!"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + + string quotation_serial = obj["quotation_serial"].ToString(); + + files fil = prmConn.QueryFirstOrDefault("select * from files where file_target_uid = @quotation_serial and file_del = 'N'", new { quotation_serial = quotation_serial}); + + if (fil == null) + { + ret.ret = "yes"; + ret.hasFile = "N"; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + else { + ret.ret = "yes"; + ret.hasFile = "Y"; + ret.fileName = fil.file_filename; + ret.fileUrl = "https://prm.bremennetwork.tw/api/fileService4Journeys.ashx?id=" + fil.file_uid; + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + + } + + + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + [Route("queryPrm")] public ActionResult QueryPrm(IFormCollection obj) { prmResult ret = new prmResult(); + authToken token = new authToken(this._httpContextAccessor); + if (token.user_isLogin == false) + { + HttpContext.Response.Cookies.Delete("token_key"); + + return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8"); + } + string search = obj["search"].ToString(); string quotation_serial = search + "%"; string quotation_name = "%" + search + "%"; - List quotations = prmConn.Query("select * from quotation where quotation_del = 'N' and quotation_invalid = 'N' and (quotation_serial like @quotation_serial or quotation_name like @quotation_name) order by quotation_serial desc ", new { quotation_serial = quotation_serial, quotation_name = quotation_name }).ToList(); + List quotations = prmConn.Query("select * from quotation where dept_uid in ('bremen', 'journeys') and quotation_del = 'N' and quotation_invalid = 'N' and (quotation_serial like @quotation_serial or quotation_name like @quotation_name) order by quotation_serial desc ", new { quotation_serial = quotation_serial, quotation_name = quotation_name }).ToList(); foreach (quotation proj in quotations) { @@ -282,6 +402,7 @@ namespace Journeys_WantHome.Controllers conn.Execute("delete kolFansType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolMedia where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolCooperateType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); + conn.Execute("delete kolTag where kol_uid = @kol_uid", new { kol_uid = kol_uid }); ret.ret = "yes"; @@ -323,6 +444,7 @@ namespace Journeys_WantHome.Controllers string kolMakeupStr = obj["kolMakeupStr"].ToString().TrimEnd(','); string kolStyleStr = obj["kolStyleStr"].ToString().TrimEnd(','); string kolFansTypeStr = obj["kolFansType"].ToString().TrimEnd(','); + string kolTagsStr = obj["kolTags"].ToString().TrimEnd(','); string mediaArrayJson = obj["mediaArrayJson"].ToString().TrimEnd(','); if (method == "") { @@ -428,6 +550,20 @@ namespace Journeys_WantHome.Controllers } } + string[] kolTagArr = kolTagsStr.Split(","); + List kolTags = new List(); + foreach (string tag in kolTagArr) { + tags tagData = conn.QueryFirstOrDefault("select * from tags where tag_uid = @tag_uid", new { tag_uid = tag }); + + if (tagData != null) { + kolTag newKolTag = new kolTag(); + newKolTag.kolTag_uid = "kt_" + GlobalClass.CreateRandomCode(12); + newKolTag.kol_uid = kol_uid; + newKolTag.tag_uid = tag; + kolTags.Add(newKolTag); + } + } + dynamic mediaJsonObj; try @@ -464,11 +600,13 @@ namespace Journeys_WantHome.Controllers conn.Execute("delete kolStyle where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolFansType where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Execute("delete kolMedia where kol_uid = @kol_uid", new { kol_uid = kol_uid }); + conn.Execute("delete kolTag where kol_uid = @kol_uid", new { kol_uid = kol_uid }); conn.Insert(kolMakeups); conn.Insert(kolStyles); conn.Insert(kolFansTypes); conn.Insert(medias); + conn.Insert(kolTags); try { @@ -584,6 +722,22 @@ namespace Journeys_WantHome.Controllers } } + string[] kolTagArr = kolTagsStr.Split(","); + List kolTags = new List(); + foreach (string tag in kolTagArr) + { + tags tagData = conn.QueryFirstOrDefault("select * from tags where tag_uid = @tag_uid", new { tag_uid = tag }); + + if (tagData != null) + { + kolTag newKolTag = new kolTag(); + newKolTag.kolTag_uid = "kt_" + GlobalClass.CreateRandomCode(12); + newKolTag.kol_uid = kol_uid; + newKolTag.tag_uid = tag; + kolTags.Add(newKolTag); + } + } + dynamic mediaJsonObj; try { @@ -617,6 +771,7 @@ namespace Journeys_WantHome.Controllers conn.Insert(kolStyles); conn.Insert(kolFansTypes); conn.Insert(medias); + conn.Insert(kolTags); try { @@ -756,6 +911,26 @@ namespace Journeys_WantHome.Controllers } + public class updatTagResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public optionData data = new optionData(); + } + public class tagListResult { + public List data = new List(); + } + public class prmFileResult { + public string ret { get; set; } = "no"; + public string err_code { get; set; } = "0000"; + public string message { get; set; } = ""; + + public string hasFile { get; set; } = "N"; + public string fileName { get; set; } = ""; + public string fileUrl { get; set; } = ""; + + } public class prmResult { public List data = new List(); } diff --git a/Models/DbTableClass.cs b/Models/DbTableClass.cs index bc92057..dca7d9e 100644 --- a/Models/DbTableClass.cs +++ b/Models/DbTableClass.cs @@ -8,6 +8,47 @@ using Newtonsoft.Json.Linq; public class DbTableClass { + [Table("kolTag")] + public class kolTag + { + [JsonIgnore] + [Key] + public int kolTag_sn { get; set; } + public string kolTag_uid { get; set; } = ""; + public string kol_uid { get; set; } = ""; + public string tag_uid { get; set; } = ""; + } + + [Table("tags")] + public class tags + { + [JsonIgnore] + [Key] + public int tag_sn { get; set; } + public string tag_uid { get; set; } = ""; + public string tag_text { get; set; } = ""; + } + + + [Table("files")] + public class files + { + [JsonIgnore] + [Key] + public int file_sn { get; set; } + public string file_uid { get; set; } + public string file_target_uid { get; set; } + public string file_url { get; set; } + public string file_filename { get; set; } + public string file_contenttype { get; set; } + public string file_del { get; set; } + public string file_create_user_uid { get; set; } + public string file_modify_user_uid { get; set; } + public DateTime file_createdate { get; set; } + public DateTime file_modifydate { get; set; } + } + + [Table("quotation")] public class quotation { diff --git a/Models/kolDetial.cs b/Models/kolDetial.cs index 4fee322..6095a9a 100644 --- a/Models/kolDetial.cs +++ b/Models/kolDetial.cs @@ -14,6 +14,7 @@ public class kolDetial : kol public List makeups = new List(); public List medias = new List(); public List styles = new List(); + public List tags = new List(); public string updateResult { get; set; } = ""; private kol _kol; @@ -65,12 +66,15 @@ public class kolDetial : kol makeups.Clear(); medias.Clear(); styles.Clear(); + tags.Clear(); List kolCooperateTypes = conn.Query("select A.* from kolCooperateType A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid} ).ToList(); List kolFansTypes = conn.Query("select A.* from kolFansType A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); List kolMakeups = conn.Query("select A.* from kolMakeup A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); List kolMedias = conn.Query("select A.* from kolMedia A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); List kolStyles = conn.Query("select A.* from kolStyle A, optionItem B where A.option_uid = B.option_uid and A.optionItem_uid = B.optionItem_uid and A.kol_uid = @kol_uid order by B.optionItem_order", new { kol_uid = this.kol_uid }).ToList(); + List kolTags = conn.Query("select A.* from kolTag A, tags B where A.tag_uid = B.tag_uid and A.kol_uid = @kol_uid", new { kol_uid = kol_uid }).ToList(); + foreach (kolCooperateType objItem in kolCooperateTypes) { @@ -100,6 +104,12 @@ public class kolDetial : kol kolStyleDetail objDetail = new kolStyleDetail(objItem); styles.Add(objDetail); } + + foreach (kolTag objItem in kolTags) + { + kolTagDetail objDetail = new kolTagDetail(objItem); + tags.Add(objDetail); + } } } @@ -179,5 +189,10 @@ public class kolDetial : kol { item.dataUpdate(); } + + foreach (var item in tags) + { + item.dataUpdate(); + } } } diff --git a/Models/kolTagDetail.cs b/Models/kolTagDetail.cs new file mode 100644 index 0000000..4df9e36 --- /dev/null +++ b/Models/kolTagDetail.cs @@ -0,0 +1,126 @@ +using Dapper; +using Dapper.Contrib.Extensions; +using System.Data.SqlClient; +using static DbTableClass; + +public class kolTagDetail : kolTag +{ + DbConn dbConn = new DbConn(); + SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); + + public string tag_text { get; set; } = ""; + + kolTag _kolTag; + + public string updateResult { get; set; } = ""; + + public kolTagDetail() + { + _kolTag = new kolTag(); + } + + public kolTagDetail(string kolTag_uid) { + _kolTag = conn.QueryFirstOrDefault("select * from kolTag where kolTag_uid = @kolTag_uid", new { kolTag_uid = kolTag_uid}); + + if (_kolTag != null) + { + Type dataType = _kolTag.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(_kolTag, null); + + this.GetType().GetProperty(propName).SetValue(this, propValue); + } + + var result = conn.QueryFirstOrDefault("select * from tags where tag_uid = @tag_uid ", new { tag_uid = tag_uid }); + + if (result != null) + { + this.tag_text = result.tag_text; + } + } + else + { + _kolTag = new kolTag(); + } + } + + public kolTagDetail(kolTag kolTag) { + this._kolTag = kolTag; + + Type dataType = _kolTag.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(_kolTag, null); + + this.GetType().GetProperty(propName).SetValue(this, propValue); + } + + var result = conn.QueryFirstOrDefault("select * from tags where tag_uid = @tag_uid ", new { tag_uid = tag_uid }); + + if (result != null) + { + this.tag_text = result.tag_text; + } + } + + public bool dataUpdate() + { + if (this._kolTag != null) + { + Type dataType = _kolTag.GetType(); + + foreach (var prop in dataType.GetProperties()) + { + string propName = prop.Name; + var valueProperty = dataType.GetProperty(propName); + object propValue = valueProperty.GetValue(this, null); + + _kolTag.GetType().GetProperty(propName).SetValue(_kolTag, propValue); + } + + if (this._kolTag.kolTag_uid == "") + { + this._kolTag.kolTag_uid = "KTAG_" + GlobalClass.CreateRandomCode(16); + this.kolTag_uid = this._kolTag.kolTag_uid; + try + { + conn.Insert(this._kolTag); + updateResult = "success"; + return true; + } + catch (Exception ex) + { + updateResult = ex.Message; + return false; + } + + } + else + { + try + { + conn.Update(this._kolTag); + updateResult = "success"; + return true; + } + catch (Exception ex) + { + updateResult = ex.Message; + return false; + } + } + } + else + { + updateResult = "null 物件無法更新"; + return false; + } + } +} diff --git a/Views/Home/KolList.cshtml b/Views/Home/KolList.cshtml index 597ff3c..284cead 100644 --- a/Views/Home/KolList.cshtml +++ b/Views/Home/KolList.cshtml @@ -216,7 +216,11 @@ 新增社群平台資料 - +
+
+ +
+
diff --git a/Views/Home/ProjectList.cshtml b/Views/Home/ProjectList.cshtml index 52164ac..ae2e56b 100644 --- a/Views/Home/ProjectList.cshtml +++ b/Views/Home/ProjectList.cshtml @@ -97,7 +97,12 @@ +
+ + Go somewhere +
+
diff --git a/Views/Shared/_LooperLayout.cshtml b/Views/Shared/_LooperLayout.cshtml index 6516aaa..6b15c75 100644 --- a/Views/Shared/_LooperLayout.cshtml +++ b/Views/Shared/_LooperLayout.cshtml @@ -223,7 +223,7 @@ - + diff --git a/wwwroot/assets/javascript/custom/kollist.js b/wwwroot/assets/javascript/custom/kollist.js index f169da1..3d4e0e3 100644 --- a/wwwroot/assets/javascript/custom/kollist.js +++ b/wwwroot/assets/javascript/custom/kollist.js @@ -6,7 +6,7 @@ var mainRowID; var mainPos; $(document).ready(function () { delMedia = ''; - + loadTagsInput(); loadMedia(); loadKolMakeupCheckboxItem(); loadKolStyleCheckboxItem(); @@ -33,6 +33,8 @@ $(document).ready(function () { var kolStyleStr = ""; var kolFansType = ""; var mediaArray = []; + var tags = $('#kol_tags').val(); + var tagsStr = ""; var src = $('#fileupload-avatar').parent().children('img').prop('src'); var origin = location.origin; @@ -52,6 +54,11 @@ $(document).ready(function () { kolFansType = kolFansType + $(this).val() + ","; }); + $.each(tags, function (key, value) { + tagsStr = tagsStr + value + ","; + + }); + $('#media_table tbody tr').each(function () { var item = { kolMedia_uid: $(this).find('td').eq(5).children('button').eq(0).attr('data-uid'), @@ -115,6 +122,7 @@ $(document).ready(function () { kolMakeupStr: kolMakeupStr, kolStyleStr: kolStyleStr, kolFansType: kolFansType, + kolTags: tagsStr, mediaArrayJson: JSON.stringify(mediaArray) } @@ -481,7 +489,83 @@ $(document).ready(function () { }); // File upload using button // ============================================================= + function loadTagsInput() { + $('#kol_tags').select2({ + width: '100%', + tags: true, + tokenSeparators: [',', ' '], + multiple: true, + minimumInputLength: 2, + placeholder: '輸入Tag用空白或逗號分隔關鍵字', + ajax: { + url: '/Api/queryTags', + dataType: 'json', + delay: 500, + type: 'post', + // 要送出的資料 + data: function (params) { + // 在伺服器會得到一個 POST 'search' + return { + search: params.term + }; + }, + processResults: function (data, params) { + console.log(data.data) + // 一定要返回 results 物件 + return { + results: data.data, + + } + } + }, + createTag: function (params) { + let term = $.trim(params.term); + if (term.length < 2) { + return null + } + + return { + id: term, + text: term, + // add indicator: + isNew: true + }; + + + } + }); + + $('#kol_tags').on('select2:select', function (e) { + let tag = e.params.data; + var formData = { + search: tag.text + } + + $.ajax({ + url: "/Api/updateTags", + type: "post", + data: formData, + success: function (data, textStatus, jqXHR) { + var obj = data.data; + if (data.ret == "yes") { + $('#kol_tags').find('[value="' + tag.text + '"]').replaceWith(''); + + + } else { + alert(data.message); + + if (data.err_code == "99999") { + location.href = "/Root/Login"; + } + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + }); + } }); @@ -588,7 +672,28 @@ function buttonClick2(obj) { $('#media_table tbody').append(trHtml); //$("input:checkbox[value='" + value.optionItem_uid + "']").prop('checked', true); }); + + + var tagArray = []; + var tagValArray = []; + $.each(obj.tags, function (key, value) { + var tagObj = {}; + tagObj.id = value.tag_uid; + tagObj.text = value.tag_text; + + tagArray.push(tagObj); + tagValArray.push(value.tag_uid); + + var newOption = new Option(value.tag_text, value.tag_uid, true, true); + $('#kol_tags').append(newOption).trigger('change'); + }); + //$('#kol_tags').select2('data').push(tagArray); + //$('#kol_tags').select2('data', tagArray); + + //$('#kol_tags').val(tagValArray).trigger('change'); + + $('#clientNewModal').modal('toggle'); } else { alert(data.message); @@ -664,8 +769,8 @@ function cleanModalData() { $.each(trList, function (index, item) { $(item).remove(); }); - - + $('#kol_tags').empty(); + $('#kol_tags').val(null).trigger('change'); } function loadMedia() { diff --git a/wwwroot/assets/javascript/custom/projectlist.js b/wwwroot/assets/javascript/custom/projectlist.js index 2ad830d..e703bcf 100644 --- a/wwwroot/assets/javascript/custom/projectlist.js +++ b/wwwroot/assets/javascript/custom/projectlist.js @@ -15,6 +15,7 @@ $(document).ready(function () { var project_name = $('#project_name').val(); var prm_serial = $('#select2-data-remote').val(); var prm_name = $('#select2-data-remote').find(':selected').text(); + var project_uid = $('#project_uid').val(); if (typeof project_isPrm === "undefined") { alert('請先選擇已執行或僅提案!'); @@ -53,8 +54,8 @@ $(document).ready(function () { project_prmSerial: prm_serial, project_name: project_name, project_year: project_year, - project_month: project_month - + project_month: project_month, + project_uid: project_uid } $.ajax({ @@ -93,7 +94,7 @@ $(document).ready(function () { //var origin = location.origin; //src = src.replace(origin, ''); //alert(src); - + $('#file_div').hide(); $("#select2-data-remote").val(null).trigger('change'); $('input:radio[name="project_isExec[]"]').prop('checked', false); $('#project_name').val(''); @@ -356,7 +357,7 @@ function buttonClick2(obj) { if (confirm('確定刪除此筆資料? 刪除後將無任何方法回復!')) { var formData = { method: "del", - poject_uid: uid + project_uid: uid } $.ajax({ @@ -384,6 +385,7 @@ function buttonClick2(obj) { } if (type == "edit") { + $('#file_div').hide(); $('#method').val('edit'); $('#project_uid').val(uid); @@ -417,6 +419,29 @@ function buttonClick2(obj) { $('#project_year_month_div').hide(); $('#project_name_div').hide(); + var fileData = { + quotation_serial: obj.project_prmSerial + } + + $.ajax({ + url: "/Api/queryPrmFile", + type: "post", + data: fileData, + success: function (data, textStatus, jqXHR) { + if (data.hasFile == 'Y') { + $('#file_div').show(); + + $('#fileUrl').text(data.fileName); + $('#fileUrl').prop('href', data.fileUrl); + } else { + $('#file_div').hide(); + } + }, + error: function (jqXHR, textStatus, errorThrown) { + alert('網路或伺服器發生錯誤,請稍後重試!'); + } + }); + var appendName = "(" + obj.project_prmSerial + ") " + obj.project_name; var newOption = new Option(appendName, obj.project_prmSerial, true, true);