private string CalculateRiderWP(string PlanCode, string PaymentMethod, string Age, string Gender, string Amount, string MainPremium)
    {
        //Call WS_SQM_CalculateService.CalculateWPRider(MainInsured (decimal), MainPremium (decimal), CustomerGender (char), CustomerAge (int), CustomerOccupationGroup (string), PaymentMethod (int), SelectedPlanCode (string), Channel (int));
        //ระบุ Channel เป็นรหัสช่องทางที่กำหนด เช่น 6, 32
        //ระบุ PaymentMethod เป็น 12 (รายปี และชำระครั้งเดียว)/06 (ราย 6 เดือน)/03 (ราย 3 เดือน)/01 (รายเดือน)
        //ระบุ CustomerGender เป็น F/M ,
        //ระบุ CustomerOccupationGroup เป็น 001

        string result = "";

        int vChannel = 32;
        int vPaymentMethod = PaymentMethod.Trim() == "OT" ? 12 : Convert.ToInt32(PaymentMethod);
        int vAge = Convert.ToInt32(Age);
        char vGender = Gender == "F" ? 'F' : 'M';
        decimal vMainInsured = Convert.ToDecimal(Amount);
        string vOccupationGroup = "001";

        //// คำนวณเบี้ยประกันของแบบประกันหลักก่อน เพื่อเอาไปใช้คำนวณสัญญาเพิ่มเติม WP
        //string mainPreium = this.CalculatePremium(PlanCode, PaymentMethod, Age, Gender, Amount);
        //decimal vMainPremium = Convert.ToDecimal(mainPreium);
        // หนึ่งบอกไม่ต้องคำนวณเบี้ยประกันของแบบประกันหลักก่อนก็ได้
        decimal vMainPremium = Convert.ToDecimal(MainPremium);

        try
        {
            MTL.NETWS_ForSmartProposal.WS_SQM_CalculateService wsobj = new MTL.NETWS_ForSmartProposal.WS_SQM_CalculateService();
            MTL.NETWS_ForSmartProposal.RiderValueElementMobile resp = new MTL.NETWS_ForSmartProposal.RiderValueElementMobile();
            resp = wsobj.CalculateWPRider(vMainInsured, vMainPremium, vGender, vAge, vOccupationGroup, vPaymentMethod, PlanCode, vChannel);
            result = resp.Rider_TotalPremium.Trim();
        }
        catch (Exception ex)
        {
            result = "notcomplete_" + ex.Message.ToString();
        }

        return result;
    }
    public CalculatePremium_Result CalculatePremium(string partnerUsername, string partnerPassword, string planCode, PaymentMethod paymentMethod, string age, Gender gender, string amount, string channel, string occupationGroup)
    {
        /*
        Call WS_SQM_CalculateService.CalculatePremium(Channel (int), SelectedPlanCode (string), PaymentMethod (int), CustomerAge (int), CustomerGender (char), MainInsured (decimal), CustomerOccupationGroup (strimg));
        ระบุ Channel เป็นรหัสช่องทางที่กำหนด เช่น 6,
        ระบุ PaymentMethod เป็น 12/06/03/01
        ระบุ CustomerGender เป็น F/M ,
        ระบุ CustomerOccupationGroup เป็น 001
        */

        CalculatePremium_Result obj = new CalculatePremium_Result();
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "CalculatePremium";

        int vChannel = 0;
        int vPaymentMethod = 0;
        int vAge = 0;
        char vGender = 'F';
        decimal vMainInsured = 0;
        string vOccupationGroup = "";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || planCode == "" || paymentMethod.ToString() == "" || age == "" || gender.ToString() == "" || amount == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + planCode + "|" + gender.ToString() + "|" + age + "|" + amount + "|" + paymentMethod.ToString() + "|" + channel + "|" + occupationGroup, this.refnum);

                obj.Result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    //vChannel = 32;
                    // 20150325: แก้ให้ระบุช่องทางมาเลย ไม่ fix ให้
                    vChannel = Convert.ToInt32(channel);
                    //vPaymentMethod = Convert.ToInt32(paymentMethod);
                    vPaymentMethod = this.PaymentMethodValues[Convert.ToInt32(paymentMethod.ToString("D"))];
                    vAge = Convert.ToInt32(age);
                    //vGender = gender.ToString().ToUpper() == "FEMALE" ? 'F' : 'M';
                    vGender = this.GenderValues[Convert.ToInt32(gender.ToString("D"))];
                    vMainInsured = Convert.ToDecimal(amount);
                    //vOccupationGroup = "001";
                    // 20150325: แก้ให้ระบุช่องทางมาเลย ไม่ fix ให้
                    vOccupationGroup = occupationGroup;

                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + planCode + "|" + vGender.ToString() + "|" + vAge + "|" + vMainInsured + "|" + vPaymentMethod + "|" + vChannel + "|" + vOccupationGroup, this.refnum);

                    try
                    {
                        MTL.NETWS_ForSmartProposal.WS_SQM_CalculateService wsobj = new MTL.NETWS_ForSmartProposal.WS_SQM_CalculateService();
                        //string result = wsobj.CalculatePremium(vChannel, planCode, vPaymentMethod, vAge, vGender, vMainInsured, vOccupationGroup);
                        string result = wsobj.CompletePremium(vChannel, planCode, vPaymentMethod, vAge, vGender, vMainInsured, vOccupationGroup);
                        if (Convert.ToDecimal(result) >= 0)
                        {
                            // ช่องทาง 32 (For Online Sales) แบบประกัน EON08C ขาย + ส่วนควบ WP
                            if (channel.Trim() == "32" && planCode == "EON08C")
                            {
                                string resultWPRider = this.CalculateRiderWP(planCode, vPaymentMethod.ToString(), vAge.ToString(), gender.ToString() == "MALE" ? "M" : "F", vMainInsured.ToString(), result);

                                result = (Convert.ToDecimal(result) + Convert.ToDecimal(resultWPRider)).ToString("N2");

                                obj.Result = "completed";
                                obj.Premium = result;
                            }
                            else
                            {
                                obj.Result = "completed";
                                obj.Premium = result;
                            }
                        }
                        else
                        {
                            if (result.Trim().Contains("ไม่พบข้อมูลเบี้ยประกัน (Premium)"))
                            {
                                obj.Result = "notcomplete_ไม่สามารถคำนวณเบี้ยประกันภัยได้ เนื่องจากอายุ หรือเพศ หรือจำนวนเงินเอาประกันภัยที่ท่านระบุไม่อยู่ในเงื่อนไขการรับประกัน";
                            }
                            else if (result.Trim().Contains("ไม่พบแบบประกัน"))
                            {
                                obj.Result = "notcomplete_ไม่สามารถคำนวณเบี้ยประกันภัยได้ เนื่องจากไม่พบข้อมูลของแบบประกันที่ท่านระบุในระบบ";
                            }
                            else
                            {
                                obj.Result = "notcomplete_" + result;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        if (ex.Message.ToString().Trim().Contains("ไม่พบข้อมูลเบี้ยประกัน (Premium)"))
                        {
                            obj.Result = "notcomplete_ไม่สามารถคำนวณเบี้ยประกันภัยได้ เนื่องจากอายุ หรือเพศ หรือจำนวนเงินเอาประกันภัยที่ท่านระบุไม่อยู่ในเงื่อนไขการรับประกัน";
                        }
                        else if (ex.Message.ToString().Trim().Contains("ไม่พบแบบประกัน"))
                        {
                            obj.Result = "notcomplete_ไม่สามารถคำนวณเบี้ยประกันภัยได้ เนื่องจากไม่พบข้อมูลของแบบประกันที่ท่านระบุในระบบ";
                        }
                        else if (ex.Message.ToString().Trim().Contains("The underlying connection was closed: A connection that was expected"))
                        {
                            obj.Result = "notcomplete_ไม่สามารถคำนวณเบี้ยประกันภัยได้ กรุณาลองใหม่อีกครั้ง";
                        }
                        else
                        {
                            obj.Result = "notcomplete_" + ex.Message.ToString();
                        }
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + planCode + "|" + vGender.ToString() + "|" + vAge + "|" + vMainInsured + "|" + vPaymentMethod + "|" + vChannel + "|" + vOccupationGroup, this.refnum);

                    obj.Result = pacobj.Result.Trim().Replace("notpass_", "notcomplete_");
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result + "|" + obj.Premium + "|" + planCode + "|" + vGender.ToString() + "|" + vAge + "|" + vMainInsured + "|" + vPaymentMethod + "|" + vChannel + "|" + vOccupationGroup, this.refnum);

            return obj;
        }
        catch (Exception ex)
        {
            obj.Result = "notcomplete_" + ex.Message.ToString();

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, obj.Result, this.refnum);

            return obj;
        }
    }