master
嘉祥 詹 2024-01-20 02:34:33 +08:00
parent 9f173d1693
commit f6a1a8dac6
6 changed files with 766 additions and 7 deletions

View File

@ -49,13 +49,188 @@ namespace Journeys_WantHome.Controllers
DbConn dbConn = new DbConn(); DbConn dbConn = new DbConn();
SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString")); SqlConnection conn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:SQLConnectionString"));
SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString")); SqlConnection elabConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:ElabConnectionString"));
SqlConnection prmConn = new SqlConnection(GlobalClass.appsettings("ConnectionStrings:DBConnectionString"));
public ApiController(IHttpContextAccessor httpContextAccessor) public ApiController(IHttpContextAccessor httpContextAccessor)
{ {
this._httpContextAccessor = httpContextAccessor; this._httpContextAccessor = httpContextAccessor;
} }
[Route("queryPrm")]
public ActionResult QueryPrm(IFormCollection obj) {
prmResult ret = new prmResult();
string search = obj["search"].ToString();
string quotation_serial = search + "%";
string quotation_name = "%" + search + "%";
List<quotation> quotations = prmConn.Query<quotation>("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();
foreach (quotation proj in quotations)
{
optionData item = new optionData();
item.id = proj.quotation_serial;
item.text = "(" + proj.quotation_serial + ") " + proj.quotation_name;
ret.data.Add(item);
}
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
[Route("projectAddEditDelGet")]
public ActionResult ProjectAddEditDelGet(IFormCollection obj)
{
projectResult ret = new projectResult();
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 method = obj["method"].ToString();
string project_uid = obj["project_uid"].ToString();
string project_isPrm = obj["project_isPrm"].ToString();
string project_prmSerial = obj["project_prmSerial"].ToString();
string project_name = obj["project_name"].ToString();
string project_year = obj["project_year"].ToString();
string project_month = obj["project_month"].ToString();
string project_isExec = project_isPrm;
if (method == "del") {
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
if (newProj == null)
{
ret.ret = "no";
ret.err_code = "2001";
ret.message = "找不到此專案資料!";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
conn.Delete<project>(newProj);
ret.ret = "yes";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
if (method == "get") {
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
if (newProj == null)
{
ret.ret = "no";
ret.err_code = "2001";
ret.message = "找不到此專案資料!";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
ret.ret = "yes";
ret.data = newProj;
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
if (method == "edit") {
project newProj = conn.QueryFirstOrDefault<project>("select * from project where project_uid = @project_uid", new { project_uid = project_uid });
if (newProj == null) {
ret.ret = "no";
ret.err_code = "2001";
ret.message = "找不到此專案資料!";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
newProj.project_name = project_name;
newProj.project_isPrm = project_isPrm;
newProj.project_year = int.Parse(project_year);
newProj.project_month = int.Parse(project_month);
newProj.project_modifydate = DateTime.Now;
newProj.project_modify_id = token.user_id;
newProj.project_prmSerial = project_prmSerial;
newProj.project_isExec = project_isExec;
conn.Update<project>(newProj);
ret.ret = "yes";
ret.data = newProj;
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
if (method == "add") {
project_uid = GlobalClass.CreateRandomCode(12);
if (project_isPrm == "Y")
{
project findProje = conn.QueryFirstOrDefault<project>("select * from project where project_prmSerial = @project_prmSerial", new { project_prmSerial = project_prmSerial });
if (findProje != null)
{
ret.ret = "no";
ret.err_code = "1001";
ret.message = "此PRM專案已經存在於KOL系統之中!";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
}
else {
project findProje = conn.QueryFirstOrDefault<project>("select * from project where project_name = @project_name and project_year = @project_year and project_month = @project_month ", new { project_name = project_name, project_year = project_year, project_month = project_month });
if (findProje != null)
{
ret.ret = "no";
ret.err_code = "1002";
ret.message = "此專案名稱已經存在於KOL系統之中!";
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
}
project newProj = new project();
newProj.project_uid = project_uid;
newProj.project_name = project_name;
newProj.project_isPrm = project_isPrm;
newProj.project_year = int.Parse(project_year);
newProj.project_month = int.Parse(project_month);
newProj.project_create_id = token.user_id;
newProj.project_modify_id = token.user_id;
newProj.project_prmSerial = project_prmSerial;
newProj.project_isExec = project_isExec;
conn.Insert(newProj);
ret.ret = "yes";
ret.data = newProj;
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
[Route("projectList")]
public ActionResult ProjectList(IFormCollection obj) {
projectListResult ret = new projectListResult();
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");
}
List<project> projects = conn.Query<project>("select * from project order by project_modifydate desc ").ToList();
ret.ret = "yes";
ret.projectList = projects;
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
}
[Route("kolList")] [Route("kolList")]
public ActionResult KolList(IFormCollection obj) { public ActionResult KolList(IFormCollection obj) {
kolListResult ret = new kolListResult(); kolListResult ret = new kolListResult();
@ -581,6 +756,31 @@ namespace Journeys_WantHome.Controllers
} }
public class prmResult {
public List<optionData> data = new List<optionData>();
}
public class optionData {
public string id { get; set; } = "";
public string text { get; set; } = "";
}
public class projectResult {
public string ret { get; set; } = "no";
public string err_code { get; set; } = "0000";
public string message { get; set; } = "";
public project data { get; set; } = new project();
}
public class projectListResult {
public string ret { get; set; } = "no";
public string err_code { get; set; } = "0000";
public string message { get; set; } = "";
public List<project> projectList { get; set; } = new List<project>();
}
public class kolListResult { public class kolListResult {
public string ret { get; set; } = ""; public string ret { get; set; } = "";
public string err_code { get; set; } = ""; public string err_code { get; set; } = "";

View File

@ -8,6 +8,29 @@ using Newtonsoft.Json.Linq;
public class DbTableClass public class DbTableClass
{ {
[Table("quotation")]
public class quotation
{
[JsonIgnore]
[Key]
public int quotation_sn { get; set; }
public string quotation_serial { get; set; }
public string quotation_name { get; set; }
public int quotation_year { get; set; }
public string dept_uid { get; set; }
public int quotation_budget { get; set; }
public string company_uid { get; set; }
public string company_serial { get; set; }
public string quotation_ps { get; set; }
public string quotation_paperfile { get; set; }
public int quotation_version { get; set; }
public string quotation_del { get; set; }
public string quotation_invalid { get; set; }
public string quotation_create_user_uid { get; set; }
public DateTime quotation_createdate { get; set; }
public DateTime quotation_modifydate { get; set; }
}
[Table("project")] [Table("project")]
public class project public class project
{ {
@ -29,6 +52,8 @@ public class DbTableClass
public string project_isExec { get; set; } = "N"; public string project_isExec { get; set; } = "N";
public string project_reason { get; set; } = "";
public DateTime project_createdate { get; set; } = DateTime.Now; public DateTime project_createdate { get; set; } = DateTime.Now;
public DateTime project_modifydate { get; set; }= DateTime.Now; public DateTime project_modifydate { get; set; }= DateTime.Now;

View File

@ -30,7 +30,7 @@
</header><!-- /.page-title-bar --> </header><!-- /.page-title-bar -->
<!-- .page-section --> <!-- .page-section -->
<div class="page-section"> <div class="page-section">
<button type="button" id="kolNewModal" class="btn btn-primary btn-floated position-absolute" title="Add new client"><i class="fa fa-plus"></i></button> <button type="button" id="projectNewModal" class="btn btn-primary btn-floated position-absolute" title="Add new client"><i class="fa fa-plus"></i></button>
<!-- .card --> <!-- .card -->
<div class="card card-fluid"> <div class="card card-fluid">
<!-- .card-body --> <!-- .card-body -->
@ -44,6 +44,7 @@
<th> 專案名稱 </th> <th> 專案名稱 </th>
<th> 狀態 </th> <th> 狀態 </th>
<th> 合作對象 </th> <th> 合作對象 </th>
<th> 資料異動時間 </th>
<th> </th> <th> </th>
</tr> </tr>
</thead> </thead>
@ -53,3 +54,83 @@
</div><!-- /.card --> </div><!-- /.card -->
</div><!-- /.page-section --> </div><!-- /.page-section -->
</div><!-- /.page-inner --> </div><!-- /.page-inner -->
<!-- Keep in mind that modals should be placed outsite of page sidebar -->
<!-- .modal -->
<form id="clientNewForm" name="clientNewForm">
<div class="modal fade" id="clientNewModal" tabindex="-1" role="dialog" aria-labelledby="clientNewModalLabel" data-backdrop="static"
data-keyboard="false" aria-hidden="true">
<!-- .modal-dialog -->
<div class="modal-dialog modal-lg" role="document">
<!-- .modal-content -->
<div class="modal-content">
<!-- .modal-header -->
<div class="modal-header">
<h6 id="clientNewModalLabel" class="modal-title inline-editable">
<span class="sr-only">Client name</span> <input id="modelTitle" type="text" class="form-control form-control-lg" placeholder="專案資料維護" required="">
</h6>
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
</button>
</div><!-- /.modal-header -->
<!-- .modal-body -->
<div class="modal-body">
<input type="hidden" id="method" />
<input type="hidden" id="project_uid" />
<!-- .form-row -->
<div class="form-row">
<div class="col-md-12" id="user_name_div">
<div class="form-group">
<label class="d-block">狀態</label>
<div class="custom-control custom-control-inline custom-radio">
<input type="radio" class="custom-control-input" name="project_isExec[]" id="rd1" value="yes"> <label class="custom-control-label" for="rd1"> 已執行</label>
</div>
<div class="custom-control custom-control-inline custom-radio">
<input type="radio" class="custom-control-input" name="project_isExec[]" id="rd2" value="no"> <label class="custom-control-label" for="rd2"> 僅提案</label>
</div>
</div>
</div>
<div class="col-md-12" id="prm_project_serial">
<!-- .form-group -->
<div class="form-group">
<label class="control-label" for="select2-data-remote">PRM專案名稱</label> <select id="select2-data-remote" class="form-control">
</select>
</div><!-- /.form-group -->
</div>
<div class="col-md-12" id="project_year_month_div">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="project_year">年度</label>
<select class="custom-select" id="project_year" required="">
</select>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="project_month">月份</label>
<select class="custom-select" id="project_month" required="">
</select>
</div>
</div>
</div>
</div>
<div class="col-md-12" id="project_name_div">
<div class="form-group">
<label for="project_name">專案名稱</label> <input type="text" id="project_name" class="form-control">
</div>
</div>
</div><!-- /.form-row -->
</div><!-- /.modal-body -->
<!-- .modal-footer -->
<div class="modal-footer">
<button type="button" id="projectSaveBtn" class="btn btn-primary">儲存</button> <button id="closeBtn" type="button" class="btn btn-light" data-dismiss="modal">關閉</button>
</div><!-- /.modal-footer -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</form><!-- /.modal -->

View File

@ -134,6 +134,10 @@
<a href="~/Home/KolList" class="menu-link"><span class="menu-icon oi oi-people"></span> <span class="menu-text">KOL 清單</span></a> <a href="~/Home/KolList" class="menu-link"><span class="menu-icon oi oi-people"></span> <span class="menu-text">KOL 清單</span></a>
</li><!-- /.menu-item --> </li><!-- /.menu-item -->
<!-- .menu-item --> <!-- .menu-item -->
<li class="menu-item">
<a href="~/Home/ProjectList" class="menu-link"><span class="menu-icon oi oi-box"></span> <span class="menu-text">案件清單</span></a>
</li><!-- /.menu-item -->
<!-- .menu-item -->
<li class="menu-item has-child" id="authMenu" style='@ViewData["authMenu"]'> <li class="menu-item has-child" id="authMenu" style='@ViewData["authMenu"]'>
<a href="#" class="menu-link"><span class="menu-icon oi oi-wrench"></span> <span class="menu-text">Auth</span></a> <!-- child menu --> <a href="#" class="menu-link"><span class="menu-icon oi oi-wrench"></span> <span class="menu-text">Auth</span></a> <!-- child menu -->
<ul class="menu"> <ul class="menu">

View File

@ -8,7 +8,8 @@
"AllowedHosts": "*", "AllowedHosts": "*",
"ConnectionStrings": { "ConnectionStrings": {
"SQLConnectionString": "Data Source=sql.bremen.com.tw;Initial Catalog=journeys_wanthome;User ID=journeys_wanthome;Password=2icR52n@9;Max Pool Size=100;", "SQLConnectionString": "Data Source=sql.bremen.com.tw;Initial Catalog=journeys_wanthome;User ID=journeys_wanthome;Password=2icR52n@9;Max Pool Size=100;",
"ElabConnectionString": "Data Source=sql.bremen.com.tw;database=elab;uid=elab;pwd=2#2k9Vfg" "ElabConnectionString": "Data Source=sql.bremen.com.tw;database=elab;uid=elab;pwd=2#2k9Vfg",
"DBConnectionString": "Data Source=sql.bremen.com.tw;Initial Catalog=prm;User ID=prm;Password=y6U6x?t5;Max Pool Size=200;"
}, },
"Admin": { "Admin": {
"uid": "system", "uid": "system",

View File

@ -1,5 +1,453 @@
 
var mainTable;
var mainRowID;
var mainPos;
$(document).ready(function () { $(document).ready(function () {
loadDataTable();
loadPrm();
loadyearmonth();
$('#projectSaveBtn').on('click', function () {
var method = $('#method').val();
var project_isPrm = $('input:radio[name="project_isExec[]"]:checked').val();
var project_year = $('#project_year').val();
var project_month = $('#project_month').val();
var project_name = $('#project_name').val();
var prm_serial = $('#select2-data-remote').val();
var prm_name = $('#select2-data-remote').find(':selected').text();
if (typeof project_isPrm === "undefined") {
alert('請先選擇已執行或僅提案!');
return;
}
if (project_isPrm == 'no' && project_name == '') {
alert('請輸入專案名稱!');
return;
}
if (project_isPrm == 'yes' && prm_serial == '') {
alert('請選擇已執行的PRM專案!');
return;
}
if (project_isPrm == 'yes' && prm_serial == null) {
alert('請選擇已執行的PRM專案!');
return;
}
if (project_isPrm == 'yes') {
project_isPrm = 'Y';
project_name = prm_name.replace('(' + prm_serial + ') ', "");
project_year = "20" + prm_serial.substr(0, 2);
project_month = parseInt(prm_serial.substr(2, 2));
} else {
project_isPrm = 'N';
}
mainTable = $('#dt-responsive').dataTable();
var formData = {
method: method,
project_isPrm: project_isPrm,
project_prmSerial: prm_serial,
project_name: project_name,
project_year: project_year,
project_month: project_month
}
$.ajax({
url: "/Api/projectAddEditDelGet",
type: "post",
data: formData,
success: function (data, textStatus, jqXHR) {
var obj = data.data;
if (data.ret == "yes") {
if (method == "add") {
mainTable.fnAddData(obj);
}
if (method == "edit") {
mainTable.fnUpdate(obj, mainPos);
}
$('#clientNewModal').modal('toggle');
} else {
alert(data.message);
if (data.err_code == "99999") {
location.href = "/Root/Login";
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
});
$('#projectNewModal').on('click', function () {
//var src = $('#fileupload-avatar').parent().children('img').prop('src');
//var origin = location.origin;
//src = src.replace(origin, '');
//alert(src);
$("#select2-data-remote").val(null).trigger('change');
$('input:radio[name="project_isExec[]"]').prop('checked', false);
$('#project_name').val('');
$('#prm_project_serial').hide();
$('#project_year_month_div').hide();
$('#project_name_div').hide();
$('#method').val('add');
$('#clientNewModal').modal('toggle');
});
$('input:radio[name="project_isExec[]"]').change(
function () {
if ($(this).is(':checked') && $(this).val() == 'yes') {
// append goes here
$('#prm_project_serial').show();
$('#project_year_month_div').hide();
$('#project_name_div').hide();
}
if ($(this).is(':checked') && $(this).val() == 'no') {
// append goes here
$('#prm_project_serial').hide();
$('#project_year_month_div').show();
$('#project_name_div').show();
}
}); });
function loadyearmonth() {
var actualDate = new Date(); // convert to actual date
var nowYear = actualDate.getFullYear();
for (tmpY = nowYear; tmpY >= 2019; tmpY--) {
$("#project_year").append($("<option></option>").attr("value", tmpY).text(tmpY + " 年度"));
}
for (tmpM = 1; tmpM <= 12; tmpM++) {
$("#project_month").append($("<option></option>").attr("value", tmpM).text(tmpM + " 月"));
}
}
function loadPrm() {
$('#select2-data-remote').select2({
language: 'zh-TW',
width: '100%',
// 最多字元限制
maximumInputLength: 12,
// 最少字元才觸發尋找, 0 不指定
minimumInputLength: 1,
// 當找不到可以使用輸入的文字
// tags: true,
placeholder: '請輸入案號或專案名稱...',
ajax: {
url: '/Api/queryPrm',
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,
// 可以啟用無線捲軸做分頁
pagination: {
more: params.page * 30 < data.total_count
}
}
}
}
});
}
function loadDataTable() {
var dataTables = {
init: function init() {
this.bindUIActions();
},
bindUIActions: function bindUIActions() {
// event handlers
this.table = this.handleDataTables();
// add buttons
//this.table.buttons().container().appendTo('#dt-buttons').unwrap();
},
handleDataTables: function handleDataTables() {
//$('#myTable').append("<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr></tfoot>");
return $('#dt-responsive').DataTable({
dom: '<\'text-muted\'Bif>\n <\'table-responsive\'trl>\n <\'mt-4\'p>',
lengthChange: true,
lengthMenu: [[25, 50, 100, -1], [25, 50, 100, "All"]],
pageLength: 25,
buttons: [
//{
// text: '休假設定',
// action: function (e, dt, node, config) {
// vacationBtnFun();
// }
//},
//'excelHtml5'
],
language: {
paginate: {
previous: '<i class="fa fa-lg fa-angle-left"></i>',
next: '<i class="fa fa-lg fa-angle-right"></i>'
},
buttons: {
copyTitle: 'Data copied',
copyKeys: 'Use your keyboard or menu to select the copy command'
}
},
autoWidth: false,
ajax: {
url: '/Api/projectList',
type: 'POST',
data: function (d) {
Object.assign(d, {
bar_area: $('#bar_area').val(),
is_lottery: $('#isLottery').val()
});
return d;
},
dataSrc: 'projectList'
},
rowId: 'project_uid',
deferRender: true,
initComplete: function () {
$('#dt-responsive').on('click', 'a', function () {
buttonClick2(this);
});
$('#dt-responsive').on('click', 'button', function () {
buttonClick2(this);
});
$('#dt-responsive').on('click', 'input[name="selectedRow[]"]', function () {
checkboxClick(this);
});
},
order: [[5, 'desc']],
info: true,
search: "搜尋:",
searching: true,
columns: [{ data: 'project_year', className: 'align-middle', orderable: false, searchable: false },
{ data: 'project_prmSerial', className: 'align-middle text-left', orderable: true, searchable: true },
{ data: 'project_name', className: 'align-middle text-left', orderable: true, searchable: true },
{ data: 'project_isExec', className: 'align-middle text-left', orderable: false, searchable: true },
{ data: 'project_uid', className: 'align-middle text-left', orderable: false, searchable: true },
{ data: 'project_modifydate', className: 'align-middle text-left', orderable: false, searchable: true },
{ data: 'project_uid', className: 'align-middle text-center', orderable: false, searchable: false }],
columnDefs: [
{
targets: 3,
className: 'align-middle text-center',
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
if (row.project_isExec == 'Y') {
return "執行";
}
if (row.project_isExec == 'N') {
return "未執行";
return "未執行,原因:" + row.project_reason;
}
return '';
//return row.gift_city + row.gift_area + row.gift_address;
//var editRet = '<a id="table-btn" class="btn btn-sm btn-secondary" href="javascript: void(0);" data-method="edit" data-uid="' + row.quotation_serial + '"><i class="fa fa-pencil-alt"></i></a> <a id="table-btn" class="btn btn-sm btn-secondary" href="javascript: void(0);" data-method="setting" data-uid="' + row.quotation_serial + '"><i class="fas fa-cog"></i></a>';
//if (row.quotationUser_perm == "A" || row.quotationUser_perm == "D" || row.quotationUser_perm == "admin" || row.quotationUser_perm == "pro") {
// editRet = editRet + ' <a id="table-btn" class="btn btn-sm btn-secondary" href="javascript: void(0);" data-method="del" data-uid="' + row.quotation_serial + '"><i class="far fa-trash-alt"></i></a>';
//}
//return editRet;
}
}
, {
targets: 4,
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
ret = '尚在開發中';
return ret;
//return '<a href="javascript: void(0); " data-method="edit" data-uid="' + row.company_uid + '">' + row.company_name + '</a>';
}
}
, {
targets: 5,
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
return (new Date(row.project_modifydate)).format("yyyy/MM/dd hh:mm:ss");
}
}
, {
targets: 6,
orderable: false,
searchable: false,
render: function render(data, type, row, meta) {
var ret = '';
ret += '<button type="button" data-uid="' + row.project_uid + '" data-method="edit" class="btn btn-sm btn-icon btn-secondary" ><i class="fa fa-pencil-alt"></i> <span class="sr-only">Edit</span></button>';
ret += '<button type="button" data-uid="' + row.project_uid + '" data-method="del" class="btn btn-sm btn-icon btn-secondary"><i class="far fa-trash-alt"></i> <span class="sr-only">Remove</span></button>';
return ret;
}
}
],
});
},
handleSearchRecords: function handleSearchRecords() {
var self = this;
$('#table-search, #filterBy').on('keyup change focus', function (e) {
var filterBy = $('#filterBy').val();
var hasFilter = filterBy !== '';
var value = $('#table-search').val();
self.table.search('').columns().search('').draw();
if (hasFilter) {
self.table.columns(filterBy).search(value).draw();
} else {
self.table.search(value).draw();
}
});
}
}
dataTables.init();
}
});
function buttonClick2(obj) {
var type = obj.getAttribute('data-method');
var uid = obj.getAttribute('data-uid');
mainTable = $('#dt-responsive').dataTable();
mainRowID = $('#' + uid);
mainPos = mainTable.fnGetPosition($('#' + uid)[0]);
if (type == "del") {
if (confirm('確定刪除此筆資料? 刪除後將無任何方法回復!')) {
var formData = {
method: "del",
poject_uid: uid
}
$.ajax({
url: "/Api/projectAddEditDelGet",
type: "post",
data: formData,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
var row = mainTable.api().row(mainRowID).remove().draw(false);
alert('刪除完成!');
} else {
alert(data.message);
if (data.err_code == "9999") {
location.href = "/Home/Index";
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
}
}
if (type == "edit") {
$('#method').val('edit');
$('#project_uid').val(uid);
var formData = {
method: "get",
project_uid: uid
}
$.ajax({
url: "/Api/projectAddEditDelGet",
type: "post",
data: formData,
success: function (data, textStatus, jqXHR) {
if (data.ret == "yes") {
$("#select2-data-remote").val(null).trigger('change');
$('input:radio[name="project_isExec[]"]').prop('checked', false);
$('#project_name').val('');
$('#prm_project_serial').hide();
$('#project_year_month_div').hide();
$('#project_name_div').hide();
var obj = data.data;
$('#method').val('edit');
$('#project_uid').val(uid);
if (obj.project_isPrm == 'Y') {
$("#rd1").prop("checked", true).trigger("click");
$('#prm_project_serial').show();
$('#project_year_month_div').hide();
$('#project_name_div').hide();
var appendName = "(" + obj.project_prmSerial + ") " + obj.project_name;
var newOption = new Option(appendName, obj.project_prmSerial, true, true);
$("#select2-data-remote").append(newOption).trigger('change');
//$("#select2-data-remote").trigger('change.select2');
} else {
$("#rd2").prop("checked", true).trigger("click");
$('#prm_project_serial').hide();
$('#project_year_month_div').show();
$('#project_name_div').show();
$("#project_year").val(obj.project_year);
$("#project_month").val(obj.project_month);
$("#project_name").val(obj.project_name).trigger('change');;
}
$('#clientNewModal').modal('toggle');
} else {
alert(data.message);
if (data.err_code == "9999") {
location.href = "/Home/Index";
}
}
},
error: function (jqXHR, textStatus, errorThrown) {
alert('網路或伺服器發生錯誤,請稍後重試!');
}
});
}
}