I have added field in salesTable and on the salesTable form. I want to put the default values like created when the sales order is created and Updated when sales order is updated. All I have to do is using chain of command.
You create a new class,extension of SalesTable, with something like this:
[ExtensionOf(tablestr(SalesTable))]
final class SalesTable_MyExt_Extension
{
void initValue(SalesType _salesType)
{
next initValue();
this.myField = "foo";
}
public void update()
{
this.myField = "bar";
next update();
}
}
Related
I want to get the transportation cost from the database in the card.php but now its write statically 25000 .this cost must be dynamic that owner of site can be change it.
in photo transportation write staticly
but I want call in from database and is dynamic
public function __construct($oldCart)
{
if($oldCart){
$this->items = $oldCart->items;
$this->totalQty = $oldCart->totalQty;
$this->totalPrice = $oldCart->totalPrice;
$this->totalPurePrice = $oldCart->totalPurePrice;
$this->totalDiscountPrice = $oldCart->totalDiscountPrice;
$this->transportation = $oldCart->transportation;
}
}
}
Do this after the code that you put the photo above.you don't need __construct. you should have getter and setter like this:
public function setTransportation($value)
{
$this->transportation= $value;
}
public function getTransportation()
{
return $this->transportation;
}
and in another method set a value (example : 5) you can give it from database:
$this->setTransportation(5);
Then get it this way:
$myTransportation=$this->getTransportation();
I have a partial class to extend one of my LinqToSql classes. In this partial class I have the following calculated field.
public bool IsInCluster
{
get
{
return Cluster != null;
}
}
In order for a grid column databound to this field to update automatically I have implemented the following partial method.
partial void OnClusterIDChanged()
{
SendPropertyChanged("IsInCluster");
}
However when I update the Cluster property as shown in the following code the OnClusterIDChanged method does not get called:
private void ExecCreateClusterCommand()
{
var cluster = new Cluster()
{
ID = Guid.NewGuid(),
MailService = AppState.CurrentMailService
};
App.DataContext.Clusters.InsertOnSubmit(cluster);
foreach (DeliveryPoint deliveryPoint in SelectedDeliveryPoints)
{
deliveryPoint.Cluster = cluster;
}
App.DataContext.SubmitChanges();
}
I have successfully used this technique with other non navigation properties related to calculated fields. Is there a way to make this work?
In your setter for Cluster, call OnClusterIDChanged, if the state has changed.
The only solution I could find for this was to create a public method in the DeliveryPoint class enabling me to call SendPropertyChanged for the required field (navigation property):
public void CallSendPropertyChanged(string propertyName)
{
SendPropertyChanged(propertyName);
}
I'm using LINQ To SQL to update a user address.
I'm trying to track what fields were updated.
The GetChangeSet() method just tells me I'm updating an entity, but doesn't tell me what fields.
What else do I need?
var item = context.Dc.Ecs_TblUserAddresses.Single(a => a.ID == updatedAddress.AddressId);
//ChangeSet tracking
item.Address1 = updatedAddress.AddressLine1;
item.Address2 = updatedAddress.AddressLine2;
item.Address3 = updatedAddress.AddressLine3;
item.City = updatedAddress.City;
item.StateID = updatedAddress.StateId;
item.Zip = updatedAddress.Zip;
item.Zip4 = updatedAddress.Zip4;
item.LastChangeUserID = request.UserMakingRequest;
item.LastChangeDateTime = DateTime.UtcNow;
ChangeSet set = context.Dc.GetChangeSet();
foreach (var update in set.Updates)
{
if (update is EberlDataContext.EberlsDC.Entities.Ecs_TblUserAddress)
{
}
}
Use ITable.GetModifiedMembers. It returns an array of ModifiedMemberInfo objects, one for each modified property on the entity. ModifiedMemberInfo contains a CurrentValue and OriginalValue, showing you exactly what has changed. It's a very handy LINQ to SQL feature.
Example:
ModifiedMemberInfo[] modifiedMembers = context.YourTable.GetModifiedMembers(yourEntityObject);
foreach (ModifiedMemberInfo mmi in modifiedMembers)
{
Console.WriteLine(string.Format("{0} --> {1}", mmi.OriginalValue, mmi.CurrentValue));
}
You can detect Updates by observing notifications of changes. Notifications are provided through the PropertyChanging or PropertyChanged events in property setters.
E.g. you can extend your generated Ecs_TblUserAddresses class like this:
public partial class Ecs_TblUserAddresses
{
partial void OnCreated()
{
this.PropertyChanged += new PropertyChangedEventHandler(User_PropertyChanged);
}
protected void User_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
string propertyName = e.PropertyName;
// do what you want
}
}
Alternatively, if you want to track a special property changing, you could use one of those OnPropertyNameChanging partial methods, e.g. (for City in your example):
partial void OnCityChanging(string value)
{
// value parameter holds a new value
}
I'm trying to filter a JTable using a TableRowFilter . It works for me on a simple example , but I can't seem to get it to work on the real thing. The filter is called , the logs are printed - but I staill see the rows . Any ideas?
public class TopicTable extends JTable {
...
public TopicTable(ITopic topic) {
super();
TopicTableDataModel model = new TopicTableDataModel(topic);
setModel(model);
setRowSorter(generateTableRowSorter(model));
setFillsViewportHeight(true);
setColumnRenderers();
}
private TableRowSorter<TableModel> generateTableRowSorter(TableModel model) {
RowFilter<Object, Object> classFilter = new RowFilter<Object, Object>() {
#Override
public boolean include(javax.swing.RowFilter.Entry<? extends Object, ? extends Object> entry) {
log.debug("Filtering? " + entry.getValue(1));
return false;
}
};
TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model);
sorter.setRowFilter(classFilter);
return sorter;
}
...
}
As all stupid bugs go - this was one of them . In another class that use this table , I used table.setAutoCreateRowSorter(true) - so even thought the original sorter still ran , the default one also did , and then nothing happened.
It's my first LINQ TO SQL Project , So definitely my question could be naive .
Till now I used to create new property in Business Object beside of every DateTime Property , That's because i need to do some processing in my DateTime property and show it in special string format for binding to UI Controls .Like :
private DateTime _insertDate;
///
/// I have "InertDate" field in my Table on Database
///
public DateTime InsertDate
{
get { return _insertDate; }
set { _insertDate = value; }
}
// Because i need to do some processing I create a readonly string property that pass InsertDate to Utility method and return special string Date
public string PInsertDate
{
get { return Utility.ToSpecialDate(_insertDate); }
}
My question is I don't know how to do it in LINQ . I did like follow but i get run time error. "Method 'System.String ToSpecialDate(System.Object)' has no supported translation to SQL"
ToosDataContext db = new ToosDataContext();
var newslist = from p in db.News
select new {p.NewsId,p.Title,tarikh =MD.Utility.ToSpecialDate( p.ReleaseDate)};
GridView1.DataSource = newslist;
GridView1.DataBind();
You need to separate out the query performed in the database from the processing to be done in process. Try this:
var newslist = db.News
// First do a select in SQL
.Select(p => new {p.NewsId, p.Title, p.ReleaseDate})
.AsEnumerable() // Do the rest in process
.Select(p => new {p.NewsId, p.Title,
tarikh = MD.Utility.ToSpecialDate(p.ReleaseDate) });