|
|
Hi, I've made a custom webcontrol that works similar to gridview but with a few extra functionalities. The control works just fine, but my designer is showing 2 issues:
- I can't drag the control from the toolbar to a page, the action isn't allowed for unknown reason.
- I have editable templates. Changing an existing template contents works perfect. However, creating a new template from designer view isn't working(it's not persisting to my pagecode). If I create it manually by typing in the template in code view, there is no issue.
I am overriding following methods of the designer
- GetEditableDesignerRegionContent
- SetEditableDesignerRegionContent
- GetDesignTimeHtml
- GetDesignTimeHtml(DesignerRegionCollection regions)
- GetEmptyDesignTimeHtml
following properties:
- ActionLists
- TemplateGroups
My control inherits from DataBoundControl.
My designer control inherits from DataBoundControlDesigner.
Each template property has following attributes:
[TemplateContainer(typeof(CustomItemsControlItem))]
[TemplateInstance(TemplateInstance.Single)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[DefaultValue(null)]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
Am I missing something? If you need code of a specific block, please ask.
|
|
|
|
|
Hi,
My requirement is "By using the web services/WCF of Amazon (and other retailers) I can upload products on Amazon (and other sites) in bulk.".
I done google. read http://docs.developer.amazonservices.com and other articals on different website, but unable to find anything that I can use or understand how to use them.
one more thing for sample application(using Amazon WCF/WS), Is it must to register on Amazon with your "CREDIT CARD DETAILS".
if you know some good articals on it plz provide links.
Thanks in advance.
modified 21-Apr-14 5:24am.
|
|
|
|
|
hi i found http://www.seesharpdot.net/?p=157[^]. it is about How to get album, dvd, and blueray cover art from Amazon. it is not what i am looking for, but helpful in understating "how to start working with Amazon APIs".
|
|
|
|
|
I will have a couple of methods that are called to mark records as deleted:
public DeleteByAddressIdResponse DeleteByAddressId(int Id)
{
Func<ClientAddressEntity, bool> whereClause = ca => ca.AddressId == Id;
return deleteClientAddresses<DeleteByAddressIdResponse >(whereClause);
}
public DeleteByAddressTypeIdResponse DeleteByAddressTypeId(int Id)
{
Func<ClientAddressEntity, bool> whereClause = ca => ca.AddressTypeId == Id;
return deleteClientAddresses<DeleteByAddressTypeIdResponse >(whereClause);
}
public DeleteByClientIdResponse DeleteByClientId(int Id)
{
Func<ClientAddressEntity, bool> whereClause = ca => ca.ClientId == Id;
return deleteClientAddresses<DeleteByClientIdResponse >(whereClause);
}
I'm trying to create a where clause for a Linq To Sql query. I'm not sure how to apply there where clause.
private T deleteClientAddresses<T>(Func<ClientAddressEntity, bool> whereClause) where T : _ResponseBase
{
var response = (T)Activator.CreateInstance(typeof(T));
using (var dc = getDataContext())
{
var entities = (from ca in dc.ClientAddresses select ca);
foreach (var entity in entities)
{
var deleteAddressResponse = DeleteAddress(entity.AddressId);
if (deleteAddressResponse.Result == Result.Success)
{
entity.IsDeleted = true;
try
{
dc.SubmitChanges();
}
catch (Exception e)
{
response.Exception = e;
break;
}
}
else
{
response.Exception = deleteAddressResponse.Exception;
}
}
}
return response;
}
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
You need to call the Where extension method[^] using the method syntax instead of the query syntax.
However, since you're using a Func<T, bool> to filter the records, the filter cannot be translated to a SQL query. As a result, all records will be loaded into memory before being passed to the filter to see if they match. If you change your code to use an Expression<Func<T, bool>> , the filter will be passed to SQL, and only the matching records will be returned.
You can also avoid the Activator.CreateInstance call by adding the new() constraint to your generic type parameter.
private T deleteClientAddresses<T>(Expression<Func<ClientAddressEntity, bool>> whereClause) where T : _ResponseBase, new()
{
var response = new T();
using (var dc = getDataContext())
{
var entities = dc.ClientAddresses.Where(whereClause);
foreach (var entity in entities)
{
...
}
}
return response;
}
public DeleteByAddressIdResponse DeleteByAddressId(int Id)
{
Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.AddressId == Id;
return deleteClientAddresses<DeleteByAddressIdResponse>(whereClause);
}
public DeleteByAddressTypeIdResponse DeleteByAddressTypeId(int Id)
{
Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.AddressTypeId == Id;
return deleteClientAddresses<DeleteByAddressTypeIdResponse>(whereClause);
}
public DeleteByClientIdResponse DeleteByClientId(int Id)
{
Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.ClientId == Id;
return deleteClientAddresses<DeleteByClientIdResponse>(whereClause);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Great suggestions. Thanks.
So now I have another problem. I have:
public DeleteByAddressIdResponse DeleteAllClientAddressesByClientId(int Id)
{
Expression<Func<ClientAddressEntity, bool>> whereClause = ca => ca.AddressId == Id;
var response = deleteClientAddresses<DeleteByAddressIdResponse >(whereClause);
return response;
}
and
private T deleteClientAddresses<T>(Expression<Func<ClientAddressEntity, bool>> whereClause) where T : _ResponseBase, new()
{
var response = new T();
using (var dc = getDataContext())
{
var entities = dc.ClientAddresses.Where(whereClause);
foreach (var entity in entities)
{
}
}
return response;
}
I'm getting
'System.Data.Linq.Table<Falcon.DAL.Data_Context.ClientAddress>' does not contain a definition for 'Where' and the best extension method overload
I installed system.linq.dynamic[^], which I thought would fix it, but no luck.
If it's not broken, fix it until it is
|
|
|
|
|
Make sure you've got a reference to the System.Core assembly, and using System.Linq; at the top of your file.
Also, your types don't match. The error message reports a type of ClientAddress , whereas your predicate is looking at a type called ClientAddressEntity . You'll need to change the filters to be Expression<Func<Falcon.DAL.Data_Context.ClientAddress, bool>> .
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Same error.
And, even after adding a ref to System.Core, in the DAL code Core' is not found in System namespace.
This is bizarre.
If it's not broken, fix it until it is
|
|
|
|
|
Sorry, I just spotted that your types don't match and updated my answer. Your filters are looking at the ClientAddressEntity type, whereas your table contains ClientAddress objects.
Your filters need to be:
Expression<Func<Falcon.DAL.Data_Context.ClientAddress, bool>>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That did it!
Many thanks
If it's not broken, fix it until it is
|
|
|
|
|
i have codin knap sack on c # and exe file
|
|
|
|
|
Leave it round the back. I'll pick it up in the morning.
|
|
|
|
|
Do not repost - it's rude, it wastes time, and it annoys people.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
|
It's the haiku version!
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
Do you have a question?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
i have coding knap sack in c# and exe file
|
|
|
|
|
But the elephant flies at midnight.
Yuri, is that you? Do you have the microfilm?
|
|
|
|
|
The fora are dark
the fora are deep
but I have promises to keep
and miles to go before I sleep
"I had the right to remain silent, but I didn't have the ability!"
Ron White, Comedian
|
|
|
|
|
Da.... the rooster barks at midnight. Look out for the elf.
I lost the microfilm comrade. I left it in some knapsack.
|
|
|
|
|
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Edit your question and provide better information.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
If you're looking for the knapsack problem[^], there's pseudocode for a simple solution on wikipedia.
|
|
|
|
|
Is there a question somewhere?
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
I am considering a change to the way I return objects from my DAL. I would like your opinion on this design.
Currently each method in the DAL returns void, an Entity, or a List<[SomeEntity]>. So as an example, my AddLookup method looks like this:
public LookupEntity AddLookup(LookupEntity entity)
{
using (FMGDataContext dc = getDataContext())
{
var lookupExists = dc.Lookups.Where(l => l.Caption.Trim().ToLower() == entity.Caption.Trim().ToLower() &&
l.LookupCode.Trim().ToLower() == entity.LookupCode.Trim().ToLower()).Any();
if (!lookupExists)
{
Lookup newLookup = new Lookup
{
LookupCode = entity.LookupCode,
LookupTypeName = entity.LookupTypeName,
Caption = entity.Caption,
Description = entity.Description,
ParentId = entity.ParentId ?? 0,
};
dc.Lookups.InsertOnSubmit(newLookup);
try
{
dc.SubmitChanges();
entity.Id = newLookup.LookupId;
}
catch (Exception e)
{
}
}
else
{
throw new DuplicateLookupException(string.Format("Lookup {0} already exists", entity.Caption));
}
}
return entity;
}
Instead, I'm considering changing all my methods to return an instance of a response object:
public class _ResponseBase
{
[DataMember]
public Result Result { get; set; }
[DataMember]
public string Message { get; set; }
private Exception _Exception;
[DataMember]
public Exception Exception
{
get { return _Exception; }
set
{
if (_Exception != value)
{
_Exception = value;
Message = _Exception.Message;
Result = Result.Failure;
}
}
}
}
So now the AddLookup method would be:
public AddLookupResponse AddLookup(LookupEntity entity)
{
AddLookupResponse response = new AddLookupResponse();
using (FalconDataContext dc = getDataContext())
{
bool exsits = (from l in dc.Lookups
where l.LookupCode.Trim().ToLower() == entity.LookupCode.Trim().ToLower()
select l).Any();
if (exsits)
{
response.Result = Result.Failure;
response.Message = string.Format("Lookup code '{0}' already exists in the Lookups table", entity.LookupCode);
}
else
{
Lookup newRecord = new Lookup
{
LookupCode = entity.LookupCode,
LookupName = entity.LookupName,
Caption = entity.Caption,
Description = entity.Description,
SystemCode = entity.SystemCode,
ParentId = entity.ParentId
};
dc.Lookups.InsertOnSubmit(newRecord);
try
{
dc.SubmitChanges();
entity.Id = newRecord.LookupId;
response.Data = entity;
}
catch (Exception e)
{
response.Exception = e;
}
}
}
return response;
}
There are some good advantages of this design:
1. The ability to return more robust data & information back to the UI.
2. A consistent design pattern across all layers
3. Better exception handling
There also some drawbacks:
1. All calls to the DAL from the UI would now have to look like this:
AddLookupResponse response = Engine.APIProxy.AddLookup(SelectedLookupItem);
if (response.Result == Result.Success)
{
}
else
{
HandleResponse(response);
}
2. There is more code for each method, even though it allows all the handling to be done in the UI.
I welcome your comments.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|