当我想在“return (byte)SaleMode.ToPost;”行中使用“SetSaleMode”时,我有一个包含这些字段和这些静态方法的类 发生此错误,有人可以帮助我吗?
这些是我的代码:
公共枚举 SaleMode:byte { ToPost = 0, Downloadable = 1, DownloadableAndFreeTrial = 2, SourceSiteSale = 3 }; 公共枚举 FilePriceMode { ProductFile = 0, Free = 1, FreeTrial = 2 };公共类 ProductDAL : BaseDAL {
#region fields public Int64 ID { get; set; } public string Name { get; set; } public Int64 Price { get; set; } public bool Private { get; set; } public Int64 ProductType { get; set; } public string Notes { get; set; } public string Image { get; set; } public DateTime Date { get; set; } public Int64 Owner { get; set; } public long Counter { get; set; } public bool Proved { get; set; } public byte[] Files { get; set; } public byte SaleMode { get; set; } public string SourceSiteSaleAddress { get; set; } public List<FilesOfProductsDAL> FOfPro; #endregion fields #region constructor public ProductDAL() { ID = -1; FOfPro = new List<FilesOfProductsDAL>(); } public ProductDAL(string saveIconPath) { ID = -1; this.Image = saveIconPath; FOfPro = new List<FilesOfProductsDAL>(); } #endregion constructor #region method public static long InsertProduct(ProductDAL objProductDAL) { try { Int64 ID; objProductDAL.SaleMode = SetSaleMode(objProductDAL); SqlCommand Sqlcomm = new SqlCommand(); Sqlcomm.CommandText = StoreQueries.InsertProduct; Sqlcomm.CommandType = CommandType.StoredProcedure; Sqlcomm.Parameters.AddWithValue("@Name", SqlDbType.NVarChar).Value = objProductDAL.Name; Sqlcomm.Parameters.AddWithValue("@Price", SqlDbType.BigInt).Value = objProductDAL.Price; Sqlcomm.Parameters.AddWithValue("@Private", SqlDbType.Bit).Value = objProductDAL.Private; Sqlcomm.Parameters.AddWithValue("@ProductType", SqlDbType.BigInt).Value = objProductDAL.ProductType; Sqlcomm.Parameters.AddWithValue("@Notes", SqlDbType.NVarChar).Value = objProductDAL.Notes; Sqlcomm.Parameters.AddWithValue("@Date", SqlDbType.DateTime).Value = objProductDAL.Date; Sqlcomm.Parameters.AddWithValue("@Image", SqlDbType.NVarChar).Value = objProductDAL.Image; Sqlcomm.Parameters.AddWithValue("@Owner", SqlDbType.BigInt).Value = 1019;//objProductDL.Owner ; Sqlcomm.Parameters.AddWithValue("@SaleMode", SqlDbType.VarBinary).Value = objProductDAL.SaleMode; if (objProductDAL.Files == null) Sqlcomm.Parameters.AddWithValue("@Files", SqlDbType.VarBinary).Value =System.Data.SqlTypes.SqlBinary.Null;// DBNull.Value; else Sqlcomm.Parameters.AddWithValue("@Files", SqlDbType.VarBinary).Value = objProductDAL.Files; if (objProductDAL.SourceSiteSaleAddress == null) Sqlcomm.Parameters.AddWithValue("@SourceSiteSaleAddress", SqlDbType.NVarChar).Value = DBNull.Value; else Sqlcomm.Parameters.AddWithValue("@SourceSiteSaleAddress", SqlDbType.NVarChar).Value = objProductDAL.SourceSiteSaleAddress; Sqlcomm.Parameters.AddWithValue("@CheangedSet", SqlDbType.NVarChar).Value = "محصول جدید است."; Sqlcomm.Parameters.AddWithValue("PID", SqlDbType.BigInt).Value =objProductDAL.ID; ID = Convert.ToInt64(ExecuteScalar(Sqlcomm)); objProductDAL.Image = objProductDAL.Image.Replace(Path.GetFileNameWithoutExtension(objProductDAL.Image), ID.ToString() ); for (int i = 0; i <objProductDAL.FOfPro.Count; i++) { objProductDAL.FOfPro[i].FileUrl = objProductDAL.FOfPro[i].FileUrl.Replace(Path.GetFileNameWithoutExtension(objProductDAL.FOfPro[i].FileUrl), Path.GetFileNameWithoutExtension(objProductDAL.FOfPro[i].FileUrl) + "." + ID.ToString() + "." + i.ToString()); } UpdateFileAndImageUrl(Store.SerializeData(objProductDAL.FOfPro), objProductDAL.Image, ID); return ID; } catch (Exception) { throw; } } private static byte SetSaleMode(ProductDAL objProductDAL) { if (objProductDAL.SourceSiteSaleAddress == null || objProductDAL.SourceSiteSaleAddress == "") { if (!ProductTypesDAL.IsDownloadable(objProductDAL.ProductType)) return (byte)SaleMode.ToPost; if (objProductDAL.FOfPro.Exists(priceMode => priceMode.FilePriceMode == (int)FilePriceMode.FreeTrial)) return (byte)SaleMode.DownloadableAndFreeTrial; else return (byte)SaleMode.Downloadable; } else return (byte)SaleMode.SourceSiteSale; }
}