public CropDetails() { InitializeComponent(); CropModel cropModel = new CropModel(); GetAllCropsCompleted handler = new GetAllCropsCompleted(LoadCropList); cropModel.GetAllCrops(new Action<List<CropModel>>(handler)); }
public DeleteCrop() { InitializeComponent(); cropModel = new CropModel(); handler = new GetAllCropsCompleted(LoadCropList); cropModel.GetAllCrops(new Action<List<CropModel>>(handler)); }
public void LoadCropById(CropModel cm) { GetFieldByIdCompleted fieldDataHandler = new GetFieldByIdCompleted(LoadFieldById); FieldModel fieldModel = new FieldModel(); fieldModel.GetFieldById(new Action<FieldModel>(fieldDataHandler), cm.FieldId); byte[] avatarImageByte = cm.AvatarImage; if (avatarImageByte != null) { MemoryStream ms = new MemoryStream(avatarImageByte); BitmapImage avatar = new BitmapImage(); avatar.SetSource(ms); AvatarImg.Source = avatar; } NameTxt.Text = cm.Name; TypeTxt.Text = cm.Type; TimeOfPlantingTxt.Text = cm.TimeOfPlanting.ToString("yyyy-MM-dd"); AreaCoverageTxt.Text = cm.CoverageValue.ToString(); WateringTxt.Text = cm.WateringFrequency + " X " + cm.WateringPeriod; HillingTxt.Text = cm.HillingTime.ToString("yyyy-MM-dd"); HarvestingTxt.Text = cm.HarvestTime.ToString("yyyy-MM-dd"); FertilizingTimeTxt.Text = cm.FertilizingTime.ToString("yyyy-MM-dd"); }
public Journal() { InitializeComponent(); CropModel cropModel = new CropModel(); GetAllCropsCallback handler = new GetAllCropsCallback(GetAllCropsCompleted); cropModel.GetAllCrops(new Action<List<CropModel>>(handler)); }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); string cropIdValue = NavigationContext.QueryString["parameter"]; int cropId = Int16.Parse(cropIdValue); GetCropByIdCompleted handler = new GetCropByIdCompleted(LoadCropById); CropModel cropModel = new CropModel(); cropModel.GetCropById(new Action<CropModel>(handler), cropId); }
// Save crop data public void saveCropData(Func<int,int> callback, CropModel cropModel) { this.cropModel = cropModel; insertCropCallback = callback; Crop c = mapCropModelToCrop(cropModel); CropServiceClient cropSvc = new CropServiceClient(); cropSvc.InsertCropDataAsync(c); cropSvc.InsertCropDataCompleted += new EventHandler <InsertCropDataCompletedEventArgs>(cropSvc_InsertCropDataCompleted); }
private void deleteBtn_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Are you sure?", "Delete Item", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { CropModel cropModel = new CropModel(); int id = ((CropModel)cropPicker.SelectedItem).Id; cropModel.DeleteCropById(id); cropModel.GetAllCrops(new Action<List<CropModel>>(handler)); } }
public void GetCropByIdCompleted(CropModel crop) { ViewGetCropByIdCallback(crop); }
private void saveBtn_Click(object sender, RoutedEventArgs e) { CropModel cropModel = new CropModel(); cropModel.Name = nameField.Text; cropModel.Type = typeField.Text; cropModel.TimeOfPlanting = timeOfPlatning.Value == null ? new DateTime() : (DateTime)timeOfPlatning.Value; cropModel.AvatarImage = avatarImage; cropModel.FieldId = fieldPicker.SelectedItem == null ? 0 : ((FieldModel)fieldPicker.SelectedItem).Id; cropModel.CoverageValue = Double.Parse(coverageValue.Text); cropModel.WateringFrequency = Int16.Parse(waterFreqPicker.SelectedItem.ToString()); cropModel.WateringPeriod = timeSortPicker.SelectedIndex.ToString(); cropModel.HarvestTime = timeOfHarvest.Value == null ? new DateTime() : (DateTime)timeOfHarvest.Value; cropModel.HillingTime = timeOfHilling.Value == null ? new DateTime() : (DateTime)timeOfHilling.Value; cropModel.FertilizingTime = timeOfFertilizing.Value == null ? new DateTime() : (DateTime)timeOfFertilizing.Value; cropModel.IllnessId = 0;//Int16.Parse(illnessField.Text); SaveCropCallback handlerCrop = new SaveCropCallback(DisplaySaveCropToastMsg); cropModel.Save(new Action<int>(handlerCrop)); }
// Maps ViewModel with service DataContract private Crop mapCropModelToCrop(CropModel cm) { Crop crop = new Crop(); crop.name = cm.Name; crop.croptype = cm.Type; crop.timeofplanting = cm.TimeOfPlanting; crop.avatarimage = cm.AvatarImage; crop.fieldcoverage = cm.CoverageValue; crop.wateringfrequency = cm.WateringFrequency; crop.wateringperiod = (Int16.Parse(cm.WateringPeriod)+1).ToString(); crop.harvesttime = cm.HarvestTime; crop.hillingtime = cm.HillingTime; crop.fertilizingtime = cm.FertilizingTime; crop.fieldid = cm.FieldId; return crop; }
// Maps DataContract from service to ViewModel private CropModel mapCropToCropModel(Crop cm) { CropModel crop = new CropModel(); crop.Id = cm.cropid; crop.Name = cm.name; crop.Type = cm.croptype; crop.TimeOfPlanting = cm.timeofplanting; crop.AvatarImage = cm.avatarimage; crop.CoverageValue = cm.fieldcoverage; crop.WateringFrequency = cm.wateringfrequency; crop.WateringPeriod = cm.wateringperiod; crop.HarvestTime = cm.harvesttime; crop.HillingTime = cm.hillingtime; crop.FertilizingTime = cm.fertilizingtime; crop.FieldId = cm.fieldid; return crop; }