Int64 ICMBillMaterialReceiveMeasurementBookMapDataAccess.Add(CMBillMaterialReceiveMeasurementBookMapEntity cMBillMaterialReceiveMeasurementBookMapEntity, DatabaseOperationType option, TransactionRequired reqTran)
        {
            try
            {
                long retValues = -99;

                switch (reqTran)
                {
                case TransactionRequired.No:
                {
                    retValues = Add(cMBillMaterialReceiveMeasurementBookMapEntity, option);
                    break;
                }

                case TransactionRequired.Yes:
                {
                    retValues = AddTran(cMBillMaterialReceiveMeasurementBookMapEntity, option);
                    break;
                }

                default:
                {
                    retValues = -99;
                    break;
                }
                }

                return(retValues);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private Int64 UpdateTran(CMBillMaterialReceiveMeasurementBookMapEntity cMBillMaterialReceiveMeasurementBookMapEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CMBillMaterialReceiveMeasurementBookMap_SET";

            Database db = DatabaseFactory.CreateDatabase();

            using (DbCommand cmd = db.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option, db);
                AddOutputParameter(cmd, db);
                AddFilterExpressionParameter(cmd, filterExpression, db);

                db.AddInParameter(cmd, "@BillMaterialReceiveMeasurementBookMapID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.BillMaterialReceiveMeasurementBookMapID);
                db.AddInParameter(cmd, "@BillID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.BillID);
                db.AddInParameter(cmd, "@MaterialReceiveID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MaterialReceiveID);
                db.AddInParameter(cmd, "@MaterialReceiveItemMapID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MaterialReceiveItemMapID);
                db.AddInParameter(cmd, "@MeasurementBookID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MeasurementBookID);
                db.AddInParameter(cmd, "@MeasurementBookDetailID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MeasurementBookDetailID);
                db.AddInParameter(cmd, "@BillPrice", DbType.Decimal, cMBillMaterialReceiveMeasurementBookMapEntity.BillPrice);

                DbConnection connection = db.CreateConnection();
                connection.Open();
                DbTransaction transaction = connection.BeginTransaction();

                try
                {
                    using (IDataReader reader = db.ExecuteReader(cmd, transaction))
                    {
                        returnCode = GetReturnCodeFromParameter(cmd);
                    }

                    if (returnCode > 0)
                    {
                        transaction.Commit();
                    }
                    else
                    {
                        throw new ArgumentException("Error Code." + returnCode.ToString());
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }
                finally
                {
                    transaction.Dispose();
                    connection.Close();
                    connection = null;
                }
            }

            return(returnCode);
        }
        private Int64 Update(CMBillMaterialReceiveMeasurementBookMapEntity cMBillMaterialReceiveMeasurementBookMapEntity, String filterExpression, DatabaseOperationType option)
        {
            long         returnCode = -99;
            const string SP         = "dbo.CMBillMaterialReceiveMeasurementBookMap_SET";

            using (DbCommand cmd = Database.GetStoredProcCommand(SP))
            {
                AddOptionParameter(cmd, option);
                AddOutputParameter(cmd);
                AddFilterExpressionParameter(cmd, filterExpression);

                Database.AddInParameter(cmd, "@BillMaterialReceiveMeasurementBookMapID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.BillMaterialReceiveMeasurementBookMapID);
                Database.AddInParameter(cmd, "@BillID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.BillID);
                Database.AddInParameter(cmd, "@MaterialReceiveID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MaterialReceiveID);
                Database.AddInParameter(cmd, "@MaterialReceiveItemMapID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MaterialReceiveItemMapID);
                Database.AddInParameter(cmd, "@MeasurementBookID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MeasurementBookID);
                Database.AddInParameter(cmd, "@MeasurementBookDetailID", DbType.Int64, cMBillMaterialReceiveMeasurementBookMapEntity.MeasurementBookDetailID);
                Database.AddInParameter(cmd, "@BillPrice", DbType.Decimal, cMBillMaterialReceiveMeasurementBookMapEntity.BillPrice);

                using (IDataReader reader = Database.ExecuteReader(cmd))
                {
                    returnCode = GetReturnCodeFromParameter(cmd);

                    switch (returnCode)
                    {
                    case SqlConstants.DB_STATUS_CODE_DATAALREADYEXIST:
                    {
                        throw new ArgumentException("CMBillMaterialReceiveMeasurementBookMapEntity already exists. Please specify another CMBillMaterialReceiveMeasurementBookMapEntity.");
                    }

                    case SqlConstants.DB_STATUS_CODE_DATAUPDATEDFROMOTHERSESSION:
                    {
                        throw new ArgumentException("CMBillMaterialReceiveMeasurementBookMapEntity data already updated from different session.");
                    }

                    case SqlConstants.DB_STATUS_CODE_FAIL_OPERATION:
                    {
                        throw new ArgumentException("CMBillMaterialReceiveMeasurementBookMapEntity already exists. Please specify another CMBillMaterialReceiveMeasurementBookMapEntity.");
                    }
                    }
                }
            }

            return(returnCode);
        }
 Int64 ICMBillMaterialReceiveMeasurementBookMapFacade.Delete(CMBillMaterialReceiveMeasurementBookMapEntity cMBillMaterialReceiveMeasurementBookMapEntity, String filterExpression, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCMBillMaterialReceiveMeasurementBookMapDataAccess().Delete(cMBillMaterialReceiveMeasurementBookMapEntity, filterExpression, option, reqTran));
 }
 Int64 ICMBillMaterialReceiveMeasurementBookMapFacade.Add(CMBillMaterialReceiveMeasurementBookMapEntity cMBillMaterialReceiveMeasurementBookMapEntity, DatabaseOperationType option, TransactionRequired reqTran)
 {
     return(DataAccessFactory.CreateCMBillMaterialReceiveMeasurementBookMapDataAccess().Add(cMBillMaterialReceiveMeasurementBookMapEntity, option, reqTran));
 }