public FactProductionTreeImporter()
        {
            dataContext   = new DataClasses1DataContext();
            dataContextS1 = new s1_DataClasses1DataContext();

            deleteAllProductionTree();
        }
 public DocSalesImporter()
 {
     dataContext   = new DataClasses1DataContext();
     dataContextS1 = new s1_DataClasses1DataContext();
 }
 public FactPricesImporter()
 {
     dataContext   = new DataClasses1DataContext();
     dataContextS1 = new s1_DataClasses1DataContext();
 }
Example #4
0
        Int64 unitIDGramm = 18; // ID for unit Gramm

        public FactManufactureDocs()
        {
            dataContext   = new DataClasses1DataContext();
            dataContextS1 = new s1_DataClasses1DataContext();
        }
        } // public void impFactMovementsDel()

        public void fromHistoryToRemains()
        {
            DateTime toDateCount = new DateTime(2016, 06, 01);


            //--------> DELETE ALL REMAINS
            deleteAllRemains();

            dataContext   = new DataClasses1DataContext();
            dataContextS1 = new s1_DataClasses1DataContext();

            DateTime now    = DateTime.Now;
            DateTime onDate = DateTime.Today; // Remains on current date

            Dictionary <Int64, string> edIzmer   = new Dictionary <Int64, string>();
            Dictionary <Int64, Int64?> edIzmerId = new Dictionary <Int64, Int64?>();
            long edIzmerGram = new long();

            Dictionary <Int64, decimal> nominalWghts = new Dictionary <Int64, decimal>();

            // ed izm
            var edIzms = from e in dataContext.DimGoods
                         select e;

            foreach (DimGoods ed in edIzms)
            {
                edIzmerId.Add(ed.ID, ed.BaseUnitID);
                edIzmer.Add(ed.ID, ed.BaseUnit);
            }
            edIzmerGram = (from e in dataContext.DimUnits
                           where e.TypeName == "г" &&
                           e.Active == true
                           select e.ID).First();
            // ed izm

            // NominalWeights
            var nomWts = from n in dataContext.DimGoods
                         where n.WeightGrammNominal != null
                         select n;

            foreach (DimGoods nw in nomWts)
            {
                nominalWghts.Add(nw.ID, nw.WeightGrammNominal.Value);
            }
            // NominalWeights

            // Delete on date
            deleteRemainsOnDate(onDate); // Fast delete from DB
            //var onDateRemains = from r in dataContext.FactRemains
            //                    where r.RemainsDate == onDate
            //                    select r;
            //dataContext.FactRemains.DeleteAllOnSubmit(onDateRemains);
            //dataContext.SubmitChanges();
            // Delete on date

            var dimDates = (from d in dataContext.DimDates
                            where d.Date == onDate
                            select d).FirstOrDefault();

            if (dimDates == null)
            {
                throw new Exception();
            }


            var remHistIn = from f in dataContext.FactMovements
                            where f.RecordKind == 0 &&
                            f.Active == true
                            //&& f.Date <= toDateCount
                            group f by new
            {
                f.WarehouseID,
                f.GoodID,
                f.ConsignNumber,
                f.Date
            }
            into g
                select new
            {
                WarehouseID   = g.Key.WarehouseID,
                GoodID        = g.Key.GoodID,
                Date          = g.Key.Date,
                ConsignNumber = g.Key.ConsignNumber,
                OnStockQty    = g.Sum(t => t.OnStockQty),
                InOrdersQty   = g.Sum(t => t.InOrdersQty)
            };
            var remHistOut = from f in dataContext.FactMovements
                             where f.RecordKind == 1 &&
                             f.Active == true
                             //&& f.Date <= toDateCount
                             group f by new
            {
                f.WarehouseID,
                f.GoodID,
                f.ConsignNumber,
                f.Date
            }
            into g
                select new
            {
                WarehouseID   = g.Key.WarehouseID,
                GoodID        = g.Key.GoodID,
                Date          = g.Key.Date,
                ConsignNumber = g.Key.ConsignNumber,
                OnStockQty    = g.Sum(t => t.OnStockQty) * (-1),
                InOrdersQty   = g.Sum(t => t.InOrdersQty) * (-1)
            };
            var remHistT = (from r in remHistIn
                            where r.OnStockQty != 0
                            select r).Concat(from r in remHistOut
                                             where r.OnStockQty != 0
                                             select r);
            var remHist = from r in remHistT
                          where r.OnStockQty != 0
                          group r by new
            {
                r.WarehouseID,
                r.GoodID,
                r.ConsignNumber
            }
            into g
                select new
            {
                WarehouseID   = g.Key.WarehouseID,
                GoodID        = g.Key.GoodID,
                ConsignNumber = g.Key.ConsignNumber,
                OnStockQty    = g.Sum(t => t.OnStockQty),
                InOrdersQty   = g.Sum(t => t.InOrdersQty)
            };

            int i = 0;

            foreach (var rh in remHist)
            {
                FactRemains rm = new FactRemains();
                rm.WarehouseID   = rh.WarehouseID;
                rm.DepartmentID  = null;
                rm.GoodID        = rh.GoodID;
                rm.ConsignNumber = rh.ConsignNumber;
                rm.RemainsDate   = onDate;
                rm.DateKey       = dimDates.DateKey;
                rm.OnStockQty    = rh.OnStockQty;
                rm.InOrdersQty   = rh.InOrdersQty;

                // Unit
                var edIzmB = (from r in edIzmer
                              where r.Key == rh.GoodID
                              select r).FirstOrDefault();
                var edIzmBId = (from r in edIzmerId
                                where r.Key == rh.GoodID
                                select r).FirstOrDefault();

                if (edIzmB.Value != null)
                {
                    rm.BaseUnitID = edIzmBId.Value; // don't move down!

                    switch (edIzmB.Value)
                    {
                    case "шт":
                        rm.QtyGram = 0;
                        rm.QtyPcs  = rh.OnStockQty;
                        break;

                    case "г":
                        rm.QtyPcs  = 0;
                        rm.QtyGram = rh.OnStockQty;
                        {
                            decimal n;
                            if (nominalWghts.TryGetValue(rm.GoodID.Value, out n) == true)
                            {
                                if (n != 0)
                                {
                                    rm.QtyPcs = rm.QtyGram / n;
                                }
                            }
                        }
                        break;

                    case "кг":
                        rm.QtyPcs     = 0;
                        rm.QtyGram    = rh.OnStockQty * (1000);
                        rm.BaseUnitID = edIzmerGram;     // repair from kg to g
                        {
                            decimal n;
                            if (nominalWghts.TryGetValue(rm.GoodID.Value, out n) == true)
                            {
                                if (n != 0)
                                {
                                    rm.QtyPcs = rm.QtyGram / n;
                                }
                            }
                        }
                        break;

                    default:
                        rm.QtyPcs  = rh.OnStockQty;
                        rm.QtyGram = 0;
                        break;
                    }
                }
                // Unit

                rm.Active = true;

                dataContext.FactRemains.InsertOnSubmit(rm);

                if (i % 250 == 0)
                {
                    dataContext.SubmitChanges();
                }
                i++;
            }
            dataContext.SubmitChanges();
        } // public void fromHistoryToRemains()
        Int64 unitIDGramm = 18; // ID for unit Gramm

        public DocProductionImporter()
        {
            dataContext   = new DataClasses1DataContext();
            dataContextS1 = new s1_DataClasses1DataContext();
        }
Example #7
0
 public FactPOSClass()
 {
     dataContext   = new DataClasses1DataContext();
     dataContextS1 = new s1_DataClasses1DataContext();
 }
        Int64 unitIDGramm = 18; // ID for unit Gramm

        public FactManufactureImporter()
        {
            dataContext   = new DataClasses1DataContext();
            dataContextS1 = new s1_DataClasses1DataContext();
        }