Ejemplo n.º 1
0
 private void ButtonClicked(object sender, EventArgs e)
 {
     if ((sender as Button) == bGenerate)
     {
         try
         {
             string QRdata1 = null;
             string QRdata2 = null;
             //get the MatchData for the selected event
             List <MatchData> scoutList = eData.GetMatchDataForEvent(selectedEvent.eventID);
             for (int i = 0; i < scoutList.Count; i++)
             {
                 //split data into two
                 if (i < Math.Round((double)scoutList.Count / 2))
                 {
                     QRdata1 += scoutList[i].teamNumber.ToString() + "," +
                                scoutList[i].matchNumber.ToString() + "," +
                                scoutList[i].result.ToString() +
                                scoutList[i].position.ToString() +
                                Convert.ToByte(scoutList[i].isTable).ToString() +
                                scoutList[i].sandstormStartLevel.ToString() +
                                scoutList[i].sandstormMode.ToString() +
                                Convert.ToByte(scoutList[i].sandstormHatch).ToString() +
                                Convert.ToByte(scoutList[i].sandstormCargo).ToString() +
                                Convert.ToByte(scoutList[i].sandstormLine).ToString() +
                                Convert.ToByte(scoutList[i].cargo).ToString() +
                                Convert.ToByte(scoutList[i].cargoWell).ToString() +
                                Convert.ToByte(scoutList[i].cargoBarely).ToString() +
                                Convert.ToByte(scoutList[i].hatch).ToString() +
                                Convert.ToByte(scoutList[i].hatchWell).ToString() +
                                Convert.ToByte(scoutList[i].hatchBarely).ToString() +
                                scoutList[i].climb.ToString() +
                                Convert.ToByte(scoutList[i].goodDrivers).ToString() +
                                scoutList[i].wouldRecommend.ToString();
                 }
                 else
                 {
                     QRdata2 += scoutList[i].teamNumber.ToString() + "," +
                                scoutList[i].matchNumber.ToString() + "," +
                                scoutList[i].result.ToString() +
                                scoutList[i].position.ToString() +
                                Convert.ToByte(scoutList[i].isTable).ToString() +
                                scoutList[i].sandstormStartLevel.ToString() +
                                scoutList[i].sandstormMode.ToString() +
                                Convert.ToByte(scoutList[i].sandstormHatch).ToString() +
                                Convert.ToByte(scoutList[i].sandstormCargo).ToString() +
                                Convert.ToByte(scoutList[i].sandstormLine).ToString() +
                                Convert.ToByte(scoutList[i].cargo).ToString() +
                                Convert.ToByte(scoutList[i].cargoWell).ToString() +
                                Convert.ToByte(scoutList[i].cargoBarely).ToString() +
                                Convert.ToByte(scoutList[i].hatch).ToString() +
                                Convert.ToByte(scoutList[i].hatchWell).ToString() +
                                Convert.ToByte(scoutList[i].hatchBarely).ToString() +
                                scoutList[i].climb.ToString() +
                                Convert.ToByte(scoutList[i].goodDrivers).ToString() +
                                scoutList[i].wouldRecommend.ToString();
                 }
             }
             //get QR code writer
             Writer writer = new QRCodeWriter();
             int    width  = this.Resources.DisplayMetrics.WidthPixels;
             //create the QR codes
             try
             {
                 BitMatrix      bm1  = writer.encode(QRdata1, BarcodeFormat.QR_CODE, width, width);
                 BitmapRenderer bit1 = new BitmapRenderer();
                 QR1.SetImageBitmap(bit1.Render(bm1, BarcodeFormat.QR_CODE, QRdata1));
                 Popup.Single("Alert", "Data for Event: '" + selectedEvent.eventName + "' Event ID: " +
                              selectedEvent.eventID.ToString() + " Generated. Please make sure that the receiving " +
                              "device has the correct event selected and that the event ids match", "OK", this);
             }
             //exception thrown if QR data strings are empty
             catch
             {
                 Popup.Single("Alert", "No data for this match", "OK", this);
             }
             //try to generate a second QR code
             try
             {
                 BitMatrix      bm2  = writer.encode(QRdata2, BarcodeFormat.QR_CODE, width, width);
                 BitmapRenderer bit2 = new BitmapRenderer();
                 QR2.SetImageBitmap(bit2.Render(bm2, BarcodeFormat.QR_CODE, QRdata2));
             }
             //do nothing if there is not enough data for a second QR code
             catch
             {
             }
         }
         //if no event is selected, it throws an exception
         catch
         {
             Popup.Single("Alert", "Please select an event to generate data for", "OK", this);
         }
     }
 }