public static bool CompareRecords(ClusterInfo cluster1, ClusterInfo cluster2, ClusterInfo cluster3, System.Windows.Forms.ToolStripProgressBar bar) { if (cluster1 == null || cluster2 == null || cluster3 == null) { return(false); } bar.Value = 0; bar.Maximum = 4; bar.Step = 1; bar.Visible = true; bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster1 = GetRecordFromCluster(cluster1); bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster2 = GetRecordFromCluster(cluster2); bar.PerformStep(); Dictionary <string, PatientRecord> recordsCluster3 = GetRecordFromCluster(cluster3); if (recordsCluster1.Count() != recordsCluster2.Count() || recordsCluster2.Count() != recordsCluster3.Count()) { return(false); } string key = ""; PatientRecord record1, record2, record3; foreach (var item in recordsCluster1) { key = item.Key; record1 = item.Value; record2 = recordsCluster2[key]; record3 = recordsCluster3[key]; if (record2 == null || record3 == null) { return(false); } if (record1.Compare(record2) && record2.Compare(record3)) { continue; } else { bar.Visible = false; return(false); } } bar.PerformStep(); bar.Visible = false; return(true); }
public bool ModifyRecord(ClusterInfo cluster, int numberOfRecords, System.Windows.Forms.ToolStripProgressBar bar) { Comm comm = new Comm(cluster.username, cluster.password, cluster.server, cluster.keyspace); comm.Connect(); ISession session = comm.GetSession(); string queryString = "SELECT key FROM patient_record LIMIT " + numberOfRecords; PreparedStatement preparedStatement = session.Prepare(queryString); BoundStatement boundStatement = preparedStatement.Bind(); RowSet result = session.Execute(boundStatement); foreach (Row row in result) { string updateString = "UPDATE patient_record SET phone_no='" + GetRandomTelNo() + "', address='" + GetRandomAddress() + "' WHERE key=" + row[0].ToString(); PreparedStatement ps = session.Prepare(updateString); BoundStatement bs = ps.Bind(); session.Execute(bs); bar.PerformStep(); } bar.Visible = false; return(true); }
public void PackedFileLoaded(PackedFile packedFile) { currentCount++; if (currentCount % 10 <= 0) { progressReporter.ReportProgressAsync(() => { label.Text = string.Format("Opening {0} ({1} of {2} files loaded)", file, currentCount, codecFileCount); progress.PerformStep(); }); } }
/// <summary> /// Uploads the schedule to the database /// </summary> /// <param name="db_conn">database connection object</param> /// <param name="pbBar">progress bar</param> public void SubmitSchedule(DBConnect db_conn, System.Windows.Forms.ToolStripProgressBar pbBar) { // upload database info string query = "INSERT INTO route (schedule_ID, payment_due, is_paid, posted_by, posted_on, starting_date, ending_date)" + " VALUES ('" + this.ScheduleID + "', '" + this.PayDay + "', '0', '" + this.Author + "', '" + DateTime.Today.ToString("yyyy-MM-dd") + "', '" + this.Start + "', '" + this._endDay + "');"; // used to count if timed out int timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query); return; } } pbBar.Maximum = 1 + this._employees.ToList().Count + this._skeleton.ToList().Count; pbBar.PerformStep(); // second part bool result = this.UploadEmployeeTables(db_conn, pbBar); // final part result = result && this.UploadMainTable(db_conn, pbBar); if (result) { System.Threading.Thread.Sleep(600); System.Windows.Forms.MessageBox.Show("Uploaded Schedule successfully."); } return; }
/// <summary> /// uploads shift data to each employee's table /// </summary> /// <param name="db_conn">database connection object</param> /// <param name="pbBar">progress bar</param> /// <returns>true if successful, false otherwise</returns> private bool UploadEmployeeTables(DBConnect db_conn, System.Windows.Forms.ToolStripProgressBar pbBar) { // format for time display string format = "HH:mm:ss"; // go through each employee foreach (Employee employee in this._employees.ToList()) { // go through each shift this person is working foreach (Shift shift in employee._shiftsWorking.ToList()) { // upload this info string query = "INSERT INTO " + employee.Username + " (date, schedule_ID, shift_ID, type, start, end, length, is_paid) " + "VALUES (" + "'" + shift.Date.ToString("yyyy-MM-dd") + "', " + "'" + this.ScheduleID + "', " + "'" + shift.ShiftNumber + "', " + "'" + shift.Name.ToUpper() + "', " + "'" + shift.StartTime.ToString(format) + "', " + "'" + shift.EndTime.ToString(format) + "', " + "'" + shift.Length.TotalHours + "', " + "'0');"; int timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } } // update progress bar pbBar.PerformStep(); } return(true); }
/// <summary> /// Uploads the main schedule table to the database /// </summary> /// <param name="db_conn">database connection object</param> /// <param name="pbBar">progress bar</param> /// <returns>true if successful, false otherwise</returns> private bool UploadShiftsNewSite(DBConnect db_conn, System.Windows.Forms.ToolStripProgressBar pbBar) { string format = "HH:mm:ss"; int timeout; string query; // for each shift in this schedule foreach (ScheduleSlot slot in this._skeleton.ToList()) { // generate insert query query = "INSERT INTO `shifts_list` (`shift_id`, sched_id, `date`, `day`, `when`, `type`, `start`, `end`, length) " + "VALUES (" + "'" + slot._shiftInfo.ShiftNumber + "', " + "'" + this.ScheduleID + "', " + "'" + slot.Date.ToString("yyyy-MM-dd") + "', " + "'" + new CultureInfo("en-US").TextInfo.ToTitleCase(slot.Day) + "', " + "'" + slot._shiftInfo.When() + "', " + "'" + slot.Name.ToUpper() + "', " + "'" + slot._shiftInfo.StartTime.ToString(format) + "', " + "'" + slot._shiftInfo.EndTime.ToString(format) + "', " + "'" + slot.Length.TotalHours + "');"; // update progress bar pbBar.PerformStep(); timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } } return(true); }
/// <summary> /// Generates the KML string. /// </summary> /// <param name="toolStripProgressBar">A windows Forms ToolStripProgressBar</param> /// <returns>The KML string.</returns> public string generateKML(ref System.Windows.Forms.ToolStripProgressBar toolStripProgressBar) { XNamespace gx = "http://www.google.com/kml/ext/2.2"; XElement document = (XElement)(new Document().ToXNode()); XDocument kml = new XDocument( new XComment("Created with excel2earth"), new XElement("kml", new XAttribute(XNamespace.Xmlns + "kml", "http://www.opengis.net/kml/2.2"), new XAttribute(XNamespace.Xmlns + "gx", "http://www.google.com/kml/ext/2.2"), document ) ); int lastRow; if (this.range.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row < this.range.Rows.Count) { lastRow = this.range.SpecialCells(Excel.XlCellType.xlCellTypeLastCell, Type.Missing).Row; } else { lastRow = this.range.Rows.Count; } toolStripProgressBar.Minimum = this.range.Cells.Row + Convert.ToInt32(this.hasHeaders); toolStripProgressBar.Maximum = lastRow; toolStripProgressBar.Value = toolStripProgressBar.Minimum; toolStripProgressBar.Step = 1; foreach (StyleMap styleMap in this.styleSelection.Values.Where(StyleMap => StyleMap != null).Distinct()) { if (!document.Descendants("StyleMap").Where(StyleMap => StyleMap.Attribute("id").Value == styleMap.id).Any()) { document.Add((XElement)styleMap.ToXNode()); } } for (int row = 1 + Convert.ToInt32(this.hasHeaders); row <= lastRow; row++) { XElement parentNode = document; Placemark placemark = new Placemark(((Excel.Range) this.range.Cells[row, this.nameColumn]).Value2.ToString()); string id = ""; DecimalDegrees decimalDegrees; double altitude = 0.0; XElement[] childElements; XName childType = "Placemark"; DateTime dateTime1; DateTime dateTime2; Geometry geometry = null; bool addElements = true; // XY Coordinates try { switch (this.coordinatesFormat) { case 0: // Decimal Degrees decimalDegrees = new DecimalDegrees(((Excel.Range) this.range.Cells[row, this.coordinatesField2Column]).Value2.ToString(), ((Excel.Range) this.range.Cells[row, this.coordinatesField1Column]).Value2.ToString()); break; case 1: // Degrees, Decimal Minutes decimalDegrees = new DegreesDecimalMinutes(((Excel.Range) this.range.Cells[row, this.coordinatesField2Column]).Value2.ToString(), ((Excel.Range) this.range.Cells[row, this.coordinatesField1Column]).Value2.ToString()).ToDecimalDegrees(); break; case 2: // Degrees, Minutes, Seconds decimalDegrees = new DegreesMinutesSeconds(((Excel.Range) this.range.Cells[row, this.coordinatesField2Column]).Value2.ToString(), ((Excel.Range) this.range.Cells[row, this.coordinatesField1Column]).Value2.ToString()).ToDecimalDegrees(); break; case 3: // Military Grid Reference System decimalDegrees = new MilitaryGridReferenceSystem(((Excel.Range) this.range.Cells[row, this.coordinatesField1Column]).Value2.ToString()).ToDecimalDegrees(); break; //case 4: // Universal Transverse Mercator // throw new NotImplementedException(); // break; default: decimalDegrees = new DecimalDegrees(0d, 0d); break; } } catch { toolStripProgressBar.PerformStep(); continue; } // Z Coodinate if (this.hasAltitude) { if (!double.TryParse(((Excel.Range) this.range.Cells[row, this.altitudeColumn]).Value2.ToString(), out altitude)) { continue; } altitude *= altitudeUnitMultipliers[this.altitudeUnit]; } Geometry.CoordinateSet coordinateSet = new Geometry.CoordinateSet(decimalDegrees.Latitude, decimalDegrees.Longitude, altitude); // Folders for (int i = 0; i < this.folderColumns.Length; i++) { XElement[] folders = (from folder in parentNode.Descendants("Folder") where folder.Element("name").Value == ((Excel.Range) this.range.Cells[row, this.folderColumns[i]]).Value2.ToString() select folder).ToArray <XElement>(); if (folders.Length < 1) // If the folder doesn't exist, create it { parentNode.Add(new Folder(((Excel.Range) this.range.Cells[row, this.folderColumns[i]]).Value2.ToString()).ToXNode()); i--; } else // If the folder exists, use it { parentNode = folders[0]; } } // Snippet if (this.hasSnippet) { placemark.snippet = ((Excel.Range) this.range.Cells[row, this.snippetColumn]).Value2.ToString(); placemark.snippetMaxLines = this.snippetMaxLines; } // Description if (this.descriptionColumns.Length > 0) { XElement descriptionTable = new XElement("table"); for (int i = 0; i < this.descriptionColumns.Length; i++) { descriptionTable.Add ( new XElement("tr", new XAttribute("style", "background-color: #" + (i % 2 == 0 ? "FFFFFF" : "DDDDDD") + ";"), new XElement("td", new XAttribute("style", "font-weight: bold;"), new XText(((Excel.Range) this.range.Cells[1, this.descriptionColumns[i]]).Value2.ToString()) ), new XElement("td", new XText(((Excel.Range) this.range.Cells[row, this.descriptionColumns[i]]).Value2.ToString()) ) ) ); } placemark.description = descriptionTable.ToString(); } // Style if (this.iconColumn > 0) { string styleKey = ((Excel.Range) this.range.Cells[row, this.iconColumn]).Value2.ToString(); if (this.styleSelection.ContainsKey(styleKey) && this.styleSelection[styleKey].id != null) { placemark.styleUrl = "#" + this.styleSelection[styleKey].id; } } // Date/Time if (this.hasTimeStamp || this.hasTimeSpan) { if (this.dateTimeFormat1 == 1) { DateTime.TryParse(((Excel.Range) this.range.Cells[row, this.dateTimeField1Column]).Value2.ToString() + " " + ((Excel.Range) this.range.Cells[row, this.dateTimeField2Column]).Value2.ToString(), out dateTime1); } else { DateTime.TryParse(((Excel.Range) this.range.Cells[row, this.dateTimeField1Column]).Value2.ToString(), new System.Globalization.CultureInfo("en-us", false).DateTimeFormat, System.Globalization.DateTimeStyles.AssumeUniversal, out dateTime1); } if (this.hasTimeStamp) { placemark.timePrimitive = new TimeStamp(dateTime1, dateTimeFormats[this.dateTimeFormat1]); } if (this.hasTimeSpan) { if (this.dateTimeFormat2 == 1) { DateTime.TryParse(((Excel.Range) this.range.Cells[row, this.dateTimeField3Column]).Value2.ToString() + " " + ((Excel.Range) this.range.Cells[row, this.dateTimeField4Column]).Value2.ToString(), out dateTime2); } else { DateTime.TryParse(((Excel.Range) this.range.Cells[row, this.dateTimeField3Column]).Value2.ToString(), out dateTime2); } placemark.timePrimitive = new excel2earth.kml.TimeSpan(dateTime1, dateTimeFormats[dateTimeFormat1], dateTime2, dateTimeFormats[dateTimeFormat2]); } } // Model Orientation modelOrientation = null; Scale modelScale = null; Link modelLink = null; if (this.hasModel) { // Orientation if (this.modelHeadingColumn > 0 || this.modelTiltColumn > 0 || this.modelRollColumn > 0) { double modelHeading = 0.0; double modelTilt = 0.0; double modelRoll = 0.0; if (this.modelHeadingColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelHeadingColumn]).Value2.ToString(), out modelHeading); } if (this.modelTiltColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelTiltColumn]).Value2.ToString(), out modelTilt); } if (this.modelRollColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelRollColumn]).Value2.ToString(), out modelRoll); } modelOrientation = new Orientation(modelHeading, modelTilt, modelRoll); } // Scale if (this.modelXScaleColumn > 0 || this.modelYScaleColumn > 0 || this.modelZScaleColumn > 0) { double modelXScale = 1.0; double modelYScale = 1.0; double modelZScale = 1.0; if (this.modelXScaleColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelXScaleColumn]).Value2.ToString(), out modelXScale); } if (this.modelYScaleColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelYScaleColumn]).Value2.ToString(), out modelYScale); } if (this.modelZScaleColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.modelZScaleColumn]).Value2.ToString(), out modelZScale); } modelScale = new Scale(modelXScale, modelYScale, modelZScale); } if (this.modelColumn > 0) { modelLink = new Link(((Excel.Range) this.range.Cells[row, this.modelColumn]).Value2.ToString()); } } // Geometry if (this.hasMultiGeometry) { id = ((Excel.Range) this.range.Cells[row, this.multiGeometryColumn]).Value2.ToString(); childElements = (from children in parentNode.Descendants(childType) where children.Element("MultiGeometry").Attribute("id").Value == id select children).ToArray <XElement>(); childType = "MultiGeometry"; if (childElements.Length < 1) // If the Placemark doesn't exist, create it { placemark.geometry = new MultiGeometry(id); parentNode.Add(placemark.ToXNode()); parentNode = (from elements in parentNode.Descendants("Placemark").Descendants(childType) where elements.Attribute("id").Value == id select elements).First(); } else // If the Placemark exists, use it { parentNode = childElements.First(); } } #region MultiType switch (this.multiType) { case 0: // None break; case 1: // Polygon id = ((Excel.Range) this.range.Cells[row, this.multiTypeGroupColumn]).Value2.ToString(); childElements = (from children in parentNode.Descendants(childType).Descendants("Polygon") where children.Attribute("id").Value == id select children).ToArray <XElement>(); if (childElements.Length < 1) // If the Placemark doesn't exist, create it { Polygon polygon = new Polygon(id); if (this.hasAltitude) { polygon.hasAltitude = true; polygon.altitudeMode = this.altitudeModeIntToEnum[this.altitudeMode]; polygon.extrude = this.extrude; polygon.tessellate = this.tesselllate; } if (childType == "Placemark") { XElement xPlacemark = (XElement)placemark.ToXNode(); parentNode.Add(xPlacemark); parentNode = xPlacemark; } XElement xPolygon = (XElement)polygon.ToXNode(); parentNode.Add(xPolygon); parentNode = xPolygon; } else // If the Placemark exists, use it { parentNode = childElements[0]; System.Windows.Forms.MessageBox.Show(parentNode.ToString()); } childType = "Polygon"; break; case 2: // MultiTrack id = ((Excel.Range) this.range.Cells[row, this.multiTypeGroupColumn]).Value2.ToString(); childElements = (from children in parentNode.Descendants(childType).Descendants(gx + "MultiTrack") where children.Attribute("id").Value == id select children).ToArray <XElement>(); if (childElements.Length < 1) // If the Placemark doesn't exist, create it { MultiTrack multiTrack = new MultiTrack(id, this.trackInterpolate); if (this.hasAltitude) { multiTrack.hasAltitude = true; multiTrack.altitudeMode = this.altitudeModeIntToEnum[this.altitudeMode]; } if (childType == "Placemark") { if (this.hasModel) { placemark.styleUrl = null; } XElement xPlacemark = (XElement)placemark.ToXNode(); xPlacemark.Descendants("TimeStamp").Remove(); parentNode.Add(xPlacemark); parentNode = xPlacemark; } XElement xMultiTrack = (XElement)multiTrack.ToXNode(); parentNode.Add(xMultiTrack); parentNode = xMultiTrack; } else // If the placemark exists, use it { parentNode = childElements.First(); } childType = gx + "MultiTrack"; break; } #endregion switch (this.dataType) { case 0: // Point geometry = new Point(new Geometry.Coordinates(coordinateSet)); if (this.hasAltitude) { ((Point)geometry).extrude = this.extrude; } break; case 1: // Line String id = ((Excel.Range) this.range.Cells[row, this.dataTypeGroupColumn]).Value2.ToString(); childElements = (from children in parentNode.Descendants(childType).Descendants("LineString") where children.Attribute("id").Value.ToString() == id select children).ToArray <XElement>(); if (childElements.Length < 1) // LineString does not exist { geometry = new LineString(id, new Geometry.Coordinates(coordinateSet)); if (this.hasAltitude) { ((LineString)geometry).extrude = this.extrude; ((LineString)geometry).tessellate = this.tesselllate; } } else // LineString exists, add coordinates { XElement coordinates = childElements[0].Element("coordinates"); coordinates.SetValue(coordinates.Value + " " + coordinateSet.getString()); updateDescriptionTable(ref this.range, ref row, ref document, (XElement)childElements[0].Parent); addElements = false; } break; case 2: // Linear Ring id = ((Excel.Range) this.range.Cells[row, this.dataTypeGroupColumn]).Value2.ToString(); if (childType != "Polygon") { childElements = (from children in parentNode.Descendants(childType).Descendants("LinearRing") where children.Attribute("id").Value == id select children).ToArray <XElement>(); } else { childElements = (from children in parentNode.Descendants().Descendants("LinearRing") where children.Attribute("id").Value == id select children).ToArray <XElement>(); } if (childElements.Length < 1) // LinearRing does not exist { geometry = new LinearRing(id, new Geometry.Coordinates(coordinateSet)); if (this.hasAltitude && childType != "Polygon") { ((LinearRing)geometry).extrude = this.extrude; ((LinearRing)geometry).tessellate = this.tesselllate; } if (childType == "Polygon") { if (!parentNode.Descendants("outerBoundaryIs").Any()) { parentNode.Add(new XElement("outerBoundaryIs", geometry.ToXNode())); } else { parentNode.Add(new XElement("innerBoundaryIs", geometry.ToXNode())); updateDescriptionTable(ref this.range, ref row, ref document, parentNode.Parent); } addElements = false; } } else // LinearRing exists, add coordinates { XElement coordinates = childElements[0].Element("coordinates"); coordinates.SetValue(coordinates.Value + " " + coordinateSet.getString()); updateDescriptionTable(ref this.range, ref row, ref document, childElements[0].Parent); addElements = false; } break; case 3: // Model geometry = new Model(new Location(coordinateSet), modelOrientation, modelScale, modelLink); break; case 4: // Track Orientation trackOrientation = null; if (this.trackHeadingColumn > 0 || this.trackTiltColumn > 0 || this.trackRollColumn > 0) { double trackHeading = 0.0; double trackTilt = 0.0; double trackRoll = 0.0; if (this.trackHeadingColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.trackHeadingColumn]).Value2.ToString(), out trackHeading); } if (this.trackTiltColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.trackTiltColumn]).Value2.ToString(), out trackTilt); } if (this.trackRollColumn > 0) { double.TryParse(((Excel.Range) this.range.Cells[row, this.trackRollColumn]).Value2.ToString(), out trackRoll); } trackOrientation = new Orientation(trackHeading, trackTilt, trackRoll); } id = ((Excel.Range) this.range.Cells[row, this.dataTypeGroupColumn]).Value2.ToString(); if (childType != gx + "MultiTrack") { childElements = (from children in parentNode.Descendants(childType).Descendants(gx + "Track") where children.Attribute("id").Value == id select children).ToArray <XElement>(); } else { childElements = (from children in parentNode.Descendants(gx + "Track") where children.Attribute("id").Value == id select children).ToArray <XElement>(); } if (childElements.Length < 1) // If the placemark doesn't exist, create it { geometry = new Track(id, new Geometry.Coordinates(coordinateSet)); if (this.hasTimeStamp) { ((Track)geometry).whens = new TimeStamp[] { (TimeStamp)placemark.timePrimitive }; } if (trackOrientation != null) { ((Track)geometry).angles = new Orientation[] { trackOrientation }; } if (this.hasModel) { ((Track)geometry).model = new Model(modelOrientation, modelScale, modelLink); } if (childType == gx + "MultiTrack" && parentNode.Descendants(gx + "Track").Any()) { updateDescriptionTable(ref this.range, ref row, ref document, parentNode.Parent); } } else { XElement track = childElements[0]; if (this.hasTimeStamp) { (from whens in track.Descendants("when") select whens).Last().AddAfterSelf(((XElement)placemark.timePrimitive.ToXNode()).Descendants("when")); } (from coords in track.Descendants(gx + "coord") select coords).Last().AddAfterSelf(new XElement(gx + "coord", coordinateSet.getString().Replace(',', ' '))); if (trackOrientation != null) { (from angles in track.Descendants(gx + "angles") select angles).Last().AddAfterSelf(new XElement(gx + "angles", trackOrientation.getString())); } updateDescriptionTable(ref this.range, ref row, ref document, childElements[0].Parent); addElements = false; } break; } if (addElements) { if (this.hasAltitude && this.multiType != 1) { geometry.hasAltitude = true; geometry.altitudeMode = this.altitudeModeIntToEnum[this.altitudeMode]; } if (childType == "Placemark") { if (this.dataType == 4) { placemark.timePrimitive = null; } placemark.geometry = geometry; parentNode.Add(placemark.ToXNode()); } else { parentNode.Add(geometry.ToXNode()); } } toolStripProgressBar.PerformStep(); } return(kml.ToString()); }
public void Unpack() { using (FileStream fs = new FileStream(this.PATH, FileMode.Open, FileAccess.Read)) { string path = Path.Combine(Path.GetDirectoryName(this.PATH), Path.GetFileNameWithoutExtension(this.PATH)); if (LB != null) { LB.Text = "Unpacking: " + Path.GetFileName(PATH); LB.GetCurrentParent().Update(); } using (MemoryStream ms = new MemoryStream(fs.extractPiece(0, 2048))) { ms.Read(this.HEADER, 0, 16); ms.Read(this.NAME, 0, 20); NameSize(this.NAME); ms.Position = 16; while (ms.Read(this.NAME, 0, NAME_SIZE) == NAME_SIZE || ms.Position > 2048) { if (this.NAME[0] == 0xCD) { break; } ms.Read(INTS, 0, 8); this.NAMES.Add(this.NAME.extractString()); this.SIZES.Add(INTS.extractInt32(4)); this.OFFSETS.Add(INTS.extractInt32(0)); } } if (PB != null) { PB.Minimum = 0; PB.Value = 0; PB.Step = 1; PB.Maximum = NAMES.Count; } Directory.CreateDirectory(path); for (int i = 0; i < this.NAMES.Count; i++) { //if (PB != null) PB.PerformStep(); System.Windows.Forms.Application.DoEvents(); int size = this.SIZES[i] * 2048; int offset = this.OFFSETS[i] * 2048; if (fs.Position != offset) { fs.Position = offset; } fs.extractPiece(0, size).Save(Path.Combine(path, this.NAMES[i])); } GenerateXML(path); if (UnpackHOG) { UnpackHOGs(); } if (LB != null) { LB.Text = "Succefully Unpacked!"; } } }
public void GenerateRecords(ClusterInfo cluster, int numebrOfRecords, System.Windows.Forms.ToolStripProgressBar bar) { Initialization(); int iteration = 0; int mc = 0; int fc = 0; Random rand = new Random(); PatientRecord record = new PatientRecord(); Comm comm = new Comm(cluster.username, cluster.password, cluster.server, cluster.keyspace); comm.Connect(); ISession session = comm.GetSession(); //Deleting existing data in the patient_record string truncateString = "truncate patient_record"; PreparedStatement ps = session.Prepare(truncateString); BoundStatement bs = ps.Bind(); session.Execute(bs); string basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); while (iteration < numebrOfRecords) { if ((fc >= 500) || (rand.Next(0, 2) == 0 && mc < 500)) { record.FirstName = MaleNames.ElementAt(mc).Item1; record.LastName = MaleNames.ElementAt(mc).Item2; record.Gender = GenderType.Male; mc++; } else { record.FirstName = FemaleNames.ElementAt(fc).Item1; record.LastName = FemaleNames.ElementAt(fc).Item2; record.Gender = GenderType.Femal; fc++; } record.DateOfBirth = GetRandomDOB(new DateTime(1950, 1, 1), DateTime.Today); record.Telephone = GetRandomTelNo(); record.Address = GetRandomAddress(); record.Date = DateTime.Now; record.Comments = "This is for future use."; string xray_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_xray" + ".png"); string mri_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_mri" + ".png"); string diagnosis_path = Path.Combine(basePath, @"Resources\" + record.LastName + "_" + record.Telephone + "_diagnosis" + ".pdf"); //Creating xray image DynamicImage(xray_path, record.GetString()); //Creating mri image DynamicImage(mri_path, record.GetString()); //Creating diagnosis pdf file var writer = new PdfWriter(diagnosis_path); var pdf = new PdfDocument(writer); var document = new Document(pdf); for (int k = 0; k < 5; k++) { document.Add(new Paragraph(record.GetString())); } document.Close(); record.XrayImageContent = ReadFile(xray_path); record.MRIImageContent = ReadFile(mri_path); record.DiagnosisPDFContent = ReadFile(diagnosis_path); string queryString = "INSERT INTO Patient_Record(key, firstName, lastName, gender, date_of_birth, phone_no, address, xray_image, xray_image_len, mri_image, mri_image_len, diagnosis_pdf, diagnosis_pdf_len, date, comment)" + " VALUES(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; PreparedStatement preparedStatement = session.Prepare(queryString); BoundStatement boundStatement = preparedStatement.Bind( record.FirstName, record.LastName, (int)record.Gender, record.DateOfBirth.ToShortDateString(), record.Telephone, record.Address, record.XrayImageContent, record.XrayImageContent.Length, record.MRIImageContent, record.MRIImageContent.Length, record.DiagnosisPDFContent, record.DiagnosisPDFContent.Length, DateTime.Now.ToShortDateString(), record.Comments ); session.Execute(boundStatement); //delete creating files after storing in the database File.Delete(xray_path); File.Delete(mri_path); File.Delete(diagnosis_path); iteration++; bar.PerformStep(); } comm.Close(); bar.Visible = false; }
private bool UploadAssignmentsNewSite(DBConnect db_conn, System.Windows.Forms.ToolStripProgressBar pbBar) { int timeout; string query; // for each shift in this schedule foreach (ScheduleSlot slot in this._skeleton.ToList()) { foreach (string employee in slot.Assigned) { // generate insert query query = "INSERT INTO `shift_assignments` (`shift_id`, sched_id, username) " + "VALUES (" + "'" + slot._shiftInfo.ShiftNumber + "', " + "'" + this.ScheduleID + "', " + "'" + employee + "');"; // update progress bar pbBar.PerformStep(); timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } } if (slot.EmployeeWorkingCount < slot.EmployeeNeededCount) { for (int x = 0; x < slot.EmployeeNeededCount - slot.EmployeeWorkingCount; x++) { query = "INSERT INTO `shift_assignments` (`shift_id`, sched_id, username, details) " + "VALUES (" + "'" + slot._shiftInfo.ShiftNumber + "', " + "'" + this.ScheduleID + "', " + "'**AV**', " + "'" + "Available" + x.ToString() + "');"; // update progress bar pbBar.PerformStep(); timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } } } } return(true); }
/// <summary> /// Uploads the main schedule table to the database /// </summary> /// <param name="db_conn">database connection object</param> /// <param name="pbBar">progress bar</param> /// <returns>true if successful, false otherwise</returns> private bool UploadMainTable(DBConnect db_conn, System.Windows.Forms.ToolStripProgressBar pbBar) { string format = "HH:mm:ss"; // create the main table first string query = "CREATE TABLE `s" + this.ScheduleID + "` (" + "`index` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0', " + "`date` DATE NOT NULL DEFAULT '0000-00-00', " + "`day` ENUM('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday') NOT NULL DEFAULT 'Monday', " + "`when` ENUM('mo','no','af','ni') NOT NULL DEFAULT 'mo', " + "`type` VARCHAR(15) NOT NULL DEFAULT '', " + "`start` TIME NOT NULL DEFAULT '00:00:00', " + "`end` TIME NOT NULL DEFAULT '00:00:00', " + "`length` FLOAT UNSIGNED NOT NULL DEFAULT '0', " + "`staffs` VARCHAR(255) NOT NULL DEFAULT '', " + "`wage` FLOAT UNSIGNED NOT NULL DEFAULT '0', " + "PRIMARY KEY (`index`)) " + "COLLATE='latin1_swedish_ci' " + "ENGINE=MyISAM" + ";"; // create it // used to count if timed out int timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } // for each shift in this schedule foreach (ScheduleSlot slot in this._skeleton.ToList()) { // generate insert query query = "INSERT INTO `s" + this.ScheduleID + "` (`index`, date, day, `when`, `type`, `start`, `end`, length, staffs, wage) " + "VALUES (" + "'" + slot._shiftInfo.ShiftNumber + "', " + "'" + slot.Date.ToString("yyyy-MM-dd") + "', " + "'" + new CultureInfo("en-US").TextInfo.ToTitleCase(slot.Day) + "', " + "'" + slot._shiftInfo.When() + "', " + "'" + slot.Name.ToUpper() + "', " + "'" + slot._shiftInfo.StartTime.ToString(format) + "', " + "'" + slot._shiftInfo.EndTime.ToString(format) + "', " + "'" + slot.Length.TotalHours + "', " + "'" + this.PeopleWorkingThis(slot) + "', " + "'0');"; // update progress bar pbBar.PerformStep(); timeout = 0; // keeps trying until command either runs successfully or connection times out while (!db_conn.RunCommand(query)) { timeout++; if (timeout > TIMEOUT) { System.Windows.Forms.MessageBox.Show("Connecting to database timed out while trying to run the following mysql statement: " + query);; return(false); } } } return(true); }