예제 #1
0
 PurchaseOrderInfo ConvertOrderToPurchaseOrder(OrderInfo order)
 {
     if (order == null)
     {
         return null;
     }
     StringBuilder builder = new StringBuilder();
     string query = "";
     foreach (LineItemInfo info in order.LineItems.Values)
     {
         builder.AppendFormat("'" + info.SkuId + "',", new object[0]);
     }
     if (builder.Length > 0)
     {
         builder = builder.Remove(builder.Length - 1, 1);
         query = string.Format("SELECT S.SkuId, S.CostPrice, p.ProductName FROM Hishop_Products P JOIN Hishop_SKUs S ON P.ProductId = S.ProductId WHERE S.SkuId IN({0});", builder);
     }
     if (order.Gifts.Count > 0)
     {
         StringBuilder builder2 = new StringBuilder();
         foreach (OrderGiftInfo info2 in order.Gifts)
         {
             builder2.AppendFormat(info2.GiftId.ToString() + ",", new object[0]);
         }
         builder2.Remove(builder2.Length - 1, 1);
         query = query + string.Format(" SELECT GiftId, CostPrice FROM Hishop_Gifts WHERE GiftId IN({0});", builder2.ToString());
     }
     DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
     Dictionary<string, PurchaseOrderItemInfo> dictionary = new Dictionary<string, PurchaseOrderItemInfo>();
     Dictionary<int, decimal> dictionary2 = new Dictionary<int, decimal>();
     using (IDataReader reader = database.ExecuteReader(sqlStringCommand))
     {
         if (order.LineItems.Values.Count > 0)
         {
             while (reader.Read())
             {
                 PurchaseOrderItemInfo info3 = new PurchaseOrderItemInfo();
                 if (reader["CostPrice"] != DBNull.Value)
                 {
                     info3.ItemCostPrice = (decimal)reader["CostPrice"];
                 }
                 info3.ItemHomeSiteDescription = (string)reader["ProductName"];
                 dictionary.Add((string)reader["SkuId"], info3);
             }
         }
         if (order.Gifts.Count > 0)
         {
             if (order.LineItems.Count > 0)
             {
                 reader.NextResult();
             }
             while (reader.Read())
             {
                 dictionary2.Add((int)reader["GiftId"], (DBNull.Value == reader["CostPrice"]) ? 0M : Convert.ToDecimal(reader["CostPrice"]));
             }
         }
     }
     IUser user = Users.GetUser(HiContext.Current.SiteSettings.UserId.Value, false);
     if ((user == null) || (user.UserRole != UserRole.Distributor))
     {
         return null;
     }
     Distributor distributor = user as Distributor;
     PurchaseOrderInfo info4 = new PurchaseOrderInfo();
     info4.PurchaseOrderId = "PO" + order.OrderId;
     info4.OrderId = order.OrderId;
     info4.Remark = order.Remark;
     info4.PurchaseStatus = OrderStatus.WaitBuyerPay;
     info4.DistributorId = distributor.UserId;
     info4.Distributorname = distributor.Username;
     info4.DistributorEmail = distributor.Email;
     info4.DistributorRealName = distributor.RealName;
     info4.DistributorQQ = distributor.QQ;
     info4.DistributorWangwang = distributor.Wangwang;
     info4.DistributorMSN = distributor.MSN;
     info4.ShippingRegion = order.ShippingRegion;
     info4.Address = order.Address;
     info4.ZipCode = order.ZipCode;
     info4.ShipTo = order.ShipTo;
     info4.TelPhone = order.TelPhone;
     info4.CellPhone = order.CellPhone;
     info4.ShippingModeId = order.ShippingModeId;
     info4.ModeName = order.ModeName;
     info4.RegionId = order.RegionId;
     info4.Freight = order.Freight;
     info4.AdjustedFreight = order.Freight;
     info4.ShipOrderNumber = order.ShipOrderNumber;
     info4.Weight = order.Weight;
     info4.RefundStatus = RefundStatus.None;
     info4.OrderTotal = order.GetTotal();
     info4.ExpressCompanyName = order.ExpressCompanyName;
     info4.ExpressCompanyAbb = order.ExpressCompanyAbb;
     foreach (LineItemInfo info5 in order.LineItems.Values)
     {
         PurchaseOrderItemInfo item = new PurchaseOrderItemInfo();
         item.PurchaseOrderId = info4.PurchaseOrderId;
         item.SkuId = info5.SkuId;
         item.ProductId = info5.ProductId;
         item.SKU = info5.SKU;
         item.Quantity = info5.ShipmentQuantity;
         foreach (KeyValuePair<string, PurchaseOrderItemInfo> pair in dictionary)
         {
             if (pair.Key == info5.SkuId)
             {
                 item.ItemCostPrice = pair.Value.ItemCostPrice;
                 item.ItemHomeSiteDescription = pair.Value.ItemHomeSiteDescription;
             }
         }
         item.ItemPurchasePrice = info5.ItemCostPrice;
         item.ItemListPrice = info5.ItemListPrice;
         item.ItemDescription = info5.ItemDescription;
         item.SKUContent = info5.SKUContent;
         item.ThumbnailsUrl = info5.ThumbnailsUrl;
         item.ItemWeight = info5.ItemWeight;
         if (string.IsNullOrEmpty(item.ItemHomeSiteDescription))
         {
             item.ItemHomeSiteDescription = item.ItemDescription;
         }
         info4.PurchaseOrderItems.Add(item);
     }
     foreach (OrderGiftInfo info7 in order.Gifts)
     {
         PurchaseOrderGiftInfo info8 = new PurchaseOrderGiftInfo();
         info8.PurchaseOrderId = info4.PurchaseOrderId;
         foreach (KeyValuePair<int, decimal> pair2 in dictionary2)
         {
             if (pair2.Key == info7.GiftId)
             {
                 info8.CostPrice = pair2.Value;
             }
         }
         info8.PurchasePrice = info7.CostPrice;
         info8.GiftId = info7.GiftId;
         info8.GiftName = info7.GiftName;
         info8.Quantity = info7.Quantity;
         info8.ThumbnailsUrl = info7.ThumbnailsUrl;
         info4.PurchaseOrderGifts.Add(info8);
     }
     foreach (OrderOptionInfo info9 in order.OrderOptions)
     {
         PurchaseOrderOptionInfo info10 = new PurchaseOrderOptionInfo();
         info10.PurchaseOrderId = info4.PurchaseOrderId;
         info10.LookupListId = info9.LookupListId;
         info10.LookupItemId = info9.LookupItemId;
         info10.ListDescription = info9.ListDescription;
         info10.ItemDescription = info9.ItemDescription;
         info10.AdjustedPrice = info9.AdjustedPrice;
         info10.CustomerTitle = info9.CustomerTitle;
         info10.CustomerDescription = info9.CustomerDescription;
         info4.PurchaseOrderOptions.Add(info10);
     }
     return info4;
 }
예제 #2
0
파일: DataMapper.cs 프로젝트: davinx/himedi
 public static PurchaseOrderOptionInfo PopulatePurchaseOrderOption(IDataReader reader)
 {
     if (reader == null)
     {
         return null;
     }
     PurchaseOrderOptionInfo info = new PurchaseOrderOptionInfo();
     info.PurchaseOrderId = (string) reader["PurchaseOrderId"];
     info.LookupListId = (int) reader["LookupListId"];
     info.LookupItemId = (int) reader["LookupItemId"];
     info.ListDescription = (string) reader["ListDescription"];
     info.ItemDescription = (string) reader["ItemDescription"];
     info.AdjustedPrice = (decimal) reader["AdjustedPrice"];
     if (reader["CustomerTitle"] != DBNull.Value)
     {
         info.CustomerTitle = (string) reader["CustomerTitle"];
     }
     if (reader["CustomerDescription"] != DBNull.Value)
     {
         info.CustomerDescription = (string) reader["CustomerDescription"];
     }
     return info;
 }