private void ocmCreate_Click(object sender, EventArgs e) { oCallAPI = new cCallAPI(); try { cmlCouponRes oCouponRes = new cmlCouponRes(); cmlCouponReq oCouponReq = new cmlCouponReq(); oCouponReq.tCML_WhoUpd = otbWhoUpd.Text; oCouponReq.tCML_WhoIns = otbWhoIns.Text; oCouponReq.tCML_StmCode = otbStmCode.Text; oCouponReq.tCML_TmnNum = otbTmnNum.Text; oCouponReq.tCML_CpnCode = otbCpnCode.Text; oCouponReq.tCML_CpnExp = otbCpnExp.Text; oCouponReq.tCML_CpnAmt = otbCpnAmt.Text; // otbUrl.Text = "http://172.16.30.151:9000/api/coupon/Create"; otbUrl.Text = "http://172.16.30.188:90/api/coupon/Create"; // otbResult.Text = oCallAPI.C_SETtCreateCoupon(otbUrl.Text, oCouponReq, nW_TimeOut); otbResult.Text = oCallAPI.C_SETtCreateCoupon(otbUrl.Text, otbWhoIns.Text, otbWhoIns.Text, otbStmCode.Text, otbTmnNum.Text, otbCpnCode.Text, otbCpnExp.Text, otbCpnAmt.Text, nW_TimeOut); } catch (Exception oEx) { MessageBox.Show("wMain : ocmCreate_Click//" + oEx.Message); } }
//ฟังก์ชัน OverLoad /// <summary> /// รับข้อมูลในการสร้างคูปองจาก Post แล้วแปลงข้อมูลเป็นJson /// </summary> /// <param name="ptUrl"></param> /// <param name="poCouponReq"></param> /// <param name="pnTimeOut"></param> /// <returns></returns> //public String C_SETtCreateCoupon(string ptUrl, cmlCouponReq poCouponReq, int pnTimeOut) //{ // try // { // oCouponRes = new cmlCouponRes(); // nW_TimeOut = pnTimeOut; // oCouponRes = C_GEToMSgReqCreate(ptUrl, poCouponReq); // switch (oCouponRes.tCML_CpnMSg) // { // case "Add Data Successful": oCouponRes.tCML_CpnMSg = "1"; break; // case "หมายเลขคูปองซ้ำ": oCouponRes.tCML_CpnMSg = "2"; break; // } // return oCouponRes.tCML_CpnMSg; // } // catch (Exception oEx) // { // throw oEx; // } //} public String C_SETtCreateCoupon(string ptUrl, string ptWhoUpd, string ptWhoIns, string ptStmCode, string ptTmnNum, string ptCpnCode, string ptCpnExp, string ptCpnAmt, int pnTimeOut) { try { oCouponReq = new cmlCouponReq(); oCouponRes = new cmlCouponRes(); oCouponReq.tCML_WhoUpd = ptWhoUpd; oCouponReq.tCML_WhoIns = ptWhoIns; oCouponReq.tCML_StmCode = ptStmCode; oCouponReq.tCML_TmnNum = ptTmnNum; oCouponReq.tCML_CpnCode = ptCpnCode; oCouponReq.tCML_CpnExp = ptCpnExp; oCouponReq.tCML_CpnAmt = ptCpnAmt; nW_TimeOut = pnTimeOut; oCouponRes = C_GEToMSgReqCreate(ptUrl, oCouponReq); switch (oCouponRes.tCML_CpnMSg) { case "Add Data Successful": oCouponRes.tCML_CpnMSg = "1"; break; case "หมายเลขคูปองซ้ำ": oCouponRes.tCML_CpnMSg = "2"; break; } return(oCouponRes.tCML_CpnMSg); } catch (Exception oEx) { throw oEx; } }
/// <summary> /// ขาใช้คูปอง Sale /Refund /Void /// </summary> /// <param name="ptUrl"></param> /// <param name="ptCpnCode"></param> /// <param name="pnTimeOut"></param> /// <returns></returns> public String C_SETtUseCoupon(string ptUrl, string ptCpnCode, int pnTimeOut) { // String[] aCouponRes; try { nW_TimeOut = pnTimeOut; oCouponRes = new cmlCouponRes(); oCouponCode = new cmlCouponCode { tCML_CpnCode = ptCpnCode }; oCouponRes = C_GEToMSgReq(ptUrl, oCouponCode); //aCouponRes = new String[] { oCouponRes.tCML_StatusCode , oCouponRes.tCML_StatusDescTH // , oCouponRes.tCML_StatusDescEN , oCouponRes.tCML_PrintDesc // , oCouponRes.tCML_RefCode , oCouponRes.tCML_TranDateTime , oCouponRes.tCML_CpnAmt ,oCouponRes.tCML_CpnMSg}; //return aCouponRes; // Arrey var tResult = oCouponRes.tCML_StatusCode + ";" + oCouponRes.tCML_StatusDescTH + ";" + oCouponRes.tCML_StatusDescEN + ";" + oCouponRes.tCML_PrintDesc + ";" + oCouponRes.tCML_RefCode + ";" + oCouponRes.tCML_TranDateTime + ";" + oCouponRes.tCML_CpnAmt + ";" + oCouponRes.tCML_CpnMSg; return(tResult); // String } catch (Exception oEx) { throw oEx; } }
public IHttpActionResult POSToSale([FromBody] cmlCouponCode poPara) { try { oC_CouponRes = new cmlCouponRes(); oC_CouponReq = new cmlCouponReq(); oC_CouponSale = new cCouponSale(); oC_CouponLog = new cCouponLog(); if (ModelState.IsValid) { oC_CouponRes = oC_CouponSale.c_CHKoCouponSale(poPara); return(Json(oC_CouponRes)); } else { return(Json(oC_CouponRes)); } } catch (Exception oEx) { log.Error(cExtensionMessageError.C_GEToErrorException(oEx)); return(Json(new { ModelState = ModelState.C_GETtErrorModaleSta(), Exception = cExtensionMessageError.C_GEToErrorException(oEx) })); } finally { oC_CouponLog.CL_SETxCouponLog(oC_CouponReq, poPara, oC_CouponRes, null); } }
public IHttpActionResult POSToCreate([FromBody] cmlCouponReq poPara) { try { oC_CouponLog = new cCouponLog(); oC_CouponRes = new cmlCouponRes(); oC_CouponCreate = new cCouponCreate(); if (ModelState.IsValid) { tC_Message = oC_CouponCreate.c_SETtCouponCreate(poPara); return(Json(new { tcml_CpnMSg = tC_Message })); // return Json(new { Message = tMessage, AccessToken = this.oAccessToKen.C_GETtGennerateAccessToken(poPara.tcml_WhoIns,5) }); } else { log.Warn(ModelState.C_GETtErrorModaleSta()); return(Json(ModelState.C_GETtErrorModaleSta())); } } catch (Exception oEx) { log.Error(cExtensionMessageError.C_GEToErrorException(oEx) + ModelState.C_GETtErrorModaleSta()); return(Json(new { ModelState = ModelState.C_GETtErrorModaleSta(), Exception = cExtensionMessageError.C_GEToErrorException(oEx) })); } finally { oC_CouponLog.CL_SETxCouponLog(poPara, null, oC_CouponRes, tC_Message); } }
/// <summary> /// ยกเลิกหมายเลขคูปอง /// </summary> /// <param name="poPara"></param> /// <returns></returns> public cmlCouponRes c_SEToCouponVoid(cmlCouponCode poPara) { cmlCouponCode oCouponCode = new cmlCouponCode(); cmlCouponRes oCouponRes = new cmlCouponRes(); oCouponCode = poPara; StringBuilder oSql; try { oSql = new StringBuilder(); oSql.AppendLine("SELECT FTCpnCode"); oSql.AppendLine("FROM TPSTCpnStatus WITH(noLOCK)"); oSql.AppendLine("WHERE FTCpnCode = '" + oCouponCode.tCML_CpnCode + "'"); oSql.AppendLine("AND FTCpnUseSta ='0'"); if (cCNSP.SP_GEToDbTbl(oSql.ToString()).Rows.Count == 0) { log.Info(cCNMS.tMS_NotfoundStatusDescENVoid); oCouponRes.tCML_StatusCode = cCNMS.tMS_NotfoundStatusCodeVoid; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_NotfoundStatusDescTHVoid; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_NotfoundStatusDescENVoid; oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); } else { log.Info(cCNMS.tMS_SuccessStatusDescENVoid); oCouponRes.tCML_StatusCode = cCNMS.tMS_SuccessStatusCodeVoid; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_SuccessStatusDescTHVoid; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_SuccessStatusDescENVoid; oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); oSql = new StringBuilder(); oSql.AppendLine("UPDATE TPSTCpnStatus WITH(ROWLOCK)"); oSql.AppendLine("SET FTCpnUseSta ='2'"); oSql.AppendLine("WHERE FTCpnCode ='" + oCouponCode.tCML_CpnCode + "'"); var nResult = cCNSP.SP_SETnDbTbl(oSql.ToString()); if (nResult > 0) { return(oCouponRes); } else { log.Info(cCNMS.tMS_ValidStatusDescENSale); oCouponRes.tCML_StatusCode = "505"; oCouponRes.tCML_StatusDescTH = "ยกเลิกสถานะคูปองไม่สำเร็จ"; oCouponRes.tCML_StatusDescEN = "Update Failed"; oCouponRes.tCML_CpnAmt = null; oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); } } } catch (SqlException oEx) { log.Error(cExtensionMessageError.C_GEToErrorException(oEx)); throw cExtensionMessageError.C_GEToErrorException(oEx); } }
/// <summary> /// /// </summary> /// <param name="ptUrl"></param> /// <param name="poCouponReq"></param> /// <returns></returns> private cmlCouponRes C_GEToMSgReqCreate(string ptUrl, cmlCouponReq poCouponReq) { try { oCouponRes = new cmlCouponRes(); var tJsonCouponReq = JsonConvert.SerializeObject(poCouponReq, Formatting.Indented); var aJsonCouponReq = Encoding.UTF8.GetBytes(tJsonCouponReq); var oHttpWebREQ = C_SEToHttpWebRequest(ptUrl, "POST", aJsonCouponReq); oCouponRes = C_GEToHttpWebResponse(oHttpWebREQ); return(oCouponRes); } catch (WebException oEx) { oCouponRes.tCML_CpnMSg = "404"; return(oCouponRes); } }
private void ocmVoid_Click(object sender, EventArgs e) { try { oFoodLandCallAPI = new cFoodLandCallAPI(); cmlCouponRes oCouponRes = new cmlCouponRes(); otbUrl.Text = otbUrl.Text = tC_Url + "Void".Trim(); oCouponRes = oFoodLandCallAPI.C_SEToCouponSta(otbUrl.Text, otbSendCoupon.Text); otbStatusCode.Text = oCouponRes.tCML_StatusCode; otbStatusDescTH.Text = oCouponRes.tCML_StatusDescTH; otbStatusDescEN.Text = oCouponRes.tCML_StatusDescEN; otbPrintDesc.Text = oCouponRes.tCML_PrintDesc; otbRefCode.Text = oCouponRes.tCML_RefCode; otbTranDateTime.Text = oCouponRes.tCML_TranDateTime; } catch (Exception oEx) { MessageBox.Show("wMain : ocmVoid_Click//" + oEx.Message); } }
private void ocmCreate_Click(object sender, EventArgs e) { try { oFoodLandCallAPI = new cFoodLandCallAPI(); cmlCouponRes oCouponRes = new cmlCouponRes(); cmlCouponReq oCouponReq = new cmlCouponReq(); otbUrl.Text = tC_Url + "Create"; oCouponReq.tCML_WhoUpd = otbWhoUpd.Text; oCouponReq.tCML_WhoIns = otbWhoIns.Text; oCouponReq.tCML_StmCode = otbStmCode.Text; oCouponReq.tCML_TmnNum = otbTmnNum.Text; oCouponReq.tCML_CpnCode = otbCpnCode.Text; oCouponReq.tCML_CpnExp = otbCpnExp.Text; oCouponReq.tCML_CpnAmt = otbCpnAmt.Text; oCouponRes = oFoodLandCallAPI.C_SEToCreateCoupon(otbUrl.Text.Trim(), oCouponReq); otbResult.Text = oCouponRes.tCML_CpnMSg; } catch (Exception oEx) { MessageBox.Show("wMain : ocmCreate_Click//" + oEx.Message); } }
public void CL_SETxCouponLog(cmlCouponReq poCouponReq, cmlCouponCode poCouponCode, cmlCouponRes poCouponRes, string ptMessage) { StringBuilder oSql; string tCouponReq; string tCouponRes; try { if (poCouponReq == null) { tCouponReq = new JavaScriptSerializer().Serialize(poCouponCode); } else { tCouponReq = new JavaScriptSerializer().Serialize(poCouponReq); } if (ptMessage == null) { tCouponRes = new JavaScriptSerializer().Serialize(poCouponRes); } else { tCouponRes = new JavaScriptSerializer().Serialize(ptMessage); } oSql = new StringBuilder(); oSql.AppendLine("INSERT INTO TPSTLogPromoCpn"); oSql.AppendLine("("); oSql.AppendLine("FDDateIns"); oSql.AppendLine(",FTTimeIns"); oSql.AppendLine(",FTWhoIns"); oSql.AppendLine(",FTRemark"); oSql.AppendLine(",FTStmCode"); oSql.AppendLine(",FTTmnNum"); oSql.AppendLine(",FTLogCode"); oSql.AppendLine(",FTShdTransNo"); oSql.AppendLine(",FTShdTransType"); oSql.AppendLine(",FTServiceName"); oSql.AppendLine(",FTReqPara"); oSql.AppendLine(",FTResPara"); oSql.AppendLine(",FTStatusCode"); oSql.AppendLine(",FTStatusDescTH"); oSql.AppendLine(",FTStatusDescEN"); oSql.AppendLine(",FTPrintDesc"); oSql.AppendLine(",FTRefCode"); oSql.AppendLine(",FTTranDateTime"); oSql.AppendLine(")"); oSql.AppendLine("VALUES"); oSql.AppendLine("("); oSql.AppendLine("CONVERT([VARCHAR](10),GETDATE(),(121))"); oSql.AppendLine(",CONVERT(VARCHAR(8),GETDATE(),108)"); oSql.AppendLine(",'admin'"); oSql.AppendLine(",''"); oSql.AppendLine(",'0300'"); oSql.AppendLine(",'" + poCouponReq.tCML_TmnNum + "'"); oSql.AppendLine(",'20170512170500'"); oSql.AppendLine(",'00332'"); oSql.AppendLine(",'01'"); oSql.AppendLine(",'ServiceName'"); oSql.AppendLine(",'" + tCouponReq + "'"); oSql.AppendLine(",'" + tCouponRes + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_StatusCode + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_StatusDescTH + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_StatusDescEN + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_PrintDesc + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_RefCode + "'"); oSql.AppendLine(",'" + poCouponRes.tCML_TranDateTime + "'"); oSql.AppendLine(")"); cCNSP.SP_GEToDbTbl(oSql.ToString()); } catch (SqlException oEx) { log.Error(oEx.Message); } }
/// <summary> /// ตรวจสอบสถานะ Coupon /// </summary> /// <param name="poPara"></param> /// <returns></returns> public cmlCouponRes c_CHKoCouponSale(cmlCouponCode poPara) { cmlCouponCode oCouponCode = new cmlCouponCode(); cmlCouponRes oCouponRes = new cmlCouponRes(); oCouponCode = poPara; DateTime oCoupondate; StringBuilder oSql, oSQL; try { oSQL = new StringBuilder(); oSQL.AppendLine("SELECT FTCpnCode,FCCpnAmt"); oSQL.AppendLine("FROM TPSTCpnStatus WITH(noLOCK)"); oSQL.AppendLine("WHERE FTCpnCode ='" + oCouponCode.tCML_CpnCode + "'"); if (cCNSP.SP_GEToDbTbl(oSQL.ToString()).Rows.Count == 0) { log.Info(cCNMS.tMS_NotfoundStatusDescENSale); oCouponRes.tCML_StatusCode = cCNMS.tMS_NotfoundStatusCodeSale; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_NotfoundStatusDescTHSale; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_NotfoundStatusDescENSale; oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy "); return(oCouponRes); } else { oSql = new StringBuilder(); oSql.AppendLine("SELECT FTCpnUseSta"); oSql.AppendLine("FROM TPSTCpnStatus WITH(noLOCK)"); oSql.AppendLine("WHERE FTCpnCode ='" + oCouponCode.tCML_CpnCode + "'"); switch (cCNSP.SP_GEToDbTbl(oSql.ToString()).Rows[0]["FTCpnUseSta"].ToString()) { case "0": oSql = new StringBuilder(); oSql.AppendLine("SELECT FDCpnExp"); oSql.AppendLine("FROM TPSTCpnStatus WITH(noLOCK)"); oSql.AppendLine("WHERE FTCpnCode ='" + oCouponCode.tCML_CpnCode + "'"); oCoupondate = DateTime.Parse(cCNSP.SP_GEToDbTbl(oSql.ToString()).Rows[0]["FDCpnExp"].ToString()); if (oCoupondate > DateTime.Now) { log.Info(cCNMS.tMS_ValidStatusDescENSale); oCouponRes.tCML_StatusCode = cCNMS.tMS_ValidStatusCodeSale; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_ValidStatusDescTHSale; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_ValidStatusDescENSale; oCouponRes.tCML_CpnAmt = cCNSP.SP_GEToDbTbl(oSQL.ToString()).Rows[0]["FCCpnAmt"].ToString(); oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); log.Info("UPDATE TPSTCpnStatus = 1"); oSql = new StringBuilder(); oSql.AppendLine("UPDATE TPSTCpnStatus WITH(ROWLOCK)"); oSql.AppendLine("SET FTCpnUseSta ='1'"); oSql.AppendLine("WHERE FTCpnCode ='" + oCouponCode.tCML_CpnCode + "'"); var nResult = cCNSP.SP_SETnDbTbl(oSql.ToString()); if (nResult > 0) { return(oCouponRes); } else { log.Info(cCNMS.tMS_ValidStatusDescENSale); oCouponRes.tCML_StatusCode = "505"; oCouponRes.tCML_StatusDescTH = "ปรับสถานะการใช้คูปองไม่สำเร็จ"; oCouponRes.tCML_StatusDescEN = "Update Failed"; oCouponRes.tCML_CpnAmt = null; oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); } } else { log.Info(cCNMS.tMS_ExpiredStatusDescENSale); oCouponRes.tCML_StatusCode = cCNMS.tMS_ExpiredStatusCodeSale; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_ExpiredStatusDescTHSale; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_ExpiredStatusDescENSale; oCouponRes.tCML_CpnAmt = cCNSP.SP_GEToDbTbl(oSQL.ToString()).Rows[0]["FCCpnAmt"].ToString(); oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); } case "1": log.Info(cCNMS.tMS_UsedStatusDescENSale); oCouponRes.tCML_StatusCode = cCNMS.tMS_UsedStatusCodeSale; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_UsedStatusDescTHSale; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_UsedStatusDescENSale; oCouponRes.tCML_CpnAmt = cCNSP.SP_GEToDbTbl(oSQL.ToString()).Rows[0]["FCCpnAmt"].ToString(); oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); case "2": log.Info(cCNMS.tMS_UsedStatusDescENSale); oCouponRes.tCML_StatusCode = cCNMS.tMS_VoidStatusCodeSale; oCouponRes.tCML_StatusDescTH = cCNMS.tMS_VoidStatusDescTHSale; oCouponRes.tCML_StatusDescEN = cCNMS.tMS_VoidStatusDescENSale; oCouponRes.tCML_CpnAmt = cCNSP.SP_GEToDbTbl(oSQL.ToString()).Rows[0]["FCCpnAmt"].ToString(); oCouponRes.tCML_TranDateTime = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"); return(oCouponRes); } } return(oCouponRes); } catch (SqlException oEx) { log.Error(cExtensionMessageError.C_GEToErrorException(oEx)); throw cExtensionMessageError.C_GEToErrorException(oEx); } }