public TankMix_Calculation_Screen_Four() : base(UITableViewStyle.Grouped, null) { this.Pushing = true; Root = new RootElement ("Results"); Result = new CalculationResult (); InitializeUserInterface (); }
public string CreateExcelFile(CalculationResult r) { var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments); var fileAddress = Path.Combine (documents, "Report.csv"); if(File.Exists(fileAddress)){ File.Delete (fileAddress); } var sb = HistoryManager.SharedInstance.GetCSVPresentFormat (r); File.WriteAllText (fileAddress,sb.ToString()); Console.Out.WriteLine (fileAddress); return fileAddress; }
public StringBuilder GetCSVPresentFormat(CalculationResult r) { var variableNameList = new List<string> (); //page 1 variableNameList.Add ("Application Volume"); variableNameList.Add ("Product Rate"); variableNameList.Add ("Adjuvant Rate"); //page 2 variableNameList.Add ("Tank Capacity"); variableNameList.Add ("Tank Remainder at Fill"); variableNameList.Add ("Sump Capacity"); //page 3 variableNameList.Add ("Field Area"); variableNameList.Add ("Boom Width"); variableNameList.Add ("Field Length"); variableNameList.Add ("Total Number of Headland Swaths"); //page 4 variableNameList.Add ("Area Treated by Tank"); variableNameList.Add ("Product Amount"); variableNameList.Add ("Adjuvant Amount"); variableNameList.Add ("Number of Tanks Needed"); variableNameList.Add ("Number of Fills"); variableNameList.Add ("Area per Round"); variableNameList.Add ("Rounds per Tank"); var amountList = new List<string> (); //page 1 amountList.Add (r.TankInput.applicationvolume_value.value.ToString()); amountList.Add (r.TankInput.productrate_value.value.ToString()); amountList.Add (r.TankInput.adjuvantrate_value.value.ToString()); //page 2 amountList.Add (r.TankInput.tankcapacity_value.value.ToString()); amountList.Add (r.TankInput.tankremainder_value.value.ToString()); amountList.Add (r.TankInput.sumpcapacity_value.value.ToString()); //page 3 amountList.Add (r.TankInput.totalarea_value.value.ToString()); amountList.Add (r.TankInput.boomwidth_value.value.ToString()); amountList.Add (r.TankInput.swathlength_value.value.ToString()); amountList.Add (r.TankInput.number_headlands_swaths_value.ToString()); //page 4 amountList.Add (string.Format("{0:00.00}",r.areatreatedbytank_value.value)); amountList.Add (string.Format("{0:00.00}",r.productamount_value.value)); amountList.Add (string.Format("{0:00.00}",r.adjuvantamount_value.value)); amountList.Add (string.Format("{0:00.00}",r.numberOfTanksNeeded)); amountList.Add (string.Format("{0:00.00}",r.numberOfFills)); amountList.Add (string.Format("{0:00.00}",r.areaperround_value.value)); amountList.Add (string.Format("{0:00.00}",r.roundpertank)); var unitList = new List<string> (); //page 1 unitList.Add (r.TankInput.applicationvolume_value.unit.ToString()); unitList.Add (r.TankInput.productrate_value.unit.ToString()); unitList.Add (r.TankInput.adjuvantrate_value.unit.ToString()); //page 2 unitList.Add (r.TankInput.tankcapacity_value.unit.ToString()); unitList.Add (r.TankInput.tankremainder_value.unit.ToString()); unitList.Add (r.TankInput.sumpcapacity_value.unit.ToString()); //page 3 unitList.Add (r.TankInput.totalarea_value.unit.ToString()); unitList.Add (r.TankInput.boomwidth_value.unit.ToString()); unitList.Add (r.TankInput.swathlength_value.unit.ToString()); unitList.Add (string.Empty); //page 4 unitList.Add (r.areatreatedbytank_value.unit.ToString()); unitList.Add (r.productamount_value.unit.ToString()); unitList.Add (r.adjuvantamount_value.unit.ToString()); unitList.Add (string.Empty); unitList.Add (string.Empty); unitList.Add (r.areaperround_value.unit.ToString()); unitList.Add (string.Empty); var output = new string[variableNameList.Count+1][]; output [0] = new string[]{"Property Name ", " Value ", " Amount "}; for(int i=1 ;i<=variableNameList.Count; i++){ output [i] = new string[]{variableNameList[i-1],amountList[i-1],unitList[i-1]}; } StringBuilder sb = new StringBuilder (); int length = output.GetLength (0); for (int i=0; i<length; i++){ sb.AppendLine (string.Join(",",output[i])); } // Fills if(r.fills.Count != 0) { for (int i = 0; i < r.fills.Count; i++) { var fillResult = new string[10][]; fillResult [0] = new string[]{ string.Empty, string.Empty, string.Empty }; fillResult [1] = new string[]{ "File" + (i + 1), string.Empty, string.Empty }; fillResult [2] = new string[]{ "Remainder", r.fills [i].Remainder.ToString (), r.fills [i].Remainder_Unit }; fillResult [3] = new string[] { "Area Treated So Far", r.fills [i].AreaTreated.ToString (), r.fills [i].AreaTreated_Unit }; fillResult [4] = new string[]{ "Area Remaning", r.fills [i].AreaRemaning.ToString (), r.fills [i].AreaRemaning_Unit }; fillResult [5] = new string[]{ "Tank Fill", r.fills [i].TankFill.ToString (), r.fills [i].TankFill_Unit }; fillResult [6] = new string[]{ "Net", r.fills [i].Net.ToString (), r.fills [i].Net_Unit }; fillResult [7] = new string[] { "This Tank Area", string.Format ("{0:00.00}", r.fills [i].ThisTankArea.ToString ()), r.fills [i].ThisTankArea_Unit }; fillResult [8] = new string[] { "Product", string.Format ("{0:00.00}", r.fills [i].Product.ToString ()), r.fills [i].Product_Unit }; fillResult [9] = new string[] { "Adjuvant", string.Format ("{0:00.00}", r.fills [i].Adjuvant.ToString ()), r.fills [i].Adjuvant_Unit }; for (int j = 0; j < fillResult.GetLength (0); j++) { sb.AppendLine (string.Join (",", fillResult [j])); } } } return sb; }
// // FILL // Remainder // Area treated so far // area remaining // tank fill // net // this tank area // product // adjuvant public TankMix_History_Result(CalculationResult R) : base(UITableViewStyle.Grouped, null) { this.Pushing = true; Root = new RootElement ("Result Detail"); ApplicationVolume = new StringElement ("Application Value",R.TankInput.applicationvolume_value.value +" "+ R.TankInput.applicationvolume_value.unit); ProductRate = new StringElement ("Product Rate",R.TankInput.productrate_value.value +" "+R.TankInput.productrate_value.unit); AdjuvantRate = new StringElement ("Adjuvant Rate",R.TankInput.adjuvantrate_value.value + " "+ R.TankInput.adjuvantrate_value.unit); TankCapacity = new StringElement ("Tank Capacity",R.TankInput.tankcapacity_value.value +" "+R.TankInput.tankcapacity_value.unit); TankRemainder = new StringElement ("Tank Remainder at Fill",R.TankInput.tankremainder_value.value +" "+R.TankInput.tankremainder_value.unit); SumpCapacity = new StringElement ("Sump Capacity",R.TankInput.sumpcapacity_value.value+" "+R.TankInput.sumpcapacity_value.unit); FieldArea = new StringElement ("Field Area",R.TankInput.totalarea_value.value +" "+R.TankInput.totalarea_value.unit); BoomWidth = new StringElement ("Boom Width",R.TankInput.boomwidth_value.value+" "+R.TankInput.boomwidth_value.unit); FieldLength = new StringElement ("Field Length",R.TankInput.swathlength_value.value+" "+R.TankInput.swathlength_value.unit); TotalNumberHeadland = new StringElement ("Total Number of Headland Swaths",R.TankInput.number_headlands_swaths_value.ToString()); AreaTreatedByTank = new StringElement ("Area Treated by Tank", string.Format("{0:00.00}",R.areatreatedbytank_value.value) + " " + R.areatreatedbytank_value.unit); ProductAmount = new StringElement ("Product Amount",string.Format("{0:00.00}",R.productamount_value.value) +" "+ R.productamount_value.unit); AdjuvantAmount = new StringElement ("Adjuvant Amount",string.Format("{0:00.00}",R.adjuvantamount_value.value) +" "+R.adjuvantamount_value.unit); TotalWater = new StringElement ("Total Water",R.totalwater_value.value +" "+R.totalwater_value.unit); NumOfTanksNeed = new StringElement ("Number of Tanks Need", string.Format("{0:00.00}",R.numberOfTanksNeeded)); NumOfFills = new StringElement ("Number of Fills",Convert.ToInt32(R.numberOfFills).ToString()); AreaPerRound = new StringElement ("Area per Round",string.Format("{0:00.00}",R.areaperround_value.value)+" "+R.areaperround_value.unit); RoundsPerTank = new StringElement ("Rounds Per Tank",string.Format("{0:00.00}",R.roundpertank)); var Section = new Section (); Section.Add (ApplicationVolume); Section.Add (ProductRate); Section.Add (AdjuvantRate); Section.Add (TankCapacity); Section.Add (TankRemainder); Section.Add (SumpCapacity); Section.Add (FieldArea); Section.Add (BoomWidth); Section.Add (FieldLength); Section.Add (TotalNumberHeadland); Section.Add (AreaTreatedByTank); Section.Add (ProductAmount); Section.Add (AdjuvantAmount); Section.Add (TotalWater); Section.Add (NumOfTanksNeed); Section.Add (NumOfFills); Section.Add (AreaPerRound); Section.Add (RoundsPerTank); Root.Add (Section); var FillBtn = new UIBarButtonItem (); FillBtn.Title = "Fills"; FillBtn.Clicked += (object sender, EventArgs e) => { if(R.numberOfFills == 0){ }else{ this.NavigationController.PushViewController(new TankMix_History_Fill(R.fills,int.Parse(R.numberOfFills.ToString())),true); } }; this.NavigationItem.RightBarButtonItem = FillBtn; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear (animated); var elements = HistoryManager.SharedInstance.GetResultList(); Root.Remove(Section); Section = new Section (); for (int i=1; i<=elements.Count;i++) { var temp = i; Section.Add (new StringElement("Result "+temp,()=>{ Console.Out.WriteLine(temp); var ActionSheet = new UIActionSheet ("Options"); ActionSheet.AddButton("Detail"); ActionSheet.AddButton("Send by Email"); ActionSheet.AddButton("Delete"); ActionSheet.AddButton("Cancel"); ActionSheet.DestructiveButtonIndex = 2; ActionSheet.CancelButtonIndex = 3; ActionSheet.Clicked += (object sender, UIButtonEventArgs e) => { if(e.ButtonIndex == 0) { // Detail Console.Out.WriteLine("Detail"); var t = new CalculationResult (); t = HistoryManager.SharedInstance.GetResultList()[temp-1]; this.NavigationController.PushViewController(new TankMix_History_Result(t),true); }else if (e.ButtonIndex == 1){ // Share Console.Out.WriteLine("Send by Email"); var Email = new MFMailComposeViewController(); if(MFMailComposeViewController.CanSendMail) { var filePath = CreateExcelFile(HistoryManager.SharedInstance.GetResultList()[temp-1]); //NSData iData = NSData.FromUrl(new NSUrl(imageList[i],false) ); NSData attachement = NSData.FromUrl(new NSUrl(filePath,false)); Email.AddAttachmentData(attachement,"text/csv","Reports"); } Email.Finished += (object s, MFComposeResultEventArgs ea) => { ea.Controller.DismissViewController(true,null); }; var msg = ""; Email.SetMessageBody(msg,false); this.NavigationController.PresentViewController(Email,true,null); this.NavigationController.PopToRootViewController(true); }else if (e.ButtonIndex == 2){ //Delete Console.Out.WriteLine("Delete"); HistoryManager.SharedInstance.GetResultList().RemoveAt(i-2); ViewWillAppear(true); }else{ // Cancel Console.Out.WriteLine("Cancel"); CreateExcelFile(HistoryManager.SharedInstance.GetResultList()[temp-1]); } }; ActionSheet.ShowInView(View); })); } Root.Add (Section); }