forked from dk96/QuotationMaker
updates
parent
7c3aaf6439
commit
34a87cbf40
|
|
@ -8,6 +8,7 @@ using Dapper;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Org.BouncyCastle.Bcpg.OpenPgp;
|
using Org.BouncyCastle.Bcpg.OpenPgp;
|
||||||
using NPOI.OpenXmlFormats.Shared;
|
using NPOI.OpenXmlFormats.Shared;
|
||||||
|
using NPOI.SS.Formula.PTG;
|
||||||
|
|
||||||
namespace QuotationMaker.Controllers
|
namespace QuotationMaker.Controllers
|
||||||
{
|
{
|
||||||
|
|
@ -56,6 +57,171 @@ namespace QuotationMaker.Controllers
|
||||||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Route("addEditDelGetProject")]
|
||||||
|
public ActionResult AddEditDelGetProject(IFormCollection obj) {
|
||||||
|
projectViewResult ret = new projectViewResult();
|
||||||
|
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 user_uid = token.user_uid;
|
||||||
|
string user_perm = token.user_perm;
|
||||||
|
string dept_uid = obj["dept_uid"].ToString();
|
||||||
|
string method = obj["method"].ToString();
|
||||||
|
string project_uid = obj["project_uid"].ToString();
|
||||||
|
string project_name = obj["project_name"].ToString();
|
||||||
|
string company_uid = obj["company_uid"].ToString();
|
||||||
|
string project_ps = obj["project_ps"].ToString();
|
||||||
|
|
||||||
|
if (token.user_id != GlobalClass.appsettings("Admin:id")) {
|
||||||
|
groupUser gpUser = conn.QueryFirstOrDefault<groupUser>("select * from groupUser where dept_uid = @dept_uid and user_uid = @user_uid ", new { dept_uid = dept_uid, user_uid = user_uid });
|
||||||
|
|
||||||
|
if (gpUser == null) {
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "99991";
|
||||||
|
ret.message = "新增的專案資料其部門不屬於目前登入的使用者!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0001";
|
||||||
|
ret.message = "沒有method!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "add") {
|
||||||
|
string errmsg = "";
|
||||||
|
|
||||||
|
if (project_name == "")
|
||||||
|
{
|
||||||
|
errmsg += "無專案名稱!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (company_uid == "")
|
||||||
|
{
|
||||||
|
errmsg += "請選擇客戶公司!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errmsg != "") {
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0002";
|
||||||
|
ret.message = errmsg;
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
project_uid = GlobalClass.CreateRandomCode(24);
|
||||||
|
|
||||||
|
project newProject = new project();
|
||||||
|
newProject.project_uid = project_uid;
|
||||||
|
newProject.dept_uid = dept_uid;
|
||||||
|
newProject.company_uid = company_uid;
|
||||||
|
newProject.project_ps = project_ps;
|
||||||
|
newProject.project_lastmodify_uid = token.user_uid;
|
||||||
|
newProject.project_name = project_name;
|
||||||
|
newProject.project_datetime = DateTime.Now.ToString("yyyy/MM/dd");
|
||||||
|
|
||||||
|
conn.Insert<project>(newProject);
|
||||||
|
|
||||||
|
projectView objView = conn.QueryFirstOrDefault<projectView>("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid});
|
||||||
|
|
||||||
|
if (objView != null)
|
||||||
|
{
|
||||||
|
ret.projectViews.Add(objView);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
project editProject = conn.QueryFirstOrDefault<project>("select * from project where project_isdel = 'N' and project_uid = @project_uid ", new { project_uid = project_uid });
|
||||||
|
|
||||||
|
if (editProject == null) {
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0004";
|
||||||
|
ret.message = "無此project_uid資料!";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "get") {
|
||||||
|
projectView objView = conn.QueryFirstOrDefault<projectView>("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid });
|
||||||
|
|
||||||
|
if (objView != null)
|
||||||
|
{
|
||||||
|
ret.projectViews.Add(objView);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "edit") {
|
||||||
|
string errmsg = "";
|
||||||
|
|
||||||
|
if (project_name == "")
|
||||||
|
{
|
||||||
|
errmsg += "無專案名稱!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (company_uid == "")
|
||||||
|
{
|
||||||
|
errmsg += "請選擇客戶公司!\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (errmsg != "")
|
||||||
|
{
|
||||||
|
ret.ret = "no";
|
||||||
|
ret.err_code = "0002";
|
||||||
|
ret.message = errmsg;
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
editProject.dept_uid = dept_uid;
|
||||||
|
editProject.company_uid = company_uid;
|
||||||
|
editProject.project_ps = project_ps;
|
||||||
|
editProject.project_lastmodify_uid = token.user_uid;
|
||||||
|
editProject.project_name = project_name;
|
||||||
|
editProject.project_modifydate = DateTime.Now;
|
||||||
|
|
||||||
|
conn.Update(editProject);
|
||||||
|
|
||||||
|
projectView objView = conn.QueryFirstOrDefault<projectView>("select * from projectView where project_isdel = 'N' and project_uid = @project_uid", new { project_uid = project_uid });
|
||||||
|
|
||||||
|
if (objView != null)
|
||||||
|
{
|
||||||
|
ret.projectViews.Add(objView);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "del") {
|
||||||
|
editProject.project_lastmodify_uid = token.user_uid;
|
||||||
|
editProject.project_isdel = "Y";
|
||||||
|
editProject.project_modifydate = DateTime.Now;
|
||||||
|
|
||||||
|
conn.Update(editProject);
|
||||||
|
|
||||||
|
ret.ret = "yes";
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
}
|
||||||
|
|
||||||
[Route("projectViewList")]
|
[Route("projectViewList")]
|
||||||
public ActionResult ProjectViewList(IFormCollection obj) {
|
public ActionResult ProjectViewList(IFormCollection obj) {
|
||||||
projectViewResult ret = new projectViewResult();
|
projectViewResult ret = new projectViewResult();
|
||||||
|
|
@ -105,7 +271,9 @@ namespace QuotationMaker.Controllers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret.projectViews = conn.Query<projectView>("select * from projectView where project_lastmodify_uid in (@user_list) and project_createdate >= @start_date and project_createdate <= @end_date", new { user_list = user_uid_list, start_date = startDateTime.ToString("yyyy/MM/dd"), end_date = endDateTime.ToString("yyyy/MM/dd 23:59:59") } ).ToList();
|
string sqlString = "select * from projectView where project_isdel = 'N' and project_lastmodify_uid in (" + user_uid_list + ") and project_createdate >= '" + startDateTime.ToString("yyyy/MM/dd") + "' and project_createdate <= '" + endDateTime.ToString("yyyy/MM/dd 23:59:59") + "'";
|
||||||
|
|
||||||
|
ret.projectViews = conn.Query<projectView>(sqlString).ToList();
|
||||||
ret.ret = "yes";
|
ret.ret = "yes";
|
||||||
|
|
||||||
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
return Content(JsonConvert.SerializeObject(ret), "application/json;charset=utf-8");
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,8 @@ public class DbTableClass
|
||||||
public string project_lastmodify_uid { get; set; } = "";
|
public string project_lastmodify_uid { 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;
|
||||||
|
|
||||||
|
public string project_isdel { get; set; } = "N";
|
||||||
public string company_name { get; set; } = "";
|
public string company_name { get; set; } = "";
|
||||||
public string company_serialNo { get; set; } = "";
|
public string company_serialNo { get; set; } = "";
|
||||||
public string company_address { get; set; } = "";
|
public string company_address { get; set; } = "";
|
||||||
|
|
@ -46,6 +48,8 @@ public class DbTableClass
|
||||||
public string project_datetime { get; set; } = "";
|
public string project_datetime { get; set; } = "";
|
||||||
public string company_uid { get; set; } = "";
|
public string company_uid { get; set; } = "";
|
||||||
public string project_ps { get; set; } = "";
|
public string project_ps { get; set; } = "";
|
||||||
|
|
||||||
|
public string project_isdel { get; set; } = "N";
|
||||||
public string project_lastmodify_uid { get; set; } = "";
|
public string project_lastmodify_uid { 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;
|
||||||
|
|
|
||||||
|
|
@ -173,7 +173,7 @@
|
||||||
</div><!-- /.modal-header -->
|
</div><!-- /.modal-header -->
|
||||||
<!-- .modal-body -->
|
<!-- .modal-body -->
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="hidden" id="prjoect_method" />
|
<input type="hidden" id="project_method" />
|
||||||
<input type="hidden" id="project_uid" />
|
<input type="hidden" id="project_uid" />
|
||||||
<!-- .form-row -->
|
<!-- .form-row -->
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,8 @@ $(document).ready(function () {
|
||||||
var project_name = $('#project_name').val();
|
var project_name = $('#project_name').val();
|
||||||
var project_ps = $('#project_ps').val();
|
var project_ps = $('#project_ps').val();
|
||||||
var project_uid = $('#project_uid').val();
|
var project_uid = $('#project_uid').val();
|
||||||
var mehtod = $('#project_method').val();
|
var method = $('#project_method').val();
|
||||||
|
var dept_uid = $('#dept_select').val();
|
||||||
|
|
||||||
var msg = '';
|
var msg = '';
|
||||||
|
|
||||||
|
|
@ -68,13 +69,48 @@ $(document).ready(function () {
|
||||||
project_uid: project_uid,
|
project_uid: project_uid,
|
||||||
project_name: project_name,
|
project_name: project_name,
|
||||||
company_uid: company_uid,
|
company_uid: company_uid,
|
||||||
project_ps: project_ps
|
project_ps: project_ps,
|
||||||
|
dept_uid: dept_uid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/Api/addEditDelGetProject",
|
||||||
|
type: "post",
|
||||||
|
data: formData,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
var obj = data.projectViews[0];
|
||||||
|
|
||||||
|
if (method == "add") {
|
||||||
|
projectTable.fnAddData(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method == "edit") {
|
||||||
|
projectTable.fnUpdate(obj, projectRowPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$('#clientProjectModal').modal('toggle');
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#dept_select').on('change', function () {
|
||||||
|
$('#dt-responsive').DataTable().ajax.reload();
|
||||||
|
});
|
||||||
$('#projectNewBtn').on('click', function () {
|
$('#projectNewBtn').on('click', function () {
|
||||||
$('#prjoect_method').val('add');
|
$('#project_method').val('add');
|
||||||
$('#clientProjectModal').modal("toggle");
|
$('#clientProjectModal').modal("toggle");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -95,6 +131,88 @@ $(document).ready(function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function buttonClick(obj) {
|
||||||
|
var type = obj.getAttribute('data-method');
|
||||||
|
var uid = obj.getAttribute('data-uid');
|
||||||
|
var dept_uid = $('#dept_select').val();
|
||||||
|
|
||||||
|
projectRowID = $('#' + uid);
|
||||||
|
|
||||||
|
projectRowPos = projectTable.fnGetPosition($('#' + uid)[0]);
|
||||||
|
|
||||||
|
if (type == "edit") {
|
||||||
|
var formData = {
|
||||||
|
method: 'get',
|
||||||
|
project_uid: uid,
|
||||||
|
dept_uid: dept_uid
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/Api/addEditDelGetProject",
|
||||||
|
type: "post",
|
||||||
|
data: formData,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
var obj = data.projectViews[0];
|
||||||
|
|
||||||
|
$("#project_method").val('edit');
|
||||||
|
$("#project_uid").val(obj.project_uid);
|
||||||
|
$("#project_name").val(obj.project_name).trigger('change');
|
||||||
|
$("#company_select").val(obj.company_uid);
|
||||||
|
$("#project_ps").val(obj.project_ps).trigger('change');
|
||||||
|
|
||||||
|
$('#clientProjectModal').modal('toggle');
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type == "del") {
|
||||||
|
if (confirm('確定刪除此筆專案資料? 所有此專案的報價單項目也會一併刪除~')) {
|
||||||
|
if (confirm('再次確認是否刪除所有此專案與報價單項目?')) {
|
||||||
|
var formData = {
|
||||||
|
method: 'del',
|
||||||
|
project_uid: uid,
|
||||||
|
dept_uid: dept_uid
|
||||||
|
}
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "/Api/addEditDelGetProject",
|
||||||
|
type: "del",
|
||||||
|
data: formData,
|
||||||
|
success: function (data, textStatus, jqXHR) {
|
||||||
|
if (data.ret == "yes") {
|
||||||
|
var row = projectTable.api().row(projectRowID).remove().draw(false);
|
||||||
|
alert('刪除成功');
|
||||||
|
|
||||||
|
} else {
|
||||||
|
alert(data.message);
|
||||||
|
|
||||||
|
if (data.err_code == "99999") {
|
||||||
|
location.href = "/Root/Login";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
|
alert('網路或伺服器發生錯誤,請稍後重試!');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function loadDataTable() {
|
function loadDataTable() {
|
||||||
var dataTables = {
|
var dataTables = {
|
||||||
init: function init() {
|
init: function init() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue