Example #1
0
        /// <summary>
        /// 구매 확정을 위한 주문 내역 전송
        /// </summary>
        /// <param name="aReceiptId"></param>
        /// <param name="aPurchaseList"></param>
        /// <returns></returns>
        public static DTOPurchasesResponse API_PostPurchaseSuccess(string aReceiptId, DTOPurchasesRequest aPurchasesRequest)
        {
            //================================================================================
            // POST http://10.1.203.12:8080/api/caffe/purchases/purchase/receipt/{receipt_id}
            //================================================================================

            //VOMenu menu = new VOMenu
            //{
            //    category = 100,
            //    code = 1,
            //    price = 1000,
            //    type = "HOT",
            //    size = "REGULAR",
            //    count = 5
            //};

            //DTOPurchasesRequest obj = new DTOPurchasesRequest
            //{
            //    purchases = new List<VOMenu>
            //    {
            //        new VOMenu
            //        {
            //            category = 100,
            //            code = 1,
            //            price = 1000,
            //            type = "HOT",
            //            size = "REGULAR",
            //            count = 5
            //        },
            //        new VOMenu
            //        {
            //            category = 200,
            //            code = 8,
            //            price = 1500,
            //            type = "HOT",
            //            size = "REGULAR",
            //            count = 1
            //        },
            //    }
            //};
            //
            //string json = JsonConvert.SerializeObject(aPurchasesRequest);

            RestSharp.RestClient  client  = new RestSharp.RestClient(URL_DCCAFFE);
            RestSharp.RestRequest request = new RestSharp.RestRequest();
            request.AddHeader("Content-Type", "application/json;charset=UTF-8");

            request.Method        = RestSharp.Method.POST;
            request.RequestFormat = RestSharp.DataFormat.Json;
            request.Resource      = URI_POST_PURCHASE;

            request.AddParameter("receipt_id", aReceiptId, RestSharp.ParameterType.UrlSegment);
            request.AddJsonBody(aPurchasesRequest);

            //----------------------------------------
            var t1 = client.ExecuteTaskAsync(request);

            t1.Wait();

            //----------------
            // error handling
            if (t1.Result.ErrorException != null)
            {
                System.Diagnostics.Debug.WriteLine("[RESPONSE] " + t1.Result.Content);
                return(null);
            }

            string json = t1.Result.Content;

            //--------------
            // debug output
            json = JsonFormatting(json);
            System.Diagnostics.Debug.WriteLine("[RESPONSE] " + json);

            //-----------------------
            // desirialized json data
            DTOPurchasesResponse dto = new DTOPurchasesResponse();

            try
            {
                dto      = JsonConvert.DeserializeObject <DTOPurchasesResponse>(json);
                dto.code = (int)t1.Result.StatusCode;
            }
            catch (Exception ex)
            {
                dto = null;
                System.Diagnostics.Debug.WriteLine("[ERROR] " + ex.Message);
            }

            return(dto);
        }
Example #2
0
        /// <summary>
        /// 주문 완료 버튼 클릭
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnOkButton(object sender, EventArgs e)
        {
            //-------------------------------------------------------------------------------------
            using (FormMessageBox dlg = new FormMessageBox())
            {
                {
                    dlg.Left        = 1430;
                    dlg.Top         = this.Location.X + (ClientSize.Height / 2) - 100;
                    dlg.XColorTitle = Color.FromArgb(73, 156, 188);
                }
                DialogResult dlgResult =
                    dlg.ShowDialog(@"구매를 완료 하시겠습니까?", @"최종 확인", CustomMessageBoxButtons.YesNo);

                if (dlgResult == DialogResult.Yes)
                {
                    //-----------------------------------------------------------------------------
                    // 영수증 프린터 연결 확인
                    //if (!ReceiptController.Instance.ConnectToUSB()) // 영수증 프린터 연결 실패
                    if (ReceiptController.Instance.GetStatus() != PRINT_STATUS.BXL_STS_CASHDRAWER_HIGH)
                    {
                        using (FormMessageBox dlgPrint = new FormMessageBox())
                        {
                            {
                                dlgPrint.Left        = 1430;
                                dlgPrint.Top         = this.Location.X + (ClientSize.Height / 2) - 100;
                                dlgPrint.XColorTitle = Color.FromArgb(73, 156, 188);
                            }

                            PRINT_STATUS printStatus = ReceiptController.Instance.GetStatus();

                            DialogResult dlgPrintResult =
                                dlgPrint.ShowDialog(@"영수증 프린터를 점검해 주세요." + Environment.NewLine + printStatus.ToString(), @"영수증 프린터 점검", CustomMessageBoxButtons.OK);
                        }
                        return;
                    }

                    //-----------------------------------------------------------------------------
                    // 구매 확정 API 호출
                    DTOPurchasesRequest  _req = GetDTOPurchaseRequest();
                    DTOPurchasesResponse _rsp = APIController.API_PostPurchaseSuccess(XReceiptId.ToString(), _req);
                    //-----------------------------------------------------------------------------

                    if (_rsp.code == 200)
                    {
                        // 영수증 출력
                        string _strUserInfo  = string.Format("{0}님 ({1})", XName, XCompany);
                        string _strPayType   = "";
                        string _totalPayment = "0";
                        if (XPayType == PAY_TYPE.MonthlyDeduction)
                        {
                            _strPayType = "월말공제";

                            // 결제 총액 계산
                            _totalPayment = (_rsp.total_price - _rsp.total_dc_price).ToString("N0");
                        }
                        else if (XPayType == PAY_TYPE.CustomerPayment)
                        {
                            _strPayType = "손님결제";

                            // 손님결제일 경우, 영수증 결제 총액을 0원으로 표시
                            _totalPayment = "0";
                        }


                        string             _strCurrentDateTime = Utilities.DateTimeFormatString.getNowDateTimeFormatString();
                        List <VOPrintMenu> _printMenuList      = GetPurchasePrintObject();

                        ReceiptController.Instance.Print(
                            _strUserInfo,
                            XReceiptId.ToString(),
                            _strPayType,
                            _printMenuList,
                            _strCurrentDateTime,
                            _rsp.total_price.ToString("N0"),        // 구매 총액
                            _rsp.total_dc_price.ToString("N0"),     // 할인 총액
                            _totalPayment                           // 결제 총액
                            );

                        // 완료
                        OnPageSuccess();
                    }
                    else
                    {
                        //-------------------------------------------------------------------------
                        using (FormMessageBox dlg1 = new FormMessageBox())
                        {
                            {
                                dlg1.Left        = 1430;
                                dlg1.Top         = this.Location.X + (ClientSize.Height / 2) - 100;
                                dlg1.XColorTitle = Color.FromArgb(73, 156, 188);
                            }
                            DialogResult dlgResult1 =
                                dlg.ShowDialog(@"구매 처리를 완료하지 못했습니다." + Environment.NewLine + _rsp.reason, @"구매 확정 처리 결과", CustomMessageBoxButtons.OK);
                        }//using
                    }
                }
            }//using
        }