private void ProductPropertyChanged(Widget w, Product product){ if(object.ReferenceEquals(w,itemEditBrand)) product.Brand = itemEditBrand.Text; else if(object.ReferenceEquals(w,itemEditModel)) product.Model = itemEditModel.Text; else if(object.ReferenceEquals(w,itemEditBarcode)) product.Serial = itemEditBarcode.Text; else if(object.ReferenceEquals(w,itemEditWarranty)){ RelativeTimeSpan span = new RelativeTimeSpan(); span.Months = itemEditWarranty.ValueAsInt; product.Warranty = span; } else if(object.ReferenceEquals(w,itemEditOwner)){ bool s = itemEditOwner.Active; itemEditAmount.Sensitive = s; itemEditUsefulLife.Sensitive = s; itemEditCost.Sensitive = s; itemEditWarranty.Sensitive = s; itemEditPurchase.Sensitive = s; itemEditDepreciationMethod.Sensitive = s; itemEditLabelMethod.Sensitive = s; itemEditShowCalendar.Sensitive = s; product.Owner = s; } else if(object.ReferenceEquals(w,itemEditWeight)){ product.Weight = itemEditWeight.Value;} else if(object.ReferenceEquals(w,itemEditAmount)) product.PurchasedAmount = (uint)itemEditAmount.ValueAsInt; else if(object.ReferenceEquals(w,itemEditUsefulLife)){ RelativeTimeSpan span = new RelativeTimeSpan(); span.Months = itemEditUsefulLife.ValueAsInt; product.UsefulLife = span; } else if(object.ReferenceEquals(w,itemEditCost)) product.Cost = itemEditCost.Value; else if(object.ReferenceEquals(w,itemEditPurchase)){ try { product.PurchaseDate = DateTime.Parse(itemEditPurchase.Text); } catch { product.PurchaseDate = null; } } else if(object.ReferenceEquals(w,itemEditDepreciationMethod)){ TreeIter iter; itemEditDepreciationMethod.GetActiveIter(out iter); product.DepreciationMethod = (DepreciationMethod)itemEditDepreciationMethod.Model.GetValue(iter,2); } else if(object.ReferenceEquals(w,itemEditLabelMethod)){ TreeIter iter; itemEditLabelMethod.GetActiveIter(out iter); product.LabelMethod = (LabelMethod)itemEditLabelMethod.Model.GetValue(iter,2); } }
private void EditProduct(Product product) { itemEditCategoryBook.ShowTabByWidget(itemEditProductAlign); itemEditBrand.Text = product.Brand.EmptyIfNull(); itemEditModel.Text = product.Model.EmptyIfNull(); itemEditBarcode.Text = product.Serial.EmptyIfNull(); itemEditWeight.Value = product.Weight; itemEditWarranty.Value = product.Warranty.Months; itemEditPurchase.Text = (product.PurchaseDate == null)?"":((DateTime)product.PurchaseDate).ToString("d"); itemEditCost.Value = product.Cost; itemEditUsefulLife.Value = product.UsefulLife.Months; itemEditAmount.Value = product.PurchasedAmount; itemEditOwner.Active = product.Owner; itemEditLabelMethod.Model.Foreach(delegate(TreeModel m, TreePath p, TreeIter i){ LabelMethod method = (LabelMethod)m.GetValue(i,2); if(method == product.LabelMethod){ itemEditLabelMethod.SetActiveIter(i); return true; } return false; }); itemEditDepreciationMethod.Model.Foreach(delegate(TreeModel m, TreePath p, TreeIter i){ DepreciationMethod method = (DepreciationMethod)m.GetValue(i,2); if(method == product.DepreciationMethod){ itemEditDepreciationMethod.SetActiveIter(i); return true; } return false; }); }