예제 #1
0
        // 租金取消
        public OperationResult <AccountingViewModel> CancelRent(RentMD Data, AuthModel Operator)
        {
            OperationResult <AccountingViewModel> result = new OperationResult <AccountingViewModel>();
            RepositoryIssueRecord repoIssueRecord = new RepositoryIssueRecord();
            OperationResult       resultIssueRecord, resultAccounting;
            DateTime            processTime = DateTime.Now;
            AccountingViewModel accounting = GetAccountingViewModel(Data.RecordID);

            // 驗證帳務紀錄
            if (accounting == null)
            {
                result.Status  = false;
                result.Message = "取消失敗 : 系統錯誤,無法取得帳務紀錄";
                result.Data    = null;

                return(result);
            }

            // 驗證刪除狀態
            if (accounting.Status.Equals(Accounting_Status.Cancel))
            {
                result.Status  = false;
                result.Message = "取消失敗 : 帳務紀錄已取消";
                result.Data    = null;

                return(result);
            }

            // 驗證管理者密碼
            if (!Data.AdministratorPwd.Equals(ConfigurationManager.AppSettings["AdministratorPwd"].Trim()))
            {
                result.Status  = false;
                result.Message = "取消失敗 : 管理者密碼錯誤";
                result.Data    = null;

                return(result);
            }

            using (clsDBDapper db = new clsDBDapper())
            {
                try
                {
                    // 開啟交易
                    db.TransactionStart(string.Format("Accounting_CancelRent_{0}", Operator.ID));

                    // 建立發行紀錄
                    IssueRecord dataIssueRecord = new IssueRecord
                    {
                        OperationType = IssueRecord_OperationType.Export,
                        Integration   = accounting.Integration,
                        Category      = IssueRecord_Category.CancelRent,
                        UpdateTime    = processTime,
                        OperatorID    = Operator.ID
                    };
                    resultIssueRecord = repoIssueRecord.Create(db, dataIssueRecord);
                    if (!resultIssueRecord.Status)
                    {
                        throw new Exception(resultIssueRecord.Message);
                    }

                    // 取消帳務紀錄
                    Accounting dataAccounting = new Accounting
                    {
                        RecordID    = accounting.RecordID,
                        Type        = accounting.Type,
                        PaymentType = accounting.PaymentType,
                        Integration = accounting.Integration,
                        Status      = Accounting_Status.Cancel,
                        OrderNo     = accounting.OrderNo,
                        MemberID    = accounting.MemberID,
                        UpdateTime  = processTime,
                        OperatorID  = Operator.ID
                    };
                    resultAccounting = Cancel(db, dataAccounting);
                    if (!resultAccounting.Status)
                    {
                        throw new Exception(resultAccounting.Message);
                    }

                    // 確認及關閉交易
                    db.TransactionCommit();
                    db.TransactionDispose();

                    // 製作回傳結果
                    result.Type    = "CancelRent";
                    result.Status  = true;
                    result.Message = "取消成功";
                    result.Data.Add(GetAccountingViewModel(dataAccounting));
                }
                catch (Exception ex)
                {
                    // 回復資料
                    db.TransactionRollBack();

                    result.Status  = false;
                    result.Message = "取消失敗 : " + ex.Message;
                    result.Data    = null;
                }
            }

            return(result);
        }
예제 #2
0
        // 租金結帳
        public OperationResult <AccountingViewModel> CheckRent(RentMD Data, AuthModel Operator)
        {
            OperationResult <AccountingViewModel> result = new OperationResult <AccountingViewModel>();
            RepositoryIssueRecord repoIssueRecord = new RepositoryIssueRecord();
            OperationResult       resultIssueRecord, resultAccounting;
            DateTime processTime = DateTime.Now;

            using (clsDBDapper db = new clsDBDapper())
            {
                try
                {
                    // 開啟交易
                    db.TransactionStart(string.Format("Accounting_CheckRent_{0}", Operator.ID));

                    // 建立發行紀錄
                    IssueRecord dataIssueRecord = new IssueRecord
                    {
                        OperationType = IssueRecord_OperationType.Import,
                        Integration   = Data.Integration,
                        Category      = IssueRecord_Category.CheckRent,
                        UpdateTime    = processTime,
                        OperatorID    = Operator.ID
                    };
                    resultIssueRecord = repoIssueRecord.Create(db, dataIssueRecord);
                    if (!resultIssueRecord.Status)
                    {
                        throw new Exception(resultIssueRecord.Message);
                    }

                    // 建立帳務紀錄
                    Accounting dataAccounting = new Accounting
                    {
                        Type        = Accounting_Type.Rent,
                        PaymentType = Accounting_PaymentType.Integration,
                        Integration = Data.Integration,
                        Status      = Accounting_Status.Normal,
                        OrderNo     = null,
                        MemberID    = null,
                        UpdateTime  = processTime,
                        OperatorID  = Operator.ID
                    };
                    resultAccounting = Create(db, dataAccounting);
                    if (!resultAccounting.Status)
                    {
                        throw new Exception(resultAccounting.Message);
                    }

                    // 確認及關閉交易
                    db.TransactionCommit();
                    db.TransactionDispose();

                    // 製作回傳結果
                    result.Type    = "CheckRent";
                    result.Status  = true;
                    result.Message = "結帳成功";
                    result.Data.Add(GetAccountingViewModel(dataAccounting));
                }
                catch (Exception ex)
                {
                    // 回復資料
                    db.TransactionRollBack();

                    result.Status  = false;
                    result.Message = "結帳失敗 : " + ex.Message;
                    result.Data    = null;
                }
            }

            return(result);
        }