コード例 #1
0
        /// <summary>
        /// Event when click confirm button, this function will register the information of invoice detail list to the system.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public ActionResult ICS040_cmdConfirm(ICS040_ScreenParameter param)
        {
            ObjectResultData res = new ObjectResultData();

            res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;

            try
            {
                if (IsSuspend(res))
                {
                    return(Json(res));
                }

                if (!ICS040_IsAllowOperate(res))
                {
                    return(Json(res));
                }

                //Validate  business, (Already confirmed with sa, need validate at this point)
                ICS040_ScreenParameter screenObject = GetScreenObject <ICS040_ScreenParameter>();
                List <doInvoice>       doInvoiceDb  = new List <doInvoice>();
                foreach (var item in screenObject.InvoiceList)
                {
                    //Get Invoice Data
                    doInvoice doInvoice = ICS040_GetInvoice(item.InvoiceNo, res);
                    if (res.IsError)
                    {
                        return(Json(res));
                    }

                    //Validate  business
                    ICS040_ValidateInvoiceBusiness(doInvoice, res);
                    if (res.IsError)
                    {
                        return(Json(res));
                    }

                    //Refresh
                    doInvoice.ExemptApproveNo = item.ExemptApproveNo;
                    doInvoiceDb.Add(doInvoice);
                }
                //Refresh
                screenObject.InvoiceList = doInvoiceDb;


                //Save Data to db
                IBillingHandler billingHandler = ServiceContainer.GetService <IBillingHandler>() as IBillingHandler;
                using (TransactionScope scope = new TransactionScope())
                {
                    try
                    {
                        foreach (doInvoice item in screenObject.InvoiceList)
                        {
                            bool isSuccess = billingHandler.RegisterInvoiceExemption(item);
                            if (!isSuccess)
                            {
                                //all Fail
                                scope.Dispose();
                                res.AddErrorMessage(MessageUtil.MODULE_INCOME, MessageUtil.MessageList.MSG7087);
                                return(Json(res));
                            }
                        }

                        //Clear session
                        screenObject.InvoiceList = new List <doInvoice>();

                        //Success
                        scope.Complete();
                        res.ResultData = "1";
                        return(Json(res));
                    }
                    catch (Exception ex)
                    {
                        //all Fail
                        scope.Dispose();
                        throw ex;
                    }
                }
            }
            catch (Exception ex)
            {
                res.MessageType = MessageModel.MESSAGE_TYPE.INFORMATION;
                res.AddErrorMessage(ex);
            }
            return(Json(res));
        }