private void printShooter(PrintPageEventArgs ev, Structs.Shooter shooter, ref float yPos) { Structs.Competitor[] competitors = CommonCode.GetCompetitors(shooter.ShooterId, "PatrolId"); foreach (Structs.Competitor comp in competitors) { if (comp.PatrolId > 0) { Structs.Patrol patrol = CommonCode.GetPatrol(comp.PatrolId); ev.Graphics.DrawString(patrol.StartDateTimeDisplay.ToShortTimeString(), printCompetitorFont, Brushes.Black, LeftMargin + tab1, yPos, new StringFormat()); ev.Graphics.DrawString(patrol.PatrolId.ToString(), printCompetitorFont, Brushes.Black, LeftMargin + tab2, yPos, new StringFormat()); } Structs.Weapon weapon = CommonCode.GetWeapon(comp.WeaponId); ev.Graphics.DrawString(weapon.Manufacturer + ", " + weapon.Model + "(" + comp.WeaponId + ")", printCompetitorFont, Brushes.Black, LeftMargin + tab3, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); } currentShooter++; }
internal void PatrolAddEmpty(bool notifyGui) { database = myInterface.databaseClass.Database; DateTime compStart = myInterface.GetCompetitions()[0].StartTime; int timeBetweenPatrols = database.Competition[0].PatrolTimeBetween; int lastStart = 0 - timeBetweenPatrols; int patrolId = 0; foreach (DatabaseDataset.PatrolsRow row in database.Patrols) { if (row.StartDateTime > lastStart) { lastStart = row.StartDateTime; } if (row.PatrolId > patrolId) { patrolId = row.PatrolId; } } Structs.Patrol patrol = new Structs.Patrol(); patrol.PatrolId = patrolId + 1; patrol.StartDateTime = compStart.AddMinutes((int)(lastStart + timeBetweenPatrols)); patrol.CompetitionId = database.Competition[0].CompetitionId; myInterface.NewPatrol(patrol, notifyGui); }
private string createPatrolHtmls(Structs.Patrol patrol) { StringBuilder html = new StringBuilder(); html.Append("<table>\r\n"); html.Append("<tr>"); html.Append("<td>Figur</td>"); html.Append("<td>Namn</td>"); html.Append("<td>Klass</td>"); html.Append("<td>Vapen</td>"); html.Append("</tr>\r\n"); Structs.Competitor[] comps = myInterface.GetCompetitors(patrol); for (int lane = 1; lane <= myInterface.GetCompetitions()[0].PatrolSize; lane++) { bool found = false; foreach (Structs.Competitor comp in comps) { if (comp.Lane == lane) { html.Append(createPatrolHtmlCompetitor(comp)); found = true; } } if (!found) { html.Append(createPatrolHtmlEmpty(lane)); } } html.Append("</table>\r\n"); return(html.ToString()); }
internal void PatrolRemoveLast() { Trace.WriteLine("CPatrolManagement: patrolRemoveLast() started on thread \"" + Thread.CurrentThread.Name + "\" ( " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )"); try { database = myInterface.databaseClass.Database; if (database.Patrols.Count == 0) { return; } Trace.WriteLine("CPatrolManagement: PatrolRemoveLast() " + " locking \"PatrolRemoveLastLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )"); lock (PatrolRemoveLastLock) { Trace.WriteLine("CPatrolManagement: PatrolRemoveLast() " + " locked \"PatrolRemoveLastLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )"); if (database.Patrols.Count == 0) { return; } int pid = getHighestPatrolId(); if (myInterface.GetCompetitorsCountPatrol(myInterface.GetPatrol(pid)) > 0) { throw new ApplicationException("CompetitorsExist"); } Structs.Patrol patrol = myInterface.GetPatrol(pid); myInterface.DelPatrol(patrol, false); Trace.WriteLine("CPatrolManagement: PatrolRemoveLast() " + " locked \"PatrolRemoveLastLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + System.Threading.Thread.CurrentThread.ManagedThreadId.ToString() + " )"); } } catch (System.Data.DeletedRowInaccessibleException) { Trace.WriteLine("CPatrolManagement: PatrolRemoveLast DeletedRowInaccessibleException. Retrying."); PatrolRemoveLast(); } finally { Trace.WriteLine("CPatrolManagement: PatrolRemoveLast ended."); } }
internal bool CheckChangePatrolConnectionTypeIsPossible( Structs.Patrol patrol, Structs.PatrolConnectionTypeEnum newPatrolConnectionType) { Structs.Competitor[] competitors = myInterface.GetCompetitors(patrol); if (competitors.Length == 0) { return(true); // Since there are no competitors, patrol is changeable } Structs.Weapon weapon = myInterface.GetWeapon(competitors[0].WeaponId); Structs.PatrolClass patrolClass = myInterface.ConvertWeaponsClassToPatrolClass( weapon.WClass, newPatrolConnectionType); foreach (Structs.Competitor competitor in competitors) { weapon = myInterface.GetWeapon(competitor.WeaponId); if (patrolClass != myInterface.ConvertWeaponsClassToPatrolClass( weapon.WClass, newPatrolConnectionType)) { return(false); } } return(true); }
private double writePatrolByClub(ref pdfPage page, Structs.Shooter[] shooters, ref double yPos) { Structs.Club club = myInterface.GetClub(shooters[0].ClubId); if (yPos + conversionPixelsToMM * (2 * fontSize + fontHeaderSize) > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } addText(page, club.ClubId, columnPatrolsByClubClubIdPos, yPos, fontHeader, fontHeaderSize); yPos = addText(page, club.Name, columnPatrolsByClubNamePos, yPos, fontHeader, fontHeaderSize); foreach (Structs.Shooter shooter in shooters) { if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } foreach (Structs.Competitor comp in myInterface.GetCompetitors(shooter.ShooterId, "PatrolId")) { if (yPos + 2 * conversionPixelsToMM * fontSize > bottomMargin) { // Paging page = getNewPage(ref yPos); yPos = writePatrolByClubHeader(page, yPos); } if (comp.PatrolId >= 1) { Structs.Patrol patrol = myInterface.GetPatrol(comp.PatrolId); string weaponText = getWeapon(myInterface.GetWeapon(comp.WeaponId)); addText(page, shooter.Givenname + ", " + shooter.Surname, columnPatrolsByClubNamePos, yPos, font, fontSize); addText(page, patrol.PatrolId.ToString() + " (" + patrol.StartDateTimeDisplay.ToShortTimeString() + ")", columnPatrolsByClubPatrolPos, yPos, font, fontSize); addText(page, weaponText, columnPatrolsByClubWeaponPos, yPos, font, fontSize); Structs.ShootersClassShort sc = (Structs.ShootersClassShort)(int) comp.ShooterClass; string classText = sc.ToString().Replace("Klass", "").Replace("Damklass", "D"); classText += myInterface.GetWeapon(comp.WeaponId).WClass.ToString().Substring(0, 1); yPos = addText(page, classText, columnPatrolsByClubClassPos, yPos, font, fontSize); yPos += 1; } } } return(yPos + 5); }
private string createPatrolHeader(Structs.Patrol patrol) { StringBuilder html = new StringBuilder(); html.Append("<b>Patrull " + patrol.PatrolId + " - " + patrol.StartDateTime.ToShortTimeString() + "</b>\r\n"); return(html.ToString()); }
internal CPrintResultLabels(ref Common.Interface newCommon, Structs.Patrol PatrolToPrint, int AlreadyPrintedLabels) : base() { CommonCode = newCommon; Patrol = PatrolToPrint; labelCount = AlreadyPrintedLabels; }
internal CPrintResultlistByPatrol(ref Common.Interface newCommon, Structs.Patrol patrolToPrint) : base() { CommonCode = newCommon; patrol = patrolToPrint; Structs.Competition competition = CommonCode.GetCompetitions()[0]; CompetitionType = competition.Type; this.NorwegianCount = competition.NorwegianCount; }
//Override the OnPrintPage to provide the printing logic for the document protected override void OnPrintPage(PrintPageEventArgs ev) { base.OnPrintPage(ev); //Work out the number of lines per page //Use the MarginBounds on the event to do this //lpp = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics) ; float topMargin = ev.MarginBounds.Top; topMargin = 25; float yPos = topMargin; leftMargin = base.DefaultPageSettings.HardMarginX; if (leftMargin < 20) { leftMargin = 20; } //Now print what we want to print Structs.Patrol patrol = CommonCode.GetPatrol(this.currentPatrol); printHeader(ev, patrol, ref yPos); yPos += 20; printPatrol(ev, patrol, ref yPos, maxLanes); // Increase current control for the next one //If we have more patrols then print another page if (this.patrolIdToPrint == -1) { if (CommonCode.GetPatrolsCount() >= this.currentPatrol) { ev.HasMorePages = true; } else { ev.HasMorePages = false; } } else { if (this.currentPatrol == this.patrolIdToPrint) { ev.HasMorePages = true; } else { ev.HasMorePages = false; } } }
private void printPatrol(PrintPageEventArgs ev, Structs.Patrol patrol, ref float yPos, int maxLanes) { placeLeftHeaderX = ev.PageBounds.Left + 10; placeLeftHeaderX = leftMargin; //placeClubX = (ev.PageBounds.Right - ev.PageBounds.Left)/2 + ev.PageBounds.Left; placeNameX = 80 + ev.PageBounds.Left; placeNameX = placeLeftHeaderX + 70; // Print competitorheader //ev.Graphics.DrawString("Namn", // printCompetitorHeaderFont, Brushes.Black, placeNameX, yPos, // new StringFormat()); //yPos += printHeaderFont.GetHeight(); // Print competitors for (int thisLane = lastPrintedLane + 1; thisLane <= maxLanes; thisLane++) { bool laneFound = false; lastPrintedLane = thisLane; foreach (Structs.Competitor comp in CommonCode.GetCompetitors(patrol, "Lane")) { if (comp.Lane == thisLane) { laneFound = true; printThisCompetitor(ev, comp, ref yPos); yPos += this.printCompetitorFont.GetHeight() / 2; } } if (!laneFound) { printEmptyCompetitor(ev, ref yPos, thisLane); yPos += this.printCompetitorFont.GetHeight() / 2; } if (yPos + heightOfOneCompetitor > (ev.PageBounds.Height - 2 * printHeaderFont.GetHeight() - 20) & thisLane < maxLanes) { return; } } currentPatrol++; lastPrintedLane = 0; }
internal string ExportPatrols() { //database = myInterface.databaseClass.database; StringBuilder html = new StringBuilder(); html.Append(createHtmlHeader()); html.Append(createCompetitionHeader()); for (int patrolId = 1; patrolId < myInterface.GetPatrolsCount(); patrolId++) { Structs.Patrol patrol = myInterface.GetPatrol(patrolId); html.Append(createPatrolHeader(patrol)); html.Append(createPatrolHtmls(patrol)); } html.Append(createHtmlFooter()); return(html.ToString()); }
private void ChangePatrolConnectionType( Structs.PatrolConnectionTypeEnum newPatrolConnectionType, Structs.Patrol patrol) { Structs.Competitor[] competitors = myInterface.GetCompetitors(patrol); if (competitors.Length == 0) { return; } Structs.Weapon weapon = myInterface.GetWeapon(competitors[0].WeaponId); Structs.PatrolClass patrolClass = myInterface.ConvertWeaponsClassToPatrolClass( weapon.WClass, newPatrolConnectionType); if (patrolClass != patrol.PClass) { patrol.PClass = patrolClass; myInterface.UpdatePatrol(patrol); } }
private void populatePatrol(Structs.Patrol thisPatrol) { Trace.WriteLine("FPatrol: populatePatrol started on thread \"" + Thread.CurrentThread.Name + "\" ( " + Thread.CurrentThread.ManagedThreadId.ToString() + " )"); this.datasetPatrol.shooters.Clear(); // Populate list with competitors from this patrol Structs.Competitor[] competitors = CommonCode.GetCompetitors(thisPatrol, "Lane"); foreach (Structs.Competitor competitor in competitors) { DatasetPatrol.shootersRow patrolRow = this.datasetPatrol.shooters.NewshootersRow(); // Fetch data for row Structs.Shooter shooter = CommonCode.GetShooter(competitor.ShooterId); Structs.Club club = CommonCode.GetClub(shooter.ClubId); Structs.Weapon weapon = CommonCode.GetWeapon(competitor.WeaponId); // Populate row patrolRow.Move = false; patrolRow.competitorId = competitor.CompetitorId; patrolRow.Name = shooter.Givenname + " " + shooter.Surname; patrolRow.Club = club.Name; patrolRow.Weapon = weapon.Manufacturer + "," + weapon.Model + "," + weapon.Caliber; patrolRow.Lane = competitor.Lane; patrolRow.WeaponClass = weapon.WClass.ToString().Substring(0, 1); this.datasetPatrol.shooters.AddshootersRow(patrolRow); } Trace.WriteLine("FPatrol: populatePatrol ended."); }
private double writePatrol(ref pdfPage page, Structs.Patrol patrol, ref double yPos) { if (yPos + conversionPixelsToMM * fontSize > bottomMargin) { page = getNewPage(ref yPos); yPos = writePatrolHeader(page, yPos); } addText(page, patrol.PatrolId.ToString() + " ( " + patrol.StartDateTimeDisplay.ToShortTimeString() + " )", columnPatrolsPatrolPos, yPos, font, fontSize); foreach (Structs.Competitor comp in myInterface.GetCompetitors(patrol)) { if (yPos + conversionPixelsToMM * fontSize > bottomMargin) { page = getNewPage(ref yPos); yPos = writePatrolHeader(page, yPos); } Structs.Shooter shooter = myInterface.GetShooter(comp.ShooterId); Structs.Club club = myInterface.GetClub(shooter.ClubId); Structs.Weapon weapon = myInterface.GetWeapon(comp.WeaponId); string weaponString = getWeapon(weapon); addText(page, shooter.Givenname + ", " + shooter.Surname, columnPatrolsNamePos, yPos, columnPatrolsClubNamePos - columnPatrolsNamePos, font, fontSize); addText(page, club.Name, columnPatrolsClubNamePos, yPos, columnPatrolsWeaponPos - columnPatrolsClubNamePos, font, fontSize); yPos = addText(page, weaponString, columnPatrolsWeaponPos, yPos, font, fontSize); yPos += 1; } return(yPos); }
private void printHeader(PrintPageEventArgs ev, Structs.Patrol patrol, ref float yPos) { //leftMargin = ev.MarginBounds.Left; int tab = 100; // Print RegistrationsInfo ev.Graphics.DrawString( "WinShooter", printAllbergFont, Brushes.Black, leftMargin, ev.PageBounds.Size.Height - 2 * printHeaderFont.GetHeight() - 20, new StringFormat()); /*ev.Graphics.DrawString("©John Allberg", * printAllbergFont, Brushes.Black, ev.PageBounds.Right-180, * ev.PageBounds.Size.Height -2*printHeaderFont.GetHeight()-20, * new StringFormat());*/ // Print logo System.Drawing.Image image = getLogo(); ev.Graphics.DrawImage( image, ev.MarginBounds.Right - image.Width, 20, image.Width, image.Height); // Print patrol header ev.Graphics.DrawString("Tävling: ", printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(CommonCode.GetCompetitions()[0].Name, printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); string patrolHeader = "Patrull: "; switch (CommonCode.CompetitionCurrent.Type) { case Structs.CompetitionTypeEnum.Field: patrolHeader = "Patrull: "; break; case Structs.CompetitionTypeEnum.MagnumField: patrolHeader = "Patrull"; break; case Structs.CompetitionTypeEnum.Precision: patrolHeader = "Lag: "; break; default: throw new ApplicationException("Unkown CompetitionType"); } ev.Graphics.DrawString(patrolHeader, printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(patrol.PatrolId.ToString(), printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); ev.Graphics.DrawString("Starttid: ", printHeaderFont, Brushes.Black, leftMargin, yPos, new StringFormat()); ev.Graphics.DrawString(patrol.StartDateTimeDisplay.ToShortTimeString(), printHeaderFont, Brushes.Black, leftMargin + tab, yPos, new StringFormat()); yPos += printHeaderFont.GetHeight(); }
private void updatePatrolWithThread() { Trace.WriteLine("FPatrol: updatePatrolWithThread started on thread \"" + Thread.CurrentThread.Name + "\" ( " + Thread.CurrentThread.ManagedThreadId.ToString() + " )"); Trace.WriteLine("FPatrol: updatePatrolWithThread locking " + "\"bindingLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + Thread.CurrentThread.ManagedThreadId.ToString() + " )"); lock (bindingLock) { try { Updating = true; Trace.WriteLine("FPatrol: updatePatrolWithThread locked " + "\"bindingLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + Thread.CurrentThread.ManagedThreadId.ToString() + " )"); try { Patrol = CommonCode.GetPatrol(patrolid); } catch (Common.CannotFindIdException) { if (InvokeRequired) { Invoke(SetVisibillity, new object[] { false }); } else { Visible = false; } return; } catch (ApplicationException) { if (InvokeRequired) { Invoke(SetVisibillity, new object[] { false }); } else { Visible = false; } return; } if (this.InvokeRequired) { this.Invoke(BindPatrolNumberAndClass); } else { this.bindPatrolNumberAndClass(); } createDatasetPatrol(); populatePatrol(Patrol); populateUnassigned(Patrol.PClass); if (this.InvokeRequired) { this.Invoke(BindDatagrid); } else { this.bindDatagrid(); } Trace.WriteLine("FPatrol: updatePatrolWithThread unlocking " + "\"bindingLock\" on thread \"" + Thread.CurrentThread.Name + "\" ( " + Thread.CurrentThread.ManagedThreadId.ToString() + " )"); } finally { Updating = false; } } Trace.WriteLine("FPatrol: updatePatrolWithThread ended."); }
private void saveCurrent() { int nrOfStations = (int)numNrOfSeries.Value; int nrOfShootsPerStation = (int)numNrOfShootPerSeries.Value; int shoots = 0; int figures = 0; switch (chkUseOnlyOneBoxForResult.Checked) { case true: figures = 1; shoots = 10 * nrOfShootsPerStation; break; case false: figures = nrOfShootsPerStation; shoots = 10 * nrOfShootsPerStation; break; } for (int i = 1; i <= CommonCode.GetStationsCount(); i++) { Structs.Station station = CommonCode.GetStation(i, false); station.Figures = figures; station.Shoots = shoots; CommonCode.UpdateStation(station); } while (CommonCode.GetStationsCount() < nrOfStations) { Structs.Station station = new Structs.Station(); station.CompetitionId = CommonCode.GetCompetitions()[0].CompetitionId; station.Figures = figures; station.Points = false; station.Shoots = shoots; station.StationNr = CommonCode.GetStationsCount() + 1; CommonCode.NewStation(station, false); } while (CommonCode.GetStationsCount() > nrOfStations) { Structs.Station station = CommonCode.GetStation(CommonCode.GetStationsCount(), false); CommonCode.DelStation(station); } Structs.Competition competition = CommonCode.GetCompetitions()[0]; int timeAvailable = competition.PatrolTimeBetween; int timeNeeded = calculateTimeRequirements(); if (timeNeeded > timeAvailable) { DialogResult res = MessageBox.Show("Du har avsatt " + timeAvailable.ToString() + " minuter för varje skjutlag.\r\n\r\n" + "Beräknad tid för varje skjutlag med hänsyn taget till " + "skjuttid (6 minuter per serie) och markeringstid " + "(6 minuter per serie) är " + timeNeeded.ToString() + " minuter.\r\n\r\n" + "Vill du öka upp avsatt tid?", "Kontrollberäkning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (res == DialogResult.Yes) { competition.PatrolTimeBetween = timeNeeded; CommonCode.UpdateCompetition(competition); DateTime patrolStart = competition.StartTime; Structs.Patrol[] patrols = CommonCode.GetPatrols(); for (int i = 0; i < patrols.Length; i++) { Structs.Patrol patrol = patrols[i]; //Trace.WriteLine(patrol.StartDateTimeDisplay.ToShortTimeString()); patrol.StartDateTime = patrolStart; patrol.StartDateTimeDisplay = patrolStart; CommonCode.UpdatePatrol(patrol); patrolStart = patrolStart.AddMinutes(timeNeeded); } } } }
DSInternetExport getShootersForPatrolExportByClub() { DSInternetExport toReturn = new DSInternetExport(); Hashtable shooters = new Hashtable(); Hashtable clubs = new Hashtable(); Hashtable weapons = new Hashtable(); foreach (Structs.Competitor comp in myInterface.GetCompetitors()) { if (comp.PatrolId != -1 & comp.Lane != -1) { DSInternetExport.PatrolsByClubRow newRow = toReturn.PatrolsByClub.NewPatrolsByClubRow(); newRow.PatrolId = comp.PatrolId; newRow.Lane = comp.Lane; Structs.Shooter shooter; if (shooters.Contains(comp.ShooterId)) { shooter = (Structs.Shooter)shooters[comp.ShooterId]; } else { shooter = myInterface.GetShooter(comp.ShooterId); shooters.Add(comp.ShooterId, shooter); } newRow.ShooterName = shooter.Surname + " " + shooter.Givenname; newRow.Payed = shooter.Payed; Structs.Club club; if (clubs.Contains(shooter.ClubId)) { club = (Structs.Club)clubs[shooter.ClubId]; } else { club = myInterface.GetClub(shooter.ClubId); clubs.Add(shooter.ClubId, club); } newRow.ClubName = club.Name; newRow.ClubId = shooter.ClubId; Structs.Patrol patrol = myInterface.GetPatrol(comp.PatrolId); newRow.Start = patrol.StartDateTimeDisplay; Structs.Weapon weapon; if (weapons.Contains(comp.WeaponId)) { weapon = (Structs.Weapon)weapons[comp.WeaponId]; } else { weapon = myInterface.GetWeapon(comp.WeaponId); weapons.Add(comp.WeaponId, weapon); } newRow.Weapon = weapon.Manufacturer; newRow.WeaponCaliber = weapon.Caliber; Structs.ShootersClassShort shootershort = (Structs.ShootersClassShort) (int) comp.ShooterClass; newRow.ShooterClass = shootershort.ToString() .Replace("Klass", "") .Replace("Damklass", "D") + weapon.WClass.ToString() .Replace("1", "") .Replace("2", "") .Replace("3", ""); toReturn.PatrolsByClub.AddPatrolsByClubRow(newRow); } } return(toReturn); }