Пример #1
0
		public static Delivery GetRandomDelivery()
		{
			var delivery = new Delivery(DateTime.Now, string.Format("DO{0}", DataHelper.GetNumericString(9)), string.Format("{0} Ubi Avenue {1} Singapore {2}", DataHelper.GetNumber(1, 99), DataHelper.GetNumber(), DataHelper.GetNumber(0, 999)));

			delivery.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));
			delivery.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));

			return delivery;
		}
		public void SaveCompletedDelivery()
		{
			var repo = new DetrackRepository<Delivery>("ab1d456a7296733ce90501565eaf3583058b183cb7c6df80");
			var history = new HistoryRepository();

			const string deliveryId1 = "8897978";

			var delivery1 = new Delivery(new DateTime(2014, 8, 29), deliveryId1);

			var response = repo.GetItems(new List<Delivery> {delivery1});

			foreach (var operationResult in response.Results)
			{
				Assert.IsTrue(history.SaveCompletedDelivery(operationResult.Delivery));
			}
		}
Пример #3
0
		public bool SaveCompletedDelivery(Delivery baseItem)
		{
			try
			{
				using (var connection = database.NewConnection())
				{
					using (IDbCommand command = connection.CreateCommand())
					{
						var update = DataItemExists(baseItem.Do);

						if (update)
							command.CommandText = @"UPDATE [@DEL_HIST_HEADER] 
														SET
															U_date = ?, 
															U_Address = ?, 
															U_Delivery_Time = ?, 
															U_Deliver_To = ?, 
															U_Phone = ?, 
															U_Notify_Email = ?, 
															U_Notify_Url = ?, 
															U_Assign_To = ?, 
															U_Instructions = ?,
															U_Zone = ?,
															U_Reason = ?,
															U_Note = ?,
															U_Received_By = ?,
															U_Image = ?,
															U_View_Image_Url = ?,
															U_Status = ?,
															U_Time = ?,
															U_Pod_Lat = ?,
															U_Pod_Lng = ?,
															U_Pod_Address = ?
														WHERE
															U_do = ?";
						else
							command.CommandText = @"INSERT INTO [@DEL_HIST_HEADER] 
													VALUES ( 
														(SELECT MAX(CODE)+1 FROM [@DEL_HIST_HEADER]), 
														(SELECT MAX(CODE)+1 FROM [@DEL_HIST_HEADER]),
														?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";

						connection.Open();

						if (update)
							database.ExecuteNonQuery(command, baseItem.Date, baseItem.Address, baseItem.Delivery_Time, baseItem.Deliver_To,
													baseItem.Phone, baseItem.Notify_Email, baseItem.Notify_Url, baseItem.Assign_To, baseItem.Instructions,
													baseItem.Zone, baseItem.Reason, baseItem.Note, baseItem.Received_By, baseItem.Image.ToString(), baseItem.View_Image_Url,
													baseItem.Status, baseItem.Time.GetValueOrDefault().ToShortTimeString(), baseItem.Pod_Lat.ToString(),
													baseItem.Pod_Lng.ToString(), baseItem.Pod_Address, int.Parse(baseItem.Do));
						else
							database.ExecuteNonQuery(command, baseItem.Date, int.Parse(baseItem.Do), baseItem.Address, baseItem.Delivery_Time, baseItem.Deliver_To, null, null,
													baseItem.Phone, baseItem.Notify_Email, baseItem.Notify_Url, baseItem.Assign_To, baseItem.Instructions,
													baseItem.Zone, baseItem.Reason, baseItem.Note, baseItem.Received_By, null, baseItem.Image.ToString(), baseItem.View_Image_Url,
													baseItem.Status, baseItem.Time.GetValueOrDefault().ToShortTimeString(), baseItem.Pod_Lat.ToString(),
													baseItem.Pod_Lng.ToString(), baseItem.Pod_Address);

						foreach (var item in baseItem.Items)
						{
							SaveItems(item, baseItem.Do);
						}
					}
				}

				return true;
			}
			catch (Exception ex)
			{
				log.Error(ex, "Error saving completed item {0}", baseItem.Do);
				return false;
			}

		}
		public void AddDelivery()
		{
			var manager = new DetrackRepository<Delivery>();

			var delivery = new Delivery(DateTime.Now, string.Format("DO{0}", DataHelper.GetNumericString(9)), string.Format("{0} Ubi Avenue {1} Singapore {2}", DataHelper.GetNumber(1, 99), DataHelper.GetNumber(), DataHelper.GetNumber(0, 999)));
			var delivery1 = new Delivery(DateTime.Now, string.Format("DO{0}", DataHelper.GetNumericString(9)), string.Format("{0} Ubi Avenue {1} Singapore {2}", DataHelper.GetNumber(1, 99), DataHelper.GetNumber(), DataHelper.GetNumber(0, 999)));

			delivery.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));
			delivery.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));

			delivery1.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));
			delivery1.Items.Add(new Item(DataHelper.GetAlphanumericString(5), DataHelper.GetAlphanumericString(50), DataHelper.GetNumber(1, 50)));

			var response = manager.Add(new List<Delivery>{delivery, delivery1});

			Assert.AreEqual(response.Info.Status, Status.ok.ToString()); 
			Assert.AreEqual(response.Info.Failed, 0);

			var listResponse = manager.GetAllForDate(DateTime.Now);

			Assert.AreEqual(listResponse.Count(), 2);
		}
		public void GetSignatureImageDelivery()
		{
			var repo = new DetrackRepository<Delivery>("ab1d456a7296733ce90501565eaf3583058b183cb7c6df80");
			const string deliveryId = "8897978";

			var delivery = new Delivery(new DateTime(2014, 8, 29), deliveryId);

			Assert.IsNotNull(repo.GetImage(delivery, ImageType.POD_PHOTO_6));
		}
		public void EditDeliveries()
		{
			var deliveryId1 = string.Format("DO{0}", DataHelper.GetNumericString(9));
			var address1 = DataHelper.GetAlphanumericString(50);

			var delivery1 = new Delivery(DateTime.Now, deliveryId1, address1);

			var deliveryId2 = string.Format("DO{0}", DataHelper.GetNumericString(9));
			var address2 = DataHelper.GetAlphanumericString(50);

			var delivery2 = new Delivery(DateTime.Now, deliveryId2, address2);

			var repo = new DetrackRepository<Delivery>();

			repo.Add(new List<Delivery>{delivery1, delivery2});

			delivery1.Address = DataHelper.GetAlphanumericString(50);
			delivery2.Address = DataHelper.GetAlphanumericString(50);

			var response = repo.EditItems(new List<Delivery> { delivery1, delivery2 });

			Assert.AreEqual(response.Info.Status, Status.ok.ToString());
			Assert.AreEqual(response.Info.Failed, 0);

			var results =
				repo.GetItems(new List<Delivery>
				{
					new Delivery(DateTime.Now, deliveryId1),
					new Delivery(DateTime.Now, deliveryId2)
				});

			Assert.AreEqual(results.Info.Status, Status.ok.ToString());
			Assert.AreEqual(results.Info.Failed, 0);

			var d1 = results.Results.Select(d => d.Delivery).FirstOrDefault(d => d.Do == deliveryId1);
			var d2 = results.Results.Select(d => d.Delivery).FirstOrDefault(d => d.Do == deliveryId2);

			Assert.IsTrue(d1 != null && d1.Address != address1);
			Assert.IsTrue(d2 != null && d1.Address != address2);
		}
Пример #7
0
		public Image GetSignatureImage(Delivery delivery)
		{
			try
			{
				Image result;
				byte[] respBytes;
				using (var client = new WebClient())
				{
					var fields = new NameValueCollection
					{
						{"key", Key},
						{"json", string.Format("{{\"date\":\"{0}-{1}-{2}\", \"do\":\"{3}\"}}", delivery.Date.Year, delivery.Date.Month, delivery.Date.Day, delivery.Do)}
					};

					 respBytes = client.UploadValues(GetSignatureImageUrl, fields);
				}
				
				using (var streamBitmap = new MemoryStream(respBytes))
				{
					using (var image = Image.FromStream(streamBitmap))
					{
						result = new Bitmap(image);
					}
				}

				var imagePath = string.Format("{0}_{1}_Signature.jpg", delivery.Date.ToString("yyyy-MM-dd"), delivery.Do);

				ImageHelper.SaveImage(imagePath, result);

				return result;
			}
			catch (Exception ex)
			{
				return null;
			}
		}