public string AddTemporaryReceiptNumberToUsingLog(string partnerUsername, string partnerPassword, string temporaryReceiptNumber, string temporaryReceiptDate, string payFor, string payForNumber, string payAmount, string agentNumber)
    {
        string result = "";
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "AddTemporaryReceiptNumberToUsingLog";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || temporaryReceiptNumber == "" || temporaryReceiptDate == "" || payFor == "" || payForNumber == "" || payAmount == "" || agentNumber == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

                result = "notcomplete_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (temporaryReceiptNumber.Length != 12 || !MTL.Utils.ThisWeb.CheckIsNumeric(temporaryReceiptNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

                result = "notconmplete_กรุณาระบุเลขที่ใบรับเงินชั่วคราวให้ถูกต้อง";
            }
            else if (payForNumber.Length < 10 || payForNumber.Length > 11 || !MTL.Utils.ThisWeb.CheckIsNumeric(payForNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

                result = "notcomplete_กรุณาระบุเลขที่กรมธรรม์ หรือเลขที่ใบคำขอเอาประกันภัยให้ถูกต้อง";
            }
            else if (agentNumber.Length != 6 || !MTL.Utils.ThisWeb.CheckIsNumeric(agentNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

                result = "notcomplete_กรุณาระบุเลขที่ตัวแทนให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

                    // ตรวจสอบเลขที่ใบรับเงินชั่วคราว
                    MTL.Utils.ThisWeb thisweb = new MTL.Utils.ThisWeb();
                    if (thisweb.CheckIsValidTemporaryBillNumber(temporaryReceiptNumber))
                    {
                        // ตรวจสอบเลขที่ใบรับเงินชั่วคราวว่าได้ถูกบันทึกว่าตัวแทนส่งงานเข้ามายังบริษัทฯ (เก็บอยู่ใน AS400) แล้วหรือยัง หรือสามารถนำมาใช้ได้หรือไม่ ผ่าน OSB EAppService
                        CheckTemporaryReceiptNumberInAs400IsCanUse_Result checkResult = new CheckTemporaryReceiptNumberInAs400IsCanUse_Result();
                        // 20150129: Comment ไว้เพื่อทดสอบไม่ต้องใช้ค่าจาก Web Services ว่าน
                        checkResult = this.CheckTemporaryReceiptNumberInAs400IsCanUse(temporaryReceiptNumber);
                        // 20150129: สำหรับทดสอบโดยไม่ต้องใช้ค่าจาก Web Services ว่าน
                        //checkResult.Result = "testja";

                        if (checkResult.Result == "false")
                        {
                            result = "notcomplete_" + checkResult.ErrorMessage.Trim();
                        }
                        else
                        {
                            // 20150129: ตรวจสอบเลขที่ใบรับเงินชั่วคราว กับเลขที่ใบคำขอเอาประกันหรือเลขที่กรมธรรม์ว่าเคยถูกใช้ไปแล้วครบจำนวนครั้งที่กำหนดหรือยัง ถ้าพบว่าเคยใช้ไปแล้วจะไม่สามารถนำไปใช้งานได้อีก
                            // 20150527: ปรับใช้ class รองรับการตรวจสอบว่าใช้เลขที่ใบรับเงินชั่วคราวนี้ได้อีกกี่ครั้ง
                            CheckTemporaryReceiptNumberAndNumberToPayInSqlIsUsedExceedLimit_Result checkTempAndNumberInSqlObj = new CheckTemporaryReceiptNumberAndNumberToPayInSqlIsUsedExceedLimit_Result();
                            checkTempAndNumberInSqlObj = this.CheckTemporaryReceiptNumberAndNumberToPayInSqlIsUsedExceedLimit(temporaryReceiptNumber, payForNumber);
                            if (checkTempAndNumberInSqlObj.Result == true)
                            {
                                result = "notcomplete_เลขที่ใบรับเงินชั่วคราวนี้ถูกนำไปใช้แล้ว";
                            }
                            else
                            {
                                using (var dbContext = new DAL.MTL_mPOSEntities())
                                {
                                    DAL.TemporaryReceiptUsingLog tempReceipt = new DAL.TemporaryReceiptUsingLog();
                                    tempReceipt.TemporaryReceiptNumber = temporaryReceiptNumber.Trim();

                                    CovertToDateResult dateObj = new CovertToDateResult();
                                    dateObj = ConvertToDate(temporaryReceiptDate);
                                    DateTime tempReceiptDate = new DateTime(dateObj.Year, dateObj.Month, dateObj.Day);
                                    tempReceipt.TemporaryReceiptDate = tempReceiptDate;

                                    tempReceipt.PayFor = payFor.Trim();
                                    tempReceipt.PayForNumber = payForNumber.Trim();
                                    tempReceipt.PayAmount = payAmount.Trim();
                                    tempReceipt.AgentNumber = agentNumber.Trim();
                                    tempReceipt.LogDateTime = DateTime.Now;

                                    dbContext.AddToTemporaryReceiptUsingLog(tempReceipt);
                                    dbContext.SaveChanges();

                                    result = "completed";
                                }
                            }
                        }
                    }
                    else
                    {
                        result = "notcomplete_เลขที่ใบรับเงินชั่วคราวไม่ถูกต้อง";
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

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

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, result + "|" + temporaryReceiptNumber + "|" + temporaryReceiptDate + "|" + payFor + "|" + payForNumber + "|" + payAmount + "|" + agentNumber, this.refnum);

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

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

            return result;
        }
    }
    // ใช้สำหรับตรวจสอบเลขที่ใบรับเงินชั่วคราวว่าได้ถูกบันทึกว่าตัวแทนส่งงานเข้ามายังบริษัทฯ (เก็บอยู่ใน AS400) แล้วหรือยัง หรือสามารถนำมาใช้ได้หรือไม่ ผ่าน OSB EAppService
    private CheckTemporaryReceiptNumberInAs400IsCanUse_Result CheckTemporaryReceiptNumberInAs400IsCanUse(string temporaryReceiptNumber)
    {
        CheckTemporaryReceiptNumberInAs400IsCanUse_Result obj = new CheckTemporaryReceiptNumberInAs400IsCanUse_Result();
        // 20150327: Wanpaya แจ้งเมื่อ 23/03/2558 สำหรับ MTLmPOS ให้ใช้ Service ในการ Validate ใหม่ โดยตัดเรื่องการ Validate เลขที่ใบรับเงินชั่วคราวซ้ำใน 1 ปี ออก
        //MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumber_PS.ValidateRecipeNumber wsObj = new MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumber_PS.ValidateRecipeNumber();
        //OSBEAppValidationRecipeNumber validateRecipeObj = new OSBEAppValidationRecipeNumber();
        //validateRecipeObj.result = wsObj.CallValidateRecipeNumber(System.DateTime.Now, temporaryReceiptNumber, "", "", out validateRecipeObj.responseCode, out validateRecipeObj.isValid, out validateRecipeObj.reasonCode, out validateRecipeObj.description);

        //MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumberWithoutDuplicate_PS.ValidateRecipeNumber wsObj = new MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumberWithoutDuplicate_PS.ValidateRecipeNumber();
        //OSBEAppValidationRecipeNumber validateRecipeObj = new OSBEAppValidationRecipeNumber();
        //validateRecipeObj.result = wsObj.CallValidateRecipeNumber(System.DateTime.Now, temporaryReceiptNumber, "", "", out validateRecipeObj.responseCode, out validateRecipeObj.isValid, out validateRecipeObj.reasonCode, out validateRecipeObj.description);

        //if (validateRecipeObj.responseCode.Trim() != "00")
        //{
        //    if (validateRecipeObj.isValid == false)
        //    {
        //        obj.Result = "false";
        //        switch (validateRecipeObj.reasonCode.Trim())
        //        {
        //            case "01":
        //                obj.ErrorMessage = "เล่มที่ใบรับเงินชั่วคราวยังไม่ได้ลงทะเบียน - W01";
        //                break;
        //            case "02":
        //                obj.ErrorMessage = "เลขที่ใบรับเงินชั่วคราวใช้ซ้ำอยู่ในระยะเวลา 1 ปี - W02";
        //                break;
        //            case "03":
        //                obj.ErrorMessage = "เลขที่ใบรับเงินชั่วคราวไม่ถูกต้อง - W03";
        //                break;
        //            case "04":
        //                // 20150604: ว่านแจ้งแก้ไขเมื่อ 28/05/2558
        //                //obj.ErrorMessage = "ใบคำขอเอาประกันมีการบันทึกเลขที่ใบรับเงินชั่วคราวอยู่แล้ว - W04";
        //                obj.ErrorMessage = "เลขที่ใบรับเงินชั่วคราวยังไม่ถูกบันทึกที่ระบบ E-Application - W04";
        //                break;
        //            default:
        //                obj.ErrorMessage = "ไม่สามารถใช้เลขที่ใบรับเงินชั่วคราวนี้ได้ - W99";
        //                break;
        //        }
        //    }
        //    else
        //    {
        //        obj.Result = "true";
        //    }
        //}
        //else
        //{
        //    obj.Result = "true";
        //}

        // ว่านส่งให้เมื่อ 06/07/2558 ส่งรายละเอียดเมื่อ 09/07/2558
        MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumberForAll_PS.ValidateRecipeNumberForAll wsObj = new MTL.OSBWS_EAppService.EApp_ForValidateRecipeNumberForAll_PS.ValidateRecipeNumberForAll();
        OSBEAppValidationRecipeNumber validateRecipeObj = new OSBEAppValidationRecipeNumber();
        validateRecipeObj.result = wsObj.CallValidateRecipeNumberForAll(System.DateTime.Now, temporaryReceiptNumber, "", "", out validateRecipeObj.isValid, out validateRecipeObj.reasonCode, out validateRecipeObj.resultCase, out validateRecipeObj.eappFoundCurrentYear, out validateRecipeObj.applicationStatus, out validateRecipeObj.eSignatureState, out validateRecipeObj.description);

        switch (validateRecipeObj.reasonCode.Trim())
        {
            case "01":
                obj.Result = "true";
                obj.ErrorMessage = "งาน Non E-App หรือ งานต่ออายุ - W01";
                break;
            case "02":
                obj.Result = "true";
                obj.ErrorMessage = "งานใหม่ E-App สามารถตัดเงินได้ - W02";
                break;
            case "91":
                obj.Result = "false";
                obj.ErrorMessage = "เล่มใบรับเงินยังไม่ได้ลงทะเบียน - W91";
                break;
            case "93":
                obj.Result = "false";
                //obj.ErrorMessage = "เลขที่ใบรับเงินไม่ถูกฟอร์แมต - W93";
                // ErrorMessage จากอ้อ ITS เมื่อ 09/07/2558
                obj.ErrorMessage = "เลขที่ใบรับเงินชั่วคราวไม่ถูกฟอร์แมต - W93";
                break;
            case "94":
                obj.Result = "false";
                obj.ErrorMessage = "ใบคำขอมีการบันทึกเลขที่ใบเสร็จอยู่แล้ว - W94";
                break;
            case "95":
                obj.Result = "false";
                //obj.ErrorMessage = "งานใหม่ที่ยังไม่ Submit หรือยังไม่ตัดสินใจเซ็นต์ E-Signature - W95";
                // ErrorMessage จากอ้อ ITS เมื่อ 09/07/2558
                obj.ErrorMessage = "ข้อมูลใบคำขอในระบบ E-Application ยังไม่เรียบร้อย กรุณาตรวจสอบใบคำขออีกครั้ง - W95";
                break;
            case "92":
                obj.Result = "false";
                //obj.ErrorMessage = "เลขซ้ำอยู่ในช่วงระยะเวลา 1 ปี - W92";
                // ErrorMessage จากอ้อ ITS เมื่อ 09/07/2558
                obj.ErrorMessage = "เลขที่ใบรับเงินชั่วคราวมีการใช้ซ้ำภายใน 1 ปี - W92";
                break;
            case "99":
                obj.Result = "false";
                obj.ErrorMessage = "Error อื่นๆ - W99";
                break;
            default:
                obj.Result = "false";
                obj.ErrorMessage = "";
                break;
        }

        return obj;
    }
    public string CheckIsValidTemporaryReceiptNumber(string partnerUsername, string partnerPassword, string temporaryReceiptNumber)
    {
        string result = "";
        RefRunningTBBLL runningobj = new RefRunningTBBLL();
        this.refnum = runningobj.AddRefRunningTBAndReturn();
        WSLogBLL logobj = new WSLogBLL();
        string methodName = "CheckIsValidTemporaryReceiptNumber";

        try
        {
            if (partnerUsername == "" || partnerPassword == "" || temporaryReceiptNumber == "")
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber, this.refnum);

                result = "notvalid_กรุณาระบุข้อมูลให้ครบถ้วน";
            }
            else if (temporaryReceiptNumber.Length != 12 || !MTL.Utils.ThisWeb.CheckIsNumeric(temporaryReceiptNumber))
            {
                this.partnerName = partnerUsername;
                // LogRequest: Insert Log Request
                logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber, this.refnum);

                result = "notvalid_กรุณาระบุเลขที่ใบรับเงินชั่วคราวให้ถูกต้อง";
            }
            else
            {
                // พิสูจน์ตัวตนของพันธมิตรก่อนที่จะให้ใช้งานจริง
                NETWS_ForPartnerAuthenticationChecking.CheckPartnerAuthentication_Result pacobj = CheckPartnerAuthenticationReturnDetail(partnerUsername, partnerPassword, this.ipaddress);
                if (pacobj.Result.Trim().ToLower() == "passed")
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber, this.refnum);

                    // ตรวจสอบเลขที่ใบรับเงินชั่วคราว
                    MTL.Utils.ThisWeb thisweb = new MTL.Utils.ThisWeb();
                    if (thisweb.CheckIsValidTemporaryBillNumber(temporaryReceiptNumber))
                    {
                        // ตรวจสอบเลขที่ใบรับเงินชั่วคราวว่าได้ถูกบันทึกว่าตัวแทนส่งงานเข้ามายังบริษัทฯ (เก็บอยู่ใน AS400) แล้วหรือยัง หรือสามารถนำมาใช้ได้หรือไม่ ผ่าน OSB EAppService
                        CheckTemporaryReceiptNumberInAs400IsCanUse_Result checkResult = new CheckTemporaryReceiptNumberInAs400IsCanUse_Result();
                        // 20150129: Comment ไว้เพื่อทดสอบไม่ต้องใช้ค่าจาก Web Services ว่าน
                        checkResult = this.CheckTemporaryReceiptNumberInAs400IsCanUse(temporaryReceiptNumber);
                        // 20150129: สำหรับทดสอบโดยไม่ต้องใช้ค่าจาก Web Services ว่าน
                        //checkResult.Result = "testja";
                        if (checkResult.Result == "false")
                        {
                            result = "notvalid_" + checkResult.ErrorMessage.Trim();
                        }
                        else
                        {
                            result = "valid_" + checkResult.ErrorMessage.Trim();
                        }
                    }
                    else
                    {
                        result = "notvalid_เลขที่ใบรับเงินชั่วคราวไม่ถูกต้อง";
                    }
                }
                else
                {
                    this.partnerName = pacobj.PartnerName;
                    // LogRequest: Insert Log Request
                    logobj.AddWSLog(this.partnerName, this.ipaddress, "Request", this.webserviceName, methodName, partnerUsername + "|" + temporaryReceiptNumber, this.refnum);

                    result = pacobj.Result.Trim().Replace("notpass_", "notvalid_");
                }
            }

            // LogResponse: Insert Log Response
            logobj.AddWSLog(this.partnerName, this.ipaddress, "Response", this.webserviceName, methodName, result + "|" + temporaryReceiptNumber, this.refnum);

            return result;
        }
        catch (Exception ex)
        {
            result = "notvalid_" + ex.Message.ToString();

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

            return result;
        }
    }