如何比较此枚举的值
public enum AccountType
{
Retailer = 1,
Customer = 2,
Manager = 3,
Employee = 4
}
Run Code Online (Sandbox Code Playgroud)
我试图在MVC4控制器中比较这个枚举的值,如下所示:
if (userProfile.AccountType.ToString() == "Retailer")
{
return RedirectToAction("Create", "Retailer");
}
return RedirectToAction("Index", "Home");
Run Code Online (Sandbox Code Playgroud)
我也尝试过这个
if (userProfile.AccountType.Equals(1))
{
return RedirectToAction("Create", "Retailer");
}
return RedirectToAction("Index", "Home");
Run Code Online (Sandbox Code Playgroud)
在每种情况下,我都得到一个未设置为对象实例的Object引用.
我想知道是否有办法为我的Xamarin项目编写通用存储库,而不是为我的对象中的每个实体编写不同的存储库.Xamarin Tasky Pro示例为Task实体提供了一个Repository,因为它是它拥有的唯一实体.
在我自己的项目中,我有多个实体,所以我的问题是如何使以下客户存储库变得通用,以便ProductManager,EmployeeManager等可以使用它.如果你知道一个例子或博客文章,请指出我正确的方向
namespace App.DataLayer
{
public class CustomerRepository
{
private ProntoDatabase _db = null;
protected static string DbLocation;
protected static CustomerRepository Me;
static CustomerRepository()
{
Me = new CustomerRepository();
}
protected CustomerRepository()
{
//set the db location;
DbLocation = DatabaseFilePath;
//instantiate the database
_db = new ProntoDatabase(DbLocation);
}
public static string DatabaseFilePath
{
get
{
const string sqliteFilename = "CustomerDB.db3";
var libraryPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
var path = Path.Combine(libraryPath, sqliteFilename);
return path;
}
}
// CRUD (Create, Read, …
Run Code Online (Sandbox Code Playgroud) 我创建了一个Android Invoice应用程序.生成的发票是具有嵌套视图的标准Android布局.我正在寻找一个可用于将此视图转换为pdf文档的库.
令我感到惊讶的是,我的搜索中没有直接的选项,或者我最后完成了第一件事.或者也许我正在寻找的是不可能的.
请有人帮我指点一个工具,它可以帮助我从Android视图转换或生成PDF.我愿意接受免费和适度的付费选择.或者让我知道,如果我正在寻找的是不可能的.
我是否遗漏了某些内容,或者是否无法将侦听器附加到新的 Android Jetpack 首选项数据存储?我认为使用 Flow 的全部意义在于我们可以在首选项数据存储上调用 flow.toLiveData() 并观察值变化的变化。
以下是我从数据存储区获取流程的方法。
val taxRatePreferenceFlow: Flow<TaxRate> = dataStore.data
.catch { exception ->
if (exception is IOException){
emit(emptyPreferences())
} else {
throw exception
}
}.map { preferences ->
val name = preferences[PreferencesKeys.TAX_LABEL] ?: "Tax"
val rate = preferences[PreferencesKeys.TAX_RATE] ?: Constants.DEFAULT_TAX_RATE.toFloat()
val type = TaxType.valueOf(preferences[PreferencesKeys.TAX_TYPE] ?: TaxType.ON_ITEMS.name)
TaxRate(name, rate, type)
}
Run Code Online (Sandbox Code Playgroud)
我希望将 Flow 转换为 LiveData,就像在 ViewModel 中一样,并监听更改,直到观察者被删除。
totalAmountLiveData.addSource(taxRateFlow.asLiveData()){ taxtRate ->
taxtRate?.let {
updateTaxAmount(it)
}
}
Run Code Online (Sandbox Code Playgroud)
然而,该观察者仅发出保存的值,并且不会随着值的更新而更新。退出并重新进入屏幕将显示更新后的值。
这是我更新数据存储中每个值的方法
suspend fun updateTaxLabel(newTaxLabel: String){
dataStore.edit { preferences ->
preferences[PreferencesKeys.TAX_LABEL] …
Run Code Online (Sandbox Code Playgroud) 我无法将记录插入表中,接收错误序列包含多个元素.我要添加的实体继承自Table Per Hierachy(TPH)关系中的另一个表.
public abstract class Reward
{
public int RewardId { get; set; }
[Display(Name = "Retailer")]
public int RetailerId { get; set; }
[Display(Name = "Reward Name")]
public string RewardName { get; set; }
[Display(Name = "Start Date")]
[DataType(DataType.DateTime)]
public DateTime StartDate { get; set; }
[Display(Name = "Start Date")]
[DataType(DataType.DateTime)]
public DateTime EndDate { get; set; }
public string Description { get; set; }
public Boolean Status { get; set; }
[Display(Name = "Reward Type")]
public Enums.RewardType …
Run Code Online (Sandbox Code Playgroud) 我无法为我的应用生成已签名的APK,我遇到错误java.io.IOException任务执行失败:'app:proguardRelease'我认为我的基本gradle文件见下文
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.okason.clients"
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.api-client:google-api-client:1.19.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
}
Run Code Online (Sandbox Code Playgroud)
生成的Proguard-rules.pro文件是空的,我没有触及SDK中的proguard-android.txt文件.我甚至试图将此文件复制到app的根目录,与app.gradle文件位于同一位置,但没有成功.
我尝试运行此命令gradlew.bat assembleRelease,[SO Question][1]
并且成功.请有人看看,让我知道我做错了什么.我已将SDK和Android Studio更新到最新版本.
我能够使用Postman和这些参数调用HTTP端点:
{
"name":"Val",
"subject":"Test"
}
Run Code Online (Sandbox Code Playgroud)
但是我无法通过Android对Volley做同样的事情:这里尝试使用JSONRequest:
HashMap<String, String> params2 = new HashMap<String, String>();
params.put("name", "Val");
params.put("subject", "Test Subject");
JsonObjectRequest jsObjRequest = new JsonObjectRequest
(Request.Method.POST, Constants.CLOUD_URL, new JSONObject(params2), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
mView.showMessage("Response: " + response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
mView.showMessage(error.getMessage());
}
});
// Access the RequestQueue through your singleton class.
VolleySingleton.getInstance(mContext).addToRequestQueue(jsObjRequest);
Run Code Online (Sandbox Code Playgroud)
这里是尝试StringRequest
private void postMessage(Context context, final String name, final String subject ){ …
Run Code Online (Sandbox Code Playgroud) 我知道Visual Studio 2013明天正式推出,希望会有更多的随附文档,特别是它关于ASP.NET身份.我在跳的同时有人可以帮助我.
我所要做的就是将当前登录用户的UserID作为外键访问我称为Retailer的表.
首先是我得到的错误消息
IEntityChangeTracker的多个实例不能引用实体对象.
这是我的POCO:
public class Retailer
{
[Key]
public int RetailerId { get; set; }
public string BusinessName { get; set; }
public string PhoneNumber { get; set; }
public string ManagerName { get; set; }
public Enums.Industry Industry { get; set; }
public virtual ApplicationUser UserProfile { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
以下是Entity Framework CodeFirst如何从上面的类创建表:
CreateTable(
"dbo.Retailers",
c => new
{
RetailerId = c.Int(nullable: false, identity: true),
BusinessName = c.String(),
PhoneNumber = c.String(),
ManagerName …
Run Code Online (Sandbox Code Playgroud) 我以为我按照推荐的Realm方法运行Async数据插件,如下所示:
public void addCustomer(final Customer customer) {
Realm insertRealm = Realm.getDefaultInstance();
insertRealm.executeTransactionAsync(new Realm.Transaction() {
@Override
public void execute(Realm backgroundRealm) {
long id = customerPrimaryKey.incrementAndGet();
customer.setId(id);
backgroundRealm.copyToRealm(customer);
}
}, new Realm.Transaction.OnSuccess() {
@Override
public void onSuccess() {
Log.d(LOG_TAG, "Customer Added");
}
}, new Realm.Transaction.OnError() {
@Override
public void onError(Throwable error) {
Log.d(LOG_TAG, error.getMessage());
}
});
insertRealm.close();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行上面的代码时,我得到"你的领域是从一个没有Looper的线程打开的,你提供了一个回调,我们需要一个Handler来调用你的回调"
我在非Activity类中运行此代码,我在这里做错了,我该如何解决它.谢谢.
更新 - 修复了 事实证明查询没有任何问题,问题是我是从IntentService调用它.我试图在应用程序第一次运行时播种数据库,所以我修复了这个:
protected void onHandleIntent(Intent intent) {
Realm realm = Realm.getDefaultInstance();
//Add sample Customers to database
List<Customer> customers = SampleCustomerData.getCustomers(); …
Run Code Online (Sandbox Code Playgroud) 我已将以下.gitignore文件放在Android Studio Project的根目录下
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Windows clutter
Thumbs.db
# Intellij IDEA (see https://intellij-support.jetbrains.com/entries/23393067)
.idea/workspace.xml
.idea/tasks.xml
.idea/datasources.xml
.idea/dataSources.ids
Run Code Online (Sandbox Code Playgroud)
但是,以下.gradle内容会不断添加到源代码管理中.
modified: .gradle/1.12/taskArtifacts/cache.properties.lock
modified: .gradle/1.12/taskArtifacts/fileHashes.bin
modified: .gradle/1.12/taskArtifacts/fileSnapshots.bin
modified: .gradle/1.12/taskArtifacts/taskArtifacts.bin
Run Code Online (Sandbox Code Playgroud)
.grad及其子文件夹在.gitignore中被标记为被忽略,但是每次我在模拟器中运行应用程序时都会不断更新.我不记得在Eclipse项目中处理这些问题了.
我上面显示的这些.gradle文件是否必须受版本控制,如果不是,我如何修改我的.gitignore实际上忽略它们?
android ×5
c# ×3
asp.net-mvc ×1
enums ×1
git ×1
gradle ×1
proguard ×1
realm ×1
sqlite-net ×1
xamarin ×1