Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using ConsoleApp1.Models;
- using System.ComponentModel.DataAnnotations;
- using System.Linq;
- using Microsoft.EntityFrameworkCore;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- using (StreamReader r = new StreamReader("data1.json"))
- {
- string json = r.ReadToEnd();
- List<DealItem> items = JsonConvert.DeserializeObject<List<DealItem>>(json);
- List<Deal> deals = new List<Deal>();
- using (DataBaseContext db = new DataBaseContext())
- {
- foreach (DealItem item in items)
- {
- Deal deal = new Deal();
- switch (item.dealStatus)
- {
- case "в работе":
- deal.dealStatus = db.DealStatus.Find(2);
- break;
- default:
- deal.dealStatus = db.DealStatus.Find(4);
- break;
- }
- deal.GUID = Guid.NewGuid().ToString();
- deal.ChildNumber = item.ChildNumber;
- deal.CarStatus = item.CarStatus;
- deal.Season = item.Season;
- deal.DealType = db.DealTypes.Where(d => d.Title == item.DealType).FirstOrDefault();
- if (item.DealDS == "")
- {
- deal.DealDS = DateTime.Now;
- }
- else deal.DealDS = DateTime.Parse(item.DealDS);
- deal.ParentDealID = item.DealIDs;
- deal.Department = db.Departments.Where(d => d.DepartmentTitle == item.Department).FirstOrDefault();
- //deals.Add(deal);
- deal.Season = item.Season;
- deal.DealType = db.DealTypes.Where(d => d.Title == item.DealType).FirstOrDefault();
- deal.SelledId = db.ContrAgents.Where(d => d.ContrAgent_Name == item.SelledId).FirstOrDefault();
- deal.ShipperId = db.ContrAgents.Where(d => d.ContrAgent_Name == item.ShipperId).FirstOrDefault();
- deal.ConsumerId = db.ContrAgents.Where(d => d.ContrAgent_Name == item.ConsumerId).FirstOrDefault();
- deal.BuyerCash = db.Cash.Where(c => c.Title == item.BuyerCash).FirstOrDefault();
- deal.SellerCash = db.Cash.Where(c => c.Title == item.SellerCash).FirstOrDefault();
- deal.ShipperCash = db.Cash.Where(c => c.Title == item.ShipperCash).FirstOrDefault();
- deal.Product = db.Products.Where(p => p.ProductTitle.ToLower() == item.Product).FirstOrDefault();
- deal.Carname = item.Carname;
- deal.Rasstoyanie = item.Rasstoyanie;
- deal.Price = item.Price;
- deal.DonePrice = item.DonePrice;
- deal.ShipPrice = item.ShipPrice;
- deal.BuyPriceWithNDSForOneKG = item.BuyPriceWithNDSForOneKG;
- deal.SellPriceWithNDSForOneKG = item.SellPriceWithNDSForOneKG;
- deal.ShipPriceWithNDSForOneKG = item.ShipPriceWithNDSForOneKG;
- deal.SafePriceForOneKG = item.SafePriceForOneKG;
- deal.SellPriceNDS = item.SellPriceNDS;
- deal.BuyPriceNDS = item.BuyPriceNDS;
- deal.ShipPriceNDS = item.ShipPriceNDS;
- deal.MoneyNDS = item.MoneyNDS;
- deal.DeltaShipping = item.DeltaShipping;
- deal.DeltaProshenaya = item.DeltaProshenaya;
- deal.SummDeltaShipp = item.SummDeltaShipp;
- switch (item.DeltaCompinsation)
- {
- case "на ТК":
- deal.DeltaCompinsation = 0;
- break;
- case "на продавце":
- deal.DeltaCompinsation = 1;
- break;
- default:
- deal.DeltaCompinsation = 2;
- break;
- }
- deal.DeltaPrice = item.DeltaPrice;
- deal.SubmitDelta = item.SubmitDelta;
- switch (item.transoprtScheme)
- {
- case "по отгруженному количеству":
- deal.transoprtScheme = TransoprtScheme.BySellCount;
- break;
- default:
- deal.transoprtScheme = TransoprtScheme.ByShipCount;
- break;
- }
- deal.ShipPriceWithNDS = item.ShipPriceWithNDS;
- deal.ShipSancForNum = item.ShipSancForNum;
- deal.TransportdopRaschod = item.TransportdopRaschod;
- deal.transoprtSummWithNDS = item.transoprtSummWithNDS;
- deal.transoprtShipNDS = item.transoprtShipNDS;
- deal.transoprtShipWithOutNDS = item.transoprtShipWithOutNDS;
- deal.ACTBUNumber = item.ACTBUNumber;
- if (item.ACTBUDate == "")
- {
- deal.ACTBUDate = DateTime.Now;
- }else deal.ACTBUDate =DateTime.Parse(item.ACTBUDate);
- deal.TTNType = item.TTNType;
- deal.transoprtPayWithNDS = item.transoprtPayWithNDS;
- switch (item.buyScheme)
- {
- case "по отгруженному количеству":
- deal.buyScheme = TransoprtScheme.BySellCount;
- break;
- default:
- deal.buyScheme = TransoprtScheme.ByShipCount;
- break;
- }
- deal.buyWithNDS = item.buyWithNDS;
- deal.buySancForLost = item.buySancForLost;
- deal.buyWithCompensation = item.buyWithCompensation;
- deal.withOutNDS = item.withOutNDS;
- deal.buyNDS = item.buyNDS;
- deal.buyActBU = item.buyActBU;
- if (item.buyActDate == "")
- {
- deal.buyActDate = DateTime.Now;
- }
- else deal.buyActDate = DateTime.Parse(item.buyActDate);
- deal.buySummWithNDS = item.buySummWithNDS;
- deal.cSNumber = item.cSNumber;
- deal.cSShipPoint = item.cSShipPoint;
- deal.cSOtgruz = item.cSOtgruz;
- deal.cSOneKGPriceWithoutNDS = item.cSOneKGPriceWithoutNDS;
- deal.cSSumm = item.cSSumm;
- if (item.safeContr == "")
- {
- deal.safeContr = null;
- }
- else deal.safeContr = db.ContrAgents.Where(s => s.ContrAgent_Name == item.safeContr).FirstOrDefault();// DateTime.Parse(item.buyActDate);
- deal.safePriceWithNDS = item.safePriceWithNDS;
- deal.safeNDSSUMM = item.safeNDSSUMM;
- deal.safeSUMMWithOutNDS = item.safeSUMMWithOutNDS;
- deal.safeActBU = item.safeActBU;
- if (item.safeActDate == "")
- {
- deal.safeActDate = DateTime.Now;
- }
- else deal.safeActDate = DateTime.Parse(item.safeActDate);
- deal.raschAgentskije = item.raschAgentskije;
- deal.raschProchee = item.raschProchee;
- deal.raschSummAll = item.raschSummAll;
- deal.prodWithNDS = item.prodWithNDS;
- deal.prodWithOutNDS = item.prodWithOutNDS;
- deal.prodNDSSumm = item.prodNDSSumm;
- deal.prodDogovor = item.prodDogovor;
- deal.prodActBU = item.prodActBU;
- if (item.prodActDate == "")
- {
- deal.prodActDate = DateTime.Now;
- }
- else deal.prodActDate = DateTime.Parse(item.prodActDate);
- deal.prodPayWithNDS = item.prodPayWithNDS;
- deal.nakRaschWithOutNDS = item.nakRaschWithOutNDS;
- deal.bazaRaspredByDepartment = item.bazaRaspredByDepartment;
- deal.nakRaschOfDepartmentWithOutNP = item.nakRaschOfDepartmentWithOutNP;
- deal.bazaRaspredelenijaAllDeals = item.bazaRaspredelenijaAllDeals;
- deal.UKZatraty = item.UKZatraty;
- deal.nakRasch = item.nakRasch;
- deal.nakRaschSUMM = item.nakRaschSUMM;
- deal.marjPribyl = item.marjPribyl;
- deal.marjiNalnost = item.marjiNalnost;
- deal.marjaOneKg = item.marjaOneKg;
- deal.MPMinusNDSNP = item.MPMinusNDSNP;
- deal.marjiNalnostNP = item.marjiNalnostNP;
- deal.marjaOneKgNP = item.marjaOneKgNP;
- deal.prybDoNP = item.prybDoNP;
- deal.nalogNP = item.nalogNP;
- deal.chistPryb = item.chistPryb;
- deal.chistPrybOneKG = item.chistPrybOneKG;
- deal.chistPrybRenta = item.chistPrybRenta;
- deal.poteriPriDostWithOutCompensation = item.poteriPriDostWithOutCompensation;
- deal.poteriPribPriDostWithOutCompensation = item.poteriPribPriDostWithOutCompensation;
- deal.poteriDostavPrijem = item.poteriDostavPrijem;
- deal.poteriPryb = item.poteriPryb;
- deal.chistPrybnedPryb = item.chistPrybnedPryb;
- deal.chistPrybOneKGFinish = item.chistPrybOneKGFinish;
- deal.finishRenta = item.finishRenta;
- deals.Add(deal);
- }
- int itemscount = deals.GroupBy(test => test.ParentDealID)
- .Select(grp => grp.First()).ToList().Count();
- for (int i = 1; i <= 67; i++)
- {
- Deal[] deals1 = deals.Where(d => d.ParentDealID == i).ToArray();
- if (deals1.Length != 0)
- {
- Deal parentDealInfo = new Deal();
- parentDealInfo = Deal.CalculateDealInfo(deals1);
- parentDealInfo.Product = deals1[0].Product;
- parentDealInfo.dealStatus = deals1[0].dealStatus;
- parentDealInfo.DealType = deals1[0].DealType;
- parentDealInfo.Season = deals1[0].Season;
- parentDealInfo.Department = deals1[0].Department;
- parentDealInfo.DealDS = deals1[0].DealDS;
- parentDealInfo.ConsumerId = deals1[0].ConsumerId;
- parentDealInfo.BuyerCash = deals1[0].BuyerCash;
- parentDealInfo.GUID = Guid.NewGuid().ToString();
- db.Add(parentDealInfo);
- db.SaveChanges();
- Console.WriteLine("Доабвлена родительская сделка: {0}", db.Deals.Where(d => d.GUID == parentDealInfo.GUID).FirstOrDefault().GUID);
- deals1 = deals1.OrderBy(d => d.ChildNumber).ToArray();
- foreach(Deal deal in deals)
- {
- Console.WriteLine(deal.DealID);
- if (deal.DealID != 0) {
- deal.DealID = 0;
- db.Add(deal);
- db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Deals OFF");
- db.SaveChanges();
- Console.WriteLine("Добавлена дочерняя сделка ID:{0}. GUID: {1}", db.Deals.Where(d => d.GUID == deal.GUID).FirstOrDefault().DealID, deal.GUID);
- db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Deals OFF");
- }
- else
- {
- db.Add(deal);
- db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Deals OFF");
- db.SaveChanges();
- Console.WriteLine("Добавлена дочерняя сделка ID:{0}. GUID: {1}", db.Deals.Where(d => d.GUID == deal.GUID).FirstOrDefault().DealID, deal.GUID);
- db.Database.ExecuteSqlCommand("SET IDENTITY_INSERT dbo.Deals OFF");
- }
- }
- }
- }
- }
- Console.ReadLine();
- }
- }
- public class DealItem
- {
- public int DealIDs { get; set; }
- public int ChildNumber { get; set; }
- public string dealStatus { get; set; }
- public string CarStatus { get; set; }
- public string Season { get; set; }
- public string DealUID { get; set; }
- public string GUID { get; set; }
- public string DealType { get; set; }
- public string buyDate { get; set; }
- public string sellDate { get; set; }
- public string DealDS { get; set; }
- public string Department { get; set; }
- public string Product { get; set; }
- public string ShipAddress { get; set; }
- public string SelledId { get; set; }
- public string ConsumerId { get; set; }
- public string ShipperId { get; set; }
- public string Shippername { get; set; }
- public string Carname { get; set; }
- public float Rasstoyanie { get; set; }
- public float Price { get; set; }
- public float ShipPrice { get; set; }
- public float DonePrice { get; set; }
- public float BuyPriceWithNDSForOneKG { get; set; }
- public float SellPriceWithNDSForOneKG { get; set; }
- public float ShipPriceWithNDSForOneKG { get; set; }
- public float SafePriceForOneKG { get; set; }
- public float SellPriceNDS { get; set; }
- public float BuyPriceNDS { get; set; }
- public float ShipPriceNDS { get; set; }
- public float SafePriceNDS { get; set; }
- public float MoneyNDS { get; set; }
- public float DeltaShipping { get; set; }
- public float DeltaProshenaya { get; set; }
- public float SummDeltaShipp { get; set; }
- public string DeltaCompinsation { get; set; }
- public float DeltaPrice { get; set; }
- public float SubmitDelta { get; set; }
- public string transoprtScheme { get; set; }
- public float ShipPriceWithNDS { get; set; }
- public float ShipSancForNum { get; set; }
- public float TransportdopRaschod { get; set; }
- public float transoprtSummWithNDS { get; set; }
- public float transoprtShipNDS { get; set; }
- public float transoprtShipWithOutNDS { get; set; }
- public string ACTBUNumber { get; set; }
- public string ACTBUDate { get; set; }
- public string TTNType { get; set; }
- public float transoprtPayWithNDS { get; set; }
- public string buyScheme { get; set; }
- public float buyWithNDS { get; set; }
- public float buySancForLost { get; set; }
- public float buyWithCompensation { get; set; }
- public float withOutNDS { get; set; }
- public float buyNDS
- {
- get; set;
- }
- public string buyActBU { get; set; }
- public string buyActDate { get; set; }
- public float buySummWithNDS { get; set; }
- public string cSNumber { get; set; }
- public string cSShipPoint { get; set; }
- public float cSOtgruz { get; set; }
- public float cSOneKGPriceWithoutNDS { get; set; }
- public float cSSumm { get; set; }
- public string safeContr { get; set; }
- public float safePriceWithNDS { get; set; }
- public float safeNDSSUMM { get; set; }
- public float safeSUMMWithOutNDS { get; set; }
- public string safeActBU { get; set; }
- public string safeActDate { get; set; }
- public float raschAgentskije { get; set; }
- public float raschProchee { get; set; }
- public float raschSummAll
- {
- get; set;
- }
- public float prodWithNDS { get; set; }
- public float prodWithOutNDS { get; set; }
- public float prodNDSSumm { get; set; }
- public string prodDogovor { get; set; }
- public string prodActBU { get; set; }
- public string prodActDate { get; set; }
- public float prodPayWithNDS { get; set; }
- public float nakRaschWithOutNDS { get; set; }
- public float bazaRaspredByDepartment { get; set; }
- public float nakRaschOfDepartmentWithOutNP { get; set; }
- public float bazaRaspredelenijaAllDeals { get; set; }
- public float UKZatraty { get; set; }
- public float nakRasch { get; set; }
- public float nakRaschSUMM { get; set; }
- public float marjPribyl { get; set; }
- public float marjiNalnost { get; set; }
- public float marjaOneKg { get; set; }
- public float MPMinusNDSNP { get; set; }
- public float marjiNalnostNP { get; set; }
- public float marjaOneKgNP { get; set; }
- public float prybDoNP { get; set; }
- public float nalogNP { get; set; }
- public float chistPryb { get; set; }
- public float chistPrybOneKG { get; set; }
- public float chistPrybRenta { get; set; }
- public float poteriPriDostWithOutCompensation { get; set; }
- public float poteriPribPriDostWithOutCompensation { get; set; }
- public float poteriDostavPrijem { get; set; }
- public float poteriPryb { get; set; }
- public float chistPrybnedPryb { get; set; }
- public float chistPrybOneKGFinish { get; set; }
- public float finishRenta { get; set; }
- public string SellerCash { get; set; }
- public string ShipperCash { get; set; }
- public string BuyerCash { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement