2018년 1월 10일 수요일
C# - return new Tuple
//---------------------------------------------------------------------
public static T ConvertDataToModel<T>(DataRow dr) where T : class, new()
{
if (dr == null)
{
return null;
}
T toObj = new T();
foreach (var prop in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
{
if (dr.Table.Columns.Contains(prop.Name) && !dr[prop.Name].Equals(DBNull.Value))
{
prop.SetValue(toObj, dr[prop.Name], null);
}
}
return toObj;
}
public static T[] ConvertDataToModelList<T>(DataTable dt) where T : class, new()
{
if (dt == null || dt.Rows.Count <= 0)
{
return null;
}
return dt.AsEnumerable().Select(x => ConvertDataToModel<T>(x)).ToArray();
}
//---------------------------------------------------------------------
var cnt = Convert.ToInt32(ds.Tables[0].Rows[0]["CNT"]);
var modelList = ModelUtil.ConvertDataToModelList<CouponMember>(ds.Tables[1]);
return new Tuple<int, CouponMember[]>(cnt, modelList);
//---------------------------------------------------------------------
[HttpPost]
public JsonResult GetDiscountCoupon(int totalProdPrice, int page, string[] venIds)
{
const int RowCnt = 5;
var bizCoupon = BizFactory.GetInstance<BizCoupon>();
var discountCoupons = bizCoupon.GetDiscountCouponMemberList(MisoMember.MemIdx, totalProdPrice, page, RowCnt, venIds); //몇개안나와서 다가져와서 처리
return Json(new { Cnt = discountCoupons.Item1, List = discountCoupons.Item2 });
}
//---------------------------------------------------------------------
function makeDiscountPopup(page) {
$.ajax({
url: "@Url.Action("GetDiscountCoupon", "Order")",
async: false,
type: "POST",
contentType: "application/json",
data: "{totalProdPrice: " + _totalProdPrice + ", page: " + page + ", venIds: [@Html.Raw(venIdsStr)]}",
success: function (result) {
if (result.Cnt == 0) {
$("#myCouponPopupClose").click();
alert("사용가능한 쿠폰이 없습니다.");
return false;
}
var htmlStr = new Array();
for(var idx = 0; idx < result.List.length; idx++) {
var item = result.List[idx];
var disPrice;
if (item.DIS_STATE == 1) { //비율
disPrice = item.DIS_PRICE + "%";
}
else {
disPrice = item.DIS_PRICE.toNumberFormat() + "원";
}
htmlStr.push('<tr><td scope="row" class="first"><input type="radio" name="myCouponItem" data-venNickname="' + item.VEN_NICKNAME + '" data-venid="' + item.DIS_VEN_ID + '" data-idx="' + item.IDX + '" data-copidx="' + item.COP_IDX + '" data-dissetprice="' + item.DIS_SETPRICE + '" data-disstate="' + item.DIS_STATE + '" data-disprice="' + item.DIS_PRICE + '" data-kind="' + item.COP_KIND + '" data-prodlist="' + item.PROD_LIST + '" /></td>');
htmlStr.push('<td class="left"><img src="/images/order/img_coupon.gif" alt="쿠폰" style="width:69px;height:34px;" />' + item.COP_NAME + '</td>');
htmlStr.push('<td>');
htmlStr.push(item.DIS_SETPRICE.toNumberFormat() + '원 이상');
if (item.DIS_VEN_ID != '0') {
htmlStr.push('<br/> (' + item.VEN_NICKNAME + ')');
}
htmlStr.push('</td>');
htmlStr.push('<td>' + disPrice + '</td>');
htmlStr.push('<td>' + item.ISSUE_DATE.toDateFormat() + '일 부터 ' + item.COP_APPLY_MONTH + '일간</td></tr>');
}
$("#tbdMyCoupon").html(htmlStr.join(''));
pager.makePage("pager", result.Cnt, 5, 5, page);
},
error: function() {
alert("실패");
}
});
}
//---------------------------------------------------------------------
피드 구독하기:
댓글 (Atom)
Flutter #0
[Flutter 교육] Dart vs JavaScript 타입 시스템 비교 1. 기본 타입 차이 숫자 타입 // Dart int integerNumber = 42; // 정수 double floatingPoint = 3.14; // 부...
-
11 SQL Client for Productive Database Administration & Development Working as a web developer or database administrator, often n...
-
JsonUtility 유니티 5.3 이상부터 JsonUtility를 지원한다. 외부 JSON 라이브러리가 필요 없다. < JsonUtility 멤버 함수 > FromJson : JSON을 오브젝트로 변환한다. 오브젝트를 생성...
댓글 없음:
댓글 쓰기