コード例 #1
0
        // 購買
        public OperationResult <OperationRecordViewModel> Purchase(OperationMD Data, AuthModel Operator)
        {
            OperationResult <OperationRecordViewModel> result = new OperationResult <OperationRecordViewModel>();
            RepositoryIssueRecord repoIssueRecord             = new RepositoryIssueRecord();
            RepositoryMember      repoMember = new RepositoryMember();
            DateTime        processTime = DateTime.Now;
            OperationResult resultIssueRecord, resultMember, resultOperationRecord;

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

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

                    // 更新會員餘額
                    BalanceOperationInfo dataBalaceOperationInfo = new BalanceOperationInfo
                    {
                        MemberID              = Data.MemberID,
                        MemberPwd             = string.Empty,
                        Integration           = Data.Integration,
                        UpdateTime            = processTime,
                        OperatorID            = Operator.ID,
                        OperationType         = BalanceOperationInfo_OperationType.Import,
                        ValidationType        = BalanceOperationInfo_ValidationType.None,
                        UpdateConsumptionDate = true
                    };
                    resultMember = repoMember.UpdateBalance(db, dataBalaceOperationInfo);
                    if (!resultMember.Status)
                    {
                        throw new Exception(resultMember.Message);
                    }

                    // 更新操作紀錄
                    OperationRecord dataOperationRecord = new OperationRecord
                    {
                        MemberID      = Data.MemberID,
                        OperationType = OperationRecord_OperationType.Purchase,
                        Integration   = Data.Integration,
                        Note          = null,
                        UpdateTime    = processTime,
                        OperatorID    = Operator.ID
                    };
                    resultOperationRecord = Create(db, dataOperationRecord);
                    if (!resultOperationRecord.Status)
                    {
                        throw new Exception(resultOperationRecord.Message);
                    }

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

                    // 製作回傳結果
                    result.Type    = "Purchase";
                    result.Status  = true;
                    result.Message = "購買成功";
                    result.Data.Add(GetOperationRecordViewModel(dataOperationRecord));
                }
                catch (Exception ex)
                {
                    // 回復資料
                    db.TransactionRollBack();

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

            return(result);
        }
コード例 #2
0
        // 餐點取消
        public OperationResult <OrderViewModel> CancelOrder(OrderMD Data, AuthModel Operator)
        {
            OperationResult <OrderViewModel> result = new OperationResult <OrderViewModel>();
            AccountingViewModel accounting          = GetAccountingViewModel(Data.OrderNo);
            DateTime            processTime         = DateTime.Now;

            // 驗證帳務紀錄
            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_CancelOrder_{0}", Operator.ID));

                    // 會員結帳 - 更新會員積分資訊 & 建立操作紀錄
                    if (accounting.PaymentType == Accounting_PaymentType.Member)
                    {
                        // 更新會員積分資訊
                        RepositoryMember repoMember   = new RepositoryMember();
                        OperationResult  resultMember = repoMember.UpdateBalance(db, new BalanceOperationInfo
                        {
                            MemberID              = Convert.ToInt64(accounting.MemberID),
                            MemberPwd             = null,
                            Integration           = accounting.Integration,
                            UpdateTime            = processTime,
                            OperatorID            = Operator.ID,
                            OperationType         = BalanceOperationInfo_OperationType.Import,
                            ValidationType        = BalanceOperationInfo_ValidationType.None,
                            UpdateConsumptionDate = true
                        });
                        if (!resultMember.Status)
                        {
                            throw new Exception(resultMember.Message);
                        }

                        // 建立積分操作紀錄
                        RepositoryOperationRecord repoOperationRecord   = new RepositoryOperationRecord();
                        OperationResult           resultOperationRecord = repoOperationRecord.Create(db, new OperationRecord
                        {
                            MemberID      = Convert.ToInt64(accounting.MemberID),
                            OperationType = OperationRecord_OperationType.CancelOrder,
                            Integration   = accounting.Integration,
                            Note          = null,
                            UpdateTime    = processTime,
                            OperatorID    = Operator.ID
                        });
                        if (!resultOperationRecord.Status)
                        {
                            throw new Exception(resultOperationRecord.Message);
                        }
                    }

                    // 積分結帳
                    if (accounting.PaymentType == Accounting_PaymentType.Member || accounting.PaymentType == Accounting_PaymentType.Integration)
                    {
                        // 建立積分發行紀錄
                        RepositoryIssueRecord repoIssueRecord   = new RepositoryIssueRecord();
                        OperationResult       resultIssueRecord = repoIssueRecord.Create(db, new IssueRecord
                        {
                            OperationType = IssueRecord_OperationType.Export,
                            Integration   = accounting.Integration,
                            Category      = IssueRecord_Category.CancelOrder,
                            UpdateTime    = processTime,
                            OperatorID    = Operator.ID
                        });
                        if (!resultIssueRecord.Status)
                        {
                            throw new Exception(resultIssueRecord.Message);
                        }
                    }

                    // 更新點餐紀錄
                    RepositoryOrder repoOrder   = new RepositoryOrder();
                    OperationResult resultOrder = repoOrder.Cancel(db, new Order
                    {
                        OrderNo    = accounting.OrderNo,
                        Status     = Order_Status.Canceled,
                        UpdateTime = processTime,
                        OperatorID = Operator.ID
                    });
                    if (!resultOrder.Status)
                    {
                        throw new Exception(resultOrder.Message);
                    }

                    // 更新帳務紀錄
                    OperationResult resultAccounting = Cancel(db, new Accounting
                    {
                        Status     = Accounting_Status.Cancel,
                        UpdateTime = processTime,
                        OperatorID = Operator.ID,
                        RecordID   = accounting.RecordID
                    });
                    if (!resultAccounting.Status)
                    {
                        throw new Exception(resultAccounting.Message);
                    }

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

                    // 製作回傳結果
                    result.Type    = "CancelOrder";
                    result.Status  = true;
                    result.Message = "取消成功";
                    result.Data.AddRange(repoOrder.GetOrderViewModel(accounting.OrderNo));
                }
                catch (Exception ex)
                {
                    // 回復資料
                    db.TransactionRollBack();

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

            return(result);
        }
