public Response CommitIssuesV7(StopWithStoreAndFailure aStop) { //string text = ""; //text = " Online Start time :" + DateTime.Now + "\n"; //WriteToFile(text); Response theResponse = new Response(); int totalFailureErrors = 0, totalImageErrors = 0, totalDeliveryErrors = 0; try { openDataConnection(); theTrans = theConnection.BeginTransaction(); if (aStop.failure != null && aStop.failure.Count > 0) { foreach (Failure aFailure in aStop.failure) { SqlCommand cmdCheckUniqueID = new SqlCommand("SELECT UniqueID FROM Failure WHERE UniqueID = '" + aFailure.uniqueID + "'", theConnection); cmdCheckUniqueID.Transaction = theTrans; object uniqueId = cmdCheckUniqueID.ExecuteScalar(); if (uniqueId != null && !string.IsNullOrEmpty(uniqueId.ToString())) { continue; } ResponseFailure addFailureResponse = AddFailureTransaction(aFailure); if (addFailureResponse.statusCode != 0) { totalFailureErrors++; } if (aFailure.photos != null && aFailure.photos.Count > 0) { foreach (Photo aPhoto in aFailure.photos) { Photo thisPhoto = new Photo(); thisPhoto.imageData = aPhoto.imageData; thisPhoto.stopID = aFailure.stopID; thisPhoto.failureID = addFailureResponse.failure.failureID; Response addPhotoResponse = AddPhotoToStopTransaction(thisPhoto); if (addPhotoResponse.statusCode != 0) { totalImageErrors++; } } } if (aFailure.deliveryCodes != null && aFailure.deliveryCodes.Count > 0) { foreach (Delivery aDelivery in aFailure.deliveryCodes) { Delivery thisDelivery = new Delivery(); thisDelivery.deliveryCode = aDelivery.deliveryCode; thisDelivery.stopID = aStop.id; thisDelivery.failureID = addFailureResponse.failure.failureID; // thisDelivery.dateAdded = aDelivery.dateAdded; Response addDeliveryResponse = AddDeliveryTransaction(thisDelivery); if (addDeliveryResponse.statusCode != 0) { totalDeliveryErrors++; } } } } } Response addStopCompletedDateResponse = AddStopCompletedDate(aStop.id.ToString(), aStop.completedDate); if (totalFailureErrors > 0 || totalImageErrors > 0 || totalDeliveryErrors > 0) { theTrans.Rollback(); theResponse.statusCode = 6; theResponse.statusDescription = "Unable to update data"; } else { theTrans.Commit(); theResponse.statusCode = 0; theResponse.statusDescription = "All data has been synchronized"; ConsolidateEmails(aStop.id.ToString()); } } catch (Exception ex) { //text = "Exception :" + ex.Message + "\n"; //WriteToFile(text); theTrans.Rollback(); theResponse.statusCode = 6; theResponse.statusDescription = "Unable to update data"; } finally { theTrans = null; closeDataConnection(); } //text = " End time :" + DateTime.Now + "\n"; //WriteToFile(text); return theResponse; }
public Response CommitIssues(StopWithStoreAndFailure aStop) { Response theResponse = new Response(); int totalFailureErrors = 0, totalImageErrors = 0; try { openDataConnection(); theTrans = theConnection.BeginTransaction(); if (aStop.failure != null && aStop.failure.Count > 0) { foreach (Failure aFailure in aStop.failure) { SqlCommand cmdCheckUniqueID = new SqlCommand("SELECT UniqueID FROM Failure WHERE UniqueID = '" + aFailure.uniqueID + "'", theConnection); cmdCheckUniqueID.Transaction = theTrans; object uniqueId = cmdCheckUniqueID.ExecuteScalar(); if (uniqueId != null && !string.IsNullOrEmpty(uniqueId.ToString())) { continue; } ResponseFailure addFailureResponse = AddFailureTransaction(aFailure); if (addFailureResponse.statusCode != 0) { totalFailureErrors++; } if (aFailure.photos != null && aFailure.photos.Count > 0) { foreach (Photo aPhoto in aFailure.photos) { Photo thisPhoto = new Photo(); thisPhoto.imageData = aPhoto.imageData; thisPhoto.stopID = aFailure.stopID; thisPhoto.failureID = addFailureResponse.failure.failureID; Response addPhotoResponse = AddPhotoToStopTransaction(thisPhoto); if (addPhotoResponse.statusCode != 0) { totalImageErrors++; } } } } } if (totalFailureErrors > 0 || totalImageErrors > 0) { theTrans.Rollback(); theResponse.statusCode = 6; theResponse.statusDescription = "Unable to update data"; } else { theTrans.Commit(); theResponse.statusCode = 0; theResponse.statusDescription = "All data has been synchronized"; ConsolidateEmails(aStop.id.ToString()); } } catch (Exception ex) { theTrans.Rollback(); theResponse.statusCode = 6; theResponse.statusDescription = "Unable to update data"; } finally { theTrans = null; closeDataConnection(); } return theResponse; }