Java to tabel SQL Server (CREATE)
HTML :
JavaScript :
Controller APP :
Controller API :
Svc :
Stored Procedure :
<div class="btn-group m-b-n-sm" id="divSaveMstFormatHeader">
<span class="btn btn-primary"><i class="fa fa-save"></i> </span>
<button class="btn btn-primary btn-outline" type="button" id="btnSaveMstFormatHeader">Simpan</button>
</div>
<span class="btn btn-primary"><i class="fa fa-save"></i> </span>
<button class="btn btn-primary btn-outline" type="button" id="btnSaveMstFormatHeader">Simpan</button>
</div>
JavaScript :
$("#divSaveMstFormatHeader").click(function () {
if ($("#ddlDetailIndicatorId").val() === "") {
swal({
title: "Indikator tidak boleh kosong"
});
} else if ($("#txtDetailWeightValue").val() === "") {
swal({
title: "Bobot tidak boleh kosong"
});
} else {
swal({
title: "Anda Yakin?",
text: "Anda akan menyimpan semua data ini!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Ya!",
closeOnConfirm: false
},
function (isConfirm) {
if (isConfirm)
{
swal("Tersimpan!", "", "success");
loadHome('/bukihcisapp/web/performance/create-mstformatheaderdetail'
+ "?format_id=" + $("#txtDetailFormatId").val()
+ "&aspectid=" + $("#txtDetailAspectId").val()
+ "&indicator_id=" + $("#ddlDetailIndicatorId").val()
+ "&weight_value=" + $("#txtDetailWeightValue").val()
+ "&remark=" + encodeURIComponent($("#txtDetailRemark").val())
+ "&ranNum=${ranNum}&u=${u}&moduleId=${moduleId}"
+ "&userId=" + $("#txtUserId").val()
+ "&userBranch=" + $("#txtUserBranch").val());
} else {
}
});
}
});
if ($("#ddlDetailIndicatorId").val() === "") {
swal({
title: "Indikator tidak boleh kosong"
});
} else if ($("#txtDetailWeightValue").val() === "") {
swal({
title: "Bobot tidak boleh kosong"
});
} else {
swal({
title: "Anda Yakin?",
text: "Anda akan menyimpan semua data ini!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Ya!",
closeOnConfirm: false
},
function (isConfirm) {
if (isConfirm)
{
swal("Tersimpan!", "", "success");
loadHome('/bukihcisapp/web/performance/create-mstformatheaderdetail'
+ "?format_id=" + $("#txtDetailFormatId").val()
+ "&aspectid=" + $("#txtDetailAspectId").val()
+ "&indicator_id=" + $("#ddlDetailIndicatorId").val()
+ "&weight_value=" + $("#txtDetailWeightValue").val()
+ "&remark=" + encodeURIComponent($("#txtDetailRemark").val())
+ "&ranNum=${ranNum}&u=${u}&moduleId=${moduleId}"
+ "&userId=" + $("#txtUserId").val()
+ "&userBranch=" + $("#txtUserBranch").val());
} else {
}
});
}
});
Controller APP :
@RequestMapping(value = "/create-mstformatheaderdetail", method = RequestMethod.GET)
private RedirectView createMstFormatHeaderDetail(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "ranNum", required = false) String ranNum,
@RequestParam(value = "u", required = false) String uName,
@RequestParam(value = "moduleId", required = false) String moduleId) throws ParseException, UnsupportedEncodingException {
RestTemplate restTemplate = new RestTemplate();
ranNumber = ranNum == null ? ranNumber : ranNum;
HttpSession currentSession = request.getSession(false) == null ? request.getSession() : request.getSession(false);
String userId = request.getParameter("userId");
String format_id = request.getParameter("format_id");
String aspect = request.getParameter("aspectid");
String indicator_id = request.getParameter("indicator_id");
String weight_value = request.getParameter("weight_value");
String remark = request.getParameter("remark");
restTemplate.getForObject(getURLBaseFromTxt_API(currentSession) + "/performance/insert-mstformatheaderdetail"
+ "?format_id=" + format_id
+ "&aspect=" + aspect
+ "&indicator_id=" + indicator_id
+ "&weight_value=" + weight_value
+ "&remark=" + remark
+ "&createdby=" + userId ,
GenericDataGrid.class);
return new RedirectView("/bukihcisapp/web/performance/grid-mstformatheaderdetail?ranNum=" + ranNumber + "&u=" + uName + "&userId=" + userId + "&moduleId=" + moduleId + "&formatid=" + format_id + "&aspect=" + aspect);
}
private RedirectView createMstFormatHeaderDetail(HttpServletRequest request, HttpServletResponse response,
@RequestParam(value = "ranNum", required = false) String ranNum,
@RequestParam(value = "u", required = false) String uName,
@RequestParam(value = "moduleId", required = false) String moduleId) throws ParseException, UnsupportedEncodingException {
RestTemplate restTemplate = new RestTemplate();
ranNumber = ranNum == null ? ranNumber : ranNum;
HttpSession currentSession = request.getSession(false) == null ? request.getSession() : request.getSession(false);
String userId = request.getParameter("userId");
String format_id = request.getParameter("format_id");
String aspect = request.getParameter("aspectid");
String indicator_id = request.getParameter("indicator_id");
String weight_value = request.getParameter("weight_value");
String remark = request.getParameter("remark");
restTemplate.getForObject(getURLBaseFromTxt_API(currentSession) + "/performance/insert-mstformatheaderdetail"
+ "?format_id=" + format_id
+ "&aspect=" + aspect
+ "&indicator_id=" + indicator_id
+ "&weight_value=" + weight_value
+ "&remark=" + remark
+ "&createdby=" + userId ,
GenericDataGrid.class);
return new RedirectView("/bukihcisapp/web/performance/grid-mstformatheaderdetail?ranNum=" + ranNumber + "&u=" + uName + "&userId=" + userId + "&moduleId=" + moduleId + "&formatid=" + format_id + "&aspect=" + aspect);
}
Controller API :
@RequestMapping(value = {"/insert-mstformatheaderdetail"}, method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> createMstFormatHeaderDetail(HttpServletRequest request) throws UnsupportedEncodingException {
LinkedHashMap<String, String> mappedParam = new LinkedHashMap<>();
String formatid = request.getParameter("format_id");
String aspect = request.getParameter("aspect");
String indicatorid = request.getParameter("indicator_id");
String weightvalue = request.getParameter("weight_value");
String remark = request.getParameter("remark");
String createdby = request.getParameter("createdby");
mappedParam.put("formatId", (formatid));
mappedParam.put("aspect", (aspect));
mappedParam.put("indicatorId", (indicatorid));
mappedParam.put("weightValue", (weightvalue));
mappedParam.put("remark", (remark));
mappedParam.put("creatorId", (createdby));
try {
performanceSvc.insertMstFormatheaderDetail(mappedParam);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return new ResponseEntity(HttpStatus.OK);
}
public ResponseEntity<Object> createMstFormatHeaderDetail(HttpServletRequest request) throws UnsupportedEncodingException {
LinkedHashMap<String, String> mappedParam = new LinkedHashMap<>();
String formatid = request.getParameter("format_id");
String aspect = request.getParameter("aspect");
String indicatorid = request.getParameter("indicator_id");
String weightvalue = request.getParameter("weight_value");
String remark = request.getParameter("remark");
String createdby = request.getParameter("createdby");
mappedParam.put("formatId", (formatid));
mappedParam.put("aspect", (aspect));
mappedParam.put("indicatorId", (indicatorid));
mappedParam.put("weightValue", (weightvalue));
mappedParam.put("remark", (remark));
mappedParam.put("creatorId", (createdby));
try {
performanceSvc.insertMstFormatheaderDetail(mappedParam);
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return new ResponseEntity(HttpStatus.OK);
}
Svc :
public Object insertMstFormatheaderDetail(LinkedHashMap paramMapped) throws SQLException {
String storedProcName = "spperformance_mst_format_detail_insert";
return genericDao.getData(storedProcName, paramMapped);
}
String storedProcName = "spperformance_mst_format_detail_insert";
return genericDao.getData(storedProcName, paramMapped);
}
Stored Procedure :
SET QUOTED_IDENTIFIER ON
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[spperformance_mst_format_detail_insert]
@formatId INT,
@aspect INT,
@indicatorId INT,
@weightValue INT,
@remark VARCHAR(200),
@creatorId VARCHAR(50)
AS
SET NOCOUNT ON
INSERT INTO dbo.performance_mst_format_detail
( format_id ,
aspect ,
indicator_id ,
weight_value ,
remark ,
status_active ,
createdby ,
createddate ,
modifiedby ,
modifieddate
)
VALUES
( @formatId , -- format_id - int
@aspect , -- aspect - int
@indicatorId , -- indicator_id - int
@weightValue , -- weight_value - int
@remark , -- remark - varchar(200)
1 , -- status_active - bit
@creatorId , -- createdby - varchar(50)
GETDATE() , -- createddate - datetime
@creatorId , -- modifiedby - varchar(50)
GETDATE() -- modifieddate - datetime
)
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[spperformance_mst_format_detail_insert]
@formatId INT,
@aspect INT,
@indicatorId INT,
@weightValue INT,
@remark VARCHAR(200),
@creatorId VARCHAR(50)
AS
SET NOCOUNT ON
INSERT INTO dbo.performance_mst_format_detail
( format_id ,
aspect ,
indicator_id ,
weight_value ,
remark ,
status_active ,
createdby ,
createddate ,
modifiedby ,
modifieddate
)
VALUES
( @formatId , -- format_id - int
@aspect , -- aspect - int
@indicatorId , -- indicator_id - int
@weightValue , -- weight_value - int
@remark , -- remark - varchar(200)
1 , -- status_active - bit
@creatorId , -- createdby - varchar(50)
GETDATE() , -- createddate - datetime
@creatorId , -- modifiedby - varchar(50)
GETDATE() -- modifieddate - datetime
)
GO
Comments
Post a Comment