コード例 #3
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);
        }
コード例 #4
0
        // 餐點結帳
        public OperationResult <AccountingViewModel> CheckOrder(OrderMD Data, AuthModel Operator)
        {
            OperationResult <AccountingViewModel> result = new OperationResult <AccountingViewModel>();
            DateTime processTime    = DateTime.Now;
            string   orderNo        = string.Format("{0}{1}", processTime.ToString("yyyyMMddHHmmss"), new Random().Next(100, 999));
            long?    integrationSum = Data.Order.Sum(x => x.Total);
            long?    memberID       = null;

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

                    // 更新會員 & 操作紀錄
                    if (Data.PaymentType == Accounting_PaymentType.Member)
                    {
                        // 更新會員積分
                        RepositoryMember repoMember   = new RepositoryMember();
                        OperationResult  resultMember = repoMember.UpdateBalance(db, new BalanceOperationInfo
                        {
                            MemberID              = Convert.ToInt64(Data.MemberID),
                            MemberPwd             = Data.MemberPwd,
                            Integration           = Convert.ToInt64(integrationSum),
                            UpdateTime            = processTime,
                            OperatorID            = Operator.ID,
                            OperationType         = BalanceOperationInfo_OperationType.Export,
                            ValidationType        = BalanceOperationInfo_ValidationType.Force,
                            UpdateConsumptionDate = true
                        });
                        if (!resultMember.Status)
                        {
                            throw new Exception(resultMember.Message);
                        }

                        // 更新積分操作紀錄
                        RepositoryOperationRecord repoOperationRecord   = new RepositoryOperationRecord();
                        OperationResult           resultOperationRecord = repoOperationRecord.Create(db, new OperationRecord
                        {
                            MemberID      = Convert.ToInt64(Data.MemberID),
                            OperationType = OperationRecord_OperationType.CheckOrder,
                            Integration   = Convert.ToInt64(integrationSum),
                            Note          = null,
                            UpdateTime    = processTime,
                            OperatorID    = Operator.ID
                        });
                        if (!resultOperationRecord.Status)
                        {
                            throw new Exception(resultOperationRecord.Message);
                        }

                        memberID = Data.MemberID;
                    }

                    // 建立發行紀錄
                    if (Data.PaymentType == Accounting_PaymentType.Member || Data.PaymentType == Accounting_PaymentType.Integration)
                    {
                        RepositoryIssueRecord repoIssueRecord   = new RepositoryIssueRecord();
                        OperationResult       resultIssueRecord = repoIssueRecord.Create(db, new IssueRecord
                        {
                            OperationType = IssueRecord_OperationType.Import,
                            Integration   = Convert.ToInt64(integrationSum),
                            Category      = IssueRecord_Category.CheckOrder,
                            UpdateTime    = processTime,
                            OperatorID    = Operator.ID
                        });
                        if (!resultIssueRecord.Status)
                        {
                            throw new Exception(resultIssueRecord.Message);
                        }
                    }

                    // 建立點餐資訊
                    RepositoryOrder repoOrder = new RepositoryOrder();
                    List <Order>    dataOrder = Data.Order.Select(x => new Order
                    {
                        OrderNo    = orderNo,
                        MealID     = x.MealID,
                        Status     = Order_Status.Preparing,
                        Quantity   = x.Quantity,
                        UpdateTime = processTime,
                        OperatorID = Operator.ID
                    }).ToList();
                    OperationResult resultOrder = repoOrder.Create(db, dataOrder);
                    if (!resultOrder.Status)
                    {
                        throw new Exception(resultOrder.Message);
                    }

                    // 建立帳務資訊
                    Accounting dataAccounting = new Accounting
                    {
                        Type        = Accounting_Type.Order,
                        PaymentType = Data.PaymentType,
                        Integration = Convert.ToInt64(integrationSum),
                        Status      = Accounting_Status.Normal,
                        OrderNo     = orderNo,
                        MemberID    = memberID,
                        UpdateTime  = processTime,
                        OperatorID  = Operator.ID
                    };
                    OperationResult resultAccounting = Create(db, dataAccounting);
                    if (!resultAccounting.Status)
                    {
                        throw new Exception(resultAccounting.Message);
                    }

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

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

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

            return(result);
        }
コード例 #5
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);
        }