public static RelativeTimeSpan Parse(string str)
        {
            RelativeTimeSpan s = new RelativeTimeSpan();
            int i= str.IndexOf(':');

            try {
                if(i == -1){
                    s.Years = (int)uint.Parse(str);
                }
                else {
                    s.Years = (int)uint.Parse(str.Substring(0,i));
                    s.MonthsInYear = (int)uint.Parse(str.Substring(i+1));
                }
            }
            catch {
                throw;
            }
            return s;
        }
Beispiel #2
0
		private void OnRelativeTimeSpanOutput(object o, OutputArgs args){			
			SpinButton spin = (SpinButton) o;
			string text;
			
			if(spin.ValueAsInt == 0)
				text = "";
			else {
				RelativeTimeSpan span = new RelativeTimeSpan();
				span.Months = spin.ValueAsInt;
				text = span.ToString();
			}
			
			if(spin.Text != text) spin.Text = text;
			args.RetVal = 1;
		}
Beispiel #3
0
		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);
			}
		}
        public static RelativeTimeSpan ParseXml(string str)
        {
            str = str.Trim();
            RelativeTimeSpan span = new RelativeTimeSpan();
            // check if it's a negative timespan
            bool negative = false;
            if(str[0] == '-'){
                negative = true;
                str = str.Substring(1);
            }
            // check if it starts with P
            if(str[0] != 'P')
                throw new FormatException("P is mandatory in duration");
            str = str.Substring(1);
            // extract the Year
            try {
                int start = str.IndexOf("Y");
                if(start >= 0){
                    span.Years = (int)uint.Parse(str.Substring(0,start));
                    str = str.Substring(start+1);
                }
                // extract the Month
                start = str.IndexOf("M");
                if(start >= 0){
                    span.MonthsInYear = (int)uint.Parse(str.Substring(0,start));
                }
            }
            catch {
                throw;
            }
            // make negative if nessesary
            if(negative)
                span.Months*=-1;

            return span;
        }