Exemplo n.º 1
0
        // 取得資料 - By RecordID
        public MemberViewModel GetMemberViewModel(long RecordID)
        {
            MemberViewModel   result = new MemberViewModel();
            DynamicParameters pars   = new DynamicParameters();

            sql = "select A.*, B.Name OperatorName from [SpadesKing].[dbo].[Member] A left join [SpadesKing].[dbo].[User] B on A.OperatorID = B.RecordID where A.RecordID = @RecordID ";
            pars.Add("@RecordID", RecordID);

            try
            {
                using (clsDBDapper db = new clsDBDapper())
                {
                    result = db.ToClass <MemberViewModel>(sql, pars).FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
                result = null;
            }
            return(result);
        }
Exemplo n.º 2
0
        // 轉移
        public OperationResult <OperationRecordViewModel> Transfer(OperationMD Data, AuthModel Operator)
        {
            OperationResult <OperationRecordViewModel> result = new OperationResult <OperationRecordViewModel>();
            RepositoryMember repoMember = new RepositoryMember();
            DateTime         processTime = DateTime.Now;
            OperationResult  resultMemberExport, resultMemberImport, resultOperationRecord;
            MemberViewModel  memberImport = repoMember.GetMemberViewModel(Data.TargetMemberID);

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

                return(result);
            }

            // 驗證轉入與轉出會員
            if (Data.MemberID == Data.TargetMemberID)
            {
                result.Status  = false;
                result.Message = "轉移失敗 : 轉入會員與轉出會員相同";
                result.Data    = null;

                return(result);
            }

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

                    // 更新會員餘額 (轉出)
                    BalanceOperationInfo dataBalaceOperationInfoExport = new BalanceOperationInfo
                    {
                        MemberID              = Data.MemberID,
                        MemberPwd             = Data.MemberPwd,
                        Integration           = Data.Integration,
                        UpdateTime            = processTime,
                        OperatorID            = Operator.ID,
                        OperationType         = BalanceOperationInfo_OperationType.Export,
                        ValidationType        = BalanceOperationInfo_ValidationType.Force,
                        UpdateConsumptionDate = true
                    };
                    resultMemberExport = repoMember.UpdateBalance(db, dataBalaceOperationInfoExport);
                    if (!resultMemberExport.Status)
                    {
                        throw new Exception(resultMemberExport.Message);
                    }

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

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

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

                    // 製作回傳結果
                    result.Type    = "Transfer";
                    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);
        }
Exemplo n.º 3
0
        // 會員積分操作
        public OperationResult UpdateBalance(clsDBDapper DB, BalanceOperationInfo Data)
        {
            OperationResult   result = new OperationResult();
            DynamicParameters pars   = new DynamicParameters();
            MemberViewModel   member = GetMemberViewModel(Data.MemberID);
            long balance             = 0;

            // 驗證會員是否存在
            if (member == null)
            {
                result.Status  = false;
                result.Message = "無法取得會員資料";
                return(result);
            }

            // 驗證密碼
            switch (Data.ValidationType)
            {
            case BalanceOperationInfo_ValidationType.None:
                break;

            case BalanceOperationInfo_ValidationType.Force:
                if (!Data.MemberPwd.Equals(member.MemberPwd))
                {
                    result.Status  = false;
                    result.Message = "會員密碼錯誤";
                    return(result);
                }
                break;

            case BalanceOperationInfo_ValidationType.Auto:
                if (Data.Integration > member.FreeChangingAmount)
                {
                    if (!Data.MemberPwd.Equals(member.MemberPwd))
                    {
                        result.Status  = false;
                        result.Message = "會員密碼錯誤";
                        return(result);
                    }
                }
                break;

            default:
                result.Status  = false;
                result.Message = "驗證類型錯誤";
                return(result);
            }

            // 取得餘額
            switch (Data.OperationType)
            {
            case BalanceOperationInfo_OperationType.Import:
                balance = member.Integration + Data.Integration;
                break;

            case BalanceOperationInfo_OperationType.Export:
                balance = member.Integration - Data.Integration;
                break;

            default:
                result.Status  = false;
                result.Message = "操作類型錯誤";
                return(result);
            }

            // 驗證餘額
            if (balance < 0)
            {
                result.Status  = false;
                result.Message = "會員餘額不足";
                return(result);
            }

            sql  = "update [SpadesKing].[dbo].[Member] ";
            sql += "set UpdateTime = @UpdateTime, OperatorID = @OperatorID, Integration = @Integration, LastConsumptionDate = @LastConsumptionDate ";
            sql += "where RecordID = @RecordID ";

            pars.Add("@UpdateTime", Data.UpdateTime);
            pars.Add("@OperatorID", Data.OperatorID);
            pars.Add("@Integration", balance);
            pars.Add("@LastConsumptionDate", Data.UpdateConsumptionDate ? Data.UpdateTime : member.LastConsumptionDate);
            pars.Add("@RecordID", Data.MemberID);

            try
            {
                result.Status = DB.ToExecuteWithTran(sql, pars);
                if (!result.Status)
                {
                    throw new Exception("無法更新資料列 (會員),請聯絡系統管理員");
                }
                result.Message = "更新成功";
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = ex.Message;
            }

            return(result);
        }
Exemplo n.º 4
0
        // 刪除
        public OperationResult <MemberViewModel> Delete(MemberMD Data)
        {
            OperationResult <MemberViewModel> result = new OperationResult <MemberViewModel>();
            DynamicParameters pars             = new DynamicParameters();
            MemberViewModel   member           = GetMemberViewModel(Data.RecordID);
            string            administratorPwd = ConfigurationManager.AppSettings["AdministratorPwd"].Trim();

            // 驗證管理者密碼
            if (!Data.AdministratorPwd.Equals(administratorPwd))
            {
                result.Status  = false;
                result.Message = "刪除失敗 : 管理者密碼錯誤";
                result.Data    = null;

                return(result);
            }

            // 驗證會員
            if (member == null)
            {
                result.Status  = false;
                result.Message = "刪除失敗 : 系統錯誤,無法取得會員資料";
                result.Data    = null;

                return(result);
            }

            // 驗證積分
            if (member.Integration > 0)
            {
                result.Status  = false;
                result.Message = "刪除失敗 : 會員仍有積分未使用,無法刪除該會員";
                result.Data    = null;

                return(result);
            }

            result.Type = "Delete";

            sql = "delete from [SpadesKing].[dbo].[Member] where RecordID = @RecordID ";
            pars.Add("@RecordID", Data.RecordID);

            try
            {
                using (clsDBDapper db = new clsDBDapper())
                {
                    result.Status = db.ToExecute(sql, pars);
                    if (!result.Status)
                    {
                        throw new Exception("資料列無法刪除 (會員),請聯絡系統管理員");
                    }
                    result.Message = "刪除成功";
                    result.Data.Add(member);
                }
            }
            catch (Exception ex)
            {
                result.Status  = false;
                result.Message = "刪除失敗 : " + ex.Message;
                result.Data    = null;
            }

            return(result);
        }